| 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/extension_util.h" | 10 #include "chrome/browser/extensions/extension_util.h" |
| 11 #include "chrome/browser/extensions/permissions_updater.h" |
| 11 #include "chrome/browser/extensions/tab_helper.h" | 12 #include "chrome/browser/extensions/tab_helper.h" |
| 12 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 13 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
| 13 #include "chrome/test/base/testing_profile.h" | 14 #include "chrome/test/base/testing_profile.h" |
| 14 #include "content/public/browser/navigation_controller.h" | 15 #include "content/public/browser/navigation_controller.h" |
| 15 #include "content/public/browser/navigation_entry.h" | 16 #include "content/public/browser/navigation_entry.h" |
| 16 #include "content/public/browser/web_contents.h" | 17 #include "content/public/browser/web_contents.h" |
| 17 #include "extensions/browser/extension_registry.h" | 18 #include "extensions/browser/extension_registry.h" |
| 18 #include "extensions/common/extension.h" | 19 #include "extensions/common/extension.h" |
| 19 #include "extensions/common/extension_builder.h" | 20 #include "extensions/common/extension_builder.h" |
| 20 #include "extensions/common/feature_switch.h" | 21 #include "extensions/common/feature_switch.h" |
| 21 #include "extensions/common/id_util.h" | 22 #include "extensions/common/id_util.h" |
| 22 #include "extensions/common/manifest.h" | 23 #include "extensions/common/manifest.h" |
| 24 #include "extensions/common/user_script.h" |
| 23 #include "extensions/common/value_builder.h" | 25 #include "extensions/common/value_builder.h" |
| 24 | 26 |
| 25 namespace extensions { | 27 namespace extensions { |
| 26 | 28 |
| 27 namespace { | 29 namespace { |
| 28 | 30 |
| 29 const char kAllHostsPermission[] = "*://*/*"; | 31 const char kAllHostsPermission[] = "*://*/*"; |
| 30 | 32 |
| 31 } // namespace | 33 } // namespace |
| 32 | 34 |
| 33 // Unittests for the ActiveScriptController mostly test the internal logic | 35 // Unittests for the ActiveScriptController mostly test the internal logic |
| 34 // of the controller itself (when to allow/deny extension script injection). | 36 // of the controller itself (when to allow/deny extension script injection). |
| 35 // Testing real injection is allowed/denied as expected (i.e., that the | 37 // Testing real injection is allowed/denied as expected (i.e., that the |
| 36 // ActiveScriptController correctly interfaces in the system) is done in the | 38 // ActiveScriptController correctly interfaces in the system) is done in the |
| 37 // ActiveScriptControllerBrowserTests. | 39 // ActiveScriptControllerBrowserTests. |
| 38 class ActiveScriptControllerUnitTest : public ChromeRenderViewHostTestHarness { | 40 class ActiveScriptControllerUnitTest : public ChromeRenderViewHostTestHarness { |
| 39 protected: | 41 protected: |
| 40 ActiveScriptControllerUnitTest(); | 42 ActiveScriptControllerUnitTest(); |
| 41 virtual ~ActiveScriptControllerUnitTest(); | 43 virtual ~ActiveScriptControllerUnitTest(); |
| 42 | 44 |
| 43 // Creates an extension with all hosts permission and adds it to the registry. | 45 // Creates an extension with all hosts permission and adds it to the registry. |
| 44 const Extension* AddExtension(); | 46 const Extension* AddExtension(); |
| 45 | 47 |
| 48 // Returns true if the |extension| requires user consent before injecting |
| 49 // a script. |
| 50 bool RequiresUserConsent(const Extension* extension) const; |
| 51 |
| 52 // Request an injection for the given |extension|. |
| 53 void RequestInjection(const Extension* extension); |
| 54 |
| 55 // Returns the number of times a given extension has had a script execute. |
| 56 size_t GetExecutionCountForExtension(const std::string& extension_id) const; |
| 57 |
| 58 ActiveScriptController* controller() const { |
| 59 return active_script_controller_; |
| 60 } |
| 61 |
| 62 private: |
| 46 // Returns the current page id. | 63 // Returns the current page id. |
| 47 int GetPageId(); | 64 int GetPageId(); |
| 48 | 65 |
| 49 // Returns a closure to use as a script execution for a given extension. | 66 // Returns a closure to use as a script execution for a given extension. |
| 50 base::Closure GetExecutionCallbackForExtension( | 67 base::Closure GetExecutionCallbackForExtension( |
| 51 const std::string& extension_id); | 68 const std::string& extension_id); |
| 52 | 69 |
| 53 // Returns the number of times a given extension has had a script execute. | |
| 54 size_t GetExecutionCountForExtension(const std::string& extension_id) const; | |
| 55 | |
| 56 ActiveScriptController* controller() { return active_script_controller_; } | |
| 57 | |
| 58 private: | |
| 59 // Increment the number of executions for the given |extension_id|. | 70 // Increment the number of executions for the given |extension_id|. |
| 60 void IncrementExecutionCount(const std::string& extension_id); | 71 void IncrementExecutionCount(const std::string& extension_id); |
| 61 | 72 |
| 62 virtual void SetUp() OVERRIDE; | 73 virtual void SetUp() OVERRIDE; |
| 63 | 74 |
| 64 // Since ActiveScriptController's behavior is behind a flag, override the | 75 // Since ActiveScriptController's behavior is behind a flag, override the |
| 65 // feature switch. | 76 // feature switch. |
| 66 FeatureSwitch::ScopedOverride feature_override_; | 77 FeatureSwitch::ScopedOverride feature_override_; |
| 67 | 78 |
| 68 // The associated ActiveScriptController. | 79 // The associated ActiveScriptController. |
| (...skipping 22 matching lines...) Expand all Loading... |
| 91 .Set("description", "an extension") | 102 .Set("description", "an extension") |
| 92 .Set("manifest_version", 2) | 103 .Set("manifest_version", 2) |
| 93 .Set("version", "1.0.0") | 104 .Set("version", "1.0.0") |
| 94 .Set("permissions", | 105 .Set("permissions", |
| 95 ListBuilder().Append(kAllHostsPermission))) | 106 ListBuilder().Append(kAllHostsPermission))) |
| 96 .SetLocation(Manifest::INTERNAL) | 107 .SetLocation(Manifest::INTERNAL) |
| 97 .SetID(kId) | 108 .SetID(kId) |
| 98 .Build(); | 109 .Build(); |
| 99 | 110 |
| 100 ExtensionRegistry::Get(profile())->AddEnabled(extension); | 111 ExtensionRegistry::Get(profile())->AddEnabled(extension); |
| 112 PermissionsUpdater(profile()).InitializePermissions(extension); |
| 101 return extension; | 113 return extension; |
| 102 } | 114 } |
| 103 | 115 |
| 116 bool ActiveScriptControllerUnitTest::RequiresUserConsent( |
| 117 const Extension* extension) const { |
| 118 PermissionsData::AccessType access_type = |
| 119 controller()->RequiresUserConsentForScriptInjectionForTesting( |
| 120 extension, UserScript::PROGRAMMATIC_SCRIPT); |
| 121 // We should never downright refuse access in these tests. |
| 122 DCHECK_NE(PermissionsData::ACCESS_DENIED, access_type); |
| 123 return access_type == PermissionsData::ACCESS_WITHHELD; |
| 124 } |
| 125 |
| 126 void ActiveScriptControllerUnitTest::RequestInjection( |
| 127 const Extension* extension) { |
| 128 controller()->RequestScriptInjectionForTesting( |
| 129 extension, |
| 130 GetPageId(), |
| 131 GetExecutionCallbackForExtension(extension->id())); |
| 132 } |
| 133 |
| 134 size_t ActiveScriptControllerUnitTest::GetExecutionCountForExtension( |
| 135 const std::string& extension_id) const { |
| 136 std::map<std::string, int>::const_iterator iter = |
| 137 extension_executions_.find(extension_id); |
| 138 if (iter != extension_executions_.end()) |
| 139 return iter->second; |
| 140 return 0u; |
| 141 } |
| 142 |
| 104 int ActiveScriptControllerUnitTest::GetPageId() { | 143 int ActiveScriptControllerUnitTest::GetPageId() { |
| 105 content::NavigationEntry* navigation_entry = | 144 content::NavigationEntry* navigation_entry = |
| 106 web_contents()->GetController().GetVisibleEntry(); | 145 web_contents()->GetController().GetVisibleEntry(); |
| 107 DCHECK(navigation_entry); // This should never be NULL. | 146 DCHECK(navigation_entry); // This should never be NULL. |
| 108 return navigation_entry->GetPageID(); | 147 return navigation_entry->GetPageID(); |
| 109 } | 148 } |
| 110 | 149 |
| 111 base::Closure ActiveScriptControllerUnitTest::GetExecutionCallbackForExtension( | 150 base::Closure ActiveScriptControllerUnitTest::GetExecutionCallbackForExtension( |
| 112 const std::string& extension_id) { | 151 const std::string& extension_id) { |
| 113 // We use base unretained here, but if this ever gets executed outside of | 152 // We use base unretained here, but if this ever gets executed outside of |
| 114 // this test's lifetime, we have a major problem anyway. | 153 // this test's lifetime, we have a major problem anyway. |
| 115 return base::Bind(&ActiveScriptControllerUnitTest::IncrementExecutionCount, | 154 return base::Bind(&ActiveScriptControllerUnitTest::IncrementExecutionCount, |
| 116 base::Unretained(this), | 155 base::Unretained(this), |
| 117 extension_id); | 156 extension_id); |
| 118 } | 157 } |
| 119 | 158 |
| 120 size_t ActiveScriptControllerUnitTest::GetExecutionCountForExtension( | |
| 121 const std::string& extension_id) const { | |
| 122 std::map<std::string, int>::const_iterator iter = | |
| 123 extension_executions_.find(extension_id); | |
| 124 if (iter != extension_executions_.end()) | |
| 125 return iter->second; | |
| 126 return 0u; | |
| 127 } | |
| 128 | |
| 129 void ActiveScriptControllerUnitTest::IncrementExecutionCount( | 159 void ActiveScriptControllerUnitTest::IncrementExecutionCount( |
| 130 const std::string& extension_id) { | 160 const std::string& extension_id) { |
| 131 ++extension_executions_[extension_id]; | 161 ++extension_executions_[extension_id]; |
| 132 } | 162 } |
| 133 | 163 |
| 134 void ActiveScriptControllerUnitTest::SetUp() { | 164 void ActiveScriptControllerUnitTest::SetUp() { |
| 135 ChromeRenderViewHostTestHarness::SetUp(); | 165 ChromeRenderViewHostTestHarness::SetUp(); |
| 136 | 166 |
| 137 TabHelper::CreateForWebContents(web_contents()); | 167 TabHelper::CreateForWebContents(web_contents()); |
| 138 TabHelper* tab_helper = TabHelper::FromWebContents(web_contents()); | 168 TabHelper* tab_helper = TabHelper::FromWebContents(web_contents()); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 150 const Extension* extension = AddExtension(); | 180 const Extension* extension = AddExtension(); |
| 151 ASSERT_TRUE(extension); | 181 ASSERT_TRUE(extension); |
| 152 | 182 |
| 153 NavigateAndCommit(GURL("https://www.google.com")); | 183 NavigateAndCommit(GURL("https://www.google.com")); |
| 154 | 184 |
| 155 // Ensure that there aren't any executions pending. | 185 // Ensure that there aren't any executions pending. |
| 156 ASSERT_EQ(0u, GetExecutionCountForExtension(extension->id())); | 186 ASSERT_EQ(0u, GetExecutionCountForExtension(extension->id())); |
| 157 ASSERT_FALSE(controller()->GetActionForExtension(extension)); | 187 ASSERT_FALSE(controller()->GetActionForExtension(extension)); |
| 158 | 188 |
| 159 // Since the extension requests all_hosts, we should require user consent. | 189 // Since the extension requests all_hosts, we should require user consent. |
| 160 EXPECT_TRUE( | 190 EXPECT_TRUE(RequiresUserConsent(extension)); |
| 161 controller()->RequiresUserConsentForScriptInjection(extension)); | |
| 162 | 191 |
| 163 // Request an injection. There should be an action visible, but no executions. | 192 // Request an injection. There should be an action visible, but no executions. |
| 164 controller()->RequestScriptInjection( | 193 RequestInjection(extension); |
| 165 extension, | |
| 166 GetPageId(), | |
| 167 GetExecutionCallbackForExtension(extension->id())); | |
| 168 EXPECT_TRUE(controller()->GetActionForExtension(extension)); | 194 EXPECT_TRUE(controller()->GetActionForExtension(extension)); |
| 169 EXPECT_EQ(0u, GetExecutionCountForExtension(extension->id())); | 195 EXPECT_EQ(0u, GetExecutionCountForExtension(extension->id())); |
| 170 | 196 |
| 171 // Click to accept the extension executing. | 197 // Click to accept the extension executing. |
| 172 controller()->OnClicked(extension); | 198 controller()->OnClicked(extension); |
| 173 | 199 |
| 174 // The extension should execute, and the action should go away. | 200 // The extension should execute, and the action should go away. |
| 175 EXPECT_EQ(1u, GetExecutionCountForExtension(extension->id())); | 201 EXPECT_EQ(1u, GetExecutionCountForExtension(extension->id())); |
| 176 EXPECT_FALSE(controller()->GetActionForExtension(extension)); | 202 EXPECT_FALSE(controller()->GetActionForExtension(extension)); |
| 177 | 203 |
| 178 // Since we already executed on the given page, we shouldn't need permission | 204 // Since we already executed on the given page, we shouldn't need permission |
| 179 // for a second time. | 205 // for a second time. |
| 180 EXPECT_FALSE( | 206 EXPECT_FALSE(RequiresUserConsent(extension)); |
| 181 controller()->RequiresUserConsentForScriptInjection(extension)); | |
| 182 | 207 |
| 183 // Reloading should clear those permissions, and we should again require user | 208 // Reloading should clear those permissions, and we should again require user |
| 184 // consent. | 209 // consent. |
| 185 Reload(); | 210 Reload(); |
| 186 EXPECT_TRUE( | 211 EXPECT_TRUE(RequiresUserConsent(extension)); |
| 187 controller()->RequiresUserConsentForScriptInjection(extension)); | |
| 188 | 212 |
| 189 // Grant access. | 213 // Grant access. |
| 190 controller()->RequestScriptInjection( | 214 RequestInjection(extension); |
| 191 extension, | |
| 192 GetPageId(), | |
| 193 GetExecutionCallbackForExtension(extension->id())); | |
| 194 controller()->OnClicked(extension); | 215 controller()->OnClicked(extension); |
| 195 EXPECT_EQ(2u, GetExecutionCountForExtension(extension->id())); | 216 EXPECT_EQ(2u, GetExecutionCountForExtension(extension->id())); |
| 196 EXPECT_FALSE(controller()->GetActionForExtension(extension)); | 217 EXPECT_FALSE(controller()->GetActionForExtension(extension)); |
| 197 | 218 |
| 198 // Navigating to another site should also clear the permissions. | 219 // Navigating to another site should also clear the permissions. |
| 199 NavigateAndCommit(GURL("https://www.foo.com")); | 220 NavigateAndCommit(GURL("https://www.foo.com")); |
| 200 EXPECT_TRUE( | 221 EXPECT_TRUE(RequiresUserConsent(extension)); |
| 201 controller()->RequiresUserConsentForScriptInjection(extension)); | |
| 202 } | 222 } |
| 203 | 223 |
| 204 // Test that injections that are not executed by the time the user navigates are | 224 // Test that injections that are not executed by the time the user navigates are |
| 205 // ignored and never execute. | 225 // ignored and never execute. |
| 206 TEST_F(ActiveScriptControllerUnitTest, PendingInjectionsRemovedAtNavigation) { | 226 TEST_F(ActiveScriptControllerUnitTest, PendingInjectionsRemovedAtNavigation) { |
| 207 const Extension* extension = AddExtension(); | 227 const Extension* extension = AddExtension(); |
| 208 ASSERT_TRUE(extension); | 228 ASSERT_TRUE(extension); |
| 209 | 229 |
| 210 NavigateAndCommit(GURL("https://www.google.com")); | 230 NavigateAndCommit(GURL("https://www.google.com")); |
| 211 | 231 |
| 212 ASSERT_EQ(0u, GetExecutionCountForExtension(extension->id())); | 232 ASSERT_EQ(0u, GetExecutionCountForExtension(extension->id())); |
| 213 | 233 |
| 214 // Request an injection. There should be an action visible, but no executions. | 234 // Request an injection. There should be an action visible, but no executions. |
| 215 controller()->RequestScriptInjection( | 235 RequestInjection(extension); |
| 216 extension, | |
| 217 GetPageId(), | |
| 218 GetExecutionCallbackForExtension(extension->id())); | |
| 219 EXPECT_TRUE(controller()->GetActionForExtension(extension)); | 236 EXPECT_TRUE(controller()->GetActionForExtension(extension)); |
| 220 EXPECT_EQ(0u, GetExecutionCountForExtension(extension->id())); | 237 EXPECT_EQ(0u, GetExecutionCountForExtension(extension->id())); |
| 221 | 238 |
| 222 // Reload. This should remove the pending injection, and we should not | 239 // Reload. This should remove the pending injection, and we should not |
| 223 // execute anything. | 240 // execute anything. |
| 224 Reload(); | 241 Reload(); |
| 225 EXPECT_FALSE(controller()->GetActionForExtension(extension)); | 242 EXPECT_FALSE(controller()->GetActionForExtension(extension)); |
| 226 EXPECT_EQ(0u, GetExecutionCountForExtension(extension->id())); | 243 EXPECT_EQ(0u, GetExecutionCountForExtension(extension->id())); |
| 227 | 244 |
| 228 // Request and accept a new injection. | 245 // Request and accept a new injection. |
| 229 controller()->RequestScriptInjection( | 246 RequestInjection(extension); |
| 230 extension, | |
| 231 GetPageId(), | |
| 232 GetExecutionCallbackForExtension(extension->id())); | |
| 233 controller()->OnClicked(extension); | 247 controller()->OnClicked(extension); |
| 234 | 248 |
| 235 // The extension should only have executed once, even though a grand total | 249 // The extension should only have executed once, even though a grand total |
| 236 // of two executions were requested. | 250 // of two executions were requested. |
| 237 EXPECT_EQ(1u, GetExecutionCountForExtension(extension->id())); | 251 EXPECT_EQ(1u, GetExecutionCountForExtension(extension->id())); |
| 238 EXPECT_FALSE(controller()->GetActionForExtension(extension)); | 252 EXPECT_FALSE(controller()->GetActionForExtension(extension)); |
| 239 } | 253 } |
| 240 | 254 |
| 241 // Test that queueing multiple pending injections, and then accepting, triggers | 255 // Test that queueing multiple pending injections, and then accepting, triggers |
| 242 // them all. | 256 // them all. |
| 243 TEST_F(ActiveScriptControllerUnitTest, MultiplePendingInjection) { | 257 TEST_F(ActiveScriptControllerUnitTest, MultiplePendingInjection) { |
| 244 const Extension* extension = AddExtension(); | 258 const Extension* extension = AddExtension(); |
| 245 ASSERT_TRUE(extension); | 259 ASSERT_TRUE(extension); |
| 246 NavigateAndCommit(GURL("https://www.google.com")); | 260 NavigateAndCommit(GURL("https://www.google.com")); |
| 247 | 261 |
| 248 ASSERT_EQ(0u, GetExecutionCountForExtension(extension->id())); | 262 ASSERT_EQ(0u, GetExecutionCountForExtension(extension->id())); |
| 249 | 263 |
| 250 const size_t kNumInjections = 3u; | 264 const size_t kNumInjections = 3u; |
| 251 // Queue multiple pending injections. | 265 // Queue multiple pending injections. |
| 252 for (size_t i = 0u; i < kNumInjections; ++i) { | 266 for (size_t i = 0u; i < kNumInjections; ++i) |
| 253 controller()->RequestScriptInjection( | 267 RequestInjection(extension); |
| 254 extension, | 268 |
| 255 GetPageId(), | |
| 256 GetExecutionCallbackForExtension(extension->id())); | |
| 257 } | |
| 258 EXPECT_EQ(0u, GetExecutionCountForExtension(extension->id())); | 269 EXPECT_EQ(0u, GetExecutionCountForExtension(extension->id())); |
| 259 | 270 |
| 260 controller()->OnClicked(extension); | 271 controller()->OnClicked(extension); |
| 261 | 272 |
| 262 // All pending injections should have executed. | 273 // All pending injections should have executed. |
| 263 EXPECT_EQ(kNumInjections, GetExecutionCountForExtension(extension->id())); | 274 EXPECT_EQ(kNumInjections, GetExecutionCountForExtension(extension->id())); |
| 264 EXPECT_FALSE(controller()->GetActionForExtension(extension)); | 275 EXPECT_FALSE(controller()->GetActionForExtension(extension)); |
| 265 } | 276 } |
| 266 | 277 |
| 267 TEST_F(ActiveScriptControllerUnitTest, ActiveScriptsUseActiveTabPermissions) { | 278 TEST_F(ActiveScriptControllerUnitTest, ActiveScriptsUseActiveTabPermissions) { |
| 268 const Extension* extension = AddExtension(); | 279 const Extension* extension = AddExtension(); |
| 269 NavigateAndCommit(GURL("https://www.google.com")); | 280 NavigateAndCommit(GURL("https://www.google.com")); |
| 270 | 281 |
| 271 ActiveTabPermissionGranter* active_tab_permission_granter = | 282 ActiveTabPermissionGranter* active_tab_permission_granter = |
| 272 TabHelper::FromWebContents(web_contents()) | 283 TabHelper::FromWebContents(web_contents()) |
| 273 ->active_tab_permission_granter(); | 284 ->active_tab_permission_granter(); |
| 274 ASSERT_TRUE(active_tab_permission_granter); | 285 ASSERT_TRUE(active_tab_permission_granter); |
| 275 // Grant the extension active tab permissions. This normally happens, e.g., | 286 // Grant the extension active tab permissions. This normally happens, e.g., |
| 276 // if the user clicks on a browser action. | 287 // if the user clicks on a browser action. |
| 277 active_tab_permission_granter->GrantIfRequested(extension); | 288 active_tab_permission_granter->GrantIfRequested(extension); |
| 278 | 289 |
| 279 // Since we have active tab permissions, we shouldn't need user consent | 290 // Since we have active tab permissions, we shouldn't need user consent |
| 280 // anymore. | 291 // anymore. |
| 281 EXPECT_FALSE(controller()->RequiresUserConsentForScriptInjection(extension)); | 292 EXPECT_FALSE(RequiresUserConsent(extension)); |
| 282 | 293 |
| 283 // Also test that granting active tab runs any pending tasks. | 294 // Also test that granting active tab runs any pending tasks. |
| 284 Reload(); | 295 Reload(); |
| 285 // Navigating should mean we need permission again. | 296 // Navigating should mean we need permission again. |
| 286 EXPECT_TRUE(controller()->RequiresUserConsentForScriptInjection(extension)); | 297 EXPECT_TRUE(RequiresUserConsent(extension)); |
| 287 | 298 |
| 288 controller()->RequestScriptInjection( | 299 RequestInjection(extension); |
| 289 extension, | |
| 290 GetPageId(), | |
| 291 GetExecutionCallbackForExtension(extension->id())); | |
| 292 EXPECT_TRUE(controller()->GetActionForExtension(extension)); | 300 EXPECT_TRUE(controller()->GetActionForExtension(extension)); |
| 293 EXPECT_EQ(0u, GetExecutionCountForExtension(extension->id())); | 301 EXPECT_EQ(0u, GetExecutionCountForExtension(extension->id())); |
| 294 | 302 |
| 295 // Grant active tab. | 303 // Grant active tab. |
| 296 active_tab_permission_granter->GrantIfRequested(extension); | 304 active_tab_permission_granter->GrantIfRequested(extension); |
| 297 | 305 |
| 298 // The pending injections should have run since active tab permission was | 306 // The pending injections should have run since active tab permission was |
| 299 // granted. | 307 // granted. |
| 300 EXPECT_EQ(1u, GetExecutionCountForExtension(extension->id())); | 308 EXPECT_EQ(1u, GetExecutionCountForExtension(extension->id())); |
| 301 EXPECT_FALSE(controller()->GetActionForExtension(extension)); | 309 EXPECT_FALSE(controller()->GetActionForExtension(extension)); |
| 302 } | 310 } |
| 303 | 311 |
| 304 TEST_F(ActiveScriptControllerUnitTest, ActiveScriptsCanHaveAllUrlsPref) { | 312 TEST_F(ActiveScriptControllerUnitTest, ActiveScriptsCanHaveAllUrlsPref) { |
| 305 const Extension* extension = AddExtension(); | 313 const Extension* extension = AddExtension(); |
| 306 ASSERT_TRUE(extension); | 314 ASSERT_TRUE(extension); |
| 307 | 315 |
| 308 NavigateAndCommit(GURL("https://www.google.com")); | 316 NavigateAndCommit(GURL("https://www.google.com")); |
| 309 EXPECT_TRUE(controller()->RequiresUserConsentForScriptInjection(extension)); | 317 EXPECT_TRUE(RequiresUserConsent(extension)); |
| 310 | 318 |
| 311 // Enable the extension on all urls. | 319 // Enable the extension on all urls. |
| 312 util::SetAllowedScriptingOnAllUrls(extension->id(), profile(), true); | 320 util::SetAllowedScriptingOnAllUrls(extension->id(), profile(), true); |
| 313 | 321 |
| 314 EXPECT_FALSE(controller()->RequiresUserConsentForScriptInjection(extension)); | 322 EXPECT_FALSE(RequiresUserConsent(extension)); |
| 315 // This should carry across navigations, and websites. | 323 // This should carry across navigations, and websites. |
| 316 NavigateAndCommit(GURL("http://www.foo.com")); | 324 NavigateAndCommit(GURL("http://www.foo.com")); |
| 317 EXPECT_FALSE(controller()->RequiresUserConsentForScriptInjection(extension)); | 325 EXPECT_FALSE(RequiresUserConsent(extension)); |
| 318 | 326 |
| 319 // Turning off the preference should have instant effect. | 327 // Turning off the preference should have instant effect. |
| 320 util::SetAllowedScriptingOnAllUrls(extension->id(), profile(), false); | 328 util::SetAllowedScriptingOnAllUrls(extension->id(), profile(), false); |
| 321 EXPECT_TRUE(controller()->RequiresUserConsentForScriptInjection(extension)); | 329 EXPECT_TRUE(RequiresUserConsent(extension)); |
| 322 | 330 |
| 323 // And should also persist across navigations and websites. | 331 // And should also persist across navigations and websites. |
| 324 NavigateAndCommit(GURL("http://www.bar.com")); | 332 NavigateAndCommit(GURL("http://www.bar.com")); |
| 325 EXPECT_TRUE(controller()->RequiresUserConsentForScriptInjection(extension)); | 333 EXPECT_TRUE(RequiresUserConsent(extension)); |
| 326 } | 334 } |
| 327 | 335 |
| 328 } // namespace extensions | 336 } // namespace extensions |
| OLD | NEW |