123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927 |
- // Copyright 2019 The Chromium Authors. All rights reserved.
- // Use of this source code is governed by a BSD-style license that can be
- // found in the LICENSE file.
- #include <memory>
- #include <string>
- #include <utility>
- #include <vector>
- #include "ash/accessibility/accessibility_controller_impl.h"
- #include "ash/app_list/app_list_bubble_presenter.h"
- #include "ash/app_list/app_list_controller_impl.h"
- #include "ash/app_list/app_list_metrics.h"
- #include "ash/app_list/app_list_model_provider.h"
- #include "ash/app_list/app_list_presenter_impl.h"
- #include "ash/app_list/model/app_list_test_model.h"
- #include "ash/app_list/model/search/search_model.h"
- #include "ash/app_list/test/app_list_test_helper.h"
- #include "ash/app_list/views/app_list_item_view.h"
- #include "ash/app_list/views/app_list_main_view.h"
- #include "ash/app_list/views/app_list_view.h"
- #include "ash/app_list/views/apps_container_view.h"
- #include "ash/app_list/views/contents_view.h"
- #include "ash/app_list/views/paged_apps_grid_view.h"
- #include "ash/app_list/views/privacy_container_view.h"
- #include "ash/app_list/views/recent_apps_view.h"
- #include "ash/app_list/views/search_result_container_view.h"
- #include "ash/app_list/views/search_result_page_view.h"
- #include "ash/app_list/views/search_result_tile_item_list_view.h"
- #include "ash/app_list/views/search_result_tile_item_view.h"
- #include "ash/app_list/views/suggestion_chip_container_view.h"
- #include "ash/constants/ash_features.h"
- #include "ash/public/cpp/app_list/app_list_types.h"
- #include "ash/public/cpp/shelf_item_delegate.h"
- #include "ash/public/cpp/shelf_model.h"
- #include "ash/shelf/home_button.h"
- #include "ash/shelf/shelf.h"
- #include "ash/shelf/shelf_navigation_widget.h"
- #include "ash/shelf/shelf_view.h"
- #include "ash/shelf/shelf_view_test_api.h"
- #include "ash/shelf/shelf_widget.h"
- #include "ash/shell.h"
- #include "ash/test/ash_test_base.h"
- #include "ash/wm/tablet_mode/tablet_mode_controller.h"
- #include "base/test/metrics/histogram_tester.h"
- #include "base/test/scoped_feature_list.h"
- #include "ui/display/screen.h"
- namespace ash {
- namespace {
- constexpr int kBrowserAppIndexOnShelf = 0;
- // A test shelf item delegate that simulates an activated window when a shelf
- // item is selected.
- class TestShelfItemDelegate : public ShelfItemDelegate {
- public:
- explicit TestShelfItemDelegate(const ShelfID& shelf_id)
- : ShelfItemDelegate(shelf_id) {}
- void ItemSelected(std::unique_ptr<ui::Event> event,
- int64_t display_id,
- ash::ShelfLaunchSource source,
- ItemSelectedCallback callback,
- const ItemFilterPredicate& filter_predicate) override {
- std::move(callback).Run(SHELF_ACTION_WINDOW_ACTIVATED, {});
- }
- void ExecuteCommand(bool from_context_menu,
- int64_t command_id,
- int32_t event_flags,
- int64_t display_id) override {}
- void Close() override {}
- };
- } // namespace
- int64_t GetPrimaryDisplayId() {
- return display::Screen::GetScreen()->GetPrimaryDisplay().id();
- }
- // Used to test that app launched metrics are properly recorded.
- class AppListMetricsTest : public AshTestBase {
- public:
- AppListMetricsTest() = default;
- AppListMetricsTest(const AppListMetricsTest&) = delete;
- AppListMetricsTest& operator=(const AppListMetricsTest&) = delete;
- ~AppListMetricsTest() override = default;
- void SetUp() override {
- AshTestBase::SetUp();
- search_model_ = AppListModelProvider::Get()->search_model();
- shelf_test_api_ = std::make_unique<ShelfViewTestAPI>(
- GetPrimaryShelf()->GetShelfViewForTesting());
- }
- protected:
- void CreateAndClickShelfItem() {
- // Add shelf item to be launched. Waits for the shelf view's bounds
- // animations to end.
- ShelfItem shelf_item;
- shelf_item.id = ShelfID("app_id");
- shelf_item.type = TYPE_BROWSER_SHORTCUT;
- ShelfModel::Get()->Add(
- shelf_item, std::make_unique<TestShelfItemDelegate>(shelf_item.id));
- shelf_test_api_->RunMessageLoopUntilAnimationsDone();
- ClickShelfItem();
- }
- void ClickShelfItem() {
- // Get location of the shelf item.
- const views::ViewModel* view_model =
- GetPrimaryShelf()->GetShelfViewForTesting()->view_model_for_test();
- LeftClickOn(view_model->view_at(kBrowserAppIndexOnShelf));
- }
- void PopulateAndLaunchSearchBoxTileItem() {
- // Populate 4 tile items.
- for (size_t i = 0; i < 4; i++) {
- auto search_result = std::make_unique<SearchResult>();
- search_result->set_display_type(SearchResultDisplayType::kTile);
- search_model_->results()->Add(std::move(search_result));
- }
- GetAppListTestHelper()->WaitUntilIdle();
- // Mark the privacy notices as dismissed so that the tile items will be the
- // first search container.
- ContentsView* contents_view = Shell::Get()
- ->app_list_controller()
- ->fullscreen_presenter()
- ->GetView()
- ->app_list_main_view()
- ->contents_view();
- Shell::Get()->app_list_controller()->MarkSuggestedContentInfoDismissed();
- contents_view->search_result_page_view()
- ->GetPrivacyContainerViewForTest()
- ->Update();
- SearchResultContainerView* search_result_container_view =
- contents_view->search_result_page_view()
- ->GetSearchResultTileItemListViewForTest();
- // Request focus on the first tile item view.
- search_result_container_view->GetFirstResultView()->RequestFocus();
- // Press return to simulate an app launch from the tile item.
- PressAndReleaseKey(ui::KeyboardCode::VKEY_RETURN);
- }
- void PopulateAndLaunchSuggestionChip() {
- // Populate 4 suggestion chips.
- for (size_t i = 0; i < 4; i++) {
- auto search_result_chip = std::make_unique<SearchResult>();
- search_result_chip->set_display_type(SearchResultDisplayType::kChip);
- search_result_chip->set_is_recommendation(true);
- search_model_->results()->Add(std::move(search_result_chip));
- }
- GetAppListTestHelper()->WaitUntilIdle();
- SearchResultContainerView* suggestions_container_ =
- Shell::Get()
- ->app_list_controller()
- ->fullscreen_presenter()
- ->GetView()
- ->app_list_main_view()
- ->contents_view()
- ->apps_container_view()
- ->suggestion_chip_container_view_for_test();
- // Get focus on the first chip.
- suggestions_container_->children().front()->RequestFocus();
- GetAppListTestHelper()->WaitUntilIdle();
- // Press return to simulate an app launch from the suggestion chip.
- PressAndReleaseKey(ui::KeyboardCode::VKEY_RETURN);
- }
- void PopulateAndLaunchAppInGrid() {
- // Populate apps in the root app grid.
- AppListModel* model = AppListModelProvider::Get()->model();
- model->AddItem(std::make_unique<AppListItem>("item 0"));
- model->AddItem(std::make_unique<AppListItem>("item 1"));
- model->AddItem(std::make_unique<AppListItem>("item 2"));
- model->AddItem(std::make_unique<AppListItem>("item 3"));
- AppListView::TestApi test_api(
- Shell::Get()->app_list_controller()->fullscreen_presenter()->GetView());
- // Focus the first item in the root app grid.
- test_api.GetRootAppsGridView()->GetItemViewAt(0)->RequestFocus();
- // Press return to simulate an app launch from a grid item.
- PressAndReleaseKey(ui::KeyboardCode::VKEY_RETURN);
- }
- private:
- SearchModel* search_model_ = nullptr;
- std::unique_ptr<ShelfViewTestAPI> shelf_test_api_;
- };
- // Suite for tests that only apply to peeking launcher (and can be deleted when
- // ProductivityLauncher is the default).
- class AppListMetricsPeekingLauncherTest : public AppListMetricsTest {
- public:
- AppListMetricsPeekingLauncherTest() {
- scoped_feature_list_.InitAndDisableFeature(features::kProductivityLauncher);
- }
- ~AppListMetricsPeekingLauncherTest() override = default;
- base::test::ScopedFeatureList scoped_feature_list_;
- };
- // Test that the histogram records an app launch from the shelf while the half
- // launcher is showing.
- TEST_F(AppListMetricsPeekingLauncherTest, HalfLaunchFromShelf) {
- base::HistogramTester histogram_tester;
- GetAppListTestHelper()->ShowAndRunLoop(GetPrimaryDisplayId());
- GetAppListTestHelper()->CheckState(AppListViewState::kPeeking);
- // Press a letter key, the AppListView should transition to kHalf.
- PressAndReleaseKey(ui::KeyboardCode::VKEY_H);
- GetAppListTestHelper()->CheckState(AppListViewState::kHalf);
- CreateAndClickShelfItem();
- GetAppListTestHelper()->WaitUntilIdle();
- histogram_tester.ExpectBucketCount(
- "Apps.AppListAppLaunchedV2.Half", AppListLaunchedFrom::kLaunchedFromShelf,
- 1 /* Number of times launched from shelf */);
- }
- // Test that the histogram records an app launch from the search box while the
- // half launcher is showing.
- TEST_F(AppListMetricsPeekingLauncherTest, HalfLaunchFromSearchBox) {
- base::HistogramTester histogram_tester;
- GetAppListTestHelper()->ShowAndRunLoop(GetPrimaryDisplayId());
- GetAppListTestHelper()->CheckState(AppListViewState::kPeeking);
- // Press a letter key, the AppListView should transition to kHalf.
- PressAndReleaseKey(ui::KeyboardCode::VKEY_H);
- GetAppListTestHelper()->CheckState(AppListViewState::kHalf);
- PopulateAndLaunchSearchBoxTileItem();
- histogram_tester.ExpectBucketCount(
- "Apps.AppListAppLaunchedV2.Half",
- AppListLaunchedFrom::kLaunchedFromSearchBox,
- 1 /* Number of times launched from search box */);
- }
- // Test that the histogram records an app launch from the search box while the
- // fullscreen search launcher is showing.
- TEST_F(AppListMetricsPeekingLauncherTest, FullscreenSearchLaunchFromSearchBox) {
- base::HistogramTester histogram_tester;
- // Press search + shift to transition to kFullscreenAllApps.
- PressAndReleaseKey(ui::KeyboardCode::VKEY_BROWSER_SEARCH, ui::EF_SHIFT_DOWN);
- GetAppListTestHelper()->CheckState(AppListViewState::kFullscreenAllApps);
- // Press a letter key, the AppListView should transition to kFullscreenSearch.
- PressAndReleaseKey(ui::KeyboardCode::VKEY_H);
- GetAppListTestHelper()->CheckState(AppListViewState::kFullscreenSearch);
- PopulateAndLaunchSearchBoxTileItem();
- GetAppListTestHelper()->WaitUntilIdle();
- histogram_tester.ExpectBucketCount(
- "Apps.AppListAppLaunchedV2.FullscreenSearch",
- AppListLaunchedFrom::kLaunchedFromSearchBox,
- 1 /* Number of times launched from search box */);
- }
- // Test that the histogram records an app launch from the shelf while the
- // fullscreen search launcher is showing.
- TEST_F(AppListMetricsPeekingLauncherTest, FullscreenSearchLaunchFromShelf) {
- base::HistogramTester histogram_tester;
- // Press search + shift to transition to kFullscreenAllApps.
- PressAndReleaseKey(ui::KeyboardCode::VKEY_BROWSER_SEARCH, ui::EF_SHIFT_DOWN);
- GetAppListTestHelper()->CheckState(AppListViewState::kFullscreenAllApps);
- // Press a letter key, the AppListView should transition to kFullscreenSearch.
- PressAndReleaseKey(ui::KeyboardCode::VKEY_H);
- GetAppListTestHelper()->CheckState(AppListViewState::kFullscreenSearch);
- CreateAndClickShelfItem();
- histogram_tester.ExpectBucketCount(
- "Apps.AppListAppLaunchedV2.FullscreenSearch",
- AppListLaunchedFrom::kLaunchedFromShelf,
- 1 /* Number of times launched from shelf */);
- }
- // Test that the histogram records an app launch from a suggestion chip while
- // the fullscreen all apps launcher is showing.
- TEST_F(AppListMetricsPeekingLauncherTest, FullscreenAllAppsLaunchFromChip) {
- base::HistogramTester histogram_tester;
- // Press search + shift to transition to kFullscreenAllApps.
- PressAndReleaseKey(ui::KeyboardCode::VKEY_BROWSER_SEARCH, ui::EF_SHIFT_DOWN);
- GetAppListTestHelper()->CheckState(AppListViewState::kFullscreenAllApps);
- PopulateAndLaunchSuggestionChip();
- histogram_tester.ExpectBucketCount(
- "Apps.AppListAppLaunchedV2.FullscreenAllApps",
- AppListLaunchedFrom::kLaunchedFromSuggestionChip,
- 1 /* Number of times launched from chip */);
- }
- // Test that the histogram records an app launch from the app grid while the
- // fullscreen all apps launcher is showing.
- TEST_F(AppListMetricsPeekingLauncherTest, FullscreenAllAppsLaunchFromGrid) {
- base::HistogramTester histogram_tester;
- // Press search + shift to transition to kFullscreenAllApps.
- PressAndReleaseKey(ui::KeyboardCode::VKEY_BROWSER_SEARCH, ui::EF_SHIFT_DOWN);
- GetAppListTestHelper()->CheckState(AppListViewState::kFullscreenAllApps);
- PopulateAndLaunchAppInGrid();
- histogram_tester.ExpectBucketCount(
- "Apps.AppListAppLaunchedV2.FullscreenAllApps",
- AppListLaunchedFrom::kLaunchedFromGrid,
- 1 /* Number of times launched from grid */);
- }
- // Test that the histogram records an app launch from the shelf while the
- // fullscreen all apps launcher is showing.
- TEST_F(AppListMetricsPeekingLauncherTest, FullscreenAllAppsLaunchFromShelf) {
- base::HistogramTester histogram_tester;
- // Press search + shift to transition to kFullscreenAllApps.
- PressAndReleaseKey(ui::KeyboardCode::VKEY_BROWSER_SEARCH, ui::EF_SHIFT_DOWN);
- GetAppListTestHelper()->CheckState(AppListViewState::kFullscreenAllApps);
- CreateAndClickShelfItem();
- histogram_tester.ExpectBucketCount(
- "Apps.AppListAppLaunchedV2.FullscreenAllApps",
- AppListLaunchedFrom::kLaunchedFromShelf,
- 1 /* Number of times launched from shelf */);
- }
- // Test that the histogram records an app launch from the shelf while the
- // peeking launcher is showing.
- TEST_F(AppListMetricsPeekingLauncherTest, PeekingLaunchFromShelf) {
- base::HistogramTester histogram_tester;
- GetAppListTestHelper()->ShowAndRunLoop(GetPrimaryDisplayId());
- GetAppListTestHelper()->CheckState(AppListViewState::kPeeking);
- CreateAndClickShelfItem();
- histogram_tester.ExpectBucketCount(
- "Apps.AppListAppLaunchedV2.Peeking",
- AppListLaunchedFrom::kLaunchedFromShelf,
- 1 /* Number of times launched from shelf */);
- }
- // Test that the histogram records an app launch from a suggestion chip while
- // the peeking launcher is showing.
- TEST_F(AppListMetricsPeekingLauncherTest, PeekingLaunchFromChip) {
- base::HistogramTester histogram_tester;
- GetAppListTestHelper()->ShowAndRunLoop(GetPrimaryDisplayId());
- GetAppListTestHelper()->CheckState(AppListViewState::kPeeking);
- PopulateAndLaunchSuggestionChip();
- histogram_tester.ExpectBucketCount(
- "Apps.AppListAppLaunchedV2.Peeking",
- AppListLaunchedFrom::kLaunchedFromSuggestionChip,
- 1 /* Number of times launched from chip */);
- }
- // Test that the histogram records an app launch from the shelf while the
- // launcher is closed.
- TEST_F(AppListMetricsPeekingLauncherTest, ClosedLaunchFromShelf) {
- base::HistogramTester histogram_tester;
- GetAppListTestHelper()->CheckState(AppListViewState::kClosed);
- CreateAndClickShelfItem();
- histogram_tester.ExpectBucketCount(
- "Apps.AppListAppLaunchedV2.Closed",
- AppListLaunchedFrom::kLaunchedFromShelf,
- 1 /* Number of times launched from shelf */);
- // Open the launcher to peeking.
- PressAndReleaseKey(ui::KeyboardCode::VKEY_BROWSER_SEARCH);
- GetAppListTestHelper()->CheckState(AppListViewState::kPeeking);
- // Close launcher back to closed.
- PressAndReleaseKey(ui::KeyboardCode::VKEY_BROWSER_SEARCH);
- GetAppListTestHelper()->CheckState(AppListViewState::kClosed);
- ClickShelfItem();
- histogram_tester.ExpectBucketCount(
- "Apps.AppListAppLaunchedV2.Closed",
- AppListLaunchedFrom::kLaunchedFromShelf,
- 2 /* Number of times launched from shelf */);
- }
- // Suite for tests that run in tablet mode, parameterized by feature
- // ProductivityLauncher.
- class AppListMetricsTabletTest : public AppListMetricsTest,
- public testing::WithParamInterface<bool> {
- public:
- AppListMetricsTabletTest() {
- const bool enable = GetParam();
- feature_list_.InitWithFeatureState(features::kProductivityLauncher, enable);
- }
- ~AppListMetricsTabletTest() override = default;
- base::test::ScopedFeatureList feature_list_;
- };
- INSTANTIATE_TEST_SUITE_P(ProductivityLauncher,
- AppListMetricsTabletTest,
- testing::Bool());
- // Test that the histogram records an app launch from the shelf while the
- // homecher all apps state is showing.
- TEST_P(AppListMetricsTabletTest, HomecherAllAppsLaunchFromShelf) {
- Shell::Get()->tablet_mode_controller()->SetEnabledForTest(true);
- base::HistogramTester histogram_tester;
- GetAppListTestHelper()->CheckState(AppListViewState::kFullscreenAllApps);
- CreateAndClickShelfItem();
- histogram_tester.ExpectBucketCount(
- "Apps.AppListAppLaunchedV2.HomecherAllApps",
- AppListLaunchedFrom::kLaunchedFromShelf,
- 1 /* Number of times launched from shelf */);
- }
- // Test that the histogram records an app launch from the app grid while the
- // homecher all apps state is showing.
- TEST_P(AppListMetricsTabletTest, HomecherAllAppsLaunchFromGrid) {
- base::HistogramTester histogram_tester;
- // Enable tablet mode.
- Shell::Get()->tablet_mode_controller()->SetEnabledForTest(true);
- GetAppListTestHelper()->CheckState(AppListViewState::kFullscreenAllApps);
- PopulateAndLaunchAppInGrid();
- histogram_tester.ExpectBucketCount(
- "Apps.AppListAppLaunchedV2.HomecherAllApps",
- AppListLaunchedFrom::kLaunchedFromGrid,
- 1 /* Number of times launched from grid */);
- }
- // Test that the histogram records an app launch from a suggestion chip while
- // the homecher all apps state is showing.
- TEST_P(AppListMetricsTabletTest, HomecherAllAppsLaunchFromChip) {
- // ProductivityLauncher does not use suggestion chips.
- if (features::IsProductivityLauncherEnabled())
- return;
- base::HistogramTester histogram_tester;
- GetAppListTestHelper()->WaitUntilIdle();
- // Enable tablet mode.
- Shell::Get()->tablet_mode_controller()->SetEnabledForTest(true);
- GetAppListTestHelper()->CheckState(AppListViewState::kFullscreenAllApps);
- PopulateAndLaunchSuggestionChip();
- histogram_tester.ExpectBucketCount(
- "Apps.AppListAppLaunchedV2.HomecherAllApps",
- AppListLaunchedFrom::kLaunchedFromSuggestionChip,
- 1 /* Number of times launched from chip */);
- }
- // Test that the histogram records an app launch from the shelf while the
- // homecher search state is showing.
- TEST_P(AppListMetricsTabletTest, HomecherSearchLaunchFromShelf) {
- base::HistogramTester histogram_tester;
- // Enable tablet mode.
- GetAppListTestHelper()->WaitUntilIdle();
- Shell::Get()->tablet_mode_controller()->SetEnabledForTest(true);
- // Press a letter key, the AppListView should transition to kFullscreenSearch.
- PressAndReleaseKey(ui::KeyboardCode::VKEY_H);
- GetAppListTestHelper()->WaitUntilIdle();
- GetAppListTestHelper()->CheckState(AppListViewState::kFullscreenSearch);
- CreateAndClickShelfItem();
- histogram_tester.ExpectBucketCount(
- "Apps.AppListAppLaunchedV2.HomecherSearch",
- AppListLaunchedFrom::kLaunchedFromShelf,
- 1 /* Number of times launched from shelf */);
- }
- // Test that the histogram records an app launch from the search box while the
- // homercher search state is showing.
- TEST_P(AppListMetricsTabletTest, HomecherSearchLaunchFromSearchBox) {
- // ProductivityLauncher does not tile search results.
- if (features::IsProductivityLauncherEnabled())
- return;
- base::HistogramTester histogram_tester;
- // Enable tablet mode.
- GetAppListTestHelper()->WaitUntilIdle();
- Shell::Get()->tablet_mode_controller()->SetEnabledForTest(true);
- // Press a letter key, the AppListView should transition to kFullscreenSearch.
- PressAndReleaseKey(ui::KeyboardCode::VKEY_H);
- GetAppListTestHelper()->WaitUntilIdle();
- GetAppListTestHelper()->CheckState(AppListViewState::kFullscreenSearch);
- // Populate search box with tile items and launch a tile item.
- PopulateAndLaunchSearchBoxTileItem();
- histogram_tester.ExpectBucketCount(
- "Apps.AppListAppLaunchedV2.HomecherSearch",
- AppListLaunchedFrom::kLaunchedFromSearchBox,
- 1 /* Number of times launched from search box */);
- }
- // Tests with feature ProductivityLauncher enabled.
- class AppListMetricsProductivityLauncherTest : public AppListMetricsTest {
- public:
- AppListMetricsProductivityLauncherTest() {
- scoped_feature_list_.InitWithFeatures({features::kProductivityLauncher},
- {});
- }
- ~AppListMetricsProductivityLauncherTest() override = default;
- base::test::ScopedFeatureList scoped_feature_list_;
- };
- // Test that the histogram records an app launch from a recent app suggestion
- // while the bubble launcher all apps is showing.
- TEST_F(AppListMetricsProductivityLauncherTest,
- BubbleAllAppsLaunchFromRecentApps) {
- base::HistogramTester histogram_tester;
- auto* helper = GetAppListTestHelper();
- helper->WaitUntilIdle();
- helper->AddRecentApps(5);
- helper->AddAppItems(5);
- helper->ShowAppList();
- helper->WaitUntilIdle();
- views::View* recent_apps = helper->GetBubbleRecentAppsView();
- // Get focus on the first chip.
- recent_apps->children().front()->RequestFocus();
- helper->WaitUntilIdle();
- // Press return to simulate an app launch from the recent apps.
- PressAndReleaseKey(ui::KeyboardCode::VKEY_RETURN);
- helper->WaitUntilIdle();
- histogram_tester.ExpectBucketCount(
- "Apps.AppListAppLaunchedV2.BubbleAllApps",
- AppListLaunchedFrom::kLaunchedFromRecentApps,
- 1 /* Number of times launched from chip */);
- }
- TEST_F(AppListMetricsProductivityLauncherTest,
- HideContinueSectionMetricInClamshellMode) {
- base::test::ScopedFeatureList feature_list(
- features::kLauncherHideContinueSection);
- base::HistogramTester histograms;
- // Show the app list with a full continue section.
- auto* helper = GetAppListTestHelper();
- helper->AddContinueSuggestionResults(4);
- helper->AddRecentApps(5);
- helper->AddAppItems(5);
- helper->ShowAppList();
- // Metric is recorded in false bucket.
- const int false_bucket = 0;
- histograms.ExpectBucketCount(
- "Apps.AppList.ContinueSectionHiddenByUser.ClamshellMode", false_bucket,
- 1);
- helper->Dismiss();
- // Hide the continue section, then show the app list.
- Shell::Get()->app_list_controller()->SetHideContinueSection(true);
- helper->ShowAppList();
- // Metric is recorded in true bucket.
- const int true_bucket = 1;
- histograms.ExpectBucketCount(
- "Apps.AppList.ContinueSectionHiddenByUser.ClamshellMode", true_bucket, 1);
- helper->Dismiss();
- }
- TEST_F(AppListMetricsProductivityLauncherTest,
- HideContinueSectionMetricInTabletMode) {
- base::test::ScopedFeatureList feature_list(
- features::kLauncherHideContinueSection);
- base::HistogramTester histograms;
- // Show the tablet mode app list with a full continue section.
- auto* helper = GetAppListTestHelper();
- helper->AddContinueSuggestionResults(4);
- helper->AddRecentApps(5);
- helper->AddAppItems(5);
- Shell::Get()->tablet_mode_controller()->SetEnabledForTest(true);
- // Metric is recorded in false bucket.
- const int false_bucket = 0;
- histograms.ExpectBucketCount(
- "Apps.AppList.ContinueSectionHiddenByUser.TabletMode", false_bucket, 1);
- Shell::Get()->tablet_mode_controller()->SetEnabledForTest(false);
- // Hide the continue section, then show the tablet mode app list.
- Shell::Get()->app_list_controller()->SetHideContinueSection(true);
- Shell::Get()->tablet_mode_controller()->SetEnabledForTest(true);
- // Metric is recorded in true bucket.
- const int true_bucket = 1;
- histograms.ExpectBucketCount(
- "Apps.AppList.ContinueSectionHiddenByUser.TabletMode", true_bucket, 1);
- }
- // Test that the histogram records an app launch from a recent app suggestion
- // while the homecher all apps is showing.
- TEST_F(AppListMetricsProductivityLauncherTest, HomecherLaunchFromRecentApps) {
- base::HistogramTester histogram_tester;
- auto* helper = GetAppListTestHelper();
- helper->WaitUntilIdle();
- helper->AddRecentApps(5);
- helper->AddAppItems(5);
- Shell::Get()->tablet_mode_controller()->SetEnabledForTest(true);
- helper->WaitUntilIdle();
- views::View* recent_apps = helper->GetFullscreenRecentAppsView();
- // Get focus on the first chip.
- recent_apps->children().front()->RequestFocus();
- helper->WaitUntilIdle();
- // Press return to simulate an app launch from the recent apps.
- PressAndReleaseKey(ui::KeyboardCode::VKEY_RETURN);
- helper->WaitUntilIdle();
- histogram_tester.ExpectBucketCount(
- "Apps.AppListAppLaunchedV2.HomecherAllApps",
- AppListLaunchedFrom::kLaunchedFromRecentApps,
- 1 /* Number of times launched from chip */);
- }
- class AppListShowSourceMetricTest : public AshTestBase {
- public:
- AppListShowSourceMetricTest() = default;
- AppListShowSourceMetricTest(const AppListShowSourceMetricTest&) = delete;
- AppListShowSourceMetricTest& operator=(const AppListShowSourceMetricTest&) =
- delete;
- ~AppListShowSourceMetricTest() override = default;
- protected:
- void ClickHomeButton() {
- LeftClickOn(GetPrimaryShelf()->navigation_widget()->GetHomeButton());
- }
- };
- // In tablet mode, test that AppListShowSource metric is only recorded when
- // pressing home button when not already home. Any presses on the home button
- // when already home should do nothing.
- TEST_F(AppListShowSourceMetricTest, TabletInAppToHome) {
- base::HistogramTester histogram_tester;
- // Enable accessibility feature that forces home button to be shown in tablet
- // mode.
- Shell::Get()
- ->accessibility_controller()
- ->SetTabletModeShelfNavigationButtonsEnabled(true);
- std::unique_ptr<views::Widget> widget = CreateTestWidget();
- Shell::Get()->tablet_mode_controller()->SetEnabledForTest(true);
- ClickHomeButton();
- histogram_tester.ExpectBucketCount(
- "Apps.AppListShowSource", kShelfButton,
- 1 /* Number of times app list is shown with a shelf button */);
- histogram_tester.ExpectBucketCount(
- "Apps.AppListShowSource", kTabletMode,
- 0 /* Number of times app list is shown by tablet mode transition */);
- GetAppListTestHelper()->CheckVisibility(true);
- // Ensure that any subsequent clicks while already at home do not count as
- // showing the app list.
- ClickHomeButton();
- histogram_tester.ExpectBucketCount(
- "Apps.AppListShowSource", kShelfButton,
- 1 /* Number of times app list shown with a shelf button */);
- histogram_tester.ExpectTotalCount("Apps.AppListShowSource", 1);
- }
- // Ensure that app list is not recorded as shown when going to tablet mode with
- // a window open.
- TEST_F(AppListShowSourceMetricTest, TabletModeWithWindowOpen) {
- base::HistogramTester histogram_tester;
- std::unique_ptr<views::Widget> widget = CreateTestWidget();
- Shell::Get()->tablet_mode_controller()->SetEnabledForTest(true);
- GetAppListTestHelper()->CheckVisibility(false);
- // Ensure that no AppListShowSource metric was recorded.
- histogram_tester.ExpectTotalCount("Apps.AppListShowSource", 0);
- }
- // Ensure that app list is recorded as shown when going to tablet mode with no
- // other windows open.
- TEST_F(AppListShowSourceMetricTest, TabletModeWithNoWindowOpen) {
- base::HistogramTester histogram_tester;
- Shell::Get()->tablet_mode_controller()->SetEnabledForTest(true);
- GetAppListTestHelper()->CheckVisibility(true);
- histogram_tester.ExpectBucketCount(
- "Apps.AppListShowSource", kTabletMode,
- 1 /* Number of times app list shown after entering tablet mode */);
- }
- class AppListBubbleShowSourceMetricTest : public AppListShowSourceMetricTest {
- public:
- AppListBubbleShowSourceMetricTest() {
- scoped_feature_list_.InitWithFeatures({features::kProductivityLauncher},
- {});
- }
- ~AppListBubbleShowSourceMetricTest() override = default;
- base::test::ScopedFeatureList scoped_feature_list_;
- };
- // Tests that showing the bubble launcher in clamshell mode records the proper
- // metrics for Apps.AppListBubbleShowSource.
- TEST_F(AppListBubbleShowSourceMetricTest, ClamshellModeHomeButton) {
- base::HistogramTester histogram_tester;
- auto* app_list_bubble_presenter =
- Shell::Get()->app_list_controller()->bubble_presenter_for_test();
- // Show the Bubble AppList.
- GetAppListTestHelper()->ShowAndRunLoop(GetPrimaryDisplayId());
- EXPECT_TRUE(app_list_bubble_presenter->IsShowing());
- // Test that the proper histogram is logged.
- histogram_tester.ExpectTotalCount("Apps.AppListBubbleShowSource", 1);
- // Hide the Bubble AppList.
- GetAppListTestHelper()->Dismiss();
- EXPECT_FALSE(app_list_bubble_presenter->IsShowing());
- // Test that no histograms were logged.
- histogram_tester.ExpectTotalCount("Apps.AppListBubbleShowSource", 1);
- // Show the Bubble AppList one more time.
- GetAppListTestHelper()->ShowAndRunLoop(GetPrimaryDisplayId());
- EXPECT_TRUE(app_list_bubble_presenter->IsShowing());
- // Test that the histogram records 2 total shows.
- histogram_tester.ExpectTotalCount("Apps.AppListBubbleShowSource", 2);
- // Test that no fullscreen app list metrics were recorded.
- histogram_tester.ExpectTotalCount("Apps.AppListShowSource", 0);
- }
- // Test that tablet mode launcher operations do not record AppListBubble
- // metrics.
- TEST_F(AppListBubbleShowSourceMetricTest,
- TabletModeDoesNotRecordAppListBubbleShow) {
- base::HistogramTester histogram_tester;
- // Enable accessibility feature that forces home button to be shown in tablet
- // mode.
- Shell::Get()
- ->accessibility_controller()
- ->SetTabletModeShelfNavigationButtonsEnabled(true);
- // Go to tablet mode, the tablet mode (non bubble) launcher will show. Create
- // a test widget so the launcher will show in the background.
- std::unique_ptr<views::Widget> widget = CreateTestWidget();
- Shell::Get()->tablet_mode_controller()->SetEnabledForTest(true);
- auto* app_list_bubble_presenter =
- Shell::Get()->app_list_controller()->bubble_presenter_for_test();
- EXPECT_FALSE(app_list_bubble_presenter->IsShowing());
- // Ensure that no AppListBubbleShowSource metric was recorded.
- histogram_tester.ExpectTotalCount("Apps.AppListBubbleShowSource", 0);
- // Press the Home Button, which hides `widget` and shows the tablet mode
- // launcher.
- ClickHomeButton();
- EXPECT_FALSE(app_list_bubble_presenter->IsShowing());
- // Test that no bubble launcher metrics were recorded.
- histogram_tester.ExpectTotalCount("Apps.AppListBubbleShowSource", 0);
- }
- // Tests that toggling the bubble launcher does not record metrics when the
- // result of the toggle is that the launcher is hidden.
- TEST_F(AppListBubbleShowSourceMetricTest, ToggleDoesNotRecordOnHide) {
- base::HistogramTester histogram_tester;
- auto* app_list_controller = Shell::Get()->app_list_controller();
- // Toggle the app list to show it.
- app_list_controller->ToggleAppList(GetPrimaryDisplayId(),
- AppListShowSource::kSearchKey,
- base::TimeTicks::Now());
- auto* app_list_bubble_presenter =
- Shell::Get()->app_list_controller()->bubble_presenter_for_test();
- ASSERT_TRUE(app_list_bubble_presenter->IsShowing());
- // Toggle the app list once more, to hide it.
- app_list_controller->ToggleAppList(GetPrimaryDisplayId(),
- AppListShowSource::kSearchKey,
- base::TimeTicks::Now());
- ASSERT_FALSE(app_list_bubble_presenter->IsShowing());
- // Test that only one show was recorded.
- histogram_tester.ExpectTotalCount("Apps.AppListBubbleShowSource", 1);
- }
- using AppListPeriodicMetricsTest = AshTestBase;
- // Verify that the number of items in the app list are recorded correctly.
- TEST_F(AppListPeriodicMetricsTest, PeriodicAppListMetrics_NumberOfApps) {
- base::HistogramTester histogram;
- histogram.ExpectTotalCount("Apps.AppList.NumberOfApps", 0);
- histogram.ExpectTotalCount("Apps.AppList.NumberOfRootLevelItems", 0);
- AppListModel* model = AppListModelProvider::Get()->model();
- // Add 5 items to the app list.
- for (int i = 0; i < 5; i++) {
- model->AddItem(
- std::make_unique<AppListItem>(base::StringPrintf("app_id_%d", i)));
- }
- // Check that 5 items are recorded as being in the app list.
- RecordPeriodicAppListMetrics();
- histogram.ExpectBucketCount("Apps.AppList.NumberOfApps", 5, 1);
- histogram.ExpectBucketCount("Apps.AppList.NumberOfRootLevelItems", 5, 1);
- histogram.ExpectTotalCount("Apps.AppList.NumberOfApps", 1);
- histogram.ExpectTotalCount("Apps.AppList.NumberOfRootLevelItems", 1);
- // Create a folder and add 3 items to it.
- const std::string folder_id = "folder_id";
- model->CreateFolderItem(folder_id);
- for (int i = 0; i < 3; i++) {
- auto item =
- std::make_unique<AppListItem>(base::StringPrintf("id_in_folder_%d", i));
- model->AddItemToFolder(std::move(item), folder_id);
- }
- // Check that the folder and its items are recorded in the metrics.
- RecordPeriodicAppListMetrics();
- histogram.ExpectBucketCount("Apps.AppList.NumberOfApps", 8, 1);
- histogram.ExpectBucketCount("Apps.AppList.NumberOfRootLevelItems", 6, 1);
- }
- TEST_F(AppListPeriodicMetricsTest, RecordFolderMetrics_ZeroFolders) {
- base::HistogramTester histogram;
- GetAppListTestHelper()->model()->PopulateApps(2);
- RecordPeriodicAppListMetrics();
- // 1 sample in the 0 folders bucket.
- EXPECT_EQ(1, histogram.GetBucketCount("Apps.AppList.NumberOfFolders", 0));
- // 1 sample in the 0 folders bucket.
- EXPECT_EQ(
- 1, histogram.GetBucketCount("Apps.AppList.NumberOfNonSystemFolders", 0));
- // 1 sample in the 0 apps bucket.
- EXPECT_EQ(1, histogram.GetBucketCount(
- "Apps.AppList.NumberOfAppsInNonSystemFolders", 0));
- }
- TEST_F(AppListPeriodicMetricsTest, RecordFolderMetrics_OneRegularFolder) {
- base::HistogramTester histogram;
- GetAppListTestHelper()->model()->CreateAndPopulateFolderWithApps(2);
- RecordPeriodicAppListMetrics();
- // 1 sample in the 1 folder bucket.
- EXPECT_EQ(1, histogram.GetBucketCount("Apps.AppList.NumberOfFolders", 1));
- // 1 sample in the 1 folder bucket.
- EXPECT_EQ(
- 1, histogram.GetBucketCount("Apps.AppList.NumberOfNonSystemFolders", 1));
- // 1 sample in the 2 apps bucket.
- EXPECT_EQ(1, histogram.GetBucketCount(
- "Apps.AppList.NumberOfAppsInNonSystemFolders", 2));
- }
- TEST_F(AppListPeriodicMetricsTest, RecordFolderMetrics_SystemFolder) {
- base::HistogramTester histogram;
- AppListFolderItem* folder =
- GetAppListTestHelper()->model()->CreateSingleItemFolder("folder_id",
- "item_id");
- folder->SetIsSystemFolder(true);
- RecordPeriodicAppListMetrics();
- // 1 sample in the 1 folder bucket.
- EXPECT_EQ(1, histogram.GetBucketCount("Apps.AppList.NumberOfFolders", 1));
- // 1 sample in the 0 folders bucket, because the folder is a system folder.
- EXPECT_EQ(
- 1, histogram.GetBucketCount("Apps.AppList.NumberOfNonSystemFolders", 0));
- // 1 sample in the 0 apps bucket, because items in system folders don't count.
- EXPECT_EQ(1, histogram.GetBucketCount(
- "Apps.AppList.NumberOfAppsInNonSystemFolders", 0));
- }
- } // namespace ash
|