1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/ui/ash/launcher/launcher_application_menu_item_model.h"
7 #include "base/macros.h"
8 #include "base/test/histogram_tester.h"
9 #include "chrome/browser/ui/ash/launcher/test/launcher_application_menu_item_model_test_api.h"
10 #include "chrome/browser/ui/ash/launcher/test/test_chrome_launcher_app_menu_item.h"
11 #include "testing/gtest/include/gtest/gtest.h"
15 const char kNumItemsEnabledHistogramName
[] =
16 "Ash.Shelf.Menu.NumItemsEnabledUponSelection";
18 const char kSelectedMenuItemIndexHistogramName
[] =
19 "Ash.Shelf.Menu.SelectedMenuItemIndex";
23 // Verifies LauncherApplicationMenuItemModel::GetNumMenuItemsEnabled() return
24 // value when there are zero menu items.
25 TEST(LauncherApplicationMenuItemModelTest
,
26 VerifyGetNumMenuItemsEnabledWithNoMenuItems
) {
27 ChromeLauncherAppMenuItems menu_items
;
28 LauncherApplicationMenuItemModel
menu_model(menu_items
.Pass());
29 LauncherApplicationMenuItemModelTestAPI
menu_model_test_api(&menu_model
);
31 EXPECT_EQ(0, menu_model_test_api
.GetNumMenuItemsEnabled());
34 // Verifies LauncherApplicationMenuItemModel::GetNumMenuItemsEnabled() return
35 // value when there are a mix of enabled and disabled menu items.
36 TEST(LauncherApplicationMenuItemModelTest
,
37 VerifyGetNumMenuItemsEnabledWithMenuItems
) {
38 ChromeLauncherAppMenuItems menu_items
;
40 TestChromeLauncherAppMenuItem
* enabled_menu_item_1
=
41 new TestChromeLauncherAppMenuItem();
42 enabled_menu_item_1
->set_is_enabled(true);
44 TestChromeLauncherAppMenuItem
* enabled_menu_item_2
=
45 new TestChromeLauncherAppMenuItem();
46 enabled_menu_item_2
->set_is_enabled(true);
48 TestChromeLauncherAppMenuItem
* enabled_menu_item_3
=
49 new TestChromeLauncherAppMenuItem();
50 enabled_menu_item_3
->set_is_enabled(true);
52 TestChromeLauncherAppMenuItem
* disabled_menu_item_1
=
53 new TestChromeLauncherAppMenuItem();
54 disabled_menu_item_1
->set_is_enabled(false);
56 menu_items
.push_back(enabled_menu_item_1
);
57 menu_items
.push_back(disabled_menu_item_1
);
58 menu_items
.push_back(enabled_menu_item_2
);
59 menu_items
.push_back(enabled_menu_item_3
);
61 LauncherApplicationMenuItemModel
menu_model(menu_items
.Pass());
62 LauncherApplicationMenuItemModelTestAPI
menu_model_test_api(&menu_model
);
64 EXPECT_EQ(3, menu_model_test_api
.GetNumMenuItemsEnabled());
67 // Verifies the correct histogram buckets are recorded for
68 // LauncherApplicationMenuItemModel::RecordMenuItemSelectedMetrics.
69 TEST(LauncherApplicationMenuItemModelTest
,
70 VerifyHistogramBucketsRecordedByRecordMenuItemSelectedMetrics
) {
71 const int kCommandId
= 3;
72 const int kNumMenuItemsEnabled
= 7;
74 base::HistogramTester histogram_tester
;
76 ChromeLauncherAppMenuItems menu_items
;
77 LauncherApplicationMenuItemModel
menu_model(menu_items
.Pass());
78 LauncherApplicationMenuItemModelTestAPI
menu_model_test_api(&menu_model
);
79 menu_model_test_api
.RecordMenuItemSelectedMetrics(kCommandId
,
80 kNumMenuItemsEnabled
);
82 histogram_tester
.ExpectTotalCount(kNumItemsEnabledHistogramName
, 1);
83 histogram_tester
.ExpectBucketCount(kNumItemsEnabledHistogramName
,
84 kNumMenuItemsEnabled
, 1);
86 histogram_tester
.ExpectTotalCount(kSelectedMenuItemIndexHistogramName
, 1);
87 histogram_tester
.ExpectBucketCount(kSelectedMenuItemIndexHistogramName
,
91 // Verify histogram data is recorded when
92 // LauncherApplicationMenuItemModel::ExecuteCommand is called.
93 TEST(LauncherApplicationMenuItemModelTest
,
94 VerifyHistogramDataIsRecordedWhenExecuteCommandIsCalled
) {
95 const int kCommandId
= 0;
98 ChromeLauncherAppMenuItems menu_items
;
99 TestChromeLauncherAppMenuItem
* menu_item
=
100 new TestChromeLauncherAppMenuItem();
101 menu_item
->set_is_enabled(true);
102 menu_items
.push_back(menu_item
);
104 base::HistogramTester histogram_tester
;
106 LauncherApplicationMenuItemModel
menu_model(menu_items
.Pass());
107 menu_model
.ExecuteCommand(kCommandId
, kFlags
);
109 histogram_tester
.ExpectTotalCount(kNumItemsEnabledHistogramName
, 1);
110 histogram_tester
.ExpectTotalCount(kSelectedMenuItemIndexHistogramName
, 1);