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 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
269 ActiveTabPermissionGranter* active_tab_permission_granter = | 269 ActiveTabPermissionGranter* active_tab_permission_granter = |
270 TabHelper::FromWebContents(web_contents()) | 270 TabHelper::FromWebContents(web_contents()) |
271 ->active_tab_permission_granter(); | 271 ->active_tab_permission_granter(); |
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( | 279 EXPECT_FALSE(controller()->RequiresUserConsentForScriptInjection(extension)); |
280 controller()->RequiresUserConsentForScriptInjection(extension)); | |
281 | 280 |
282 // TODO(rdevlin.cronin): We should also implement/test that granting active | 281 // Also test that granting active tab runs any pending tasks. |
283 // tab permissions automatically runs any pending injections. | 282 NavigateAndCommit(GURL("https://www.google.com")); |
| 283 // Navigating should mean we need permission again. |
| 284 EXPECT_TRUE(controller()->RequiresUserConsentForScriptInjection(extension)); |
| 285 |
| 286 controller()->RequestScriptInjection( |
| 287 extension, |
| 288 GetPageId(), |
| 289 GetExecutionCallbackForExtension(extension->id())); |
| 290 EXPECT_TRUE(controller()->GetActionForExtension(extension)); |
| 291 EXPECT_EQ(0u, GetExecutionCountForExtension(extension->id())); |
| 292 |
| 293 // Grant active tab. |
| 294 active_tab_permission_granter->GrantIfRequested(extension); |
| 295 |
| 296 // The pending injections should have run since active tab permission was |
| 297 // granted. |
| 298 EXPECT_EQ(1u, GetExecutionCountForExtension(extension->id())); |
| 299 EXPECT_FALSE(controller()->GetActionForExtension(extension)); |
284 } | 300 } |
285 | 301 |
286 } // namespace extensions | 302 } // namespace extensions |
OLD | NEW |