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" | |
| 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" | |
| 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 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 457 // listening for. | 462 // listening for. |
| 458 ui_test_utils::NavigateToURLWithDisposition( | 463 ui_test_utils::NavigateToURLWithDisposition( |
| 459 browser(), extension->GetResourceURL("fire_event.html"), | 464 browser(), extension->GetResourceURL("fire_event.html"), |
| 460 WindowOpenDisposition::NEW_FOREGROUND_TAB, | 465 WindowOpenDisposition::NEW_FOREGROUND_TAB, |
| 461 ui_test_utils::BROWSER_TEST_NONE); | 466 ui_test_utils::BROWSER_TEST_NONE); |
| 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 |
|
Devlin
2017/03/29 21:36:49
We probably shouldn't be relying on a test that's
nrpeter
2017/03/30 00:06:05
Looks like this was disabled ~4 years ago on Windo
Devlin
2017/03/30 00:33:53
We don't have FLAKY_ tests on chrome; only disable
nrpeter
2017/03/31 21:43:34
I opted for the second option, creating another br
| |
| 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(ExtensionApiTestWithManagementPolicy, |
| 472 extensions::PermissionsRequestFunction::SetIgnoreUserGestureForTests(true); | 477 MAYBE_ContentScriptPermissionsApi) { |
| 473 extensions::PermissionsRequestFunction::SetAutoConfirmForTests(true); | 478 // Set enterprise policy to block injection to policy specified host. |
| 479 { | |
| 480 ExtensionManagementPolicyUpdater pref(&policy_provider_); | |
| 481 pref.AddRuntimeBlockedHost("*", "*://example.com/*"); | |
| 482 } | |
| 483 PermissionsRequestFunction::SetAutoConfirmForTests(true); | |
| 484 PermissionsRequestFunction::SetIgnoreUserGestureForTests(true); | |
| 474 host_resolver()->AddRule("*.com", "127.0.0.1"); | 485 host_resolver()->AddRule("*.com", "127.0.0.1"); |
| 475 ASSERT_TRUE(StartEmbeddedTestServer()); | 486 ASSERT_TRUE(StartEmbeddedTestServer()); |
| 476 ASSERT_TRUE(RunExtensionTest("content_scripts/permissions")) << message_; | 487 ASSERT_TRUE(RunExtensionTest("content_scripts/permissions")) << message_; |
| 477 } | 488 } |
| 478 | 489 |
| 479 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, ContentScriptBypassPageCSP) { | 490 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, ContentScriptBypassPageCSP) { |
| 480 ASSERT_TRUE(StartEmbeddedTestServer()); | 491 ASSERT_TRUE(StartEmbeddedTestServer()); |
| 481 ASSERT_TRUE(RunExtensionTest("content_scripts/bypass_page_csp")) << message_; | 492 ASSERT_TRUE(RunExtensionTest("content_scripts/bypass_page_csp")) << message_; |
| 482 } | 493 } |
| 483 | 494 |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 660 ExtensionTestMessageListener iframe_loaded_listener("iframe loaded", false); | 671 ExtensionTestMessageListener iframe_loaded_listener("iframe loaded", false); |
| 661 ExtensionTestMessageListener content_script_listener("script injected", | 672 ExtensionTestMessageListener content_script_listener("script injected", |
| 662 false); | 673 false); |
| 663 LoadExtension(data_dir.AppendASCII("script_a_com")); | 674 LoadExtension(data_dir.AppendASCII("script_a_com")); |
| 664 LoadExtension(data_dir.AppendASCII("background_page_iframe")); | 675 LoadExtension(data_dir.AppendASCII("background_page_iframe")); |
| 665 iframe_loaded_listener.WaitUntilSatisfied(); | 676 iframe_loaded_listener.WaitUntilSatisfied(); |
| 666 EXPECT_FALSE(content_script_listener.was_satisfied()); | 677 EXPECT_FALSE(content_script_listener.was_satisfied()); |
| 667 } | 678 } |
| 668 | 679 |
| 669 } // namespace extensions | 680 } // namespace extensions |
| OLD | NEW |