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/files/scoped_temp_dir.h" | 9 #include "base/files/scoped_temp_dir.h" |
10 #include "base/numerics/safe_conversions.h" | 10 #include "base/numerics/safe_conversions.h" |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 bool actual) { | 46 bool actual) { |
47 EXPECT_EQ(expected, actual); | 47 EXPECT_EQ(expected, actual); |
48 continuation.Run(); | 48 continuation.Run(); |
49 } | 49 } |
50 | 50 |
51 // http://crbug.com/368570 | 51 // http://crbug.com/368570 |
52 IN_PROC_BROWSER_TEST_F(ChromeServiceWorkerTest, | 52 IN_PROC_BROWSER_TEST_F(ChromeServiceWorkerTest, |
53 CanShutDownWithRegisteredServiceWorker) { | 53 CanShutDownWithRegisteredServiceWorker) { |
54 WriteFile(FILE_PATH_LITERAL("service_worker.js"), ""); | 54 WriteFile(FILE_PATH_LITERAL("service_worker.js"), ""); |
55 WriteFile(FILE_PATH_LITERAL("service_worker.js.mock-http-headers"), | 55 WriteFile(FILE_PATH_LITERAL("service_worker.js.mock-http-headers"), |
56 "HTTP/1.0 200 OK\nContent-Type: text/javascript\n"); | 56 "HTTP/1.1 200 OK\nContent-Type: text/javascript"); |
57 | 57 |
58 embedded_test_server()->ServeFilesFromDirectory(service_worker_dir_.path()); | 58 embedded_test_server()->ServeFilesFromDirectory(service_worker_dir_.path()); |
59 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | 59 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
60 | 60 |
61 content::ServiceWorkerContext* sw_context = | 61 content::ServiceWorkerContext* sw_context = |
62 content::BrowserContext::GetDefaultStoragePartition(browser()->profile()) | 62 content::BrowserContext::GetDefaultStoragePartition(browser()->profile()) |
63 ->GetServiceWorkerContext(); | 63 ->GetServiceWorkerContext(); |
64 | 64 |
65 base::RunLoop run_loop; | 65 base::RunLoop run_loop; |
66 sw_context->RegisterServiceWorker( | 66 sw_context->RegisterServiceWorker( |
67 embedded_test_server()->GetURL("/"), | 67 embedded_test_server()->GetURL("/"), |
68 embedded_test_server()->GetURL("/service_worker.js"), | 68 embedded_test_server()->GetURL("/service_worker.js"), |
69 base::Bind(&ExpectResultAndRun, true, run_loop.QuitClosure())); | 69 base::Bind(&ExpectResultAndRun, true, run_loop.QuitClosure())); |
70 run_loop.Run(); | 70 run_loop.Run(); |
71 | 71 |
72 // Leave the Service Worker registered, and make sure that the browser can | 72 // Leave the Service Worker registered, and make sure that the browser can |
73 // shut down without DCHECK'ing. It'd be nice to check here that the SW is | 73 // shut down without DCHECK'ing. It'd be nice to check here that the SW is |
74 // actually occupying a process, but we don't yet have the public interface to | 74 // actually occupying a process, but we don't yet have the public interface to |
75 // do that. | 75 // do that. |
76 } | 76 } |
77 | 77 |
78 // http://crbug.com/419290 | 78 // http://crbug.com/419290 |
79 IN_PROC_BROWSER_TEST_F(ChromeServiceWorkerTest, | 79 IN_PROC_BROWSER_TEST_F(ChromeServiceWorkerTest, |
80 CanCloseIncognitoWindowWithServiceWorkerController) { | 80 CanCloseIncognitoWindowWithServiceWorkerController) { |
81 WriteFile(FILE_PATH_LITERAL("service_worker.js"), ""); | 81 WriteFile(FILE_PATH_LITERAL("service_worker.js"), ""); |
82 WriteFile(FILE_PATH_LITERAL("service_worker.js.mock-http-headers"), | 82 WriteFile(FILE_PATH_LITERAL("service_worker.js.mock-http-headers"), |
83 "HTTP/1.0 200 OK\nContent-Type: text/javascript\n"); | 83 "HTTP/1.1 200 OK\nContent-Type: text/javascript"); |
84 WriteFile(FILE_PATH_LITERAL("test.html"), ""); | 84 WriteFile(FILE_PATH_LITERAL("test.html"), ""); |
85 | 85 |
86 embedded_test_server()->ServeFilesFromDirectory(service_worker_dir_.path()); | 86 embedded_test_server()->ServeFilesFromDirectory(service_worker_dir_.path()); |
87 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | 87 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
88 | 88 |
89 Browser* incognito = CreateIncognitoBrowser(); | 89 Browser* incognito = CreateIncognitoBrowser(); |
90 content::ServiceWorkerContext* sw_context = | 90 content::ServiceWorkerContext* sw_context = |
91 content::BrowserContext::GetDefaultStoragePartition(incognito->profile()) | 91 content::BrowserContext::GetDefaultStoragePartition(incognito->profile()) |
92 ->GetServiceWorkerContext(); | 92 ->GetServiceWorkerContext(); |
93 | 93 |
94 base::RunLoop run_loop; | 94 base::RunLoop run_loop; |
95 sw_context->RegisterServiceWorker( | 95 sw_context->RegisterServiceWorker( |
96 embedded_test_server()->GetURL("/"), | 96 embedded_test_server()->GetURL("/"), |
97 embedded_test_server()->GetURL("/service_worker.js"), | 97 embedded_test_server()->GetURL("/service_worker.js"), |
98 base::Bind(&ExpectResultAndRun, true, run_loop.QuitClosure())); | 98 base::Bind(&ExpectResultAndRun, true, run_loop.QuitClosure())); |
99 run_loop.Run(); | 99 run_loop.Run(); |
100 | 100 |
101 ui_test_utils::NavigateToURL(incognito, | 101 ui_test_utils::NavigateToURL(incognito, |
102 embedded_test_server()->GetURL("/test.html")); | 102 embedded_test_server()->GetURL("/test.html")); |
103 | 103 |
104 content::WindowedNotificationObserver observer( | 104 content::WindowedNotificationObserver observer( |
105 chrome::NOTIFICATION_BROWSER_CLOSED, content::Source<Browser>(incognito)); | 105 chrome::NOTIFICATION_BROWSER_CLOSED, content::Source<Browser>(incognito)); |
106 incognito->window()->Close(); | 106 incognito->window()->Close(); |
107 observer.Wait(); | 107 observer.Wait(); |
108 | 108 |
109 // Test passes if we don't crash. | 109 // Test passes if we don't crash. |
110 } | 110 } |
111 | 111 |
112 } // namespace | 112 } // namespace |
OLD | NEW |