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

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

Issue 2142523004: M52: Merge "Reland: service worker: Don't control a subframe of an insecure context" (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2743
Patch Set: fix compile errors Created 4 years, 5 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"
11 #include "chrome/browser/extensions/extension_apitest.h" 11 #include "chrome/browser/extensions/extension_apitest.h"
12 #include "chrome/browser/extensions/extension_service.h" 12 #include "chrome/browser/extensions/extension_service.h"
13 #include "chrome/browser/notifications/desktop_notification_profile_util.h" 13 #include "chrome/browser/notifications/desktop_notification_profile_util.h"
14 #include "chrome/browser/push_messaging/push_messaging_app_identifier.h" 14 #include "chrome/browser/push_messaging/push_messaging_app_identifier.h"
15 #include "chrome/browser/push_messaging/push_messaging_service_factory.h" 15 #include "chrome/browser/push_messaging/push_messaging_service_factory.h"
16 #include "chrome/browser/push_messaging/push_messaging_service_impl.h" 16 #include "chrome/browser/push_messaging/push_messaging_service_impl.h"
17 #include "chrome/browser/services/gcm/fake_gcm_profile_service.h" 17 #include "chrome/browser/services/gcm/fake_gcm_profile_service.h"
18 #include "chrome/browser/services/gcm/gcm_profile_service_factory.h" 18 #include "chrome/browser/services/gcm/gcm_profile_service_factory.h"
19 #include "chrome/browser/ui/tabs/tab_strip_model.h" 19 #include "chrome/browser/ui/tabs/tab_strip_model.h"
20 #include "chrome/test/base/ui_test_utils.h" 20 #include "chrome/test/base/ui_test_utils.h"
21 #include "components/version_info/version_info.h" 21 #include "components/version_info/version_info.h"
22 #include "content/public/browser/navigation_controller.h" 22 #include "content/public/browser/navigation_controller.h"
23 #include "content/public/browser/navigation_entry.h" 23 #include "content/public/browser/navigation_entry.h"
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/origin_util.h"
26 #include "content/public/common/page_type.h" 27 #include "content/public/common/page_type.h"
27 #include "content/public/test/background_sync_test_util.h" 28 #include "content/public/test/background_sync_test_util.h"
28 #include "content/public/test/browser_test_utils.h" 29 #include "content/public/test/browser_test_utils.h"
29 #include "extensions/browser/extension_host.h" 30 #include "extensions/browser/extension_host.h"
30 #include "extensions/browser/extension_registry.h" 31 #include "extensions/browser/extension_registry.h"
31 #include "extensions/browser/process_manager.h" 32 #include "extensions/browser/process_manager.h"
32 #include "extensions/test/background_page_watcher.h" 33 #include "extensions/test/background_page_watcher.h"
33 #include "extensions/test/extension_test_message_listener.h" 34 #include "extensions/test/extension_test_message_listener.h"
35 #include "net/dns/mock_host_resolver.h"
34 #include "net/test/embedded_test_server/embedded_test_server.h" 36 #include "net/test/embedded_test_server/embedded_test_server.h"
35 37
36 namespace extensions { 38 namespace extensions {
37 39
38 namespace { 40 namespace {
39 41
40 // Pass into ServiceWorkerTest::StartTestFromBackgroundPage to indicate that 42 // Pass into ServiceWorkerTest::StartTestFromBackgroundPage to indicate that
41 // registration is expected to succeed. 43 // registration is expected to succeed.
42 std::string* const kExpectSuccess = nullptr; 44 std::string* const kExpectSuccess = nullptr;
43 45
(...skipping 558 matching lines...) Expand 10 before | Expand all | Expand 10 after
602 // This test also verifies that if the requested resource exists in the manifest 604 // This test also verifies that if the requested resource exists in the manifest
603 // but is not present in the extension directory, the Service Worker can still 605 // but is not present in the extension directory, the Service Worker can still
604 // serve the resource file. 606 // serve the resource file.
605 IN_PROC_BROWSER_TEST_F(ServiceWorkerTest, WebAccessibleResourcesIframeSrc) { 607 IN_PROC_BROWSER_TEST_F(ServiceWorkerTest, WebAccessibleResourcesIframeSrc) {
606 const Extension* extension = LoadExtensionWithFlags( 608 const Extension* extension = LoadExtensionWithFlags(
607 test_data_dir_.AppendASCII( 609 test_data_dir_.AppendASCII(
608 "service_worker/web_accessible_resources/iframe_src"), 610 "service_worker/web_accessible_resources/iframe_src"),
609 kFlagNone); 611 kFlagNone);
610 ASSERT_TRUE(extension); 612 ASSERT_TRUE(extension);
611 ASSERT_TRUE(StartEmbeddedTestServer()); 613 ASSERT_TRUE(StartEmbeddedTestServer());
612 GURL page_url = embedded_test_server()->GetURL( 614
613 "/extensions/api_test/service_worker/web_accessible_resources/" 615 // Service workers can only control secure contexts
614 "webpage.html"); 616 // (https://w3c.github.io/webappsec-secure-contexts/). For documents, this
617 // typically means the document must have a secure origin AND all its ancestor
618 // frames must have documents with secure origins. However, extension pages
619 // are considered secure, even if they have an ancestor document that is an
620 // insecure context (see GetSchemesBypassingSecureContextCheckWhitelist). So
621 // extension service workers must be able to control an extension page
622 // embedded in an insecure context. To test this, set up an insecure
623 // (non-localhost, non-https) URL for the web page. This page will create
624 // iframes that load extension pages that must be controllable by service
625 // worker.
626 host_resolver()->AddRule("a.com", "127.0.0.1");
627 GURL page_url =
628 embedded_test_server()->GetURL("a.com",
629 "/extensions/api_test/service_worker/"
630 "web_accessible_resources/webpage.html");
631 EXPECT_FALSE(content::IsOriginSecure(page_url));
615 632
616 content::WebContents* web_contents = AddTab(browser(), page_url); 633 content::WebContents* web_contents = AddTab(browser(), page_url);
617 std::string result; 634 std::string result;
618 // webpage.html will create an iframe pointing to a resource from |extension|. 635 // webpage.html will create an iframe pointing to a resource from |extension|.
619 // Expect the resource to be served by the extension. 636 // Expect the resource to be served by the extension.
620 EXPECT_TRUE(content::ExecuteScriptAndExtractString( 637 EXPECT_TRUE(content::ExecuteScriptAndExtractString(
621 web_contents, base::StringPrintf("window.testIframe('%s', 'iframe.html')", 638 web_contents, base::StringPrintf("window.testIframe('%s', 'iframe.html')",
622 extension->id().c_str()), 639 extension->id().c_str()),
623 &result)); 640 &result));
624 EXPECT_EQ("FROM_EXTENSION_RESOURCE", result); 641 EXPECT_EQ("FROM_EXTENSION_RESOURCE", result);
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
735 push_message_listener.set_failure_message("FAIL"); 752 push_message_listener.set_failure_message("FAIL");
736 gcm::IncomingMessage message; 753 gcm::IncomingMessage message;
737 message.sender_id = "1234567890"; 754 message.sender_id = "1234567890";
738 message.raw_data = "testdata"; 755 message.raw_data = "testdata";
739 message.decrypted = true; 756 message.decrypted = true;
740 push_service()->OnMessage(app_identifier.app_id(), message); 757 push_service()->OnMessage(app_identifier.app_id(), message);
741 EXPECT_TRUE(push_message_listener.WaitUntilSatisfied()); 758 EXPECT_TRUE(push_message_listener.WaitUntilSatisfied());
742 } 759 }
743 760
744 } // namespace extensions 761 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/chrome_content_browser_client.cc ('k') | content/browser/service_worker/service_worker_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698