[go: nahoru, domu]

blob: 72e2b1c8990b8f0f3087c5d82f14b4b377a99b9d [file] [log] [blame]
Avi Drissman3a215d1e2022-09-07 19:43:091// Copyright 2019 The Chromium Authors
Matthew Mourgos105a91f2019-05-08 23:30:482// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include <memory>
Matthew Mourgosa6330ce2021-06-24 04:19:136#include <string>
Ahmed Fakhry1b6ea0b2020-07-09 01:45:247#include <utility>
Matthew Mourgos105a91f2019-05-08 23:30:488#include <vector>
9
Katie Dektar582ae102023-12-13 03:15:5410#include "ash/accessibility/accessibility_controller.h"
Alex Newcomerfe776032021-06-16 21:17:0811#include "ash/app_list/app_list_bubble_presenter.h"
Matthew Mourgos105a91f2019-05-08 23:30:4812#include "ash/app_list/app_list_controller_impl.h"
Matthew Mourgos4c287d62019-10-25 22:46:1613#include "ash/app_list/app_list_metrics.h"
Toni Barzic80143512021-10-29 15:41:4514#include "ash/app_list/app_list_model_provider.h"
James Cook4f4c3612021-05-27 21:45:2215#include "ash/app_list/app_list_presenter_impl.h"
James Cook1c617932021-04-01 16:42:0916#include "ash/app_list/model/app_list_test_model.h"
Matthew Mourgos105a91f2019-05-08 23:30:4817#include "ash/app_list/model/search/search_model.h"
18#include "ash/app_list/test/app_list_test_helper.h"
Matthew Mourgos105a91f2019-05-08 23:30:4819#include "ash/app_list/views/app_list_item_view.h"
20#include "ash/app_list/views/app_list_main_view.h"
21#include "ash/app_list/views/app_list_view.h"
22#include "ash/app_list/views/apps_container_view.h"
Matthew Mourgos105a91f2019-05-08 23:30:4823#include "ash/app_list/views/contents_view.h"
Matthew Mourgosa205f302021-09-08 22:28:2124#include "ash/app_list/views/paged_apps_grid_view.h"
James Cook44ddf212022-07-26 17:49:2325#include "ash/app_list/views/recent_apps_view.h"
Matthew Mourgos105a91f2019-05-08 23:30:4826#include "ash/app_list/views/search_result_container_view.h"
27#include "ash/app_list/views/search_result_page_view.h"
Alex Newcomerfe776032021-06-16 21:17:0828#include "ash/constants/ash_features.h"
Xiyuan Xia68b3b2c2019-05-28 18:50:3929#include "ash/public/cpp/app_list/app_list_types.h"
Matthew Mourgos105a91f2019-05-08 23:30:4830#include "ash/public/cpp/shelf_item_delegate.h"
31#include "ash/public/cpp/shelf_model.h"
Matthew Mourgos4c287d62019-10-25 22:46:1632#include "ash/shelf/home_button.h"
Matthew Mourgos105a91f2019-05-08 23:30:4833#include "ash/shelf/shelf.h"
Manu Cornet759eed92020-01-15 23:30:2634#include "ash/shelf/shelf_navigation_widget.h"
Matthew Mourgos105a91f2019-05-08 23:30:4835#include "ash/shelf/shelf_view.h"
36#include "ash/shelf/shelf_view_test_api.h"
37#include "ash/shell.h"
38#include "ash/test/ash_test_base.h"
39#include "ash/wm/tablet_mode/tablet_mode_controller.h"
Arthur Sonzogni834e018f2023-04-22 10:20:0240#include "base/memory/raw_ptr.h"
Matthew Mourgos105a91f2019-05-08 23:30:4841#include "base/test/metrics/histogram_tester.h"
Alex Newcomerfe776032021-06-16 21:17:0842#include "base/test/scoped_feature_list.h"
Ana Salazarbe73a3d2023-06-23 01:37:4343#include "ui/compositor/scoped_animation_duration_scale_mode.h"
Eriko Kurimotoc6585fc2023-11-20 06:03:3244#include "ui/display/display_observer.h"
Matthew Mourgos105a91f2019-05-08 23:30:4845#include "ui/display/screen.h"
Eriko Kurimotoc6585fc2023-11-20 06:03:3246#include "ui/display/tablet_state.h"
Matthew Mourgos105a91f2019-05-08 23:30:4847
48namespace ash {
49
50namespace {
51
Manu Cornet471267152019-06-19 20:38:1852constexpr int kBrowserAppIndexOnShelf = 0;
53
Matthew Mourgos105a91f2019-05-08 23:30:4854// A test shelf item delegate that simulates an activated window when a shelf
Ana Salazarbe73a3d2023-06-23 01:37:4355// item is selected. When |wait_for_tablet_mode_| is set, the delegate will wait
56// for tablet mode animation start to run the callback that activates the
57// window.
Eriko Kurimotoc6585fc2023-11-20 06:03:3258class TestShelfItemDelegate : public ShelfItemDelegate,
59 display::DisplayObserver {
Matthew Mourgos105a91f2019-05-08 23:30:4860 public:
61 explicit TestShelfItemDelegate(const ShelfID& shelf_id)
62 : ShelfItemDelegate(shelf_id) {}
63
Ana Salazarbe73a3d2023-06-23 01:37:4364 TestShelfItemDelegate(const ShelfID& shelf_id, bool wait_for_tablet_mode)
65 : ShelfItemDelegate(shelf_id),
66 wait_for_tablet_mode_(wait_for_tablet_mode) {
67 if (wait_for_tablet_mode_) {
Eriko Kurimotoc6585fc2023-11-20 06:03:3268 display::Screen::GetScreen()->AddObserver(this);
Ana Salazarbe73a3d2023-06-23 01:37:4369 }
70 }
71
Eriko Kurimotoc6585fc2023-11-20 06:03:3272 ~TestShelfItemDelegate() override {
73 display::Screen::GetScreen()->RemoveObserver(this);
74 }
75
Matthew Mourgos105a91f2019-05-08 23:30:4876 void ItemSelected(std::unique_ptr<ui::Event> event,
77 int64_t display_id,
78 ash::ShelfLaunchSource source,
Ahmed Fakhry1b6ea0b2020-07-09 01:45:2479 ItemSelectedCallback callback,
80 const ItemFilterPredicate& filter_predicate) override {
Ana Salazarbe73a3d2023-06-23 01:37:4381 if (wait_for_tablet_mode_) {
82 callback_ = std::move(callback);
83 return;
84 }
Mike Wasserman3bfabb192019-05-17 01:08:3485 std::move(callback).Run(SHELF_ACTION_WINDOW_ACTIVATED, {});
Matthew Mourgos105a91f2019-05-08 23:30:4886 }
87 void ExecuteCommand(bool from_context_menu,
88 int64_t command_id,
89 int32_t event_flags,
90 int64_t display_id) override {}
91 void Close() override {}
Ana Salazarbe73a3d2023-06-23 01:37:4392
Eriko Kurimotoc6585fc2023-11-20 06:03:3293 void OnDisplayTabletStateChanged(display::TabletState state) override {
94 if (!callback_ || state != display::TabletState::kEnteringTabletMode) {
Ana Salazarbe73a3d2023-06-23 01:37:4395 return;
96 }
97 std::move(callback_).Run(SHELF_ACTION_WINDOW_ACTIVATED, {});
98 }
99
Ana Salazarbe73a3d2023-06-23 01:37:43100 private:
101 bool wait_for_tablet_mode_ = false;
102 ItemSelectedCallback callback_;
Matthew Mourgos105a91f2019-05-08 23:30:48103};
104
105} // namespace
106
107int64_t GetPrimaryDisplayId() {
108 return display::Screen::GetScreen()->GetPrimaryDisplay().id();
109}
110
111// Used to test that app launched metrics are properly recorded.
James Cook4b851152021-12-28 21:38:26112class AppListMetricsTest : public AshTestBase {
Matthew Mourgos105a91f2019-05-08 23:30:48113 public:
James Cook4b851152021-12-28 21:38:26114 AppListMetricsTest() = default;
Peter Boströmec31a042021-09-16 23:37:34115
James Cook4b851152021-12-28 21:38:26116 AppListMetricsTest(const AppListMetricsTest&) = delete;
117 AppListMetricsTest& operator=(const AppListMetricsTest&) = delete;
Peter Boströmec31a042021-09-16 23:37:34118
James Cook4b851152021-12-28 21:38:26119 ~AppListMetricsTest() override = default;
Matthew Mourgos105a91f2019-05-08 23:30:48120
121 void SetUp() override {
Matthew Mourgos105a91f2019-05-08 23:30:48122 AshTestBase::SetUp();
123
Toni Barzic80143512021-10-29 15:41:45124 search_model_ = AppListModelProvider::Get()->search_model();
Matthew Mourgos105a91f2019-05-08 23:30:48125
Andrew Xub940f4d2019-09-17 01:06:50126 shelf_test_api_ = std::make_unique<ShelfViewTestAPI>(
127 GetPrimaryShelf()->GetShelfViewForTesting());
Matthew Mourgos105a91f2019-05-08 23:30:48128 }
129
Matthew Mourgos105a91f2019-05-08 23:30:48130 protected:
Ana Salazarbe73a3d2023-06-23 01:37:43131 void CreateShelfItem(bool wait_for_tablet_mode = false) {
Andrew Xub940f4d2019-09-17 01:06:50132 // Add shelf item to be launched. Waits for the shelf view's bounds
133 // animations to end.
Matthew Mourgos105a91f2019-05-08 23:30:48134 ShelfItem shelf_item;
Manu Cornet164f6a22019-12-20 16:37:33135 shelf_item.id = ShelfID("app_id");
Matthew Mourgos105a91f2019-05-08 23:30:48136 shelf_item.type = TYPE_BROWSER_SHORTCUT;
Ana Salazarbe73a3d2023-06-23 01:37:43137 ShelfModel::Get()->Add(shelf_item,
138 std::make_unique<TestShelfItemDelegate>(
139 shelf_item.id, wait_for_tablet_mode));
Andrew Xub940f4d2019-09-17 01:06:50140 shelf_test_api_->RunMessageLoopUntilAnimationsDone();
Ana Salazarbe73a3d2023-06-23 01:37:43141 }
Matthew Mourgos105a91f2019-05-08 23:30:48142
Ana Salazarbe73a3d2023-06-23 01:37:43143 void CreateAndClickShelfItem() {
144 CreateShelfItem();
Matthew Mourgos105a91f2019-05-08 23:30:48145 ClickShelfItem();
146 }
147
148 void ClickShelfItem() {
149 // Get location of the shelf item.
Andrew Xub940f4d2019-09-17 01:06:50150 const views::ViewModel* view_model =
151 GetPrimaryShelf()->GetShelfViewForTesting()->view_model_for_test();
James Cookd7379362021-12-30 00:54:09152 LeftClickOn(view_model->view_at(kBrowserAppIndexOnShelf));
Matthew Mourgos105a91f2019-05-08 23:30:48153 }
154
Joanmarie Diggs33842842022-09-08 18:47:44155 void PopulateAndLaunchAppInGrid(int num = 4) {
Matthew Mourgos105a91f2019-05-08 23:30:48156 // Populate apps in the root app grid.
Toni Barzic80143512021-10-29 15:41:45157 AppListModel* model = AppListModelProvider::Get()->model();
Joanmarie Diggs33842842022-09-08 18:47:44158 for (int i = 0; i < num; i++) {
159 AppListItem* item = model->AddItem(
160 std::make_unique<AppListItem>(base::StringPrintf("item %d", i)));
161 // Give each item a name so that the accessibility paint checks pass.
162 // (Focusable items should have accessible names.)
163 model->SetItemName(item, item->id());
164 }
Matthew Mourgos105a91f2019-05-08 23:30:48165
Manu Cornet191c3142019-10-09 06:31:32166 AppListView::TestApi test_api(
James Cook26dd0022022-01-10 23:28:28167 Shell::Get()->app_list_controller()->fullscreen_presenter()->GetView());
Matthew Mourgos105a91f2019-05-08 23:30:48168
169 // Focus the first item in the root app grid.
170 test_api.GetRootAppsGridView()->GetItemViewAt(0)->RequestFocus();
171
172 // Press return to simulate an app launch from a grid item.
James Cook70501b22021-08-09 17:19:18173 PressAndReleaseKey(ui::KeyboardCode::VKEY_RETURN);
Matthew Mourgos105a91f2019-05-08 23:30:48174 }
175
176 private:
Bartek Nowierskideb75842023-12-27 02:32:42177 raw_ptr<SearchModel, DanglingUntriaged> search_model_ = nullptr;
Andrew Xub940f4d2019-09-17 01:06:50178 std::unique_ptr<ShelfViewTestAPI> shelf_test_api_;
Matthew Mourgos105a91f2019-05-08 23:30:48179};
180
Ana Salazarf5b57062022-10-25 17:47:37181// Suite for tests that run in tablet mode.
182class AppListMetricsTabletTest : public AppListMetricsTest {
James Cook4b851152021-12-28 21:38:26183 public:
Ana Salazarf5b57062022-10-25 17:47:37184 AppListMetricsTabletTest() = default;
James Cook4b851152021-12-28 21:38:26185 ~AppListMetricsTabletTest() override = default;
Ana Salazarf5b57062022-10-25 17:47:37186 void SetUp() override {
187 AppListMetricsTest::SetUp();
188 Shell::Get()->tablet_mode_controller()->SetEnabledForTest(true);
189 GetAppListTestHelper()->CheckState(AppListViewState::kFullscreenAllApps);
190 }
James Cook4b851152021-12-28 21:38:26191};
James Cook4b851152021-12-28 21:38:26192
Matthew Mourgos105a91f2019-05-08 23:30:48193// Test that the histogram records an app launch from the shelf while the
194// homecher all apps state is showing.
Ana Salazarf5b57062022-10-25 17:47:37195TEST_F(AppListMetricsTabletTest, HomecherAllAppsLaunchFromShelf) {
Matthew Mourgos105a91f2019-05-08 23:30:48196 base::HistogramTester histogram_tester;
197
Matthew Mourgos105a91f2019-05-08 23:30:48198 CreateAndClickShelfItem();
199
200 histogram_tester.ExpectBucketCount(
201 "Apps.AppListAppLaunchedV2.HomecherAllApps",
Timothy Loh72c87992019-05-22 07:11:34202 AppListLaunchedFrom::kLaunchedFromShelf,
Matthew Mourgos105a91f2019-05-08 23:30:48203 1 /* Number of times launched from shelf */);
204}
205
Ana Salazarbe73a3d2023-06-23 01:37:43206// Test that the histogram records an app launch from the shelf while the
207// the tablet animation is running.
208TEST_F(AppListMetricsTest, TapOnItemDuringTabletModeAnimation) {
209 base::HistogramTester histogram_tester;
210 Shell::Get()->tablet_mode_controller()->SetEnabledForTest(false);
211
212 CreateShelfItem(/*wait_for_tablet_mode=*/true);
213
214 std::unique_ptr<views::Widget> widget = CreateTestWidget();
215 ui::ScopedAnimationDurationScaleMode non_zero_duration_mode(
216 ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION);
217 ClickShelfItem();
218
219 Shell::Get()->tablet_mode_controller()->SetEnabledForTest(true);
220 GetPrimaryShelf()->shelf_widget()->LayoutRootViewIfNecessary();
221 GetAppListTestHelper()->CheckVisibility(false);
222
223 histogram_tester.ExpectBucketCount(
224 "Apps.AppListAppLaunchedV2.Closed",
225 AppListLaunchedFrom::kLaunchedFromShelf,
226 1 /* Number of times launched from shelf */);
227}
228
Matthew Mourgos105a91f2019-05-08 23:30:48229// Test that the histogram records an app launch from the app grid while the
230// homecher all apps state is showing.
Ana Salazarf5b57062022-10-25 17:47:37231TEST_F(AppListMetricsTabletTest, HomecherAllAppsLaunchFromGrid) {
Matthew Mourgos105a91f2019-05-08 23:30:48232 base::HistogramTester histogram_tester;
Matthew Mourgos105a91f2019-05-08 23:30:48233 PopulateAndLaunchAppInGrid();
234
235 histogram_tester.ExpectBucketCount(
236 "Apps.AppListAppLaunchedV2.HomecherAllApps",
Timothy Loh72c87992019-05-22 07:11:34237 AppListLaunchedFrom::kLaunchedFromGrid,
Matthew Mourgos105a91f2019-05-08 23:30:48238 1 /* Number of times launched from grid */);
239}
240
Matthew Mourgos105a91f2019-05-08 23:30:48241// Test that the histogram records an app launch from the shelf while the
242// homecher search state is showing.
Ana Salazarf5b57062022-10-25 17:47:37243TEST_F(AppListMetricsTabletTest, HomecherSearchLaunchFromShelf) {
Matthew Mourgos105a91f2019-05-08 23:30:48244 base::HistogramTester histogram_tester;
245
Matthew Mourgos105a91f2019-05-08 23:30:48246 // Press a letter key, the AppListView should transition to kFullscreenSearch.
James Cook70501b22021-08-09 17:19:18247 PressAndReleaseKey(ui::KeyboardCode::VKEY_H);
Matthew Mourgos105a91f2019-05-08 23:30:48248 GetAppListTestHelper()->WaitUntilIdle();
Manu Cornet164f6a22019-12-20 16:37:33249 GetAppListTestHelper()->CheckState(AppListViewState::kFullscreenSearch);
Matthew Mourgos105a91f2019-05-08 23:30:48250
251 CreateAndClickShelfItem();
252
253 histogram_tester.ExpectBucketCount(
254 "Apps.AppListAppLaunchedV2.HomecherSearch",
Timothy Loh72c87992019-05-22 07:11:34255 AppListLaunchedFrom::kLaunchedFromShelf,
Matthew Mourgos105a91f2019-05-08 23:30:48256 1 /* Number of times launched from shelf */);
257}
258
Ana Salazar1df67352021-11-17 00:34:12259// Test that the histogram records an app launch from a recent app suggestion
260// while the bubble launcher all apps is showing.
Ana Salazaraddeb8c2022-10-18 23:31:47261TEST_F(AppListMetricsTest, BubbleAllAppsLaunchFromRecentApps) {
Ana Salazar1df67352021-11-17 00:34:12262 base::HistogramTester histogram_tester;
263 auto* helper = GetAppListTestHelper();
264
265 helper->WaitUntilIdle();
266
267 helper->AddRecentApps(5);
268 helper->AddAppItems(5);
269 helper->ShowAppList();
270
271 helper->WaitUntilIdle();
272 views::View* recent_apps = helper->GetBubbleRecentAppsView();
273
274 // Get focus on the first chip.
275 recent_apps->children().front()->RequestFocus();
276 helper->WaitUntilIdle();
277
278 // Press return to simulate an app launch from the recent apps.
279 PressAndReleaseKey(ui::KeyboardCode::VKEY_RETURN);
280 helper->WaitUntilIdle();
281
282 histogram_tester.ExpectBucketCount(
283 "Apps.AppListAppLaunchedV2.BubbleAllApps",
284 AppListLaunchedFrom::kLaunchedFromRecentApps,
285 1 /* Number of times launched from chip */);
286}
287
Ana Salazaraddeb8c2022-10-18 23:31:47288TEST_F(AppListMetricsTest, HideContinueSectionMetricInClamshellMode) {
James Cook42577bc2022-05-02 17:40:17289 base::HistogramTester histograms;
290
291 // Show the app list with a full continue section.
292 auto* helper = GetAppListTestHelper();
293 helper->AddContinueSuggestionResults(4);
294 helper->AddRecentApps(5);
295 helper->AddAppItems(5);
296 helper->ShowAppList();
297
298 // Metric is recorded in false bucket.
299 const int false_bucket = 0;
300 histograms.ExpectBucketCount(
301 "Apps.AppList.ContinueSectionHiddenByUser.ClamshellMode", false_bucket,
302 1);
303 helper->Dismiss();
304
305 // Hide the continue section, then show the app list.
306 Shell::Get()->app_list_controller()->SetHideContinueSection(true);
307 helper->ShowAppList();
308
309 // Metric is recorded in true bucket.
310 const int true_bucket = 1;
311 histograms.ExpectBucketCount(
312 "Apps.AppList.ContinueSectionHiddenByUser.ClamshellMode", true_bucket, 1);
313 helper->Dismiss();
314}
315
Ana Salazaraddeb8c2022-10-18 23:31:47316TEST_F(AppListMetricsTest, HideContinueSectionMetricInTabletMode) {
James Cook42577bc2022-05-02 17:40:17317 base::HistogramTester histograms;
318
319 // Show the tablet mode app list with a full continue section.
320 auto* helper = GetAppListTestHelper();
321 helper->AddContinueSuggestionResults(4);
322 helper->AddRecentApps(5);
323 helper->AddAppItems(5);
324 Shell::Get()->tablet_mode_controller()->SetEnabledForTest(true);
325
326 // Metric is recorded in false bucket.
327 const int false_bucket = 0;
328 histograms.ExpectBucketCount(
329 "Apps.AppList.ContinueSectionHiddenByUser.TabletMode", false_bucket, 1);
330 Shell::Get()->tablet_mode_controller()->SetEnabledForTest(false);
331
332 // Hide the continue section, then show the tablet mode app list.
333 Shell::Get()->app_list_controller()->SetHideContinueSection(true);
334 Shell::Get()->tablet_mode_controller()->SetEnabledForTest(true);
335
336 // Metric is recorded in true bucket.
337 const int true_bucket = 1;
338 histograms.ExpectBucketCount(
339 "Apps.AppList.ContinueSectionHiddenByUser.TabletMode", true_bucket, 1);
340}
341
Ana Salazar1df67352021-11-17 00:34:12342// Test that the histogram records an app launch from a recent app suggestion
343// while the homecher all apps is showing.
Ana Salazaraddeb8c2022-10-18 23:31:47344TEST_F(AppListMetricsTest, HomecherLaunchFromRecentApps) {
Ana Salazar1df67352021-11-17 00:34:12345 base::HistogramTester histogram_tester;
346 auto* helper = GetAppListTestHelper();
347
348 helper->WaitUntilIdle();
349
350 helper->AddRecentApps(5);
351 helper->AddAppItems(5);
352 Shell::Get()->tablet_mode_controller()->SetEnabledForTest(true);
353
354 helper->WaitUntilIdle();
355 views::View* recent_apps = helper->GetFullscreenRecentAppsView();
356
357 // Get focus on the first chip.
358 recent_apps->children().front()->RequestFocus();
359 helper->WaitUntilIdle();
360
361 // Press return to simulate an app launch from the recent apps.
362 PressAndReleaseKey(ui::KeyboardCode::VKEY_RETURN);
363 helper->WaitUntilIdle();
364
365 histogram_tester.ExpectBucketCount(
366 "Apps.AppListAppLaunchedV2.HomecherAllApps",
367 AppListLaunchedFrom::kLaunchedFromRecentApps,
368 1 /* Number of times launched from chip */);
369}
370
Matthew Mourgos4c287d62019-10-25 22:46:16371class AppListShowSourceMetricTest : public AshTestBase {
372 public:
373 AppListShowSourceMetricTest() = default;
Peter Boströmec31a042021-09-16 23:37:34374
375 AppListShowSourceMetricTest(const AppListShowSourceMetricTest&) = delete;
376 AppListShowSourceMetricTest& operator=(const AppListShowSourceMetricTest&) =
377 delete;
378
Matthew Mourgos4c287d62019-10-25 22:46:16379 ~AppListShowSourceMetricTest() override = default;
380
381 protected:
382 void ClickHomeButton() {
James Cookd7379362021-12-30 00:54:09383 LeftClickOn(GetPrimaryShelf()->navigation_widget()->GetHomeButton());
Matthew Mourgos4c287d62019-10-25 22:46:16384 }
Matthew Mourgos4c287d62019-10-25 22:46:16385};
386
387// In tablet mode, test that AppListShowSource metric is only recorded when
388// pressing home button when not already home. Any presses on the home button
389// when already home should do nothing.
390TEST_F(AppListShowSourceMetricTest, TabletInAppToHome) {
391 base::HistogramTester histogram_tester;
392
Alex Newcomerfe776032021-06-16 21:17:08393 // Enable accessibility feature that forces home button to be shown in tablet
394 // mode.
395 Shell::Get()
396 ->accessibility_controller()
397 ->SetTabletModeShelfNavigationButtonsEnabled(true);
Toni Barzic4c37d1e02020-02-15 01:40:05398
Matthew Mourgos4c287d62019-10-25 22:46:16399 std::unique_ptr<views::Widget> widget = CreateTestWidget();
400 Shell::Get()->tablet_mode_controller()->SetEnabledForTest(true);
401
402 ClickHomeButton();
403 histogram_tester.ExpectBucketCount(
Lei Zhangb9109ac2022-09-19 20:03:53404 "Apps.AppListShowSource", AppListShowSource::kShelfButton,
Matthew Mourgos4c287d62019-10-25 22:46:16405 1 /* Number of times app list is shown with a shelf button */);
406 histogram_tester.ExpectBucketCount(
Lei Zhangb9109ac2022-09-19 20:03:53407 "Apps.AppListShowSource", AppListShowSource::kTabletMode,
Matthew Mourgos4c287d62019-10-25 22:46:16408 0 /* Number of times app list is shown by tablet mode transition */);
409
410 GetAppListTestHelper()->CheckVisibility(true);
411
412 // Ensure that any subsequent clicks while already at home do not count as
413 // showing the app list.
414 ClickHomeButton();
415 histogram_tester.ExpectBucketCount(
Lei Zhangb9109ac2022-09-19 20:03:53416 "Apps.AppListShowSource", AppListShowSource::kShelfButton,
Matthew Mourgos4c287d62019-10-25 22:46:16417 1 /* Number of times app list shown with a shelf button */);
James Cook233288d2021-04-30 19:00:29418 histogram_tester.ExpectTotalCount("Apps.AppListShowSource", 1);
Matthew Mourgos4c287d62019-10-25 22:46:16419}
420
421// Ensure that app list is not recorded as shown when going to tablet mode with
422// a window open.
423TEST_F(AppListShowSourceMetricTest, TabletModeWithWindowOpen) {
424 base::HistogramTester histogram_tester;
425
426 std::unique_ptr<views::Widget> widget = CreateTestWidget();
427 Shell::Get()->tablet_mode_controller()->SetEnabledForTest(true);
428 GetAppListTestHelper()->CheckVisibility(false);
429
Alex Newcomerfe776032021-06-16 21:17:08430 // Ensure that no AppListShowSource metric was recorded.
James Cook233288d2021-04-30 19:00:29431 histogram_tester.ExpectTotalCount("Apps.AppListShowSource", 0);
Matthew Mourgos4c287d62019-10-25 22:46:16432}
433
434// Ensure that app list is recorded as shown when going to tablet mode with no
435// other windows open.
436TEST_F(AppListShowSourceMetricTest, TabletModeWithNoWindowOpen) {
437 base::HistogramTester histogram_tester;
438
439 Shell::Get()->tablet_mode_controller()->SetEnabledForTest(true);
440 GetAppListTestHelper()->CheckVisibility(true);
441
442 histogram_tester.ExpectBucketCount(
Lei Zhangb9109ac2022-09-19 20:03:53443 "Apps.AppListShowSource", AppListShowSource::kTabletMode,
Matthew Mourgos4c287d62019-10-25 22:46:16444 1 /* Number of times app list shown after entering tablet mode */);
445}
446
James Cookb661f3802021-09-30 21:43:20447// Tests that showing the bubble launcher in clamshell mode records the proper
Alex Newcomerfe776032021-06-16 21:17:08448// metrics for Apps.AppListBubbleShowSource.
Ana Salazaraddeb8c2022-10-18 23:31:47449TEST_F(AppListShowSourceMetricTest, ClamshellModeHomeButton) {
Alex Newcomerfe776032021-06-16 21:17:08450 base::HistogramTester histogram_tester;
451 auto* app_list_bubble_presenter =
452 Shell::Get()->app_list_controller()->bubble_presenter_for_test();
453 // Show the Bubble AppList.
454 GetAppListTestHelper()->ShowAndRunLoop(GetPrimaryDisplayId());
455 EXPECT_TRUE(app_list_bubble_presenter->IsShowing());
456
457 // Test that the proper histogram is logged.
458 histogram_tester.ExpectTotalCount("Apps.AppListBubbleShowSource", 1);
459
460 // Hide the Bubble AppList.
461 GetAppListTestHelper()->Dismiss();
462 EXPECT_FALSE(app_list_bubble_presenter->IsShowing());
463
464 // Test that no histograms were logged.
465 histogram_tester.ExpectTotalCount("Apps.AppListBubbleShowSource", 1);
466
467 // Show the Bubble AppList one more time.
468 GetAppListTestHelper()->ShowAndRunLoop(GetPrimaryDisplayId());
469 EXPECT_TRUE(app_list_bubble_presenter->IsShowing());
470
471 // Test that the histogram records 2 total shows.
472 histogram_tester.ExpectTotalCount("Apps.AppListBubbleShowSource", 2);
473
474 // Test that no fullscreen app list metrics were recorded.
475 histogram_tester.ExpectTotalCount("Apps.AppListShowSource", 0);
476}
477
478// Test that tablet mode launcher operations do not record AppListBubble
479// metrics.
Ana Salazaraddeb8c2022-10-18 23:31:47480TEST_F(AppListShowSourceMetricTest, TabletModeDoesNotRecordAppListBubbleShow) {
Alex Newcomerfe776032021-06-16 21:17:08481 base::HistogramTester histogram_tester;
482 // Enable accessibility feature that forces home button to be shown in tablet
483 // mode.
484 Shell::Get()
485 ->accessibility_controller()
486 ->SetTabletModeShelfNavigationButtonsEnabled(true);
487
488 // Go to tablet mode, the tablet mode (non bubble) launcher will show. Create
489 // a test widget so the launcher will show in the background.
490 std::unique_ptr<views::Widget> widget = CreateTestWidget();
491 Shell::Get()->tablet_mode_controller()->SetEnabledForTest(true);
492 auto* app_list_bubble_presenter =
493 Shell::Get()->app_list_controller()->bubble_presenter_for_test();
494 EXPECT_FALSE(app_list_bubble_presenter->IsShowing());
495
496 // Ensure that no AppListBubbleShowSource metric was recorded.
497 histogram_tester.ExpectTotalCount("Apps.AppListBubbleShowSource", 0);
498
499 // Press the Home Button, which hides `widget` and shows the tablet mode
500 // launcher.
501 ClickHomeButton();
502 EXPECT_FALSE(app_list_bubble_presenter->IsShowing());
503
James Cookb661f3802021-09-30 21:43:20504 // Test that no bubble launcher metrics were recorded.
Alex Newcomerfe776032021-06-16 21:17:08505 histogram_tester.ExpectTotalCount("Apps.AppListBubbleShowSource", 0);
506}
507
James Cookb661f3802021-09-30 21:43:20508// Tests that toggling the bubble launcher does not record metrics when the
509// result of the toggle is that the launcher is hidden.
Ana Salazaraddeb8c2022-10-18 23:31:47510TEST_F(AppListShowSourceMetricTest, ToggleDoesNotRecordOnHide) {
Alex Newcomerfe776032021-06-16 21:17:08511 base::HistogramTester histogram_tester;
512 auto* app_list_controller = Shell::Get()->app_list_controller();
513
James Cookb661f3802021-09-30 21:43:20514 // Toggle the app list to show it.
Alex Newcomerfe776032021-06-16 21:17:08515 app_list_controller->ToggleAppList(GetPrimaryDisplayId(),
516 AppListShowSource::kSearchKey,
517 base::TimeTicks::Now());
518 auto* app_list_bubble_presenter =
519 Shell::Get()->app_list_controller()->bubble_presenter_for_test();
520 ASSERT_TRUE(app_list_bubble_presenter->IsShowing());
521
James Cookb661f3802021-09-30 21:43:20522 // Toggle the app list once more, to hide it.
Alex Newcomerfe776032021-06-16 21:17:08523 app_list_controller->ToggleAppList(GetPrimaryDisplayId(),
524 AppListShowSource::kSearchKey,
525 base::TimeTicks::Now());
526 ASSERT_FALSE(app_list_bubble_presenter->IsShowing());
527 // Test that only one show was recorded.
528 histogram_tester.ExpectTotalCount("Apps.AppListBubbleShowSource", 1);
529}
530
James Cookf76e8582022-05-19 23:46:53531using AppListPeriodicMetricsTest = AshTestBase;
Matthew Mourgosa6330ce2021-06-24 04:19:13532
533// Verify that the number of items in the app list are recorded correctly.
James Cookf76e8582022-05-19 23:46:53534TEST_F(AppListPeriodicMetricsTest, PeriodicAppListMetrics_NumberOfApps) {
Matthew Mourgosa6330ce2021-06-24 04:19:13535 base::HistogramTester histogram;
536 histogram.ExpectTotalCount("Apps.AppList.NumberOfApps", 0);
537 histogram.ExpectTotalCount("Apps.AppList.NumberOfRootLevelItems", 0);
538
Toni Barzic80143512021-10-29 15:41:45539 AppListModel* model = AppListModelProvider::Get()->model();
Matthew Mourgosa6330ce2021-06-24 04:19:13540
541 // Add 5 items to the app list.
542 for (int i = 0; i < 5; i++) {
543 model->AddItem(
544 std::make_unique<AppListItem>(base::StringPrintf("app_id_%d", i)));
545 }
546
547 // Check that 5 items are recorded as being in the app list.
548 RecordPeriodicAppListMetrics();
549 histogram.ExpectBucketCount("Apps.AppList.NumberOfApps", 5, 1);
550 histogram.ExpectBucketCount("Apps.AppList.NumberOfRootLevelItems", 5, 1);
551 histogram.ExpectTotalCount("Apps.AppList.NumberOfApps", 1);
552 histogram.ExpectTotalCount("Apps.AppList.NumberOfRootLevelItems", 1);
553
554 // Create a folder and add 3 items to it.
Toni Barzic2fcc80342021-11-04 18:18:45555 const std::string folder_id = "folder_id";
Wen-Chien Wang3ff66252022-07-07 20:21:55556 model->CreateFolderItem(folder_id);
Matthew Mourgosa6330ce2021-06-24 04:19:13557 for (int i = 0; i < 3; i++) {
558 auto item =
559 std::make_unique<AppListItem>(base::StringPrintf("id_in_folder_%d", i));
560 model->AddItemToFolder(std::move(item), folder_id);
561 }
562
563 // Check that the folder and its items are recorded in the metrics.
564 RecordPeriodicAppListMetrics();
565 histogram.ExpectBucketCount("Apps.AppList.NumberOfApps", 8, 1);
566 histogram.ExpectBucketCount("Apps.AppList.NumberOfRootLevelItems", 6, 1);
567}
568
James Cookf76e8582022-05-19 23:46:53569TEST_F(AppListPeriodicMetricsTest, RecordFolderMetrics_ZeroFolders) {
570 base::HistogramTester histogram;
571 GetAppListTestHelper()->model()->PopulateApps(2);
572
573 RecordPeriodicAppListMetrics();
574
575 // 1 sample in the 0 folders bucket.
576 EXPECT_EQ(1, histogram.GetBucketCount("Apps.AppList.NumberOfFolders", 0));
577 // 1 sample in the 0 folders bucket.
578 EXPECT_EQ(
579 1, histogram.GetBucketCount("Apps.AppList.NumberOfNonSystemFolders", 0));
580 // 1 sample in the 0 apps bucket.
581 EXPECT_EQ(1, histogram.GetBucketCount(
582 "Apps.AppList.NumberOfAppsInNonSystemFolders", 0));
583}
584
585TEST_F(AppListPeriodicMetricsTest, RecordFolderMetrics_OneRegularFolder) {
586 base::HistogramTester histogram;
587 GetAppListTestHelper()->model()->CreateAndPopulateFolderWithApps(2);
588
589 RecordPeriodicAppListMetrics();
590
591 // 1 sample in the 1 folder bucket.
592 EXPECT_EQ(1, histogram.GetBucketCount("Apps.AppList.NumberOfFolders", 1));
593 // 1 sample in the 1 folder bucket.
594 EXPECT_EQ(
595 1, histogram.GetBucketCount("Apps.AppList.NumberOfNonSystemFolders", 1));
596 // 1 sample in the 2 apps bucket.
597 EXPECT_EQ(1, histogram.GetBucketCount(
598 "Apps.AppList.NumberOfAppsInNonSystemFolders", 2));
599}
600
James Cook5382b632022-05-20 00:32:20601TEST_F(AppListPeriodicMetricsTest, RecordFolderMetrics_SystemFolder) {
James Cookf76e8582022-05-19 23:46:53602 base::HistogramTester histogram;
603 AppListFolderItem* folder =
604 GetAppListTestHelper()->model()->CreateSingleItemFolder("folder_id",
605 "item_id");
James Cook5382b632022-05-20 00:32:20606 folder->SetIsSystemFolder(true);
James Cookf76e8582022-05-19 23:46:53607
608 RecordPeriodicAppListMetrics();
609
610 // 1 sample in the 1 folder bucket.
611 EXPECT_EQ(1, histogram.GetBucketCount("Apps.AppList.NumberOfFolders", 1));
612 // 1 sample in the 0 folders bucket, because the folder is a system folder.
613 EXPECT_EQ(
614 1, histogram.GetBucketCount("Apps.AppList.NumberOfNonSystemFolders", 0));
615 // 1 sample in the 0 apps bucket, because items in system folders don't count.
616 EXPECT_EQ(1, histogram.GetBucketCount(
617 "Apps.AppList.NumberOfAppsInNonSystemFolders", 0));
618}
619
Matthew Mourgos105a91f2019-05-08 23:30:48620} // namespace ash