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

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: change useCache to updateViaCache Created 3 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 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 489 matching lines...) Expand 10 before | Expand all | Expand 10 after
670 WriteFile(FILE_PATH_LITERAL("sw.js"), 674 WriteFile(FILE_PATH_LITERAL("sw.js"),
671 "self.oninstall = function(e) {\n" 675 "self.oninstall = function(e) {\n"
672 " e.waitUntil(new Promise(r => { /* never resolve */ }));\n" 676 " e.waitUntil(new Promise(r => { /* never resolve */ }));\n"
673 " };\n" 677 " };\n"
674 "self.onfetch = function(e) {};"); 678 "self.onfetch = function(e) {};");
675 InitializeServer(); 679 InitializeServer();
676 base::RunLoop run_loop; 680 base::RunLoop run_loop;
677 GetServiceWorkerContext()->RegisterServiceWorker( 681 GetServiceWorkerContext()->RegisterServiceWorker(
678 embedded_test_server()->GetURL("/scope/"), 682 embedded_test_server()->GetURL("/scope/"),
679 embedded_test_server()->GetURL("/sw.js"), 683 embedded_test_server()->GetURL("/sw.js"),
684 blink::WebServiceWorkerUpdateViaCache::kImports,
680 base::Bind(&ExpectResultAndRun<bool>, true, run_loop.QuitClosure())); 685 base::Bind(&ExpectResultAndRun<bool>, true, run_loop.QuitClosure()));
681 run_loop.Run(); 686 run_loop.Run();
682 RunNavigationHintTest("/scope/", 687 RunNavigationHintTest("/scope/",
683 content::StartServiceWorkerForNavigationHintResult:: 688 content::StartServiceWorkerForNavigationHintResult::
684 NO_ACTIVE_SERVICE_WORKER_VERSION, 689 NO_ACTIVE_SERVICE_WORKER_VERSION,
685 false); 690 false);
686 } 691 }
687 692
688 IN_PROC_BROWSER_TEST_F(ChromeServiceWorkerNavigationHintTest, NoFetchHandler) { 693 IN_PROC_BROWSER_TEST_F(ChromeServiceWorkerNavigationHintTest, NoFetchHandler) {
689 WriteFile(FILE_PATH_LITERAL("sw.js"), "/* empty */"); 694 WriteFile(FILE_PATH_LITERAL("sw.js"), "/* empty */");
690 WriteFile(FILE_PATH_LITERAL("test.html"), kInstallAndWaitForActivatedPage); 695 WriteFile(FILE_PATH_LITERAL("test.html"), kInstallAndWaitForActivatedPage);
691 InitializeServer(); 696 InitializeServer();
692 NavigateToPageAndWaitForReadyTitle("/test.html"); 697 NavigateToPageAndWaitForReadyTitle("/test.html");
693 GetServiceWorkerContext()->StopAllServiceWorkersForOrigin( 698 GetServiceWorkerContext()->StopAllServiceWorkersForOrigin(
694 embedded_test_server()->base_url()); 699 embedded_test_server()->base_url());
695 RunNavigationHintTest( 700 RunNavigationHintTest(
696 "/scope/", 701 "/scope/",
697 content::StartServiceWorkerForNavigationHintResult::NO_FETCH_HANDLER, 702 content::StartServiceWorkerForNavigationHintResult::NO_FETCH_HANDLER,
698 false); 703 false);
699 } 704 }
700 705
701 } // namespace 706 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698