#include "chrome/browser/ui/intent_picker_tab_helper.h"
#include "base/memory/raw_ptr.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/scoped_feature_list.h"
#include "chrome/browser/apps/intent_helper/intent_chip_display_prefs.h"
#include "chrome/browser/apps/link_capturing/intent_picker_info.h"
#include "chrome/browser/apps/link_capturing/link_capturing_feature_test_support.h"
#include "chrome/test/base/chrome_render_view_host_test_harness.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/base/models/image_model.h"
#if BUILDFLAG(IS_CHROMEOS)
#include "chrome/browser/apps/link_capturing/metrics/intent_handling_metrics.h"
#endif
class IntentPickerTabHelperTest : public ChromeRenderViewHostTestHarness { … };
class IntentPickerTabHelperPlatformAgnosticTest
: public IntentPickerTabHelperTest { … };
TEST_F(IntentPickerTabHelperPlatformAgnosticTest, ShowOrHideIcon) { … }
TEST_F(IntentPickerTabHelperPlatformAgnosticTest, ShowIconForApps) { … }
TEST_F(IntentPickerTabHelperPlatformAgnosticTest,
ShowIconForApps_ExpandedChip) { … }
TEST_F(IntentPickerTabHelperPlatformAgnosticTest,
ShowIconForApps_CollapsedChip) { … }
TEST_F(IntentPickerTabHelperPlatformAgnosticTest,
ShowIntentIcon_ResetsExpandedState) { … }
#if BUILDFLAG(IS_CHROMEOS)
TEST_F(IntentPickerTabHelperTest, LinkCapturing_EntryPointShown) {
base::HistogramTester histogram_tester;
NavigateAndCommit(GURL("https://www.google.com"));
helper()->MaybeShowIconForApps({});
histogram_tester.ExpectBucketCount("ChromeOS.Intents.IntentPickerIconEvent",
apps::IntentPickerIconEvent::kIconShown,
0);
histogram_tester.ExpectBucketCount(
"ChromeOS.Intents.LinkCapturingEvent2.WebApp",
apps::IntentHandlingMetrics::LinkCapturingEvent::kEntryPointShown, 0);
histogram_tester.ExpectBucketCount(
"ChromeOS.Intents.LinkCapturingEvent2.ArcApp",
apps::IntentHandlingMetrics::LinkCapturingEvent::kEntryPointShown, 0);
histogram_tester.ExpectBucketCount(
"ChromeOS.Intents.LinkCapturingEvent2",
apps::IntentHandlingMetrics::LinkCapturingEvent::kEntryPointShown, 0);
{
std::vector<apps::IntentPickerAppInfo> apps_list;
apps_list = {
{apps::PickerEntryType::kWeb, ui::ImageModel(), "app_id", "Test app"},
{apps::PickerEntryType::kArc, ui::ImageModel(), "app_id", "Test app"}};
helper()->MaybeShowIconForApps(std::move(apps_list));
}
histogram_tester.ExpectBucketCount("ChromeOS.Intents.IntentPickerIconEvent",
apps::IntentPickerIconEvent::kIconShown,
1);
histogram_tester.ExpectBucketCount(
"ChromeOS.Intents.LinkCapturingEvent2.WebApp",
apps::IntentHandlingMetrics::LinkCapturingEvent::kEntryPointShown, 1);
histogram_tester.ExpectBucketCount(
"ChromeOS.Intents.LinkCapturingEvent2.ArcApp",
apps::IntentHandlingMetrics::LinkCapturingEvent::kEntryPointShown, 1);
histogram_tester.ExpectBucketCount(
"ChromeOS.Intents.LinkCapturingEvent2",
apps::IntentHandlingMetrics::LinkCapturingEvent::kEntryPointShown, 1);
helper()->MaybeShowIconForApps({});
{
std::vector<apps::IntentPickerAppInfo> apps_list;
apps_list = {
{apps::PickerEntryType::kWeb, ui::ImageModel(), "app_id", "Test app"}};
helper()->MaybeShowIconForApps(std::move(apps_list));
}
histogram_tester.ExpectBucketCount("ChromeOS.Intents.IntentPickerIconEvent",
apps::IntentPickerIconEvent::kIconShown,
2);
histogram_tester.ExpectBucketCount(
"ChromeOS.Intents.LinkCapturingEvent2.WebApp",
apps::IntentHandlingMetrics::LinkCapturingEvent::kEntryPointShown, 2);
histogram_tester.ExpectBucketCount(
"ChromeOS.Intents.LinkCapturingEvent2.ArcApp",
apps::IntentHandlingMetrics::LinkCapturingEvent::kEntryPointShown, 1);
histogram_tester.ExpectBucketCount(
"ChromeOS.Intents.LinkCapturingEvent2",
apps::IntentHandlingMetrics::LinkCapturingEvent::kEntryPointShown, 2);
helper()->MaybeShowIconForApps({});
{
std::vector<apps::IntentPickerAppInfo> apps_list;
apps_list = {
{apps::PickerEntryType::kArc, ui::ImageModel(), "app_id", "Test app"}};
helper()->MaybeShowIconForApps(std::move(apps_list));
}
histogram_tester.ExpectBucketCount("ChromeOS.Intents.IntentPickerIconEvent",
apps::IntentPickerIconEvent::kIconShown,
3);
histogram_tester.ExpectBucketCount(
"ChromeOS.Intents.LinkCapturingEvent2.WebApp",
apps::IntentHandlingMetrics::LinkCapturingEvent::kEntryPointShown, 2);
histogram_tester.ExpectBucketCount(
"ChromeOS.Intents.LinkCapturingEvent2.ArcApp",
apps::IntentHandlingMetrics::LinkCapturingEvent::kEntryPointShown, 2);
histogram_tester.ExpectBucketCount(
"ChromeOS.Intents.LinkCapturingEvent2",
apps::IntentHandlingMetrics::LinkCapturingEvent::kEntryPointShown, 3);
helper()->MaybeShowIconForApps({});
{
std::vector<apps::IntentPickerAppInfo> apps_list;
apps_list = {{apps::PickerEntryType::kMacOs, ui::ImageModel(), "app_id",
"Test app"}};
helper()->MaybeShowIconForApps(std::move(apps_list));
}
histogram_tester.ExpectBucketCount("ChromeOS.Intents.IntentPickerIconEvent",
apps::IntentPickerIconEvent::kIconShown,
4);
histogram_tester.ExpectBucketCount(
"ChromeOS.Intents.LinkCapturingEvent2.WebApp",
apps::IntentHandlingMetrics::LinkCapturingEvent::kEntryPointShown, 2);
histogram_tester.ExpectBucketCount(
"ChromeOS.Intents.LinkCapturingEvent2.ArcApp",
apps::IntentHandlingMetrics::LinkCapturingEvent::kEntryPointShown, 2);
histogram_tester.ExpectBucketCount(
"ChromeOS.Intents.LinkCapturingEvent2",
apps::IntentHandlingMetrics::LinkCapturingEvent::kEntryPointShown, 4);
}
#else
TEST_F(IntentPickerTabHelperTest, IconShownMetricsTriggered) { … }
#endif