Chromium Code Reviews| 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" |
| 11 #include "chrome/browser/extensions/menu_manager_factory.h" | 11 #include "chrome/browser/extensions/menu_manager_factory.h" |
| 12 #include "chrome/browser/ui/browser.h" | 12 #include "chrome/browser/ui/browser.h" |
| 13 #include "chrome/browser/ui/host_desktop.h" | 13 #include "chrome/browser/ui/host_desktop.h" |
| 14 #include "chrome/common/extensions/api/context_menus.h" | 14 #include "chrome/common/extensions/api/context_menus.h" |
| 15 #include "chrome/grit/generated_resources.h" | 15 #include "chrome/grit/generated_resources.h" |
| 16 #include "chrome/test/base/test_browser_window.h" | 16 #include "chrome/test/base/test_browser_window.h" |
| 17 #include "chrome/test/base/testing_profile.h" | 17 #include "chrome/test/base/testing_profile.h" |
| 18 #include "components/crx_file/id_util.h" | 18 #include "components/crx_file/id_util.h" |
| 19 #include "extensions/browser/extension_prefs.h" | 19 #include "extensions/browser/extension_prefs.h" |
| 20 #include "extensions/browser/extension_system.h" | 20 #include "extensions/browser/extension_system.h" |
| 21 #include "extensions/browser/test_management_policy.h" | 21 #include "extensions/browser/test_management_policy.h" |
| 22 #include "extensions/common/extension_builder.h" | 22 #include "extensions/common/extension_builder.h" |
| 23 #include "extensions/common/feature_switch.h" | 23 #include "extensions/common/feature_switch.h" |
| 24 #include "extensions/common/manifest.h" | 24 #include "extensions/common/manifest.h" |
| 25 #include "extensions/common/manifest_constants.h" | 25 #include "extensions/common/manifest_constants.h" |
| 26 #include "extensions/common/value_builder.h" | 26 #include "extensions/common/value_builder.h" |
| 27 #include "testing/gtest/include/gtest/gtest.h" | 27 #include "testing/gtest/include/gtest/gtest.h" |
| 28 #include "ui/base/l10n/l10n_util.h" | 28 #include "ui/base/l10n/l10n_util.h" |
| 29 | 29 |
| 30 #if defined(OS_WIN) | |
| 31 #include "chrome/browser/prefs/incognito_mode_prefs.h" | |
| 32 #endif // defined(OS_WIN) | |
| 33 | |
| 30 namespace extensions { | 34 namespace extensions { |
| 31 | 35 |
| 32 namespace { | 36 namespace { |
| 33 | 37 |
| 34 // Build an extension to pass to the menu constructor, with the an action | 38 // Build an extension to pass to the menu constructor, with the an action |
| 35 // specified by |action_key|. | 39 // specified by |action_key|. |
| 36 scoped_refptr<const Extension> BuildExtension(const std::string& name, | 40 scoped_refptr<const Extension> BuildExtension(const std::string& name, |
| 37 const char* action_key, | 41 const char* action_key, |
| 38 Manifest::Location location) { | 42 Manifest::Location location) { |
| 39 return ExtensionBuilder() | 43 return ExtensionBuilder() |
| 40 .SetManifest(DictionaryBuilder() | 44 .SetManifest(DictionaryBuilder() |
| 41 .Set("name", name) | 45 .Set("name", name) |
| 42 .Set("version", "1") | 46 .Set("version", "1") |
| 43 .Set("manifest_version", 2) | 47 .Set("manifest_version", 2) |
| 44 .Set(action_key, DictionaryBuilder().Pass())) | 48 .Set(action_key, DictionaryBuilder().Pass())) |
| 45 .SetID(crx_file::id_util::GenerateId(name)) | 49 .SetID(crx_file::id_util::GenerateId(name)) |
| 46 .SetLocation(location) | 50 .SetLocation(location) |
| 47 .Build(); | 51 .Build(); |
| 48 } | 52 } |
| 49 | 53 |
| 50 // Create a Browser for the ExtensionContextMenuModel to use. | 54 // Create a Browser for the ExtensionContextMenuModel to use. |
| 51 scoped_ptr<Browser> CreateBrowser(Profile* profile) { | 55 scoped_ptr<Browser> CreateBrowser(Profile* profile) { |
| 56 #if defined(OS_WIN) | |
| 57 IncognitoModePrefs::InitializePlatformParentalControls(); | |
|
gab
2015/02/25 20:23:52
IMO this belongs in SetUpTestCase() in the test fi
robliao
2015/02/26 21:03:51
Done for test classes. Global calls like chrome::C
| |
| 58 #endif // defined(OS_WIN) | |
| 59 | |
| 52 Browser::CreateParams params(profile, chrome::GetActiveDesktop()); | 60 Browser::CreateParams params(profile, chrome::GetActiveDesktop()); |
| 53 TestBrowserWindow test_window; | 61 TestBrowserWindow test_window; |
| 54 params.window = &test_window; | 62 params.window = &test_window; |
| 55 return scoped_ptr<Browser>(new Browser(params)); | 63 return scoped_ptr<Browser>(new Browser(params)); |
| 56 } | 64 } |
| 57 | 65 |
| 58 // Returns the index of the given |command_id| in the given |menu|, or -1 if it | 66 // Returns the index of the given |command_id| in the given |menu|, or -1 if it |
| 59 // is not found. | 67 // is not found. |
| 60 int GetCommandIndex(const scoped_refptr<ExtensionContextMenuModel> menu, | 68 int GetCommandIndex(const scoped_refptr<ExtensionContextMenuModel> menu, |
| 61 int command_id) { | 69 int command_id) { |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 293 // Hide the browser action. This should mean the string is "show". | 301 // Hide the browser action. This should mean the string is "show". |
| 294 ExtensionActionAPI::SetBrowserActionVisibility( | 302 ExtensionActionAPI::SetBrowserActionVisibility( |
| 295 prefs, browser_action->id(), false); | 303 prefs, browser_action->id(), false); |
| 296 menu = new ExtensionContextMenuModel(browser_action.get(), browser.get()); | 304 menu = new ExtensionContextMenuModel(browser_action.get(), browser.get()); |
| 297 index = GetCommandIndex(menu, visibility_command); | 305 index = GetCommandIndex(menu, visibility_command); |
| 298 EXPECT_NE(-1, index); | 306 EXPECT_NE(-1, index); |
| 299 EXPECT_EQ(show_string, menu->GetLabelAt(index)); | 307 EXPECT_EQ(show_string, menu->GetLabelAt(index)); |
| 300 } | 308 } |
| 301 | 309 |
| 302 } // namespace extensions | 310 } // namespace extensions |
| OLD | NEW |