OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 <map> | 5 #include <map> |
6 | 6 |
7 #include "base/values.h" | 7 #include "base/values.h" |
8 #include "chrome/browser/extensions/active_script_controller.h" | 8 #include "chrome/browser/extensions/active_script_controller.h" |
9 #include "chrome/browser/extensions/active_tab_permission_granter.h" | 9 #include "chrome/browser/extensions/active_tab_permission_granter.h" |
10 #include "chrome/browser/extensions/api/extension_action/extension_action_api.h" | 10 #include "chrome/browser/extensions/api/extension_action/extension_action_api.h" |
| 11 #include "chrome/browser/extensions/extension_sync_service_factory.h" |
11 #include "chrome/browser/extensions/extension_util.h" | 12 #include "chrome/browser/extensions/extension_util.h" |
12 #include "chrome/browser/extensions/permissions_updater.h" | 13 #include "chrome/browser/extensions/permissions_updater.h" |
13 #include "chrome/browser/extensions/tab_helper.h" | 14 #include "chrome/browser/extensions/tab_helper.h" |
14 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 15 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
15 #include "chrome/test/base/testing_profile.h" | 16 #include "chrome/test/base/testing_profile.h" |
16 #include "components/crx_file/id_util.h" | 17 #include "components/crx_file/id_util.h" |
17 #include "content/public/browser/navigation_controller.h" | 18 #include "content/public/browser/navigation_controller.h" |
18 #include "content/public/browser/navigation_entry.h" | 19 #include "content/public/browser/navigation_entry.h" |
19 #include "content/public/browser/web_contents.h" | 20 #include "content/public/browser/web_contents.h" |
20 #include "extensions/browser/extension_registry.h" | 21 #include "extensions/browser/extension_registry.h" |
21 #include "extensions/common/extension.h" | 22 #include "extensions/common/extension.h" |
22 #include "extensions/common/extension_builder.h" | 23 #include "extensions/common/extension_builder.h" |
23 #include "extensions/common/feature_switch.h" | 24 #include "extensions/common/feature_switch.h" |
24 #include "extensions/common/manifest.h" | 25 #include "extensions/common/manifest.h" |
25 #include "extensions/common/user_script.h" | 26 #include "extensions/common/user_script.h" |
26 #include "extensions/common/value_builder.h" | 27 #include "extensions/common/value_builder.h" |
27 | 28 |
28 namespace extensions { | 29 namespace extensions { |
29 | 30 |
30 namespace { | 31 namespace { |
31 | 32 |
32 const char kAllHostsPermission[] = "*://*/*"; | 33 const char kAllHostsPermission[] = "*://*/*"; |
33 | 34 |
| 35 // We skip syncing for testing purposes. |
| 36 KeyedService* BuildSyncService(content::BrowserContext* context) { |
| 37 return nullptr; |
| 38 } |
| 39 |
34 } // namespace | 40 } // namespace |
35 | 41 |
36 // Unittests for the ActiveScriptController mostly test the internal logic | 42 // Unittests for the ActiveScriptController mostly test the internal logic |
37 // of the controller itself (when to allow/deny extension script injection). | 43 // of the controller itself (when to allow/deny extension script injection). |
38 // Testing real injection is allowed/denied as expected (i.e., that the | 44 // Testing real injection is allowed/denied as expected (i.e., that the |
39 // ActiveScriptController correctly interfaces in the system) is done in the | 45 // ActiveScriptController correctly interfaces in the system) is done in the |
40 // ActiveScriptControllerBrowserTests. | 46 // ActiveScriptControllerBrowserTests. |
41 class ActiveScriptControllerUnitTest : public ChromeRenderViewHostTestHarness { | 47 class ActiveScriptControllerUnitTest : public ChromeRenderViewHostTestHarness { |
42 protected: | 48 protected: |
43 ActiveScriptControllerUnitTest(); | 49 ActiveScriptControllerUnitTest(); |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 } | 162 } |
157 | 163 |
158 void ActiveScriptControllerUnitTest::IncrementExecutionCount( | 164 void ActiveScriptControllerUnitTest::IncrementExecutionCount( |
159 const std::string& extension_id) { | 165 const std::string& extension_id) { |
160 ++extension_executions_[extension_id]; | 166 ++extension_executions_[extension_id]; |
161 } | 167 } |
162 | 168 |
163 void ActiveScriptControllerUnitTest::SetUp() { | 169 void ActiveScriptControllerUnitTest::SetUp() { |
164 ChromeRenderViewHostTestHarness::SetUp(); | 170 ChromeRenderViewHostTestHarness::SetUp(); |
165 | 171 |
| 172 ExtensionSyncServiceFactory::GetInstance()->SetTestingFactory( |
| 173 profile(), &BuildSyncService); |
| 174 |
166 TabHelper::CreateForWebContents(web_contents()); | 175 TabHelper::CreateForWebContents(web_contents()); |
167 TabHelper* tab_helper = TabHelper::FromWebContents(web_contents()); | 176 TabHelper* tab_helper = TabHelper::FromWebContents(web_contents()); |
168 // These should never be NULL. | 177 // These should never be NULL. |
169 DCHECK(tab_helper); | 178 DCHECK(tab_helper); |
170 active_script_controller_ = tab_helper->active_script_controller(); | 179 active_script_controller_ = tab_helper->active_script_controller(); |
171 DCHECK(active_script_controller_); | 180 DCHECK(active_script_controller_); |
172 } | 181 } |
173 | 182 |
174 // Test that extensions with all_hosts require permission to execute, and, once | 183 // Test that extensions with all_hosts require permission to execute, and, once |
175 // that permission is granted, do execute. | 184 // that permission is granted, do execute. |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
411 EXPECT_TRUE(RequiresUserConsent(extension)); | 420 EXPECT_TRUE(RequiresUserConsent(extension)); |
412 // Different subdomain... | 421 // Different subdomain... |
413 NavigateAndCommit(GURL("https://en.google.com/foo/bar")); | 422 NavigateAndCommit(GURL("https://en.google.com/foo/bar")); |
414 EXPECT_TRUE(RequiresUserConsent(extension)); | 423 EXPECT_TRUE(RequiresUserConsent(extension)); |
415 // Only the "always run" origin should be allowed to run without user consent. | 424 // Only the "always run" origin should be allowed to run without user consent. |
416 NavigateAndCommit(GURL("https://www.google.com/foo/bar")); | 425 NavigateAndCommit(GURL("https://www.google.com/foo/bar")); |
417 EXPECT_FALSE(RequiresUserConsent(extension)); | 426 EXPECT_FALSE(RequiresUserConsent(extension)); |
418 } | 427 } |
419 | 428 |
420 } // namespace extensions | 429 } // namespace extensions |
OLD | NEW |