OLD | NEW |
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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 service_worker_dir_.GetPath()); | 77 service_worker_dir_.GetPath()); |
78 ASSERT_TRUE(embedded_test_server()->Start()); | 78 ASSERT_TRUE(embedded_test_server()->Start()); |
79 | 79 |
80 content::ServiceWorkerContext* sw_context = | 80 content::ServiceWorkerContext* sw_context = |
81 content::BrowserContext::GetDefaultStoragePartition(browser()->profile()) | 81 content::BrowserContext::GetDefaultStoragePartition(browser()->profile()) |
82 ->GetServiceWorkerContext(); | 82 ->GetServiceWorkerContext(); |
83 | 83 |
84 base::RunLoop run_loop; | 84 base::RunLoop run_loop; |
85 sw_context->RegisterServiceWorker( | 85 sw_context->RegisterServiceWorker( |
86 embedded_test_server()->GetURL("/"), | 86 embedded_test_server()->GetURL("/"), |
87 embedded_test_server()->GetURL("/service_worker.js"), | 87 embedded_test_server()->GetURL("/service_worker.js"), false, |
88 base::Bind(&ExpectResultAndRun, true, run_loop.QuitClosure())); | 88 base::Bind(&ExpectResultAndRun, true, run_loop.QuitClosure())); |
89 run_loop.Run(); | 89 run_loop.Run(); |
90 | 90 |
91 // Leave the Service Worker registered, and make sure that the browser can | 91 // Leave the Service Worker registered, and make sure that the browser can |
92 // shut down without DCHECK'ing. It'd be nice to check here that the SW is | 92 // shut down without DCHECK'ing. It'd be nice to check here that the SW is |
93 // actually occupying a process, but we don't yet have the public interface to | 93 // actually occupying a process, but we don't yet have the public interface to |
94 // do that. | 94 // do that. |
95 } | 95 } |
96 | 96 |
97 // http://crbug.com/419290 | 97 // http://crbug.com/419290 |
98 IN_PROC_BROWSER_TEST_F(ChromeServiceWorkerTest, | 98 IN_PROC_BROWSER_TEST_F(ChromeServiceWorkerTest, |
99 CanCloseIncognitoWindowWithServiceWorkerController) { | 99 CanCloseIncognitoWindowWithServiceWorkerController) { |
100 WriteFile(FILE_PATH_LITERAL("service_worker.js"), ""); | 100 WriteFile(FILE_PATH_LITERAL("service_worker.js"), ""); |
101 WriteFile(FILE_PATH_LITERAL("service_worker.js.mock-http-headers"), | 101 WriteFile(FILE_PATH_LITERAL("service_worker.js.mock-http-headers"), |
102 "HTTP/1.1 200 OK\nContent-Type: text/javascript"); | 102 "HTTP/1.1 200 OK\nContent-Type: text/javascript"); |
103 WriteFile(FILE_PATH_LITERAL("test.html"), ""); | 103 WriteFile(FILE_PATH_LITERAL("test.html"), ""); |
104 | 104 |
105 embedded_test_server()->ServeFilesFromDirectory( | 105 embedded_test_server()->ServeFilesFromDirectory( |
106 service_worker_dir_.GetPath()); | 106 service_worker_dir_.GetPath()); |
107 ASSERT_TRUE(embedded_test_server()->Start()); | 107 ASSERT_TRUE(embedded_test_server()->Start()); |
108 | 108 |
109 Browser* incognito = CreateIncognitoBrowser(); | 109 Browser* incognito = CreateIncognitoBrowser(); |
110 content::ServiceWorkerContext* sw_context = | 110 content::ServiceWorkerContext* sw_context = |
111 content::BrowserContext::GetDefaultStoragePartition(incognito->profile()) | 111 content::BrowserContext::GetDefaultStoragePartition(incognito->profile()) |
112 ->GetServiceWorkerContext(); | 112 ->GetServiceWorkerContext(); |
113 | 113 |
114 base::RunLoop run_loop; | 114 base::RunLoop run_loop; |
115 sw_context->RegisterServiceWorker( | 115 sw_context->RegisterServiceWorker( |
116 embedded_test_server()->GetURL("/"), | 116 embedded_test_server()->GetURL("/"), |
117 embedded_test_server()->GetURL("/service_worker.js"), | 117 embedded_test_server()->GetURL("/service_worker.js"), false, |
118 base::Bind(&ExpectResultAndRun, true, run_loop.QuitClosure())); | 118 base::Bind(&ExpectResultAndRun, true, run_loop.QuitClosure())); |
119 run_loop.Run(); | 119 run_loop.Run(); |
120 | 120 |
121 ui_test_utils::NavigateToURL(incognito, | 121 ui_test_utils::NavigateToURL(incognito, |
122 embedded_test_server()->GetURL("/test.html")); | 122 embedded_test_server()->GetURL("/test.html")); |
123 | 123 |
124 content::WindowedNotificationObserver observer( | 124 content::WindowedNotificationObserver observer( |
125 chrome::NOTIFICATION_BROWSER_CLOSED, content::Source<Browser>(incognito)); | 125 chrome::NOTIFICATION_BROWSER_CLOSED, content::Source<Browser>(incognito)); |
126 incognito->window()->Close(); | 126 incognito->window()->Close(); |
127 observer.Wait(); | 127 observer.Wait(); |
(...skipping 13 matching lines...) Expand all Loading... |
141 ->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_JAVASCRIPT, | 141 ->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_JAVASCRIPT, |
142 CONTENT_SETTING_BLOCK); | 142 CONTENT_SETTING_BLOCK); |
143 | 143 |
144 content::ServiceWorkerContext* sw_context = | 144 content::ServiceWorkerContext* sw_context = |
145 content::BrowserContext::GetDefaultStoragePartition(browser()->profile()) | 145 content::BrowserContext::GetDefaultStoragePartition(browser()->profile()) |
146 ->GetServiceWorkerContext(); | 146 ->GetServiceWorkerContext(); |
147 | 147 |
148 base::RunLoop run_loop; | 148 base::RunLoop run_loop; |
149 sw_context->RegisterServiceWorker( | 149 sw_context->RegisterServiceWorker( |
150 embedded_test_server()->GetURL("/"), | 150 embedded_test_server()->GetURL("/"), |
151 embedded_test_server()->GetURL("/service_worker.js"), | 151 embedded_test_server()->GetURL("/service_worker.js"), false, |
152 base::Bind(&ExpectResultAndRun, false, run_loop.QuitClosure())); | 152 base::Bind(&ExpectResultAndRun, false, run_loop.QuitClosure())); |
153 run_loop.Run(); | 153 run_loop.Run(); |
154 } | 154 } |
155 | 155 |
156 IN_PROC_BROWSER_TEST_F(ChromeServiceWorkerTest, | 156 IN_PROC_BROWSER_TEST_F(ChromeServiceWorkerTest, |
157 FallbackMainResourceRequestWhenJSDisabled) { | 157 FallbackMainResourceRequestWhenJSDisabled) { |
158 WriteFile( | 158 WriteFile( |
159 FILE_PATH_LITERAL("sw.js"), | 159 FILE_PATH_LITERAL("sw.js"), |
160 "self.onfetch = function(e) {" | 160 "self.onfetch = function(e) {" |
161 " e.respondWith(new Response('<title>Fail</title>'," | 161 " e.respondWith(new Response('<title>Fail</title>'," |
(...skipping 544 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
706 NoFetchEventHandler) { | 706 NoFetchEventHandler) { |
707 WriteFile(FILE_PATH_LITERAL("sw.js"), "// no fetch event handler."); | 707 WriteFile(FILE_PATH_LITERAL("sw.js"), "// no fetch event handler."); |
708 WriteFile(FILE_PATH_LITERAL("scope.html"), "<title>Done</title>"); | 708 WriteFile(FILE_PATH_LITERAL("scope.html"), "<title>Done</title>"); |
709 WriteTestHtmlFile(); | 709 WriteTestHtmlFile(); |
710 RunNavigationHintTest(); | 710 RunNavigationHintTest(); |
711 // The service worker must NOT be started by a navigation hint. | 711 // The service worker must NOT be started by a navigation hint. |
712 histogram_tester_.ExpectTotalCount(kNavigationHintLinkMouseDownMetricName, 0); | 712 histogram_tester_.ExpectTotalCount(kNavigationHintLinkMouseDownMetricName, 0); |
713 } | 713 } |
714 | 714 |
715 } // namespace | 715 } // namespace |
OLD | NEW |