OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ash/common/shelf/shelf_application_menu_model.h" | 5 #include "ash/common/shelf/shelf_application_menu_model.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "ash/common/test/test_shelf_item_delegate.h" | 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" | 10 #include "base/macros.h" |
12 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
13 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
14 #include "base/test/histogram_tester.h" | 13 #include "base/test/histogram_tester.h" |
15 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
16 | 15 |
17 namespace ash { | 16 namespace ash { |
18 | 17 |
19 namespace { | 18 namespace { |
20 | 19 |
(...skipping 22 matching lines...) Expand all Loading... |
43 private: | 42 private: |
44 // The ShelfApplicationMenuModel to provide internal access to. Not owned. | 43 // The ShelfApplicationMenuModel to provide internal access to. Not owned. |
45 ShelfApplicationMenuModel* menu_; | 44 ShelfApplicationMenuModel* menu_; |
46 | 45 |
47 DISALLOW_COPY_AND_ASSIGN(ShelfApplicationMenuModelTestAPI); | 46 DISALLOW_COPY_AND_ASSIGN(ShelfApplicationMenuModelTestAPI); |
48 }; | 47 }; |
49 | 48 |
50 // Verifies the menu contents given an empty item list. | 49 // Verifies the menu contents given an empty item list. |
51 TEST(ShelfApplicationMenuModelTest, VerifyContentsWithNoMenuItems) { | 50 TEST(ShelfApplicationMenuModelTest, VerifyContentsWithNoMenuItems) { |
52 base::string16 title = base::ASCIIToUTF16("title"); | 51 base::string16 title = base::ASCIIToUTF16("title"); |
53 ShelfApplicationMenuModel menu(title, ShelfAppMenuItemList(), nullptr); | 52 ShelfApplicationMenuModel menu(title, ShelfItemDelegate::MenuItemList(), |
| 53 nullptr); |
54 // Expect the title with separators. | 54 // Expect the title with separators. |
55 ASSERT_EQ(static_cast<int>(3), menu.GetItemCount()); | 55 ASSERT_EQ(static_cast<int>(3), menu.GetItemCount()); |
56 EXPECT_EQ(ui::MenuModel::TYPE_SEPARATOR, menu.GetTypeAt(0)); | 56 EXPECT_EQ(ui::MenuModel::TYPE_SEPARATOR, menu.GetTypeAt(0)); |
57 EXPECT_EQ(ui::MenuModel::TYPE_COMMAND, menu.GetTypeAt(1)); | 57 EXPECT_EQ(ui::MenuModel::TYPE_COMMAND, menu.GetTypeAt(1)); |
58 EXPECT_EQ(title, menu.GetLabelAt(1)); | 58 EXPECT_EQ(title, menu.GetLabelAt(1)); |
59 EXPECT_FALSE(menu.IsEnabledAt(1)); | 59 EXPECT_FALSE(menu.IsEnabledAt(1)); |
60 EXPECT_EQ(ui::MenuModel::TYPE_SEPARATOR, menu.GetTypeAt(2)); | 60 EXPECT_EQ(ui::MenuModel::TYPE_SEPARATOR, menu.GetTypeAt(2)); |
61 } | 61 } |
62 | 62 |
63 // Verifies the menu contents given a non-empty item list. | 63 // Verifies the menu contents given a non-empty item list. |
64 TEST(ShelfApplicationMenuModelTest, VerifyContentsWithMenuItems) { | 64 TEST(ShelfApplicationMenuModelTest, VerifyContentsWithMenuItems) { |
65 ShelfAppMenuItemList items; | 65 ShelfItemDelegate::MenuItemList items; |
66 base::string16 title1 = base::ASCIIToUTF16("title1"); | 66 base::string16 title1 = base::ASCIIToUTF16("title1"); |
67 base::string16 title2 = base::ASCIIToUTF16("title2"); | 67 base::string16 title2 = base::ASCIIToUTF16("title2"); |
68 base::string16 title3 = base::ASCIIToUTF16("title3"); | 68 base::string16 title3 = base::ASCIIToUTF16("title3"); |
69 items.push_back(base::MakeUnique<ShelfApplicationMenuItem>(0, title1)); | 69 items.push_back(ash::mojom::MenuItem::New()); |
70 items.push_back(base::MakeUnique<ShelfApplicationMenuItem>(1, title2)); | 70 items[0]->label = title1; |
71 items.push_back(base::MakeUnique<ShelfApplicationMenuItem>(2, title3)); | 71 items.push_back(ash::mojom::MenuItem::New()); |
| 72 items[1]->label = title2; |
| 73 items.push_back(ash::mojom::MenuItem::New()); |
| 74 items[2]->label = title3; |
72 | 75 |
73 base::string16 title = base::ASCIIToUTF16("title"); | 76 base::string16 title = base::ASCIIToUTF16("title"); |
74 ShelfApplicationMenuModel menu(title, std::move(items), nullptr); | 77 ShelfApplicationMenuModel menu(title, std::move(items), nullptr); |
75 ShelfApplicationMenuModelTestAPI menu_test_api(&menu); | 78 ShelfApplicationMenuModelTestAPI menu_test_api(&menu); |
76 | 79 |
77 // Expect the title with separators, the enabled items, and another separator. | 80 // Expect the title with separators, the enabled items, and another separator. |
78 ASSERT_EQ(static_cast<int>(7), menu.GetItemCount()); | 81 ASSERT_EQ(static_cast<int>(7), menu.GetItemCount()); |
79 EXPECT_EQ(ui::MenuModel::TYPE_SEPARATOR, menu.GetTypeAt(0)); | 82 EXPECT_EQ(ui::MenuModel::TYPE_SEPARATOR, menu.GetTypeAt(0)); |
80 EXPECT_EQ(ui::MenuModel::TYPE_COMMAND, menu.GetTypeAt(1)); | 83 EXPECT_EQ(ui::MenuModel::TYPE_COMMAND, menu.GetTypeAt(1)); |
81 EXPECT_EQ(title, menu.GetLabelAt(1)); | 84 EXPECT_EQ(title, menu.GetLabelAt(1)); |
(...skipping 11 matching lines...) Expand all Loading... |
93 EXPECT_EQ(ui::MenuModel::TYPE_SEPARATOR, menu.GetTypeAt(6)); | 96 EXPECT_EQ(ui::MenuModel::TYPE_SEPARATOR, menu.GetTypeAt(6)); |
94 } | 97 } |
95 | 98 |
96 // Verifies RecordMenuItemSelectedMetrics uses the correct histogram buckets. | 99 // Verifies RecordMenuItemSelectedMetrics uses the correct histogram buckets. |
97 TEST(ShelfApplicationMenuModelTest, VerifyHistogramBuckets) { | 100 TEST(ShelfApplicationMenuModelTest, VerifyHistogramBuckets) { |
98 const int kCommandId = 3; | 101 const int kCommandId = 3; |
99 const int kNumMenuItemsEnabled = 7; | 102 const int kNumMenuItemsEnabled = 7; |
100 | 103 |
101 base::HistogramTester histogram_tester; | 104 base::HistogramTester histogram_tester; |
102 | 105 |
103 ShelfAppMenuItemList items; | 106 ShelfItemDelegate::MenuItemList items; |
104 ShelfApplicationMenuModel menu(base::ASCIIToUTF16("title"), std::move(items), | 107 ShelfApplicationMenuModel menu(base::ASCIIToUTF16("title"), std::move(items), |
105 nullptr); | 108 nullptr); |
106 ShelfApplicationMenuModelTestAPI menu_test_api(&menu); | 109 ShelfApplicationMenuModelTestAPI menu_test_api(&menu); |
107 menu_test_api.RecordMenuItemSelectedMetrics(kCommandId, kNumMenuItemsEnabled); | 110 menu_test_api.RecordMenuItemSelectedMetrics(kCommandId, kNumMenuItemsEnabled); |
108 | 111 |
109 histogram_tester.ExpectTotalCount(kNumItemsEnabledHistogramName, 1); | 112 histogram_tester.ExpectTotalCount(kNumItemsEnabledHistogramName, 1); |
110 histogram_tester.ExpectBucketCount(kNumItemsEnabledHistogramName, | 113 histogram_tester.ExpectBucketCount(kNumItemsEnabledHistogramName, |
111 kNumMenuItemsEnabled, 1); | 114 kNumMenuItemsEnabled, 1); |
112 | 115 |
113 histogram_tester.ExpectTotalCount(kSelectedMenuItemIndexHistogramName, 1); | 116 histogram_tester.ExpectTotalCount(kSelectedMenuItemIndexHistogramName, 1); |
114 histogram_tester.ExpectBucketCount(kSelectedMenuItemIndexHistogramName, | 117 histogram_tester.ExpectBucketCount(kSelectedMenuItemIndexHistogramName, |
115 kCommandId, 1); | 118 kCommandId, 1); |
116 } | 119 } |
117 | 120 |
118 // Verify histogram data is recorded when ExecuteCommand is called. | 121 // Verify histogram data is recorded when ExecuteCommand is called. |
119 TEST(ShelfApplicationMenuModelTest, VerifyHistogramOnExecute) { | 122 TEST(ShelfApplicationMenuModelTest, VerifyHistogramOnExecute) { |
120 base::HistogramTester histogram_tester; | 123 base::HistogramTester histogram_tester; |
121 | 124 |
122 ShelfAppMenuItemList items; | 125 ShelfItemDelegate::MenuItemList items; |
| 126 items.push_back(ash::mojom::MenuItem::New()); |
| 127 test::TestShelfItemDelegate test_delegate(nullptr); |
123 base::string16 title = base::ASCIIToUTF16("title"); | 128 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); | 129 ShelfApplicationMenuModel menu(title, std::move(items), &test_delegate); |
127 menu.ExecuteCommand(0, 0); | 130 menu.ExecuteCommand(0, 0); |
128 | 131 |
129 histogram_tester.ExpectTotalCount(kNumItemsEnabledHistogramName, 1); | 132 histogram_tester.ExpectTotalCount(kNumItemsEnabledHistogramName, 1); |
130 histogram_tester.ExpectTotalCount(kSelectedMenuItemIndexHistogramName, 1); | 133 histogram_tester.ExpectTotalCount(kSelectedMenuItemIndexHistogramName, 1); |
131 } | 134 } |
132 | 135 |
133 } // namespace ash | 136 } // namespace ash |
OLD | NEW |