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

Side by Side Diff: chrome/browser/chrome_service_worker_browsertest.cc

Issue 2771823002: Implement updateViaCache flag and no-cache by default for main service worker scripts
Patch Set: fix IPC Created 3 years, 4 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
« no previous file with comments | « chrome/browser/DEPS ('k') | content/browser/DEPS » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 // This file tests that Service Workers (a Content feature) work in the Chromium 5 // This file tests that Service Workers (a Content feature) work in the Chromium
6 // embedder. 6 // embedder.
7 7
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/files/scoped_temp_dir.h" 10 #include "base/files/scoped_temp_dir.h"
(...skipping 16 matching lines...) Expand all
27 #include "chrome/test/base/ui_test_utils.h" 27 #include "chrome/test/base/ui_test_utils.h"
28 #include "components/content_settings/core/browser/host_content_settings_map.h" 28 #include "components/content_settings/core/browser/host_content_settings_map.h"
29 #include "content/public/browser/browser_context.h" 29 #include "content/public/browser/browser_context.h"
30 #include "content/public/browser/render_frame_host.h" 30 #include "content/public/browser/render_frame_host.h"
31 #include "content/public/browser/service_worker_context.h" 31 #include "content/public/browser/service_worker_context.h"
32 #include "content/public/browser/storage_partition.h" 32 #include "content/public/browser/storage_partition.h"
33 #include "content/public/browser/web_contents.h" 33 #include "content/public/browser/web_contents.h"
34 #include "content/public/test/browser_test_utils.h" 34 #include "content/public/test/browser_test_utils.h"
35 #include "net/test/embedded_test_server/embedded_test_server.h" 35 #include "net/test/embedded_test_server/embedded_test_server.h"
36 #include "ppapi/shared_impl/ppapi_switches.h" 36 #include "ppapi/shared_impl/ppapi_switches.h"
37 #include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWor kerUpdateViaCache.h"
37 38
38 namespace { 39 namespace {
39 40
40 const std::string kInstallAndWaitForActivatedPage = 41 const std::string kInstallAndWaitForActivatedPage =
41 "<script>" 42 "<script>"
42 "navigator.serviceWorker.register('./sw.js', {scope: './scope/'})" 43 "navigator.serviceWorker.register('./sw.js', {scope: './scope/'})"
43 " .then(function(reg) {" 44 " .then(function(reg) {"
44 " reg.addEventListener('updatefound', function() {" 45 " reg.addEventListener('updatefound', function() {"
45 " var worker = reg.installing;" 46 " var worker = reg.installing;"
46 " worker.addEventListener('statechange', function() {" 47 " worker.addEventListener('statechange', function() {"
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 WriteFile(FILE_PATH_LITERAL("service_worker.js"), ""); 111 WriteFile(FILE_PATH_LITERAL("service_worker.js"), "");
111 112
112 embedded_test_server()->ServeFilesFromDirectory( 113 embedded_test_server()->ServeFilesFromDirectory(
113 service_worker_dir_.GetPath()); 114 service_worker_dir_.GetPath());
114 ASSERT_TRUE(embedded_test_server()->Start()); 115 ASSERT_TRUE(embedded_test_server()->Start());
115 116
116 base::RunLoop run_loop; 117 base::RunLoop run_loop;
117 GetServiceWorkerContext()->RegisterServiceWorker( 118 GetServiceWorkerContext()->RegisterServiceWorker(
118 embedded_test_server()->GetURL("/"), 119 embedded_test_server()->GetURL("/"),
119 embedded_test_server()->GetURL("/service_worker.js"), 120 embedded_test_server()->GetURL("/service_worker.js"),
121 blink::WebServiceWorkerUpdateViaCache::kImports,
120 base::Bind(&ExpectResultAndRun<bool>, true, run_loop.QuitClosure())); 122 base::Bind(&ExpectResultAndRun<bool>, true, run_loop.QuitClosure()));
121 run_loop.Run(); 123 run_loop.Run();
122 124
123 // Leave the Service Worker registered, and make sure that the browser can 125 // Leave the Service Worker registered, and make sure that the browser can
124 // shut down without DCHECK'ing. It'd be nice to check here that the SW is 126 // shut down without DCHECK'ing. It'd be nice to check here that the SW is
125 // actually occupying a process, but we don't yet have the public interface to 127 // actually occupying a process, but we don't yet have the public interface to
126 // do that. 128 // do that.
127 } 129 }
128 130
129 // http://crbug.com/419290 131 // http://crbug.com/419290
130 IN_PROC_BROWSER_TEST_F(ChromeServiceWorkerTest, 132 IN_PROC_BROWSER_TEST_F(ChromeServiceWorkerTest,
131 CanCloseIncognitoWindowWithServiceWorkerController) { 133 CanCloseIncognitoWindowWithServiceWorkerController) {
132 WriteFile(FILE_PATH_LITERAL("service_worker.js"), ""); 134 WriteFile(FILE_PATH_LITERAL("service_worker.js"), "");
133 WriteFile(FILE_PATH_LITERAL("service_worker.js.mock-http-headers"), 135 WriteFile(FILE_PATH_LITERAL("service_worker.js.mock-http-headers"),
134 "HTTP/1.1 200 OK\nContent-Type: text/javascript"); 136 "HTTP/1.1 200 OK\nContent-Type: text/javascript");
135 WriteFile(FILE_PATH_LITERAL("test.html"), ""); 137 WriteFile(FILE_PATH_LITERAL("test.html"), "");
136 InitializeServer(); 138 InitializeServer();
137 139
138 Browser* incognito = CreateIncognitoBrowser(); 140 Browser* incognito = CreateIncognitoBrowser();
139 141
140 base::RunLoop run_loop; 142 base::RunLoop run_loop;
141 GetServiceWorkerContext()->RegisterServiceWorker( 143 GetServiceWorkerContext()->RegisterServiceWorker(
142 embedded_test_server()->GetURL("/"), 144 embedded_test_server()->GetURL("/"),
143 embedded_test_server()->GetURL("/service_worker.js"), 145 embedded_test_server()->GetURL("/service_worker.js"),
146 blink::WebServiceWorkerUpdateViaCache::kImports,
144 base::Bind(&ExpectResultAndRun<bool>, true, run_loop.QuitClosure())); 147 base::Bind(&ExpectResultAndRun<bool>, true, run_loop.QuitClosure()));
145 run_loop.Run(); 148 run_loop.Run();
146 149
147 ui_test_utils::NavigateToURL(incognito, 150 ui_test_utils::NavigateToURL(incognito,
148 embedded_test_server()->GetURL("/test.html")); 151 embedded_test_server()->GetURL("/test.html"));
149 152
150 content::WindowedNotificationObserver observer( 153 content::WindowedNotificationObserver observer(
151 chrome::NOTIFICATION_BROWSER_CLOSED, content::Source<Browser>(incognito)); 154 chrome::NOTIFICATION_BROWSER_CLOSED, content::Source<Browser>(incognito));
152 incognito->window()->Close(); 155 incognito->window()->Close();
153 observer.Wait(); 156 observer.Wait();
154 157
155 // Test passes if we don't crash. 158 // Test passes if we don't crash.
156 } 159 }
157 160
158 IN_PROC_BROWSER_TEST_F(ChromeServiceWorkerTest, 161 IN_PROC_BROWSER_TEST_F(ChromeServiceWorkerTest,
159 FailRegisterServiceWorkerWhenJSDisabled) { 162 FailRegisterServiceWorkerWhenJSDisabled) {
160 WriteFile(FILE_PATH_LITERAL("service_worker.js"), ""); 163 WriteFile(FILE_PATH_LITERAL("service_worker.js"), "");
161 InitializeServer(); 164 InitializeServer();
162 165
163 HostContentSettingsMapFactory::GetForProfile(browser()->profile()) 166 HostContentSettingsMapFactory::GetForProfile(browser()->profile())
164 ->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_JAVASCRIPT, 167 ->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_JAVASCRIPT,
165 CONTENT_SETTING_BLOCK); 168 CONTENT_SETTING_BLOCK);
166 169
167 base::RunLoop run_loop; 170 base::RunLoop run_loop;
168 GetServiceWorkerContext()->RegisterServiceWorker( 171 GetServiceWorkerContext()->RegisterServiceWorker(
169 embedded_test_server()->GetURL("/"), 172 embedded_test_server()->GetURL("/"),
170 embedded_test_server()->GetURL("/service_worker.js"), 173 embedded_test_server()->GetURL("/service_worker.js"),
174 blink::WebServiceWorkerUpdateViaCache::kImports,
171 base::Bind(&ExpectResultAndRun<bool>, false, run_loop.QuitClosure())); 175 base::Bind(&ExpectResultAndRun<bool>, false, run_loop.QuitClosure()));
172 run_loop.Run(); 176 run_loop.Run();
173 } 177 }
174 178
175 IN_PROC_BROWSER_TEST_F(ChromeServiceWorkerTest, 179 IN_PROC_BROWSER_TEST_F(ChromeServiceWorkerTest,
176 FallbackMainResourceRequestWhenJSDisabled) { 180 FallbackMainResourceRequestWhenJSDisabled) {
177 WriteFile( 181 WriteFile(
178 FILE_PATH_LITERAL("sw.js"), 182 FILE_PATH_LITERAL("sw.js"),
179 "self.onfetch = function(e) {" 183 "self.onfetch = function(e) {"
180 " e.respondWith(new Response('<title>Fail</title>'," 184 " e.respondWith(new Response('<title>Fail</title>',"
(...skipping 495 matching lines...) Expand 10 before | Expand all | Expand 10 after
676 WriteFile(FILE_PATH_LITERAL("sw.js"), 680 WriteFile(FILE_PATH_LITERAL("sw.js"),
677 "self.oninstall = function(e) {\n" 681 "self.oninstall = function(e) {\n"
678 " e.waitUntil(new Promise(r => { /* never resolve */ }));\n" 682 " e.waitUntil(new Promise(r => { /* never resolve */ }));\n"
679 " };\n" 683 " };\n"
680 "self.onfetch = function(e) {};"); 684 "self.onfetch = function(e) {};");
681 InitializeServer(); 685 InitializeServer();
682 base::RunLoop run_loop; 686 base::RunLoop run_loop;
683 GetServiceWorkerContext()->RegisterServiceWorker( 687 GetServiceWorkerContext()->RegisterServiceWorker(
684 embedded_test_server()->GetURL("/scope/"), 688 embedded_test_server()->GetURL("/scope/"),
685 embedded_test_server()->GetURL("/sw.js"), 689 embedded_test_server()->GetURL("/sw.js"),
690 blink::WebServiceWorkerUpdateViaCache::kImports,
686 base::Bind(&ExpectResultAndRun<bool>, true, run_loop.QuitClosure())); 691 base::Bind(&ExpectResultAndRun<bool>, true, run_loop.QuitClosure()));
687 run_loop.Run(); 692 run_loop.Run();
688 RunNavigationHintTest("/scope/", 693 RunNavigationHintTest("/scope/",
689 content::StartServiceWorkerForNavigationHintResult:: 694 content::StartServiceWorkerForNavigationHintResult::
690 NO_ACTIVE_SERVICE_WORKER_VERSION, 695 NO_ACTIVE_SERVICE_WORKER_VERSION,
691 false); 696 false);
692 } 697 }
693 698
694 IN_PROC_BROWSER_TEST_F(ChromeServiceWorkerNavigationHintTest, NoFetchHandler) { 699 IN_PROC_BROWSER_TEST_F(ChromeServiceWorkerNavigationHintTest, NoFetchHandler) {
695 WriteFile(FILE_PATH_LITERAL("sw.js"), "/* empty */"); 700 WriteFile(FILE_PATH_LITERAL("sw.js"), "/* empty */");
696 WriteFile(FILE_PATH_LITERAL("test.html"), kInstallAndWaitForActivatedPage); 701 WriteFile(FILE_PATH_LITERAL("test.html"), kInstallAndWaitForActivatedPage);
697 InitializeServer(); 702 InitializeServer();
698 NavigateToPageAndWaitForReadyTitle("/test.html"); 703 NavigateToPageAndWaitForReadyTitle("/test.html");
699 GetServiceWorkerContext()->StopAllServiceWorkersForOrigin( 704 GetServiceWorkerContext()->StopAllServiceWorkersForOrigin(
700 embedded_test_server()->base_url()); 705 embedded_test_server()->base_url());
701 RunNavigationHintTest( 706 RunNavigationHintTest(
702 "/scope/", 707 "/scope/",
703 content::StartServiceWorkerForNavigationHintResult::NO_FETCH_HANDLER, 708 content::StartServiceWorkerForNavigationHintResult::NO_FETCH_HANDLER,
704 false); 709 false);
705 } 710 }
706 711
707 } // namespace 712 } // namespace
OLDNEW
« no previous file with comments | « chrome/browser/DEPS ('k') | content/browser/DEPS » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698