Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <stddef.h> | 5 #include <stddef.h> |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| 11 #include "base/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
| 12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
| 13 #include "build/build_config.h" | 13 #include "build/build_config.h" |
| 14 #include "chrome/browser/extensions/api/permissions/permissions_api.h" | 14 #include "chrome/browser/extensions/api/permissions/permissions_api.h" |
| 15 #include "chrome/browser/extensions/extension_apitest.h" | 15 #include "chrome/browser/extensions/extension_apitest.h" |
| 16 #include "chrome/browser/extensions/extension_management_constants.h" | |
|
dcheng
2017/03/31 23:48:06
I'm not sure this is used.
nrpeter
2017/04/05 23:13:26
Done.
| |
| 17 #include "chrome/browser/extensions/extension_management_test_util.h" | |
| 16 #include "chrome/browser/extensions/extension_service.h" | 18 #include "chrome/browser/extensions/extension_service.h" |
| 19 #include "chrome/browser/extensions/extension_with_management_policy_apitest.h" | |
| 17 #include "chrome/browser/extensions/test_extension_dir.h" | 20 #include "chrome/browser/extensions/test_extension_dir.h" |
| 18 #include "chrome/browser/ui/browser.h" | 21 #include "chrome/browser/ui/browser.h" |
| 19 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 22 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 20 #include "chrome/common/chrome_switches.h" | 23 #include "chrome/common/chrome_switches.h" |
| 21 #include "chrome/test/base/ui_test_utils.h" | 24 #include "chrome/test/base/ui_test_utils.h" |
| 22 #include "components/app_modal/javascript_dialog_extensions_client.h" | 25 #include "components/app_modal/javascript_dialog_extensions_client.h" |
| 23 #include "components/app_modal/javascript_dialog_manager.h" | 26 #include "components/app_modal/javascript_dialog_manager.h" |
| 27 #include "components/policy/core/browser/browser_policy_connector.h" | |
| 28 #include "components/policy/core/common/mock_configuration_policy_provider.h" | |
|
dcheng
2017/03/31 23:48:05
Ditto
nrpeter
2017/04/01 00:19:02
Done.
| |
| 24 #include "content/public/browser/javascript_dialog_manager.h" | 29 #include "content/public/browser/javascript_dialog_manager.h" |
| 25 #include "content/public/browser/render_frame_host.h" | 30 #include "content/public/browser/render_frame_host.h" |
| 26 #include "content/public/browser/web_contents.h" | 31 #include "content/public/browser/web_contents.h" |
| 27 #include "content/public/browser/web_contents_delegate.h" | 32 #include "content/public/browser/web_contents_delegate.h" |
| 28 #include "content/public/test/browser_test_utils.h" | 33 #include "content/public/test/browser_test_utils.h" |
| 29 #include "extensions/browser/notification_types.h" | 34 #include "extensions/browser/notification_types.h" |
| 30 #include "extensions/common/extension.h" | 35 #include "extensions/common/extension.h" |
| 31 #include "extensions/test/extension_test_message_listener.h" | 36 #include "extensions/test/extension_test_message_listener.h" |
| 32 #include "extensions/test/result_catcher.h" | 37 #include "extensions/test/result_catcher.h" |
| 33 #include "net/dns/mock_host_resolver.h" | 38 #include "net/dns/mock_host_resolver.h" |
| (...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 322 // but takes in an optional value so that we don't have to do this. | 327 // but takes in an optional value so that we don't have to do this. |
| 323 void SetUpCommandLine(base::CommandLine* command_line) override { | 328 void SetUpCommandLine(base::CommandLine* command_line) override { |
| 324 ExtensionApiTest::SetUpCommandLine(command_line); | 329 ExtensionApiTest::SetUpCommandLine(command_line); |
| 325 // We change the Webstore URL to be http://cws.com. We need to do this so | 330 // We change the Webstore URL to be http://cws.com. We need to do this so |
| 326 // we can check that css injection is not allowed on the webstore (which | 331 // we can check that css injection is not allowed on the webstore (which |
| 327 // could lead to spoofing). Unfortunately, host_resolver seems to have | 332 // could lead to spoofing). Unfortunately, host_resolver seems to have |
| 328 // problems with redirecting "chrome.google.com" to the test server, so we | 333 // problems with redirecting "chrome.google.com" to the test server, so we |
| 329 // can't use the real Webstore's URL. If this changes, we could clean this | 334 // can't use the real Webstore's URL. If this changes, we could clean this |
| 330 // up. | 335 // up. |
| 331 command_line->AppendSwitchASCII( | 336 command_line->AppendSwitchASCII( |
| 332 switches::kAppsGalleryURL, | 337 ::switches::kAppsGalleryURL, |
| 333 base::StringPrintf("http://%s", kWebstoreDomain)); | 338 base::StringPrintf("http://%s", kWebstoreDomain)); |
| 334 } | 339 } |
| 335 }; | 340 }; |
| 336 | 341 |
| 337 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, | 342 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, |
| 338 ContentScriptDuplicateScriptInjection) { | 343 ContentScriptDuplicateScriptInjection) { |
| 339 host_resolver()->AddRule("maps.google.com", "127.0.0.1"); | 344 host_resolver()->AddRule("maps.google.com", "127.0.0.1"); |
| 340 ASSERT_TRUE(StartEmbeddedTestServer()); | 345 ASSERT_TRUE(StartEmbeddedTestServer()); |
| 341 | 346 |
| 342 GURL url( | 347 GURL url( |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 462 EXPECT_TRUE(catcher.GetNextResult()); | 467 EXPECT_TRUE(catcher.GetNextResult()); |
| 463 } | 468 } |
| 464 | 469 |
| 465 // Flaky on Windows. http://crbug.com/248418 | 470 // Flaky on Windows. http://crbug.com/248418 |
| 466 #if defined(OS_WIN) | 471 #if defined(OS_WIN) |
| 467 #define MAYBE_ContentScriptPermissionsApi DISABLED_ContentScriptPermissionsApi | 472 #define MAYBE_ContentScriptPermissionsApi DISABLED_ContentScriptPermissionsApi |
| 468 #else | 473 #else |
| 469 #define MAYBE_ContentScriptPermissionsApi ContentScriptPermissionsApi | 474 #define MAYBE_ContentScriptPermissionsApi ContentScriptPermissionsApi |
| 470 #endif | 475 #endif |
| 471 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, MAYBE_ContentScriptPermissionsApi) { | 476 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, MAYBE_ContentScriptPermissionsApi) { |
| 472 extensions::PermissionsRequestFunction::SetIgnoreUserGestureForTests(true); | |
| 473 extensions::PermissionsRequestFunction::SetAutoConfirmForTests(true); | |
| 474 host_resolver()->AddRule("*.com", "127.0.0.1"); | 477 host_resolver()->AddRule("*.com", "127.0.0.1"); |
| 475 ASSERT_TRUE(StartEmbeddedTestServer()); | 478 ASSERT_TRUE(StartEmbeddedTestServer()); |
| 476 ASSERT_TRUE(RunExtensionTest("content_scripts/permissions")) << message_; | 479 ASSERT_TRUE(RunExtensionTest("content_scripts/permissions")) << message_; |
| 477 } | 480 } |
| 478 | 481 |
| 482 IN_PROC_BROWSER_TEST_F(ExtensionApiTestWithManagementPolicy, | |
| 483 ContentScriptPolicy) { | |
| 484 // Set enterprise policy to block injection to policy specified host. | |
| 485 { | |
| 486 ExtensionManagementPolicyUpdater pref(&policy_provider_); | |
| 487 pref.AddRuntimeBlockedHost("*", "*://example.com/*"); | |
| 488 } | |
| 489 PermissionsRequestFunction::SetAutoConfirmForTests(true); | |
| 490 PermissionsRequestFunction::SetIgnoreUserGestureForTests(true); | |
| 491 host_resolver()->AddRule("*.com", "127.0.0.1"); | |
| 492 ASSERT_TRUE(StartEmbeddedTestServer()); | |
| 493 ASSERT_TRUE(RunExtensionTest("content_scripts/policy")) << message_; | |
| 494 } | |
| 495 | |
| 479 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, ContentScriptBypassPageCSP) { | 496 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, ContentScriptBypassPageCSP) { |
| 480 ASSERT_TRUE(StartEmbeddedTestServer()); | 497 ASSERT_TRUE(StartEmbeddedTestServer()); |
| 481 ASSERT_TRUE(RunExtensionTest("content_scripts/bypass_page_csp")) << message_; | 498 ASSERT_TRUE(RunExtensionTest("content_scripts/bypass_page_csp")) << message_; |
| 482 } | 499 } |
| 483 | 500 |
| 484 // Test that when injecting a blocking content script, other scripts don't run | 501 // Test that when injecting a blocking content script, other scripts don't run |
| 485 // until the blocking script finishes. | 502 // until the blocking script finishes. |
| 486 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, ContentScriptBlockingScript) { | 503 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, ContentScriptBlockingScript) { |
| 487 ASSERT_TRUE(StartEmbeddedTestServer()); | 504 ASSERT_TRUE(StartEmbeddedTestServer()); |
| 488 | 505 |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 660 ExtensionTestMessageListener iframe_loaded_listener("iframe loaded", false); | 677 ExtensionTestMessageListener iframe_loaded_listener("iframe loaded", false); |
| 661 ExtensionTestMessageListener content_script_listener("script injected", | 678 ExtensionTestMessageListener content_script_listener("script injected", |
| 662 false); | 679 false); |
| 663 LoadExtension(data_dir.AppendASCII("script_a_com")); | 680 LoadExtension(data_dir.AppendASCII("script_a_com")); |
| 664 LoadExtension(data_dir.AppendASCII("background_page_iframe")); | 681 LoadExtension(data_dir.AppendASCII("background_page_iframe")); |
| 665 iframe_loaded_listener.WaitUntilSatisfied(); | 682 iframe_loaded_listener.WaitUntilSatisfied(); |
| 666 EXPECT_FALSE(content_script_listener.was_satisfied()); | 683 EXPECT_FALSE(content_script_listener.was_satisfied()); |
| 667 } | 684 } |
| 668 | 685 |
| 669 } // namespace extensions | 686 } // namespace extensions |
| OLD | NEW |