| 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 <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 #include "extensions/browser/test_management_policy.h" | 36 #include "extensions/browser/test_management_policy.h" |
| 37 #include "extensions/common/extension_builder.h" | 37 #include "extensions/common/extension_builder.h" |
| 38 #include "extensions/common/feature_switch.h" | 38 #include "extensions/common/feature_switch.h" |
| 39 #include "extensions/common/manifest.h" | 39 #include "extensions/common/manifest.h" |
| 40 #include "extensions/common/manifest_constants.h" | 40 #include "extensions/common/manifest_constants.h" |
| 41 #include "extensions/common/manifest_handlers/options_page_info.h" | 41 #include "extensions/common/manifest_handlers/options_page_info.h" |
| 42 #include "extensions/common/permissions/permissions_data.h" | 42 #include "extensions/common/permissions/permissions_data.h" |
| 43 #include "extensions/common/value_builder.h" | 43 #include "extensions/common/value_builder.h" |
| 44 #include "testing/gtest/include/gtest/gtest.h" | 44 #include "testing/gtest/include/gtest/gtest.h" |
| 45 #include "ui/base/l10n/l10n_util.h" | 45 #include "ui/base/l10n/l10n_util.h" |
| 46 #include "ui/display/test/test_screen.h" |
| 46 #include "ui/gfx/image/image.h" | 47 #include "ui/gfx/image/image.h" |
| 47 | 48 |
| 48 namespace extensions { | 49 namespace extensions { |
| 49 | 50 |
| 50 namespace { | 51 namespace { |
| 51 | 52 |
| 52 void Increment(int* i) { | 53 void Increment(int* i) { |
| 53 CHECK(i); | 54 CHECK(i); |
| 54 ++(*i); | 55 ++(*i); |
| 55 } | 56 } |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 const char* action_key, | 134 const char* action_key, |
| 134 Manifest::Location location, | 135 Manifest::Location location, |
| 135 const std::string& host_permission); | 136 const std::string& host_permission); |
| 136 | 137 |
| 137 Browser* GetBrowser(); | 138 Browser* GetBrowser(); |
| 138 | 139 |
| 139 void SetUp() override; | 140 void SetUp() override; |
| 140 void TearDown() override; | 141 void TearDown() override; |
| 141 | 142 |
| 142 private: | 143 private: |
| 144 display::test::TestScreen test_screen_; |
| 143 std::unique_ptr<TestBrowserWindow> test_window_; | 145 std::unique_ptr<TestBrowserWindow> test_window_; |
| 144 std::unique_ptr<Browser> browser_; | 146 std::unique_ptr<Browser> browser_; |
| 145 | 147 |
| 146 DISALLOW_COPY_AND_ASSIGN(ExtensionContextMenuModelTest); | 148 DISALLOW_COPY_AND_ASSIGN(ExtensionContextMenuModelTest); |
| 147 }; | 149 }; |
| 148 | 150 |
| 149 ExtensionContextMenuModelTest::ExtensionContextMenuModelTest() {} | 151 ExtensionContextMenuModelTest::ExtensionContextMenuModelTest() {} |
| 150 | 152 |
| 151 const Extension* ExtensionContextMenuModelTest::AddExtension( | 153 const Extension* ExtensionContextMenuModelTest::AddExtension( |
| 152 const std::string& name, | 154 const std::string& name, |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 if (!browser_) { | 187 if (!browser_) { |
| 186 Browser::CreateParams params(profile()); | 188 Browser::CreateParams params(profile()); |
| 187 test_window_.reset(new TestBrowserWindow()); | 189 test_window_.reset(new TestBrowserWindow()); |
| 188 params.window = test_window_.get(); | 190 params.window = test_window_.get(); |
| 189 browser_.reset(new Browser(params)); | 191 browser_.reset(new Browser(params)); |
| 190 } | 192 } |
| 191 return browser_.get(); | 193 return browser_.get(); |
| 192 } | 194 } |
| 193 | 195 |
| 194 void ExtensionContextMenuModelTest::SetUp() { | 196 void ExtensionContextMenuModelTest::SetUp() { |
| 197 display::Screen::SetScreenInstance(&test_screen_); |
| 195 ExtensionServiceTestBase::SetUp(); | 198 ExtensionServiceTestBase::SetUp(); |
| 196 if (content::IsBrowserSideNavigationEnabled()) | 199 if (content::IsBrowserSideNavigationEnabled()) |
| 197 content::BrowserSideNavigationSetUp(); | 200 content::BrowserSideNavigationSetUp(); |
| 198 } | 201 } |
| 199 | 202 |
| 200 void ExtensionContextMenuModelTest::TearDown() { | 203 void ExtensionContextMenuModelTest::TearDown() { |
| 201 if (content::IsBrowserSideNavigationEnabled()) | 204 if (content::IsBrowserSideNavigationEnabled()) |
| 202 content::BrowserSideNavigationTearDown(); | 205 content::BrowserSideNavigationTearDown(); |
| 203 ExtensionServiceTestBase::TearDown(); | 206 ExtensionServiceTestBase::TearDown(); |
| 207 display::Screen::SetScreenInstance(nullptr); |
| 204 } | 208 } |
| 205 | 209 |
| 206 // Tests that applicable menu items are disabled when a ManagementPolicy | 210 // Tests that applicable menu items are disabled when a ManagementPolicy |
| 207 // prohibits them. | 211 // prohibits them. |
| 208 TEST_F(ExtensionContextMenuModelTest, RequiredInstallationsDisablesItems) { | 212 TEST_F(ExtensionContextMenuModelTest, RequiredInstallationsDisablesItems) { |
| 209 InitializeEmptyExtensionService(); | 213 InitializeEmptyExtensionService(); |
| 210 | 214 |
| 211 // Test that management policy can determine whether or not policy-installed | 215 // Test that management policy can determine whether or not policy-installed |
| 212 // extensions can be installed/uninstalled. | 216 // extensions can be installed/uninstalled. |
| 213 const Extension* extension = AddExtension( | 217 const Extension* extension = AddExtension( |
| (...skipping 493 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 707 "no_action", nullptr, Manifest::INTERNAL); | 711 "no_action", nullptr, Manifest::INTERNAL); |
| 708 ExtensionContextMenuModel menu(no_action, GetBrowser(), | 712 ExtensionContextMenuModel menu(no_action, GetBrowser(), |
| 709 ExtensionContextMenuModel::VISIBLE, nullptr); | 713 ExtensionContextMenuModel::VISIBLE, nullptr); |
| 710 int inspect_popup_index = | 714 int inspect_popup_index = |
| 711 menu.GetIndexOfCommandId(ExtensionContextMenuModel::INSPECT_POPUP); | 715 menu.GetIndexOfCommandId(ExtensionContextMenuModel::INSPECT_POPUP); |
| 712 EXPECT_EQ(-1, inspect_popup_index); | 716 EXPECT_EQ(-1, inspect_popup_index); |
| 713 } | 717 } |
| 714 } | 718 } |
| 715 | 719 |
| 716 } // namespace extensions | 720 } // namespace extensions |
| OLD | NEW |