OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 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 "chrome/app/chrome_command_ids.h" |
| 6 #include "chrome/browser/renderer_context_menu/arc_app_menu_observer_chromeos.h" |
| 7 #include "testing/gtest/include/gtest/gtest.h" |
| 8 |
| 9 TEST(ArcAppMenuObserverTest, TestGetIndexForCommandId) { |
| 10 // All tests in this file assume that 3 and 10 IDC command IDs are reserved |
| 11 // for the main and sub menus, respectively. |
| 12 ASSERT_EQ( |
| 13 3, IDC_CONTENT_CONTEXT_ARC_APP_LAST - IDC_CONTENT_CONTEXT_ARC_APP1 + 1); |
| 14 ASSERT_EQ(10, IDC_CONTENT_CONTEXT_ARC_SUB_APP_LAST - |
| 15 IDC_CONTENT_CONTEXT_ARC_SUB_APP1 + 1); |
| 16 |
| 17 EXPECT_EQ(0, ArcAppMenuObserver::GetIndexForCommandIdForTesting( |
| 18 IDC_CONTENT_CONTEXT_ARC_APP1)); |
| 19 EXPECT_EQ(1, ArcAppMenuObserver::GetIndexForCommandIdForTesting( |
| 20 IDC_CONTENT_CONTEXT_ARC_APP2)); |
| 21 EXPECT_EQ(2, ArcAppMenuObserver::GetIndexForCommandIdForTesting( |
| 22 IDC_CONTENT_CONTEXT_ARC_APP3)); |
| 23 EXPECT_EQ(-1, ArcAppMenuObserver::GetIndexForCommandIdForTesting( |
| 24 IDC_CONTENT_CONTEXT_ARC_SUB_MENU)); |
| 25 EXPECT_EQ(2, ArcAppMenuObserver::GetIndexForCommandIdForTesting( |
| 26 IDC_CONTENT_CONTEXT_ARC_SUB_APP1)); // not 3 |
| 27 EXPECT_EQ(3, ArcAppMenuObserver::GetIndexForCommandIdForTesting( |
| 28 IDC_CONTENT_CONTEXT_ARC_SUB_APP2)); |
| 29 EXPECT_EQ(4, ArcAppMenuObserver::GetIndexForCommandIdForTesting( |
| 30 IDC_CONTENT_CONTEXT_ARC_SUB_APP3)); |
| 31 EXPECT_EQ(5, ArcAppMenuObserver::GetIndexForCommandIdForTesting( |
| 32 IDC_CONTENT_CONTEXT_ARC_SUB_APP4)); |
| 33 EXPECT_EQ(6, ArcAppMenuObserver::GetIndexForCommandIdForTesting( |
| 34 IDC_CONTENT_CONTEXT_ARC_SUB_APP5)); |
| 35 EXPECT_EQ(7, ArcAppMenuObserver::GetIndexForCommandIdForTesting( |
| 36 IDC_CONTENT_CONTEXT_ARC_SUB_APP6)); |
| 37 EXPECT_EQ(8, ArcAppMenuObserver::GetIndexForCommandIdForTesting( |
| 38 IDC_CONTENT_CONTEXT_ARC_SUB_APP7)); |
| 39 EXPECT_EQ(9, ArcAppMenuObserver::GetIndexForCommandIdForTesting( |
| 40 IDC_CONTENT_CONTEXT_ARC_SUB_APP8)); |
| 41 EXPECT_EQ(10, ArcAppMenuObserver::GetIndexForCommandIdForTesting( |
| 42 IDC_CONTENT_CONTEXT_ARC_SUB_APP9)); |
| 43 EXPECT_EQ(11, ArcAppMenuObserver::GetIndexForCommandIdForTesting( |
| 44 IDC_CONTENT_CONTEXT_ARC_SUB_APP10)); |
| 45 |
| 46 // Test with unknown ID. |
| 47 EXPECT_EQ(-1, ArcAppMenuObserver::GetIndexForCommandIdForTesting( |
| 48 IDC_CONTENT_CONTEXT_SEARCHWEBFOR)); |
| 49 } |
| 50 |
| 51 TEST(ArcAppMenuObserverTest, TestGetCommandIdsToEnable) { |
| 52 std::set<int> result = ArcAppMenuObserver::GetCommandIdsToEnableForTesting(0); |
| 53 EXPECT_EQ(0U, result.size()); |
| 54 |
| 55 result = ArcAppMenuObserver::GetCommandIdsToEnableForTesting(1); |
| 56 EXPECT_EQ(1U, result.size()); |
| 57 EXPECT_EQ(1U, result.count(IDC_CONTENT_CONTEXT_ARC_APP1)); |
| 58 |
| 59 result = ArcAppMenuObserver::GetCommandIdsToEnableForTesting(2); |
| 60 EXPECT_EQ(2U, result.size()); |
| 61 EXPECT_EQ(1U, result.count(IDC_CONTENT_CONTEXT_ARC_APP1)); |
| 62 EXPECT_EQ(1U, result.count(IDC_CONTENT_CONTEXT_ARC_APP2)); |
| 63 |
| 64 result = ArcAppMenuObserver::GetCommandIdsToEnableForTesting(3); |
| 65 EXPECT_EQ(3U, result.size()); |
| 66 EXPECT_EQ(1U, result.count(IDC_CONTENT_CONTEXT_ARC_APP1)); |
| 67 EXPECT_EQ(1U, result.count(IDC_CONTENT_CONTEXT_ARC_APP2)); |
| 68 EXPECT_EQ(1U, result.count(IDC_CONTENT_CONTEXT_ARC_APP3)); |
| 69 |
| 70 // Test if app names will overflow to the sub menu. |
| 71 result = ArcAppMenuObserver::GetCommandIdsToEnableForTesting(4); |
| 72 EXPECT_EQ(5U, result.size()); // app names and "More" |
| 73 EXPECT_EQ(1U, result.count(IDC_CONTENT_CONTEXT_ARC_APP1)); |
| 74 EXPECT_EQ(1U, result.count(IDC_CONTENT_CONTEXT_ARC_APP2)); |
| 75 // In this case, IDC_CONTENT_CONTEXT_ARC_APP3 should be hidden. |
| 76 EXPECT_EQ(1U, result.count(IDC_CONTENT_CONTEXT_ARC_SUB_MENU)); |
| 77 EXPECT_EQ(1U, result.count(IDC_CONTENT_CONTEXT_ARC_SUB_APP1)); |
| 78 EXPECT_EQ(1U, result.count(IDC_CONTENT_CONTEXT_ARC_SUB_APP2)); |
| 79 |
| 80 result = ArcAppMenuObserver::GetCommandIdsToEnableForTesting(11); |
| 81 EXPECT_EQ(12U, result.size()); |
| 82 EXPECT_EQ(1U, result.count(IDC_CONTENT_CONTEXT_ARC_APP1)); |
| 83 EXPECT_EQ(1U, result.count(IDC_CONTENT_CONTEXT_ARC_APP2)); |
| 84 EXPECT_EQ(1U, result.count(IDC_CONTENT_CONTEXT_ARC_SUB_MENU)); |
| 85 for (size_t i = 0; i < 9; ++i) { |
| 86 EXPECT_EQ(1U, result.count(IDC_CONTENT_CONTEXT_ARC_SUB_APP1 + i)) << i; |
| 87 } |
| 88 |
| 89 // The main and sub menus can show up to 12 (=3+10-1) app names. |
| 90 result = ArcAppMenuObserver::GetCommandIdsToEnableForTesting(12); |
| 91 EXPECT_EQ(13U, result.size()); |
| 92 EXPECT_EQ(1U, result.count(IDC_CONTENT_CONTEXT_ARC_APP1)); |
| 93 EXPECT_EQ(1U, result.count(IDC_CONTENT_CONTEXT_ARC_APP2)); |
| 94 EXPECT_EQ(1U, result.count(IDC_CONTENT_CONTEXT_ARC_SUB_MENU)); |
| 95 for (size_t i = 0; i < 10; ++i) { |
| 96 EXPECT_EQ(1U, result.count(IDC_CONTENT_CONTEXT_ARC_SUB_APP1 + i)) << i; |
| 97 } |
| 98 |
| 99 result = ArcAppMenuObserver::GetCommandIdsToEnableForTesting(13); |
| 100 EXPECT_EQ(13U, result.size()); // still 13 |
| 101 EXPECT_EQ(1U, result.count(IDC_CONTENT_CONTEXT_ARC_APP1)); |
| 102 EXPECT_EQ(1U, result.count(IDC_CONTENT_CONTEXT_ARC_APP2)); |
| 103 EXPECT_EQ(1U, result.count(IDC_CONTENT_CONTEXT_ARC_SUB_MENU)); |
| 104 for (size_t i = 0; i < 10; ++i) { // still 10 |
| 105 EXPECT_EQ(1U, result.count(IDC_CONTENT_CONTEXT_ARC_SUB_APP1 + i)) << i; |
| 106 } |
| 107 |
| 108 result = ArcAppMenuObserver::GetCommandIdsToEnableForTesting(1000); |
| 109 EXPECT_EQ(13U, result.size()); // still 13 |
| 110 EXPECT_EQ(1U, result.count(IDC_CONTENT_CONTEXT_ARC_APP1)); |
| 111 EXPECT_EQ(1U, result.count(IDC_CONTENT_CONTEXT_ARC_APP2)); |
| 112 EXPECT_EQ(1U, result.count(IDC_CONTENT_CONTEXT_ARC_SUB_MENU)); |
| 113 for (size_t i = 0; i < 10; ++i) { // still 10 |
| 114 EXPECT_EQ(1U, result.count(IDC_CONTENT_CONTEXT_ARC_SUB_APP1 + i)) << i; |
| 115 } |
| 116 } |
| 117 |
| 118 TEST(ArcAppMenuObserverTest, TestGetCommandIdsToDisable) { |
| 119 std::set<int> result = |
| 120 ArcAppMenuObserver::GetCommandIdsToDisableForTesting(0); |
| 121 // 3 items for the main menu, 1 item for "More", and 10 items for the sub |
| 122 // menu. 14 in total. |
| 123 EXPECT_EQ(14U, result.size()); |
| 124 |
| 125 result = ArcAppMenuObserver::GetCommandIdsToDisableForTesting(1); |
| 126 EXPECT_EQ(13U, result.size()); |
| 127 EXPECT_EQ(1U, result.count(IDC_CONTENT_CONTEXT_ARC_APP2)); |
| 128 EXPECT_EQ(1U, result.count(IDC_CONTENT_CONTEXT_ARC_APP3)); |
| 129 EXPECT_EQ(1U, result.count(IDC_CONTENT_CONTEXT_ARC_SUB_MENU)); |
| 130 for (size_t i = 0; i < 10; ++i) { |
| 131 EXPECT_EQ(1U, result.count(IDC_CONTENT_CONTEXT_ARC_SUB_APP1 + i)) << i; |
| 132 } |
| 133 |
| 134 result = ArcAppMenuObserver::GetCommandIdsToDisableForTesting(2); |
| 135 EXPECT_EQ(12U, result.size()); |
| 136 EXPECT_EQ(1U, result.count(IDC_CONTENT_CONTEXT_ARC_APP3)); |
| 137 EXPECT_EQ(1U, result.count(IDC_CONTENT_CONTEXT_ARC_SUB_MENU)); |
| 138 for (size_t i = 0; i < 10; ++i) { |
| 139 EXPECT_EQ(1U, result.count(IDC_CONTENT_CONTEXT_ARC_SUB_APP1 + i)) << i; |
| 140 } |
| 141 |
| 142 result = ArcAppMenuObserver::GetCommandIdsToDisableForTesting(3); |
| 143 EXPECT_EQ(11U, result.size()); |
| 144 EXPECT_EQ(1U, result.count(IDC_CONTENT_CONTEXT_ARC_SUB_MENU)); |
| 145 for (size_t i = 0; i < 10; ++i) { |
| 146 EXPECT_EQ(1U, result.count(IDC_CONTENT_CONTEXT_ARC_SUB_APP1 + i)) << i; |
| 147 } |
| 148 |
| 149 result = ArcAppMenuObserver::GetCommandIdsToDisableForTesting(4); |
| 150 // The first 2 items in the main menu, "More", and the first 2 items in the |
| 151 // sub menu are enalbed, hence 9 (=14-(2+1+2)). |
| 152 EXPECT_EQ(9U, result.size()); |
| 153 EXPECT_EQ(1U, result.count(IDC_CONTENT_CONTEXT_ARC_APP3)); |
| 154 for (size_t i = 2; i < 10; ++i) { |
| 155 EXPECT_EQ(1U, result.count(IDC_CONTENT_CONTEXT_ARC_SUB_APP1 + i)) << i; |
| 156 } |
| 157 |
| 158 result = ArcAppMenuObserver::GetCommandIdsToDisableForTesting(11); |
| 159 EXPECT_EQ(2U, result.size()); |
| 160 EXPECT_EQ(1U, result.count(IDC_CONTENT_CONTEXT_ARC_APP3)); |
| 161 EXPECT_EQ(1U, result.count(IDC_CONTENT_CONTEXT_ARC_SUB_APP10)); |
| 162 |
| 163 result = ArcAppMenuObserver::GetCommandIdsToDisableForTesting(12); |
| 164 EXPECT_EQ(1U, result.size()); |
| 165 EXPECT_EQ(1U, result.count(IDC_CONTENT_CONTEXT_ARC_APP3)); |
| 166 |
| 167 result = ArcAppMenuObserver::GetCommandIdsToDisableForTesting(13); |
| 168 EXPECT_EQ(1U, result.size()); |
| 169 EXPECT_EQ(1U, result.count(IDC_CONTENT_CONTEXT_ARC_APP3)); |
| 170 |
| 171 result = ArcAppMenuObserver::GetCommandIdsToDisableForTesting(1000); |
| 172 EXPECT_EQ(1U, result.size()); |
| 173 EXPECT_EQ(1U, result.count(IDC_CONTENT_CONTEXT_ARC_APP3)); |
| 174 } |
| 175 |
| 176 TEST(ArcAppMenuObserverTest, TestGetCommandIdsToEnableDisable) { |
| 177 for (int apps = 0; apps < 20; ++apps) { |
| 178 const size_t enabled = |
| 179 ArcAppMenuObserver::GetCommandIdsToEnableForTesting(apps).size(); |
| 180 const size_t disabled = |
| 181 ArcAppMenuObserver::GetCommandIdsToDisableForTesting(apps).size(); |
| 182 EXPECT_EQ(14U, enabled + disabled) << apps; |
| 183 } |
| 184 } |
OLD | NEW |