OLD | NEW |
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 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 }; | 92 }; |
93 | 93 |
94 } // namespace | 94 } // namespace |
95 | 95 |
96 class ServiceWorkerTest : public ExtensionApiTest { | 96 class ServiceWorkerTest : public ExtensionApiTest { |
97 public: | 97 public: |
98 ServiceWorkerTest() : current_channel_(version_info::Channel::STABLE) {} | 98 ServiceWorkerTest() : current_channel_(version_info::Channel::STABLE) {} |
99 | 99 |
100 ~ServiceWorkerTest() override {} | 100 ~ServiceWorkerTest() override {} |
101 | 101 |
| 102 void SetUpOnMainThread() override { |
| 103 ExtensionApiTest::SetUpOnMainThread(); |
| 104 host_resolver()->AddRule("a.com", "127.0.0.1"); |
| 105 } |
| 106 |
102 protected: | 107 protected: |
103 // Returns the ProcessManager for the test's profile. | 108 // Returns the ProcessManager for the test's profile. |
104 ProcessManager* process_manager() { return ProcessManager::Get(profile()); } | 109 ProcessManager* process_manager() { return ProcessManager::Get(profile()); } |
105 | 110 |
106 // Starts running a test from the background page test extension. | 111 // Starts running a test from the background page test extension. |
107 // | 112 // |
108 // This registers a service worker with |script_name|, and fetches the | 113 // This registers a service worker with |script_name|, and fetches the |
109 // registration result. | 114 // registration result. |
110 // | 115 // |
111 // If |error_or_null| is null (kExpectSuccess), success is expected and this | 116 // If |error_or_null| is null (kExpectSuccess), success is expected and this |
(...skipping 634 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
746 // (https://w3c.github.io/webappsec-secure-contexts/). For documents, this | 751 // (https://w3c.github.io/webappsec-secure-contexts/). For documents, this |
747 // typically means the document must have a secure origin AND all its ancestor | 752 // typically means the document must have a secure origin AND all its ancestor |
748 // frames must have documents with secure origins. However, extension pages | 753 // frames must have documents with secure origins. However, extension pages |
749 // are considered secure, even if they have an ancestor document that is an | 754 // are considered secure, even if they have an ancestor document that is an |
750 // insecure context (see GetSchemesBypassingSecureContextCheckWhitelist). So | 755 // insecure context (see GetSchemesBypassingSecureContextCheckWhitelist). So |
751 // extension service workers must be able to control an extension page | 756 // extension service workers must be able to control an extension page |
752 // embedded in an insecure context. To test this, set up an insecure | 757 // embedded in an insecure context. To test this, set up an insecure |
753 // (non-localhost, non-https) URL for the web page. This page will create | 758 // (non-localhost, non-https) URL for the web page. This page will create |
754 // iframes that load extension pages that must be controllable by service | 759 // iframes that load extension pages that must be controllable by service |
755 // worker. | 760 // worker. |
756 host_resolver()->AddRule("a.com", "127.0.0.1"); | |
757 GURL page_url = | 761 GURL page_url = |
758 embedded_test_server()->GetURL("a.com", | 762 embedded_test_server()->GetURL("a.com", |
759 "/extensions/api_test/service_worker/" | 763 "/extensions/api_test/service_worker/" |
760 "web_accessible_resources/webpage.html"); | 764 "web_accessible_resources/webpage.html"); |
761 EXPECT_FALSE(content::IsOriginSecure(page_url)); | 765 EXPECT_FALSE(content::IsOriginSecure(page_url)); |
762 | 766 |
763 content::WebContents* web_contents = AddTab(browser(), page_url); | 767 content::WebContents* web_contents = AddTab(browser(), page_url); |
764 std::string result; | 768 std::string result; |
765 // webpage.html will create an iframe pointing to a resource from |extension|. | 769 // webpage.html will create an iframe pointing to a resource from |extension|. |
766 // Expect the resource to be served by the extension. | 770 // Expect the resource to be served by the extension. |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
878 message.sender_id = "1234567890"; | 882 message.sender_id = "1234567890"; |
879 message.raw_data = "testdata"; | 883 message.raw_data = "testdata"; |
880 message.decrypted = true; | 884 message.decrypted = true; |
881 push_service()->SetMessageCallbackForTesting(run_loop.QuitClosure()); | 885 push_service()->SetMessageCallbackForTesting(run_loop.QuitClosure()); |
882 push_service()->OnMessage(app_identifier.app_id(), message); | 886 push_service()->OnMessage(app_identifier.app_id(), message); |
883 EXPECT_TRUE(push_message_listener.WaitUntilSatisfied()); | 887 EXPECT_TRUE(push_message_listener.WaitUntilSatisfied()); |
884 run_loop.Run(); // Wait until the message is handled by push service. | 888 run_loop.Run(); // Wait until the message is handled by push service. |
885 } | 889 } |
886 | 890 |
887 } // namespace extensions | 891 } // namespace extensions |
OLD | NEW |