| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/extensions/extension_context_menu_model.h" | 5 #include "chrome/browser/extensions/extension_context_menu_model.h" |
| 6 | 6 |
| 7 #include "chrome/browser/extensions/api/extension_action/extension_action_api.h" | 7 #include "chrome/browser/extensions/api/extension_action/extension_action_api.h" |
| 8 #include "chrome/browser/extensions/extension_service.h" | 8 #include "chrome/browser/extensions/extension_service.h" |
| 9 #include "chrome/browser/extensions/extension_service_test_base.h" | 9 #include "chrome/browser/extensions/extension_service_test_base.h" |
| 10 #include "chrome/browser/extensions/menu_manager.h" | 10 #include "chrome/browser/extensions/menu_manager.h" |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 MenuManager* manager = static_cast<MenuManager*>( | 165 MenuManager* manager = static_cast<MenuManager*>( |
| 166 (MenuManagerFactory::GetInstance()->SetTestingFactoryAndUse( | 166 (MenuManagerFactory::GetInstance()->SetTestingFactoryAndUse( |
| 167 profile(), | 167 profile(), |
| 168 &MenuManagerFactory::BuildServiceInstanceForTesting))); | 168 &MenuManagerFactory::BuildServiceInstanceForTesting))); |
| 169 ASSERT_TRUE(manager); | 169 ASSERT_TRUE(manager); |
| 170 | 170 |
| 171 scoped_refptr<ExtensionContextMenuModel> menu( | 171 scoped_refptr<ExtensionContextMenuModel> menu( |
| 172 new ExtensionContextMenuModel(extension.get(), browser.get())); | 172 new ExtensionContextMenuModel(extension.get(), browser.get())); |
| 173 | 173 |
| 174 // There should be no extension items yet. | 174 // There should be no extension items yet. |
| 175 EXPECT_EQ(0, CountExtensionItems(menu)); | 175 EXPECT_EQ(0, CountExtensionItems(menu.get())); |
| 176 | 176 |
| 177 // Add a browser action menu item for |extension| to |manager|. | 177 // Add a browser action menu item for |extension| to |manager|. |
| 178 AddContextItemAndRefreshModel( | 178 AddContextItemAndRefreshModel( |
| 179 manager, extension.get(), MenuItem::BROWSER_ACTION, menu); | 179 manager, extension.get(), MenuItem::BROWSER_ACTION, menu.get()); |
| 180 | 180 |
| 181 // Since |extension| has a page action, the browser action menu item should | 181 // Since |extension| has a page action, the browser action menu item should |
| 182 // not be present. | 182 // not be present. |
| 183 EXPECT_EQ(0, CountExtensionItems(menu)); | 183 EXPECT_EQ(0, CountExtensionItems(menu.get())); |
| 184 | 184 |
| 185 // Add a page action menu item and reset the context menu. | 185 // Add a page action menu item and reset the context menu. |
| 186 AddContextItemAndRefreshModel( | 186 AddContextItemAndRefreshModel( |
| 187 manager, extension.get(), MenuItem::PAGE_ACTION, menu); | 187 manager, extension.get(), MenuItem::PAGE_ACTION, menu.get()); |
| 188 | 188 |
| 189 // The page action item should be present because |extension| has a page | 189 // The page action item should be present because |extension| has a page |
| 190 // action. | 190 // action. |
| 191 EXPECT_EQ(1, CountExtensionItems(menu)); | 191 EXPECT_EQ(1, CountExtensionItems(menu.get())); |
| 192 | 192 |
| 193 // Create more page action items to test top level menu item limitations. | 193 // Create more page action items to test top level menu item limitations. |
| 194 for (int i = 0; i < api::context_menus::ACTION_MENU_TOP_LEVEL_LIMIT; ++i) | 194 for (int i = 0; i < api::context_menus::ACTION_MENU_TOP_LEVEL_LIMIT; ++i) |
| 195 AddContextItemAndRefreshModel( | 195 AddContextItemAndRefreshModel( |
| 196 manager, extension.get(), MenuItem::PAGE_ACTION, menu); | 196 manager, extension.get(), MenuItem::PAGE_ACTION, menu.get()); |
| 197 | 197 |
| 198 // The menu should only have a limited number of extension items, since they | 198 // The menu should only have a limited number of extension items, since they |
| 199 // are all top level items, and we limit the number of top level extension | 199 // are all top level items, and we limit the number of top level extension |
| 200 // items. | 200 // items. |
| 201 EXPECT_EQ(api::context_menus::ACTION_MENU_TOP_LEVEL_LIMIT, | 201 EXPECT_EQ(api::context_menus::ACTION_MENU_TOP_LEVEL_LIMIT, |
| 202 CountExtensionItems(menu)); | 202 CountExtensionItems(menu.get())); |
| 203 | 203 |
| 204 AddContextItemAndRefreshModel( | 204 AddContextItemAndRefreshModel( |
| 205 manager, extension.get(), MenuItem::PAGE_ACTION, menu); | 205 manager, extension.get(), MenuItem::PAGE_ACTION, menu.get()); |
| 206 | 206 |
| 207 // Adding another top level item should not increase the count. | 207 // Adding another top level item should not increase the count. |
| 208 EXPECT_EQ(api::context_menus::ACTION_MENU_TOP_LEVEL_LIMIT, | 208 EXPECT_EQ(api::context_menus::ACTION_MENU_TOP_LEVEL_LIMIT, |
| 209 CountExtensionItems(menu)); | 209 CountExtensionItems(menu.get())); |
| 210 } | 210 } |
| 211 | 211 |
| 212 // Test that the "show" and "hide" menu items appear correctly in the extension | 212 // Test that the "show" and "hide" menu items appear correctly in the extension |
| 213 // context menu. | 213 // context menu. |
| 214 TEST_F(ExtensionContextMenuModelTest, ExtensionContextMenuShowAndHide) { | 214 TEST_F(ExtensionContextMenuModelTest, ExtensionContextMenuShowAndHide) { |
| 215 InitializeEmptyExtensionService(); | 215 InitializeEmptyExtensionService(); |
| 216 scoped_refptr<const Extension> page_action = | 216 scoped_refptr<const Extension> page_action = |
| 217 BuildExtension("page_action_extension", manifest_keys::kPageAction); | 217 BuildExtension("page_action_extension", manifest_keys::kPageAction); |
| 218 ASSERT_TRUE(page_action.get()); | 218 ASSERT_TRUE(page_action.get()); |
| 219 scoped_refptr<const Extension> browser_action = | 219 scoped_refptr<const Extension> browser_action = |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 266 // Hide the browser action. This should mean the string is "show". | 266 // Hide the browser action. This should mean the string is "show". |
| 267 ExtensionActionAPI::SetBrowserActionVisibility( | 267 ExtensionActionAPI::SetBrowserActionVisibility( |
| 268 prefs, browser_action->id(), false); | 268 prefs, browser_action->id(), false); |
| 269 menu = new ExtensionContextMenuModel(browser_action.get(), browser.get()); | 269 menu = new ExtensionContextMenuModel(browser_action.get(), browser.get()); |
| 270 index = GetCommandIndex(menu, visibility_command); | 270 index = GetCommandIndex(menu, visibility_command); |
| 271 EXPECT_NE(-1, index); | 271 EXPECT_NE(-1, index); |
| 272 EXPECT_EQ(show_string, menu->GetLabelAt(index)); | 272 EXPECT_EQ(show_string, menu->GetLabelAt(index)); |
| 273 } | 273 } |
| 274 | 274 |
| 275 } // namespace extensions | 275 } // namespace extensions |
| OLD | NEW |