| 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/extension_util.h" | 11 #include "chrome/browser/extensions/extension_util.h" |
| 11 #include "chrome/browser/extensions/permissions_updater.h" | 12 #include "chrome/browser/extensions/permissions_updater.h" |
| 12 #include "chrome/browser/extensions/tab_helper.h" | 13 #include "chrome/browser/extensions/tab_helper.h" |
| 13 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 14 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
| 14 #include "chrome/test/base/testing_profile.h" | 15 #include "chrome/test/base/testing_profile.h" |
| 15 #include "components/crx_file/id_util.h" | 16 #include "components/crx_file/id_util.h" |
| 16 #include "content/public/browser/navigation_controller.h" | 17 #include "content/public/browser/navigation_controller.h" |
| 17 #include "content/public/browser/navigation_entry.h" | 18 #include "content/public/browser/navigation_entry.h" |
| 18 #include "content/public/browser/web_contents.h" | 19 #include "content/public/browser/web_contents.h" |
| 19 #include "extensions/browser/extension_registry.h" | 20 #include "extensions/browser/extension_registry.h" |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 TEST_F(ActiveScriptControllerUnitTest, RequestPermissionAndExecute) { | 176 TEST_F(ActiveScriptControllerUnitTest, RequestPermissionAndExecute) { |
| 176 const Extension* extension = AddExtension(); | 177 const Extension* extension = AddExtension(); |
| 177 ASSERT_TRUE(extension); | 178 ASSERT_TRUE(extension); |
| 178 | 179 |
| 179 NavigateAndCommit(GURL("https://www.google.com")); | 180 NavigateAndCommit(GURL("https://www.google.com")); |
| 180 | 181 |
| 181 // Ensure that there aren't any executions pending. | 182 // Ensure that there aren't any executions pending. |
| 182 ASSERT_EQ(0u, GetExecutionCountForExtension(extension->id())); | 183 ASSERT_EQ(0u, GetExecutionCountForExtension(extension->id())); |
| 183 ASSERT_FALSE(controller()->WantsToRun(extension)); | 184 ASSERT_FALSE(controller()->WantsToRun(extension)); |
| 184 | 185 |
| 186 ExtensionActionAPI* extension_action_api = |
| 187 ExtensionActionAPI::Get(profile()); |
| 188 ASSERT_FALSE(extension_action_api->ExtensionWantsToRun(extension, |
| 189 web_contents())); |
| 190 |
| 185 // Since the extension requests all_hosts, we should require user consent. | 191 // Since the extension requests all_hosts, we should require user consent. |
| 186 EXPECT_TRUE(RequiresUserConsent(extension)); | 192 EXPECT_TRUE(RequiresUserConsent(extension)); |
| 187 | 193 |
| 188 // Request an injection. The extension should want to run, but should not have | 194 // Request an injection. The extension should want to run, but should not have |
| 189 // executed. | 195 // executed. |
| 190 RequestInjection(extension); | 196 RequestInjection(extension); |
| 191 EXPECT_TRUE(controller()->WantsToRun(extension)); | 197 EXPECT_TRUE(controller()->WantsToRun(extension)); |
| 198 EXPECT_TRUE(extension_action_api->ExtensionWantsToRun(extension, |
| 199 web_contents())); |
| 192 EXPECT_EQ(0u, GetExecutionCountForExtension(extension->id())); | 200 EXPECT_EQ(0u, GetExecutionCountForExtension(extension->id())); |
| 193 | 201 |
| 194 // Click to accept the extension executing. | 202 // Click to accept the extension executing. |
| 195 controller()->OnClicked(extension); | 203 controller()->OnClicked(extension); |
| 196 | 204 |
| 197 // The extension should execute, and the extension shouldn't want to run. | 205 // The extension should execute, and the extension shouldn't want to run. |
| 198 EXPECT_EQ(1u, GetExecutionCountForExtension(extension->id())); | 206 EXPECT_EQ(1u, GetExecutionCountForExtension(extension->id())); |
| 199 EXPECT_FALSE(controller()->WantsToRun(extension)); | 207 EXPECT_FALSE(controller()->WantsToRun(extension)); |
| 208 EXPECT_FALSE(extension_action_api->ExtensionWantsToRun(extension, |
| 209 web_contents())); |
| 200 | 210 |
| 201 // Since we already executed on the given page, we shouldn't need permission | 211 // Since we already executed on the given page, we shouldn't need permission |
| 202 // for a second time. | 212 // for a second time. |
| 203 EXPECT_FALSE(RequiresUserConsent(extension)); | 213 EXPECT_FALSE(RequiresUserConsent(extension)); |
| 204 | 214 |
| 205 // Reloading and same-origin navigations shouldn't clear those permissions, | 215 // Reloading and same-origin navigations shouldn't clear those permissions, |
| 206 // and we shouldn't require user constent again. | 216 // and we shouldn't require user constent again. |
| 207 Reload(); | 217 Reload(); |
| 208 EXPECT_FALSE(RequiresUserConsent(extension)); | 218 EXPECT_FALSE(RequiresUserConsent(extension)); |
| 209 NavigateAndCommit(GURL("https://www.google.com/foo")); | 219 NavigateAndCommit(GURL("https://www.google.com/foo")); |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 401 EXPECT_TRUE(RequiresUserConsent(extension)); | 411 EXPECT_TRUE(RequiresUserConsent(extension)); |
| 402 // Different subdomain... | 412 // Different subdomain... |
| 403 NavigateAndCommit(GURL("https://en.google.com/foo/bar")); | 413 NavigateAndCommit(GURL("https://en.google.com/foo/bar")); |
| 404 EXPECT_TRUE(RequiresUserConsent(extension)); | 414 EXPECT_TRUE(RequiresUserConsent(extension)); |
| 405 // Only the "always run" origin should be allowed to run without user consent. | 415 // Only the "always run" origin should be allowed to run without user consent. |
| 406 NavigateAndCommit(GURL("https://www.google.com/foo/bar")); | 416 NavigateAndCommit(GURL("https://www.google.com/foo/bar")); |
| 407 EXPECT_FALSE(RequiresUserConsent(extension)); | 417 EXPECT_FALSE(RequiresUserConsent(extension)); |
| 408 } | 418 } |
| 409 | 419 |
| 410 } // namespace extensions | 420 } // namespace extensions |
| OLD | NEW |