Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(500)

Side by Side Diff: chrome/browser/extensions/content_script_apitest.cc

Issue 2499493004: Communicate ExtensionSettings policy to renderers (Closed)
Patch Set: -Removed old includes, added lock check to SetUsesDefaultHostRestrictions Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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_test_util.h"
16 #include "chrome/browser/extensions/extension_service.h" 17 #include "chrome/browser/extensions/extension_service.h"
18 #include "chrome/browser/extensions/extension_with_management_policy_apitest.h"
17 #include "chrome/browser/extensions/test_extension_dir.h" 19 #include "chrome/browser/extensions/test_extension_dir.h"
18 #include "chrome/browser/ui/browser.h" 20 #include "chrome/browser/ui/browser.h"
19 #include "chrome/browser/ui/tabs/tab_strip_model.h" 21 #include "chrome/browser/ui/tabs/tab_strip_model.h"
20 #include "chrome/common/chrome_switches.h" 22 #include "chrome/common/chrome_switches.h"
21 #include "chrome/test/base/ui_test_utils.h" 23 #include "chrome/test/base/ui_test_utils.h"
22 #include "components/app_modal/javascript_dialog_extensions_client.h" 24 #include "components/app_modal/javascript_dialog_extensions_client.h"
23 #include "components/app_modal/javascript_dialog_manager.h" 25 #include "components/app_modal/javascript_dialog_manager.h"
24 #include "content/public/browser/javascript_dialog_manager.h" 26 #include "content/public/browser/javascript_dialog_manager.h"
25 #include "content/public/browser/render_frame_host.h" 27 #include "content/public/browser/render_frame_host.h"
26 #include "content/public/browser/web_contents.h" 28 #include "content/public/browser/web_contents.h"
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 // but takes in an optional value so that we don't have to do this. 324 // but takes in an optional value so that we don't have to do this.
323 void SetUpCommandLine(base::CommandLine* command_line) override { 325 void SetUpCommandLine(base::CommandLine* command_line) override {
324 ExtensionApiTest::SetUpCommandLine(command_line); 326 ExtensionApiTest::SetUpCommandLine(command_line);
325 // We change the Webstore URL to be http://cws.com. We need to do this so 327 // 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 328 // we can check that css injection is not allowed on the webstore (which
327 // could lead to spoofing). Unfortunately, host_resolver seems to have 329 // could lead to spoofing). Unfortunately, host_resolver seems to have
328 // problems with redirecting "chrome.google.com" to the test server, so we 330 // 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 331 // can't use the real Webstore's URL. If this changes, we could clean this
330 // up. 332 // up.
331 command_line->AppendSwitchASCII( 333 command_line->AppendSwitchASCII(
332 switches::kAppsGalleryURL, 334 ::switches::kAppsGalleryURL,
333 base::StringPrintf("http://%s", kWebstoreDomain)); 335 base::StringPrintf("http://%s", kWebstoreDomain));
334 } 336 }
335 }; 337 };
336 338
337 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, 339 IN_PROC_BROWSER_TEST_F(ExtensionApiTest,
338 ContentScriptDuplicateScriptInjection) { 340 ContentScriptDuplicateScriptInjection) {
339 host_resolver()->AddRule("maps.google.com", "127.0.0.1"); 341 host_resolver()->AddRule("maps.google.com", "127.0.0.1");
340 ASSERT_TRUE(StartEmbeddedTestServer()); 342 ASSERT_TRUE(StartEmbeddedTestServer());
341 343
342 GURL url( 344 GURL url(
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
462 EXPECT_TRUE(catcher.GetNextResult()); 464 EXPECT_TRUE(catcher.GetNextResult());
463 } 465 }
464 466
465 // Flaky on Windows. http://crbug.com/248418 467 // Flaky on Windows. http://crbug.com/248418
466 #if defined(OS_WIN) 468 #if defined(OS_WIN)
467 #define MAYBE_ContentScriptPermissionsApi DISABLED_ContentScriptPermissionsApi 469 #define MAYBE_ContentScriptPermissionsApi DISABLED_ContentScriptPermissionsApi
468 #else 470 #else
469 #define MAYBE_ContentScriptPermissionsApi ContentScriptPermissionsApi 471 #define MAYBE_ContentScriptPermissionsApi ContentScriptPermissionsApi
470 #endif 472 #endif
471 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, MAYBE_ContentScriptPermissionsApi) { 473 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, MAYBE_ContentScriptPermissionsApi) {
472 extensions::PermissionsRequestFunction::SetIgnoreUserGestureForTests(true);
473 extensions::PermissionsRequestFunction::SetAutoConfirmForTests(true);
Devlin 2017/04/03 15:52:23 This will break this test...
nrpeter 2017/04/03 22:35:48 Done.
474 host_resolver()->AddRule("*.com", "127.0.0.1"); 474 host_resolver()->AddRule("*.com", "127.0.0.1");
475 ASSERT_TRUE(StartEmbeddedTestServer()); 475 ASSERT_TRUE(StartEmbeddedTestServer());
476 ASSERT_TRUE(RunExtensionTest("content_scripts/permissions")) << message_; 476 ASSERT_TRUE(RunExtensionTest("content_scripts/permissions")) << message_;
477 } 477 }
478 478
479 IN_PROC_BROWSER_TEST_F(ExtensionApiTestWithManagementPolicy,
480 ContentScriptPolicy) {
481 // Set enterprise policy to block injection to policy specified host.
482 {
483 ExtensionManagementPolicyUpdater pref(&policy_provider_);
484 pref.AddRuntimeBlockedHost("*", "*://example.com/*");
485 }
486 PermissionsRequestFunction::SetAutoConfirmForTests(true);
487 PermissionsRequestFunction::SetIgnoreUserGestureForTests(true);
488 host_resolver()->AddRule("*.com", "127.0.0.1");
489 ASSERT_TRUE(StartEmbeddedTestServer());
490 ASSERT_TRUE(RunExtensionTest("content_scripts/policy")) << message_;
491 }
492
479 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, ContentScriptBypassPageCSP) { 493 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, ContentScriptBypassPageCSP) {
480 ASSERT_TRUE(StartEmbeddedTestServer()); 494 ASSERT_TRUE(StartEmbeddedTestServer());
481 ASSERT_TRUE(RunExtensionTest("content_scripts/bypass_page_csp")) << message_; 495 ASSERT_TRUE(RunExtensionTest("content_scripts/bypass_page_csp")) << message_;
482 } 496 }
483 497
484 // Test that when injecting a blocking content script, other scripts don't run 498 // Test that when injecting a blocking content script, other scripts don't run
485 // until the blocking script finishes. 499 // until the blocking script finishes.
486 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, ContentScriptBlockingScript) { 500 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, ContentScriptBlockingScript) {
487 ASSERT_TRUE(StartEmbeddedTestServer()); 501 ASSERT_TRUE(StartEmbeddedTestServer());
488 502
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
660 ExtensionTestMessageListener iframe_loaded_listener("iframe loaded", false); 674 ExtensionTestMessageListener iframe_loaded_listener("iframe loaded", false);
661 ExtensionTestMessageListener content_script_listener("script injected", 675 ExtensionTestMessageListener content_script_listener("script injected",
662 false); 676 false);
663 LoadExtension(data_dir.AppendASCII("script_a_com")); 677 LoadExtension(data_dir.AppendASCII("script_a_com"));
664 LoadExtension(data_dir.AppendASCII("background_page_iframe")); 678 LoadExtension(data_dir.AppendASCII("background_page_iframe"));
665 iframe_loaded_listener.WaitUntilSatisfied(); 679 iframe_loaded_listener.WaitUntilSatisfied();
666 EXPECT_FALSE(content_script_listener.was_satisfied()); 680 EXPECT_FALSE(content_script_listener.was_satisfied());
667 } 681 }
668 682
669 } // namespace extensions 683 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698