| 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/api/permissions/permissions_api.h" | 5 #include "chrome/browser/extensions/api/permissions/permissions_api.h" |
| 6 #include "chrome/browser/extensions/extension_apitest.h" | 6 #include "chrome/browser/extensions/extension_apitest.h" |
| 7 #include "chrome/browser/extensions/extension_management_test_util.h" | 7 #include "chrome/browser/extensions/extension_management_test_util.h" |
| 8 #include "chrome/browser/extensions/extension_with_management_policy_apitest.h" |
| 8 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
| 9 #include "chrome/browser/ui/browser.h" | 10 #include "chrome/browser/ui/browser.h" |
| 10 #include "components/policy/core/browser/browser_policy_connector.h" | 11 #include "components/policy/core/browser/browser_policy_connector.h" |
| 11 #include "components/policy/core/common/mock_configuration_policy_provider.h" | 12 #include "components/policy/core/common/mock_configuration_policy_provider.h" |
| 12 #include "extensions/browser/extension_prefs.h" | 13 #include "extensions/browser/extension_prefs.h" |
| 13 #include "extensions/common/permissions/permission_set.h" | 14 #include "extensions/common/permissions/permission_set.h" |
| 14 #include "extensions/common/switches.h" | 15 #include "extensions/common/switches.h" |
| 15 #include "net/dns/mock_host_resolver.h" | 16 #include "net/dns/mock_host_resolver.h" |
| 16 | 17 |
| 17 namespace extensions { | 18 namespace extensions { |
| 18 | 19 |
| 19 namespace { | 20 namespace { |
| 20 | 21 |
| 21 static void AddPattern(URLPatternSet* extent, const std::string& pattern) { | 22 static void AddPattern(URLPatternSet* extent, const std::string& pattern) { |
| 22 int schemes = URLPattern::SCHEME_ALL; | 23 int schemes = URLPattern::SCHEME_ALL; |
| 23 extent->AddPattern(URLPattern(schemes, pattern)); | 24 extent->AddPattern(URLPattern(schemes, pattern)); |
| 24 } | 25 } |
| 25 | 26 |
| 26 } // namespace | 27 } // namespace |
| 27 | 28 |
| 28 class ExperimentalApiTest : public ExtensionApiTest { | 29 class ExperimentalApiTest : public ExtensionApiTest { |
| 29 public: | 30 public: |
| 30 void SetUpCommandLine(base::CommandLine* command_line) override { | 31 void SetUpCommandLine(base::CommandLine* command_line) override { |
| 31 ExtensionApiTest::SetUpCommandLine(command_line); | 32 ExtensionApiTest::SetUpCommandLine(command_line); |
| 32 command_line->AppendSwitch(switches::kEnableExperimentalExtensionApis); | 33 command_line->AppendSwitch(switches::kEnableExperimentalExtensionApis); |
| 33 } | 34 } |
| 34 }; | 35 }; |
| 35 | 36 |
| 36 class ExtensionApiTestWithManagementPolicy : public ExtensionApiTest { | |
| 37 public: | |
| 38 void SetUpInProcessBrowserTestFixture() override { | |
| 39 ExtensionApiTest::SetUpInProcessBrowserTestFixture(); | |
| 40 EXPECT_CALL(policy_provider_, IsInitializationComplete(testing::_)) | |
| 41 .WillRepeatedly(testing::Return(true)); | |
| 42 policy_provider_.SetAutoRefresh(); | |
| 43 policy::BrowserPolicyConnector::SetPolicyProviderForTesting( | |
| 44 &policy_provider_); | |
| 45 } | |
| 46 | |
| 47 protected: | |
| 48 policy::MockConfigurationPolicyProvider policy_provider_; | |
| 49 }; | |
| 50 | |
| 51 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, PermissionsFail) { | 37 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, PermissionsFail) { |
| 52 ASSERT_TRUE(RunExtensionTest("permissions/disabled")) << message_; | 38 ASSERT_TRUE(RunExtensionTest("permissions/disabled")) << message_; |
| 53 | 39 |
| 54 // Since the experimental APIs require a flag, this will fail even though | 40 // Since the experimental APIs require a flag, this will fail even though |
| 55 // it's enabled. | 41 // it's enabled. |
| 56 // TODO(erikkay) This test is currently broken because LoadExtension in | 42 // TODO(erikkay) This test is currently broken because LoadExtension in |
| 57 // ExtensionBrowserTest doesn't actually fail, it just times out. To fix this | 43 // ExtensionBrowserTest doesn't actually fail, it just times out. To fix this |
| 58 // I'll need to add an EXTENSION_LOAD_ERROR notification, which is probably | 44 // I'll need to add an EXTENSION_LOAD_ERROR notification, which is probably |
| 59 // too much for the branch. I'll enable this on trunk later. | 45 // too much for the branch. I'll enable this on trunk later. |
| 60 // ASSERT_FALSE(RunExtensionTest("permissions/enabled"))) << message_; | 46 // ASSERT_FALSE(RunExtensionTest("permissions/enabled"))) << message_; |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 // Tests that requesting an optional permission from a background page, with | 181 // Tests that requesting an optional permission from a background page, with |
| 196 // another window open, grants the permission and updates the bindings | 182 // another window open, grants the permission and updates the bindings |
| 197 // (chrome.whatever, in this case chrome.alarms). Regression test for | 183 // (chrome.whatever, in this case chrome.alarms). Regression test for |
| 198 // crbug.com/435141, see details there for trickiness. | 184 // crbug.com/435141, see details there for trickiness. |
| 199 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, OptionalPermissionsUpdatesBindings) { | 185 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, OptionalPermissionsUpdatesBindings) { |
| 200 ASSERT_TRUE(RunExtensionTest("permissions/optional_updates_bindings")) | 186 ASSERT_TRUE(RunExtensionTest("permissions/optional_updates_bindings")) |
| 201 << message_; | 187 << message_; |
| 202 } | 188 } |
| 203 | 189 |
| 204 } // namespace extensions | 190 } // namespace extensions |
| OLD | NEW |