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