Chromium Code Reviews| 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/tab_helper.h" | 10 #include "chrome/browser/extensions/tab_helper.h" |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 212 // Request an injection. There should be an action visible, but no executions. | 212 // Request an injection. There should be an action visible, but no executions. |
| 213 controller()->RequestScriptInjection( | 213 controller()->RequestScriptInjection( |
| 214 extension, | 214 extension, |
| 215 GetPageId(), | 215 GetPageId(), |
| 216 GetExecutionCallbackForExtension(extension->id())); | 216 GetExecutionCallbackForExtension(extension->id())); |
| 217 EXPECT_TRUE(controller()->GetActionForExtension(extension)); | 217 EXPECT_TRUE(controller()->GetActionForExtension(extension)); |
| 218 EXPECT_EQ(0u, GetExecutionCountForExtension(extension->id())); | 218 EXPECT_EQ(0u, GetExecutionCountForExtension(extension->id())); |
| 219 | 219 |
| 220 // Navigate away. This should remove the pending injection, and we should not | 220 // Navigate away. This should remove the pending injection, and we should not |
| 221 // execute anything. | 221 // execute anything. |
| 222 NavigateAndCommit(GURL("https://www.google.com")); | 222 Reload(); |
|
nasko
2014/05/29 22:59:30
nit: Either the action or the comment is incorrect
Nate Chapin
2014/05/29 23:03:46
Depends on your definition of "away" :)
Will clar
| |
| 223 EXPECT_FALSE(controller()->GetActionForExtension(extension)); | 223 EXPECT_FALSE(controller()->GetActionForExtension(extension)); |
| 224 EXPECT_EQ(0u, GetExecutionCountForExtension(extension->id())); | 224 EXPECT_EQ(0u, GetExecutionCountForExtension(extension->id())); |
| 225 | 225 |
| 226 // Request and accept a new injection. | 226 // Request and accept a new injection. |
| 227 controller()->RequestScriptInjection( | 227 controller()->RequestScriptInjection( |
| 228 extension, | 228 extension, |
| 229 GetPageId(), | 229 GetPageId(), |
| 230 GetExecutionCallbackForExtension(extension->id())); | 230 GetExecutionCallbackForExtension(extension->id())); |
| 231 controller()->OnClicked(extension); | 231 controller()->OnClicked(extension); |
| 232 | 232 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 272 ASSERT_TRUE(active_tab_permission_granter); | 272 ASSERT_TRUE(active_tab_permission_granter); |
| 273 // Grant the extension active tab permissions. This normally happens, e.g., | 273 // Grant the extension active tab permissions. This normally happens, e.g., |
| 274 // if the user clicks on a browser action. | 274 // if the user clicks on a browser action. |
| 275 active_tab_permission_granter->GrantIfRequested(extension); | 275 active_tab_permission_granter->GrantIfRequested(extension); |
| 276 | 276 |
| 277 // Since we have active tab permissions, we shouldn't need user consent | 277 // Since we have active tab permissions, we shouldn't need user consent |
| 278 // anymore. | 278 // anymore. |
| 279 EXPECT_FALSE(controller()->RequiresUserConsentForScriptInjection(extension)); | 279 EXPECT_FALSE(controller()->RequiresUserConsentForScriptInjection(extension)); |
| 280 | 280 |
| 281 // Also test that granting active tab runs any pending tasks. | 281 // Also test that granting active tab runs any pending tasks. |
| 282 NavigateAndCommit(GURL("https://www.google.com")); | 282 Reload(); |
| 283 // Navigating should mean we need permission again. | 283 // Navigating should mean we need permission again. |
| 284 EXPECT_TRUE(controller()->RequiresUserConsentForScriptInjection(extension)); | 284 EXPECT_TRUE(controller()->RequiresUserConsentForScriptInjection(extension)); |
| 285 | 285 |
| 286 controller()->RequestScriptInjection( | 286 controller()->RequestScriptInjection( |
| 287 extension, | 287 extension, |
| 288 GetPageId(), | 288 GetPageId(), |
| 289 GetExecutionCallbackForExtension(extension->id())); | 289 GetExecutionCallbackForExtension(extension->id())); |
| 290 EXPECT_TRUE(controller()->GetActionForExtension(extension)); | 290 EXPECT_TRUE(controller()->GetActionForExtension(extension)); |
| 291 EXPECT_EQ(0u, GetExecutionCountForExtension(extension->id())); | 291 EXPECT_EQ(0u, GetExecutionCountForExtension(extension->id())); |
| 292 | 292 |
| 293 // Grant active tab. | 293 // Grant active tab. |
| 294 active_tab_permission_granter->GrantIfRequested(extension); | 294 active_tab_permission_granter->GrantIfRequested(extension); |
| 295 | 295 |
| 296 // The pending injections should have run since active tab permission was | 296 // The pending injections should have run since active tab permission was |
| 297 // granted. | 297 // granted. |
| 298 EXPECT_EQ(1u, GetExecutionCountForExtension(extension->id())); | 298 EXPECT_EQ(1u, GetExecutionCountForExtension(extension->id())); |
| 299 EXPECT_FALSE(controller()->GetActionForExtension(extension)); | 299 EXPECT_FALSE(controller()->GetActionForExtension(extension)); |
| 300 } | 300 } |
| 301 | 301 |
| 302 } // namespace extensions | 302 } // namespace extensions |
| OLD | NEW |