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

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

Issue 2009453002: service worker: Don't control a subframe of an insecure context (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: selfreview Created 4 years, 6 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 <stdint.h> 5 #include <stdint.h>
6 6
7 #include "base/bind_helpers.h" 7 #include "base/bind_helpers.h"
8 #include "base/macros.h" 8 #include "base/macros.h"
9 #include "base/strings/stringprintf.h" 9 #include "base/strings/stringprintf.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
(...skipping 13 matching lines...) Expand all
24 #include "content/public/browser/web_contents.h" 24 #include "content/public/browser/web_contents.h"
25 #include "content/public/common/content_switches.h" 25 #include "content/public/common/content_switches.h"
26 #include "content/public/common/page_type.h" 26 #include "content/public/common/page_type.h"
27 #include "content/public/test/background_sync_test_util.h" 27 #include "content/public/test/background_sync_test_util.h"
28 #include "content/public/test/browser_test_utils.h" 28 #include "content/public/test/browser_test_utils.h"
29 #include "extensions/browser/extension_host.h" 29 #include "extensions/browser/extension_host.h"
30 #include "extensions/browser/extension_registry.h" 30 #include "extensions/browser/extension_registry.h"
31 #include "extensions/browser/process_manager.h" 31 #include "extensions/browser/process_manager.h"
32 #include "extensions/test/background_page_watcher.h" 32 #include "extensions/test/background_page_watcher.h"
33 #include "extensions/test/extension_test_message_listener.h" 33 #include "extensions/test/extension_test_message_listener.h"
34 #include "net/dns/mock_host_resolver.h"
34 #include "net/test/embedded_test_server/embedded_test_server.h" 35 #include "net/test/embedded_test_server/embedded_test_server.h"
35 36
36 namespace extensions { 37 namespace extensions {
37 38
38 namespace { 39 namespace {
39 40
40 // Pass into ServiceWorkerTest::StartTestFromBackgroundPage to indicate that 41 // Pass into ServiceWorkerTest::StartTestFromBackgroundPage to indicate that
41 // registration is expected to succeed. 42 // registration is expected to succeed.
42 std::string* const kExpectSuccess = nullptr; 43 std::string* const kExpectSuccess = nullptr;
43 44
(...skipping 623 matching lines...) Expand 10 before | Expand all | Expand 10 after
667 // present in the extension directory. Expect the resources of the iframe to 668 // present in the extension directory. Expect the resources of the iframe to
668 // be served by the Service Worker. 669 // be served by the Service Worker.
669 EXPECT_TRUE(content::ExecuteScriptAndExtractString( 670 EXPECT_TRUE(content::ExecuteScriptAndExtractString(
670 web_contents, 671 web_contents,
671 base::StringPrintf("window.testIframe('%s', 'iframe_non_existent.html')", 672 base::StringPrintf("window.testIframe('%s', 'iframe_non_existent.html')",
672 extension->id().c_str()), 673 extension->id().c_str()),
673 &result)); 674 &result));
674 EXPECT_EQ("FROM_SW_RESOURCE", result); 675 EXPECT_EQ("FROM_SW_RESOURCE", result);
675 } 676 }
676 677
678 // Tests that service worker serves resources even if they are embedded in an
679 // insecure context.
680 IN_PROC_BROWSER_TEST_F(ServiceWorkerTest,
681 WebAccessibleResourcesInsecureIframe) {
alexmos 2016/06/02 23:54:47 Can you run this through the linux_site_isolation
falken 2016/06/03 08:22:05 That trybot is in the CQ_INCLUDE_TRYBOT so the CQ
682 const Extension* extension = LoadExtensionWithFlags(
683 test_data_dir_.AppendASCII(
684 "service_worker/web_accessible_resources/iframe_src"),
685 kFlagNone);
686 ASSERT_TRUE(extension);
687 ASSERT_TRUE(StartEmbeddedTestServer());
688 GURL page_url = embedded_test_server()->GetURL(
689 "/extensions/api_test/service_worker/web_accessible_resources/"
690 "webpage.html");
691 host_resolver()->AddRule("a.com", "127.0.0.1");
692 GURL::Replacements replace_host_and_scheme;
693 replace_host_and_scheme.SetHostStr("a.com");
694 replace_host_and_scheme.SetSchemeStr("http");
695 page_url = page_url.ReplaceComponents(replace_host_and_scheme);
alexmos 2016/06/02 23:54:47 Why not just use embedded_test_server()->GetURL("a
falken 2016/06/03 08:22:05 Done. This is because I just copied jww's test in
696
697 content::WebContents* web_contents = AddTab(browser(), page_url);
698 std::string result;
699 // webpage.html will create an iframe pointing to a resource from |extension|.
700 // Expect the resource to be served by the extension.
701 EXPECT_TRUE(content::ExecuteScriptAndExtractString(
702 web_contents, base::StringPrintf("window.testIframe('%s', 'iframe.html')",
703 extension->id().c_str()),
704 &result));
705 EXPECT_EQ("FROM_EXTENSION_RESOURCE", result);
706
707 ExtensionTestMessageListener service_worker_ready_listener("SW_READY", false);
708 EXPECT_TRUE(ExecuteScriptInBackgroundPageNoWait(
709 extension->id(), "window.registerServiceWorker()"));
710 EXPECT_TRUE(service_worker_ready_listener.WaitUntilSatisfied());
711
712 result.clear();
713 // webpage.html will create another iframe pointing to a resource from
714 // |extension| as before. But this time, the resource should be be served
715 // from the Service Worker.
716 EXPECT_TRUE(content::ExecuteScriptAndExtractString(
717 web_contents, base::StringPrintf("window.testIframe('%s', 'iframe.html')",
718 extension->id().c_str()),
719 &result));
720 EXPECT_EQ("FROM_SW_RESOURCE", result);
721
722 result.clear();
723 // webpage.html will create yet another iframe pointing to a resource that
724 // exists in the extension manifest's web_accessible_resources, but is not
725 // present in the extension directory. Expect the resources of the iframe to
726 // be served by the Service Worker.
727 EXPECT_TRUE(content::ExecuteScriptAndExtractString(
728 web_contents,
729 base::StringPrintf("window.testIframe('%s', 'iframe_non_existent.html')",
730 extension->id().c_str()),
731 &result));
732 EXPECT_EQ("FROM_SW_RESOURCE", result);
733 }
734
677 IN_PROC_BROWSER_TEST_F(ServiceWorkerBackgroundSyncTest, Sync) { 735 IN_PROC_BROWSER_TEST_F(ServiceWorkerBackgroundSyncTest, Sync) {
678 const Extension* extension = LoadExtensionWithFlags( 736 const Extension* extension = LoadExtensionWithFlags(
679 test_data_dir_.AppendASCII("service_worker/sync"), kFlagNone); 737 test_data_dir_.AppendASCII("service_worker/sync"), kFlagNone);
680 ASSERT_TRUE(extension); 738 ASSERT_TRUE(extension);
681 ui_test_utils::NavigateToURL(browser(), 739 ui_test_utils::NavigateToURL(browser(),
682 extension->GetResourceURL("page.html")); 740 extension->GetResourceURL("page.html"));
683 content::WebContents* web_contents = 741 content::WebContents* web_contents =
684 browser()->tab_strip_model()->GetActiveWebContents(); 742 browser()->tab_strip_model()->GetActiveWebContents();
685 743
686 // Prevent firing by going offline. 744 // Prevent firing by going offline.
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
754 message.sender_id = "1234567890"; 812 message.sender_id = "1234567890";
755 message.raw_data = "testdata"; 813 message.raw_data = "testdata";
756 message.decrypted = true; 814 message.decrypted = true;
757 push_service()->SetMessageCallbackForTesting(run_loop.QuitClosure()); 815 push_service()->SetMessageCallbackForTesting(run_loop.QuitClosure());
758 push_service()->OnMessage(app_identifier.app_id(), message); 816 push_service()->OnMessage(app_identifier.app_id(), message);
759 EXPECT_TRUE(push_message_listener.WaitUntilSatisfied()); 817 EXPECT_TRUE(push_message_listener.WaitUntilSatisfied());
760 run_loop.Run(); // Wait until the message is handled by push service. 818 run_loop.Run(); // Wait until the message is handled by push service.
761 } 819 }
762 820
763 } // namespace extensions 821 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698