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

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

Issue 2734653002: chromeos: Move files in //ash/common to //ash (Closed)
Patch Set: fix a11y tests, fix docs Created 3 years, 9 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
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/common/test/test_shelf_item_delegate.h"
10 #include "ash/public/cpp/shelf_application_menu_item.h"
11 #include "base/macros.h"
12 #include "base/memory/ptr_util.h"
13 #include "base/strings/utf_string_conversions.h"
14 #include "base/test/histogram_tester.h"
15 #include "testing/gtest/include/gtest/gtest.h"
16
17 namespace ash {
18
19 namespace {
20
21 const char kNumItemsEnabledHistogramName[] =
22 "Ash.Shelf.Menu.NumItemsEnabledUponSelection";
23
24 const char kSelectedMenuItemIndexHistogramName[] =
25 "Ash.Shelf.Menu.SelectedMenuItemIndex";
26
27 } // namespace
28
29 // Test API to provide internal access to a ShelfApplicationMenuModel.
30 class ShelfApplicationMenuModelTestAPI {
31 public:
32 // Creates a test api to access the internals of the |menu|.
33 explicit ShelfApplicationMenuModelTestAPI(ShelfApplicationMenuModel* menu)
34 : menu_(menu) {}
35 ~ShelfApplicationMenuModelTestAPI() {}
36
37 // Give public access to this metrics recording functions.
38 void RecordMenuItemSelectedMetrics(int command_id,
39 int num_menu_items_enabled) {
40 menu_->RecordMenuItemSelectedMetrics(command_id, num_menu_items_enabled);
41 }
42
43 private:
44 // The ShelfApplicationMenuModel to provide internal access to. Not owned.
45 ShelfApplicationMenuModel* menu_;
46
47 DISALLOW_COPY_AND_ASSIGN(ShelfApplicationMenuModelTestAPI);
48 };
49
50 // Verifies the menu contents given an empty item list.
51 TEST(ShelfApplicationMenuModelTest, VerifyContentsWithNoMenuItems) {
52 base::string16 title = base::ASCIIToUTF16("title");
53 ShelfApplicationMenuModel menu(title, ShelfAppMenuItemList(), nullptr);
54 // Expect the title with separators.
55 ASSERT_EQ(static_cast<int>(3), menu.GetItemCount());
56 EXPECT_EQ(ui::MenuModel::TYPE_SEPARATOR, menu.GetTypeAt(0));
57 EXPECT_EQ(ui::MenuModel::TYPE_COMMAND, menu.GetTypeAt(1));
58 EXPECT_EQ(title, menu.GetLabelAt(1));
59 EXPECT_FALSE(menu.IsEnabledAt(1));
60 EXPECT_EQ(ui::MenuModel::TYPE_SEPARATOR, menu.GetTypeAt(2));
61 }
62
63 // Verifies the menu contents given a non-empty item list.
64 TEST(ShelfApplicationMenuModelTest, VerifyContentsWithMenuItems) {
65 ShelfAppMenuItemList items;
66 base::string16 title1 = base::ASCIIToUTF16("title1");
67 base::string16 title2 = base::ASCIIToUTF16("title2");
68 base::string16 title3 = base::ASCIIToUTF16("title3");
69 items.push_back(base::MakeUnique<ShelfApplicationMenuItem>(0, title1));
70 items.push_back(base::MakeUnique<ShelfApplicationMenuItem>(1, title2));
71 items.push_back(base::MakeUnique<ShelfApplicationMenuItem>(2, title3));
72
73 base::string16 title = base::ASCIIToUTF16("title");
74 ShelfApplicationMenuModel menu(title, std::move(items), nullptr);
75 ShelfApplicationMenuModelTestAPI menu_test_api(&menu);
76
77 // Expect the title with separators, the enabled items, and another separator.
78 ASSERT_EQ(static_cast<int>(7), menu.GetItemCount());
79 EXPECT_EQ(ui::MenuModel::TYPE_SEPARATOR, menu.GetTypeAt(0));
80 EXPECT_EQ(ui::MenuModel::TYPE_COMMAND, menu.GetTypeAt(1));
81 EXPECT_EQ(title, menu.GetLabelAt(1));
82 EXPECT_FALSE(menu.IsEnabledAt(1));
83 EXPECT_EQ(ui::MenuModel::TYPE_SEPARATOR, menu.GetTypeAt(2));
84 EXPECT_EQ(ui::MenuModel::TYPE_COMMAND, menu.GetTypeAt(3));
85 EXPECT_EQ(title1, menu.GetLabelAt(3));
86 EXPECT_TRUE(menu.IsEnabledAt(3));
87 EXPECT_EQ(ui::MenuModel::TYPE_COMMAND, menu.GetTypeAt(4));
88 EXPECT_EQ(title2, menu.GetLabelAt(4));
89 EXPECT_TRUE(menu.IsEnabledAt(4));
90 EXPECT_EQ(ui::MenuModel::TYPE_COMMAND, menu.GetTypeAt(5));
91 EXPECT_EQ(title3, menu.GetLabelAt(5));
92 EXPECT_TRUE(menu.IsEnabledAt(5));
93 EXPECT_EQ(ui::MenuModel::TYPE_SEPARATOR, menu.GetTypeAt(6));
94 }
95
96 // Verifies RecordMenuItemSelectedMetrics uses the correct histogram buckets.
97 TEST(ShelfApplicationMenuModelTest, VerifyHistogramBuckets) {
98 const int kCommandId = 3;
99 const int kNumMenuItemsEnabled = 7;
100
101 base::HistogramTester histogram_tester;
102
103 ShelfAppMenuItemList items;
104 ShelfApplicationMenuModel menu(base::ASCIIToUTF16("title"), std::move(items),
105 nullptr);
106 ShelfApplicationMenuModelTestAPI menu_test_api(&menu);
107 menu_test_api.RecordMenuItemSelectedMetrics(kCommandId, kNumMenuItemsEnabled);
108
109 histogram_tester.ExpectTotalCount(kNumItemsEnabledHistogramName, 1);
110 histogram_tester.ExpectBucketCount(kNumItemsEnabledHistogramName,
111 kNumMenuItemsEnabled, 1);
112
113 histogram_tester.ExpectTotalCount(kSelectedMenuItemIndexHistogramName, 1);
114 histogram_tester.ExpectBucketCount(kSelectedMenuItemIndexHistogramName,
115 kCommandId, 1);
116 }
117
118 // Verify histogram data is recorded when ExecuteCommand is called.
119 TEST(ShelfApplicationMenuModelTest, VerifyHistogramOnExecute) {
120 base::HistogramTester histogram_tester;
121
122 ShelfAppMenuItemList items;
123 base::string16 title = base::ASCIIToUTF16("title");
124 items.push_back(base::MakeUnique<ShelfApplicationMenuItem>(0, title));
125 test::TestShelfItemDelegate test_delegate(nullptr);
126 ShelfApplicationMenuModel menu(title, std::move(items), &test_delegate);
127 menu.ExecuteCommand(0, 0);
128
129 histogram_tester.ExpectTotalCount(kNumItemsEnabledHistogramName, 1);
130 histogram_tester.ExpectTotalCount(kSelectedMenuItemIndexHistogramName, 1);
131 }
132
133 } // namespace ash
OLDNEW
« no previous file with comments | « ash/common/shelf/shelf_application_menu_model.cc ('k') | ash/common/shelf/shelf_background_animator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698