Chromium Code Reviews| 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" |
| 11 #include "base/run_loop.h" | 11 #include "base/run_loop.h" |
| 12 #include "chrome/browser/chrome_notification_types.h" | |
| 12 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
| 13 #include "chrome/browser/ui/browser.h" | 14 #include "chrome/browser/ui/browser.h" |
| 15 #include "chrome/browser/ui/browser_window.h" | |
| 14 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 16 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 15 #include "chrome/test/base/in_process_browser_test.h" | 17 #include "chrome/test/base/in_process_browser_test.h" |
| 18 #include "chrome/test/base/ui_test_utils.h" | |
| 16 #include "content/public/browser/browser_context.h" | 19 #include "content/public/browser/browser_context.h" |
| 17 #include "content/public/browser/service_worker_context.h" | 20 #include "content/public/browser/service_worker_context.h" |
| 18 #include "content/public/browser/storage_partition.h" | 21 #include "content/public/browser/storage_partition.h" |
| 19 #include "content/public/browser/web_contents.h" | 22 #include "content/public/browser/web_contents.h" |
| 20 #include "net/test/embedded_test_server/embedded_test_server.h" | 23 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 21 | 24 |
| 22 namespace { | 25 namespace { |
| 23 | 26 |
| 24 class ChromeServiceWorkerTest : public InProcessBrowserTest { | 27 class ChromeServiceWorkerTest : public InProcessBrowserTest { |
| 25 protected: | 28 protected: |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 54 | 57 |
| 55 embedded_test_server()->ServeFilesFromDirectory(service_worker_dir_.path()); | 58 embedded_test_server()->ServeFilesFromDirectory(service_worker_dir_.path()); |
| 56 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | 59 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 57 | 60 |
| 58 content::ServiceWorkerContext* sw_context = | 61 content::ServiceWorkerContext* sw_context = |
| 59 content::BrowserContext::GetDefaultStoragePartition(browser()->profile()) | 62 content::BrowserContext::GetDefaultStoragePartition(browser()->profile()) |
| 60 ->GetServiceWorkerContext(); | 63 ->GetServiceWorkerContext(); |
| 61 | 64 |
| 62 base::RunLoop run_loop; | 65 base::RunLoop run_loop; |
| 63 sw_context->RegisterServiceWorker( | 66 sw_context->RegisterServiceWorker( |
| 64 embedded_test_server()->GetURL("/*"), | 67 embedded_test_server()->GetURL("/"), |
| 65 embedded_test_server()->GetURL("/service_worker.js"), | 68 embedded_test_server()->GetURL("/service_worker.js"), |
| 66 base::Bind(&ExpectResultAndRun, true, run_loop.QuitClosure())); | 69 base::Bind(&ExpectResultAndRun, true, run_loop.QuitClosure())); |
| 67 run_loop.Run(); | 70 run_loop.Run(); |
| 68 | 71 |
| 69 // 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 |
| 70 // 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 |
| 71 // 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 |
| 72 // do that. | 75 // do that. |
| 73 } | 76 } |
| 74 | 77 |
| 78 // http://crbug.com/419290 | |
| 79 IN_PROC_BROWSER_TEST_F(ChromeServiceWorkerTest, | |
| 80 CanCloseIncognitoWindowWithServiceWorkerController) { | |
| 81 WriteFile(FILE_PATH_LITERAL("service_worker.js"), ""); | |
| 82 WriteFile(FILE_PATH_LITERAL("service_worker.js.mock-http-headers"), | |
| 83 "HTTP/1.1 200 OK\nContent-Type: text/javascript"); | |
| 84 WriteFile(FILE_PATH_LITERAL("test.html"), ""); | |
| 85 | |
| 86 embedded_test_server()->ServeFilesFromDirectory(service_worker_dir_.path()); | |
| 87 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | |
| 88 | |
| 89 Browser* incognito = CreateIncognitoBrowser(); | |
| 90 content::ServiceWorkerContext* sw_context = | |
| 91 content::BrowserContext::GetDefaultStoragePartition(incognito->profile()) | |
| 92 ->GetServiceWorkerContext(); | |
| 93 | |
| 94 base::RunLoop run_loop; | |
| 95 sw_context->RegisterServiceWorker( | |
| 96 embedded_test_server()->GetURL("/"), | |
| 97 embedded_test_server()->GetURL("/service_worker.js"), | |
| 98 base::Bind(&ExpectResultAndRun, true, run_loop.QuitClosure())); | |
| 99 run_loop.Run(); | |
| 100 | |
| 101 ui_test_utils::NavigateToURL(incognito, | |
| 102 embedded_test_server()->GetURL("/test.html")); | |
| 103 | |
| 104 content::WindowedNotificationObserver observer( | |
| 105 chrome::NOTIFICATION_BROWSER_CLOSED, content::Source<Browser>(incognito)); | |
| 106 incognito->window()->Close(); | |
| 107 observer.Wait(); | |
| 108 | |
| 109 // Test passes if we don't crash. | |
|
falken
2014/10/21 09:36:35
On ToT this test just prints "Test failed" with no
| |
| 110 } | |
| 111 | |
| 75 } // namespace | 112 } // namespace |
| OLD | NEW |