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" |
(...skipping 14 matching lines...) Expand all Loading... |
25 #include "extensions/common/manifest.h" | 25 #include "extensions/common/manifest.h" |
26 #include "extensions/common/user_script.h" | 26 #include "extensions/common/user_script.h" |
27 #include "extensions/common/value_builder.h" | 27 #include "extensions/common/value_builder.h" |
28 | 28 |
29 namespace extensions { | 29 namespace extensions { |
30 | 30 |
31 namespace { | 31 namespace { |
32 | 32 |
33 const char kAllHostsPermission[] = "*://*/*"; | 33 const char kAllHostsPermission[] = "*://*/*"; |
34 | 34 |
35 // We skip syncing for testing purposes. | |
36 KeyedService* BuildSyncService(content::BrowserContext* context) { | |
37 return nullptr; | |
38 } | |
39 | |
40 } // namespace | 35 } // namespace |
41 | 36 |
42 // Unittests for the ActiveScriptController mostly test the internal logic | 37 // Unittests for the ActiveScriptController mostly test the internal logic |
43 // of the controller itself (when to allow/deny extension script injection). | 38 // of the controller itself (when to allow/deny extension script injection). |
44 // Testing real injection is allowed/denied as expected (i.e., that the | 39 // Testing real injection is allowed/denied as expected (i.e., that the |
45 // ActiveScriptController correctly interfaces in the system) is done in the | 40 // ActiveScriptController correctly interfaces in the system) is done in the |
46 // ActiveScriptControllerBrowserTests. | 41 // ActiveScriptControllerBrowserTests. |
47 class ActiveScriptControllerUnitTest : public ChromeRenderViewHostTestHarness { | 42 class ActiveScriptControllerUnitTest : public ChromeRenderViewHostTestHarness { |
48 protected: | 43 protected: |
49 ActiveScriptControllerUnitTest(); | 44 ActiveScriptControllerUnitTest(); |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 } | 157 } |
163 | 158 |
164 void ActiveScriptControllerUnitTest::IncrementExecutionCount( | 159 void ActiveScriptControllerUnitTest::IncrementExecutionCount( |
165 const std::string& extension_id) { | 160 const std::string& extension_id) { |
166 ++extension_executions_[extension_id]; | 161 ++extension_executions_[extension_id]; |
167 } | 162 } |
168 | 163 |
169 void ActiveScriptControllerUnitTest::SetUp() { | 164 void ActiveScriptControllerUnitTest::SetUp() { |
170 ChromeRenderViewHostTestHarness::SetUp(); | 165 ChromeRenderViewHostTestHarness::SetUp(); |
171 | 166 |
172 ExtensionSyncServiceFactory::GetInstance()->SetTestingFactory( | 167 // Skip syncing for testing purposes. |
173 profile(), &BuildSyncService); | 168 ExtensionSyncServiceFactory::GetInstance()->SetTestingFactory(profile(), |
| 169 nullptr); |
174 | 170 |
175 TabHelper::CreateForWebContents(web_contents()); | 171 TabHelper::CreateForWebContents(web_contents()); |
176 TabHelper* tab_helper = TabHelper::FromWebContents(web_contents()); | 172 TabHelper* tab_helper = TabHelper::FromWebContents(web_contents()); |
177 // These should never be NULL. | 173 // These should never be NULL. |
178 DCHECK(tab_helper); | 174 DCHECK(tab_helper); |
179 active_script_controller_ = tab_helper->active_script_controller(); | 175 active_script_controller_ = tab_helper->active_script_controller(); |
180 DCHECK(active_script_controller_); | 176 DCHECK(active_script_controller_); |
181 } | 177 } |
182 | 178 |
183 // Test that extensions with all_hosts require permission to execute, and, once | 179 // Test that extensions with all_hosts require permission to execute, and, once |
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
420 EXPECT_TRUE(RequiresUserConsent(extension)); | 416 EXPECT_TRUE(RequiresUserConsent(extension)); |
421 // Different subdomain... | 417 // Different subdomain... |
422 NavigateAndCommit(GURL("https://en.google.com/foo/bar")); | 418 NavigateAndCommit(GURL("https://en.google.com/foo/bar")); |
423 EXPECT_TRUE(RequiresUserConsent(extension)); | 419 EXPECT_TRUE(RequiresUserConsent(extension)); |
424 // Only the "always run" origin should be allowed to run without user consent. | 420 // Only the "always run" origin should be allowed to run without user consent. |
425 NavigateAndCommit(GURL("https://www.google.com/foo/bar")); | 421 NavigateAndCommit(GURL("https://www.google.com/foo/bar")); |
426 EXPECT_FALSE(RequiresUserConsent(extension)); | 422 EXPECT_FALSE(RequiresUserConsent(extension)); |
427 } | 423 } |
428 | 424 |
429 } // namespace extensions | 425 } // namespace extensions |
OLD | NEW |