Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(402)

Side by Side Diff: ash/common/shelf/shelf_application_menu_model_unittest.cc

Issue 2671923002: mash: Cleanup ash shelf application menu code. (Closed)
Patch Set: Address comments. Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ash/common/shelf/shelf_application_menu_model.cc ('k') | ash/common/shelf/shelf_controller.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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.
4
5 #include "ash/common/shelf/shelf_application_menu_model.h"
6
7 #include <utility>
8
9 #include "ash/public/cpp/shelf_application_menu_item.h"
10 #include "base/macros.h"
11 #include "base/memory/ptr_util.h"
12 #include "base/strings/utf_string_conversions.h"
13 #include "base/test/histogram_tester.h"
14 #include "testing/gtest/include/gtest/gtest.h"
15
16 namespace ash {
17
18 namespace {
19
20 const char kNumItemsEnabledHistogramName[] =
21 "Ash.Shelf.Menu.NumItemsEnabledUponSelection";
22
23 const char kSelectedMenuItemIndexHistogramName[] =
24 "Ash.Shelf.Menu.SelectedMenuItemIndex";
25
26 } // namespace
27
28 // Test API to provide internal access to a ShelfApplicationMenuModel.
29 class ShelfApplicationMenuModelTestAPI {
30 public:
31 // Creates a test api to access the internals of the |menu|.
32 explicit ShelfApplicationMenuModelTestAPI(ShelfApplicationMenuModel* menu)
33 : menu_(menu) {}
34 ~ShelfApplicationMenuModelTestAPI() {}
35
36 // Give public access to this metrics recording functions.
37 void RecordMenuItemSelectedMetrics(int command_id,
38 int num_menu_items_enabled) {
39 menu_->RecordMenuItemSelectedMetrics(command_id, num_menu_items_enabled);
40 }
41
42 private:
43 // The ShelfApplicationMenuModel to provide internal access to. Not owned.
44 ShelfApplicationMenuModel* menu_;
45
46 DISALLOW_COPY_AND_ASSIGN(ShelfApplicationMenuModelTestAPI);
47 };
48
49 // Verifies the menu contents given an empty item list.
50 TEST(ShelfApplicationMenuModelTest, VerifyContentsWithNoMenuItems) {
51 base::string16 title = base::ASCIIToUTF16("title");
52 ShelfApplicationMenuModel menu(title, ShelfAppMenuItemList());
53 // Expect the title with separators.
54 ASSERT_EQ(static_cast<int>(3), menu.GetItemCount());
55 EXPECT_EQ(ui::MenuModel::TYPE_SEPARATOR, menu.GetTypeAt(0));
56 EXPECT_EQ(ui::MenuModel::TYPE_COMMAND, menu.GetTypeAt(1));
57 EXPECT_EQ(title, menu.GetLabelAt(1));
58 EXPECT_FALSE(menu.IsEnabledAt(1));
59 EXPECT_EQ(ui::MenuModel::TYPE_SEPARATOR, menu.GetTypeAt(2));
60 }
61
62 // Verifies the menu contents given a non-empty item list.
63 TEST(ShelfApplicationMenuModelTest, VerifyContentsWithMenuItems) {
64 ShelfAppMenuItemList items;
65 base::string16 title1 = base::ASCIIToUTF16("title1");
66 base::string16 title2 = base::ASCIIToUTF16("title2");
67 base::string16 title3 = base::ASCIIToUTF16("title3");
James Cook 2017/02/07 16:32:24 I like how you used different titles. "Vary your d
msw 2017/02/07 18:19:15 Acknowledged.
68 items.push_back(base::MakeUnique<ShelfApplicationMenuItem>(title1));
69 items.push_back(base::MakeUnique<ShelfApplicationMenuItem>(title2));
70 items.push_back(base::MakeUnique<ShelfApplicationMenuItem>(title3));
71
72 base::string16 title = base::ASCIIToUTF16("title");
73 ShelfApplicationMenuModel menu(title, std::move(items));
74 ShelfApplicationMenuModelTestAPI menu_test_api(&menu);
75
76 // Expect the title with separators, the enabled items, and another separator.
77 ASSERT_EQ(static_cast<int>(7), menu.GetItemCount());
78 EXPECT_EQ(ui::MenuModel::TYPE_SEPARATOR, menu.GetTypeAt(0));
79 EXPECT_EQ(ui::MenuModel::TYPE_COMMAND, menu.GetTypeAt(1));
80 EXPECT_EQ(title, menu.GetLabelAt(1));
81 EXPECT_FALSE(menu.IsEnabledAt(1));
82 EXPECT_EQ(ui::MenuModel::TYPE_SEPARATOR, menu.GetTypeAt(2));
83 EXPECT_EQ(ui::MenuModel::TYPE_COMMAND, menu.GetTypeAt(3));
84 EXPECT_EQ(title1, menu.GetLabelAt(3));
85 EXPECT_TRUE(menu.IsEnabledAt(3));
86 EXPECT_EQ(ui::MenuModel::TYPE_COMMAND, menu.GetTypeAt(4));
87 EXPECT_EQ(title2, menu.GetLabelAt(4));
88 EXPECT_TRUE(menu.IsEnabledAt(4));
89 EXPECT_EQ(ui::MenuModel::TYPE_COMMAND, menu.GetTypeAt(5));
90 EXPECT_EQ(title3, menu.GetLabelAt(5));
91 EXPECT_TRUE(menu.IsEnabledAt(5));
92 EXPECT_EQ(ui::MenuModel::TYPE_SEPARATOR, menu.GetTypeAt(6));
93 }
94
95 // Verifies RecordMenuItemSelectedMetrics uses the correct histogram buckets.
96 TEST(ShelfApplicationMenuModelTest, VerifyHistogramBuckets) {
97 const int kCommandId = 3;
98 const int kNumMenuItemsEnabled = 7;
99
100 base::HistogramTester histogram_tester;
101
102 ShelfAppMenuItemList items;
103 ShelfApplicationMenuModel menu(base::ASCIIToUTF16("title"), std::move(items));
104 ShelfApplicationMenuModelTestAPI menu_test_api(&menu);
105 menu_test_api.RecordMenuItemSelectedMetrics(kCommandId, kNumMenuItemsEnabled);
106
107 histogram_tester.ExpectTotalCount(kNumItemsEnabledHistogramName, 1);
108 histogram_tester.ExpectBucketCount(kNumItemsEnabledHistogramName,
109 kNumMenuItemsEnabled, 1);
110
111 histogram_tester.ExpectTotalCount(kSelectedMenuItemIndexHistogramName, 1);
112 histogram_tester.ExpectBucketCount(kSelectedMenuItemIndexHistogramName,
113 kCommandId, 1);
114 }
115
116 // Verify histogram data is recorded when ExecuteCommand is called.
117 TEST(ShelfApplicationMenuModelTest, VerifyHistogramOnExecute) {
118 base::HistogramTester histogram_tester;
119
120 ShelfAppMenuItemList items;
121 base::string16 title = base::ASCIIToUTF16("title");
122 items.push_back(base::MakeUnique<ShelfApplicationMenuItem>(title));
123 ShelfApplicationMenuModel menu(title, std::move(items));
124 menu.ExecuteCommand(0, 0);
125
126 histogram_tester.ExpectTotalCount(kNumItemsEnabledHistogramName, 1);
127 histogram_tester.ExpectTotalCount(kSelectedMenuItemIndexHistogramName, 1);
128 }
129
130 } // namespace ash
OLDNEW
« no previous file with comments | « ash/common/shelf/shelf_application_menu_model.cc ('k') | ash/common/shelf/shelf_controller.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698