| 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" |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 controller()->OnClicked(extension); | 187 controller()->OnClicked(extension); |
| 188 | 188 |
| 189 // The extension should execute, and the action should go away. | 189 // The extension should execute, and the action should go away. |
| 190 EXPECT_EQ(1u, GetExecutionCountForExtension(extension->id())); | 190 EXPECT_EQ(1u, GetExecutionCountForExtension(extension->id())); |
| 191 EXPECT_FALSE(controller()->GetActionForExtension(extension)); | 191 EXPECT_FALSE(controller()->GetActionForExtension(extension)); |
| 192 | 192 |
| 193 // Since we already executed on the given page, we shouldn't need permission | 193 // Since we already executed on the given page, we shouldn't need permission |
| 194 // for a second time. | 194 // for a second time. |
| 195 EXPECT_FALSE(RequiresUserConsent(extension)); | 195 EXPECT_FALSE(RequiresUserConsent(extension)); |
| 196 | 196 |
| 197 // Reloading should clear those permissions, and we should again require user | 197 // Reloading and same-origin navigations shouldn't clear those permissions, |
| 198 // consent. | 198 // and we shouldn't require user constent again. |
| 199 Reload(); | 199 Reload(); |
| 200 EXPECT_FALSE(RequiresUserConsent(extension)); |
| 201 NavigateAndCommit(GURL("https://www.google.com/foo")); |
| 202 EXPECT_FALSE(RequiresUserConsent(extension)); |
| 203 NavigateAndCommit(GURL("https://www.google.com/bar")); |
| 204 EXPECT_FALSE(RequiresUserConsent(extension)); |
| 205 |
| 206 // Cross-origin navigations should clear permissions. |
| 207 NavigateAndCommit(GURL("https://otherdomain.google.com")); |
| 200 EXPECT_TRUE(RequiresUserConsent(extension)); | 208 EXPECT_TRUE(RequiresUserConsent(extension)); |
| 201 | 209 |
| 202 // Grant access. | 210 // Grant access. |
| 203 RequestInjection(extension); | 211 RequestInjection(extension); |
| 204 controller()->OnClicked(extension); | 212 controller()->OnClicked(extension); |
| 205 EXPECT_EQ(2u, GetExecutionCountForExtension(extension->id())); | 213 EXPECT_EQ(2u, GetExecutionCountForExtension(extension->id())); |
| 206 EXPECT_FALSE(controller()->GetActionForExtension(extension)); | 214 EXPECT_FALSE(controller()->GetActionForExtension(extension)); |
| 207 | 215 |
| 208 // Navigating to another site should also clear the permissions. | 216 // Navigating to another site should also clear the permissions. |
| 209 NavigateAndCommit(GURL("https://www.foo.com")); | 217 NavigateAndCommit(GURL("https://www.foo.com")); |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 273 ->active_tab_permission_granter(); | 281 ->active_tab_permission_granter(); |
| 274 ASSERT_TRUE(active_tab_permission_granter); | 282 ASSERT_TRUE(active_tab_permission_granter); |
| 275 // Grant the extension active tab permissions. This normally happens, e.g., | 283 // Grant the extension active tab permissions. This normally happens, e.g., |
| 276 // if the user clicks on a browser action. | 284 // if the user clicks on a browser action. |
| 277 active_tab_permission_granter->GrantIfRequested(extension); | 285 active_tab_permission_granter->GrantIfRequested(extension); |
| 278 | 286 |
| 279 // Since we have active tab permissions, we shouldn't need user consent | 287 // Since we have active tab permissions, we shouldn't need user consent |
| 280 // anymore. | 288 // anymore. |
| 281 EXPECT_FALSE(RequiresUserConsent(extension)); | 289 EXPECT_FALSE(RequiresUserConsent(extension)); |
| 282 | 290 |
| 283 // Also test that granting active tab runs any pending tasks. | 291 // Reloading and other same-origin navigations maintain the permission to |
| 292 // execute. |
| 284 Reload(); | 293 Reload(); |
| 285 // Navigating should mean we need permission again. | 294 EXPECT_FALSE(RequiresUserConsent(extension)); |
| 295 NavigateAndCommit(GURL("https://www.google.com/foo")); |
| 296 EXPECT_FALSE(RequiresUserConsent(extension)); |
| 297 NavigateAndCommit(GURL("https://www.google.com/bar")); |
| 298 EXPECT_FALSE(RequiresUserConsent(extension)); |
| 299 |
| 300 // Navigating to a different origin will require user consent again. |
| 301 NavigateAndCommit(GURL("https://yahoo.com")); |
| 302 EXPECT_TRUE(RequiresUserConsent(extension)); |
| 303 |
| 304 // Back to the original origin should also re-require constent. |
| 305 NavigateAndCommit(GURL("https://www.google.com")); |
| 286 EXPECT_TRUE(RequiresUserConsent(extension)); | 306 EXPECT_TRUE(RequiresUserConsent(extension)); |
| 287 | 307 |
| 288 RequestInjection(extension); | 308 RequestInjection(extension); |
| 289 EXPECT_TRUE(controller()->GetActionForExtension(extension)); | 309 EXPECT_TRUE(controller()->GetActionForExtension(extension)); |
| 290 EXPECT_EQ(0u, GetExecutionCountForExtension(extension->id())); | 310 EXPECT_EQ(0u, GetExecutionCountForExtension(extension->id())); |
| 291 | 311 |
| 292 // Grant active tab. | 312 // Grant active tab. |
| 293 active_tab_permission_granter->GrantIfRequested(extension); | 313 active_tab_permission_granter->GrantIfRequested(extension); |
| 294 | 314 |
| 295 // The pending injections should have run since active tab permission was | 315 // The pending injections should have run since active tab permission was |
| (...skipping 20 matching lines...) Expand all Loading... |
| 316 // Turning off the preference should have instant effect. | 336 // Turning off the preference should have instant effect. |
| 317 util::SetAllowedScriptingOnAllUrls(extension->id(), profile(), false); | 337 util::SetAllowedScriptingOnAllUrls(extension->id(), profile(), false); |
| 318 EXPECT_TRUE(RequiresUserConsent(extension)); | 338 EXPECT_TRUE(RequiresUserConsent(extension)); |
| 319 | 339 |
| 320 // And should also persist across navigations and websites. | 340 // And should also persist across navigations and websites. |
| 321 NavigateAndCommit(GURL("http://www.bar.com")); | 341 NavigateAndCommit(GURL("http://www.bar.com")); |
| 322 EXPECT_TRUE(RequiresUserConsent(extension)); | 342 EXPECT_TRUE(RequiresUserConsent(extension)); |
| 323 } | 343 } |
| 324 | 344 |
| 325 } // namespace extensions | 345 } // namespace extensions |
| OLD | NEW |