| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "base/bind.h" |
| 5 #include "base/file_path.h" | 6 #include "base/file_path.h" |
| 7 #include "base/path_service.h" |
| 8 #include "base/stringprintf.h" |
| 6 #include "base/string_util.h" | 9 #include "base/string_util.h" |
| 7 #include "base/test/test_timeouts.h" | 10 #include "base/test/test_timeouts.h" |
| 8 #include "base/threading/platform_thread.h" | 11 #include "base/utf_string_conversions.h" |
| 9 #include "chrome/app/chrome_command_ids.h" | 12 #include "chrome/browser/ui/browser.h" |
| 10 #include "chrome/test/automation/automation_proxy.h" | |
| 11 #include "chrome/test/automation/browser_proxy.h" | |
| 12 #include "chrome/test/automation/tab_proxy.h" | |
| 13 #include "chrome/test/base/layout_test_http_server.h" | |
| 14 #include "chrome/test/base/ui_test_utils.h" | 13 #include "chrome/test/base/ui_test_utils.h" |
| 15 #include "chrome/test/ui/ui_layout_test.h" | 14 #include "content/browser/worker_host/worker_process_host.h" |
| 16 #include "content/browser/worker_host/worker_service_impl.h" | 15 #include "content/browser/worker_host/worker_service_impl.h" |
| 17 #include "content/public/common/url_constants.h" | 16 #include "content/public/browser/browser_thread.h" |
| 18 #include "net/test/test_server.h" | 17 #include "content/public/common/content_paths.h" |
| 19 | 18 #include "content/test/layout_browsertest.h" |
| 19 #include "googleurl/src/gurl.h" |
| 20 |
| 21 using content::BrowserThread; |
| 20 using content::WorkerServiceImpl; | 22 using content::WorkerServiceImpl; |
| 21 | 23 |
| 22 namespace { | 24 class WorkerLayoutTest : public InProcessBrowserLayoutTest { |
| 23 | 25 public: |
| 24 const char kTestCompleteCookie[] = "status"; | 26 WorkerLayoutTest() : InProcessBrowserLayoutTest( |
| 25 const char kTestCompleteSuccess[] = "OK"; | 27 FilePath(), FilePath().AppendASCII("fast").AppendASCII("workers")) { |
| 26 const FilePath::CharType* kTestDir = | 28 } |
| 27 FILE_PATH_LITERAL("workers"); | 29 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { |
| 28 const FilePath::CharType* kManySharedWorkersFile = | 30 InProcessBrowserLayoutTest::SetUpInProcessBrowserTestFixture(); |
| 29 FILE_PATH_LITERAL("many_shared_workers.html"); | 31 AddResourceForLayoutTest( |
| 30 const FilePath::CharType* kQuerySharedWorkerShutdownFile = | 32 FilePath().AppendASCII("fast").AppendASCII("js"), |
| 31 FILE_PATH_LITERAL("queued_shared_worker_shutdown.html"); | 33 FilePath().AppendASCII("resources")); |
| 32 const FilePath::CharType* kShutdownSharedWorkerFile = | 34 } |
| 33 FILE_PATH_LITERAL("shutdown_shared_worker.html"); | 35 }; |
| 34 const FilePath::CharType* kSingleSharedWorkersFile = | |
| 35 FILE_PATH_LITERAL("single_shared_worker.html"); | |
| 36 const FilePath::CharType* kWorkerClose = | |
| 37 FILE_PATH_LITERAL("worker_close.html"); | |
| 38 | |
| 39 } // anonymous namespace | |
| 40 | |
| 41 class WorkerTest : public UILayoutTest { | |
| 42 protected: | |
| 43 virtual ~WorkerTest() { } | |
| 44 | |
| 45 void RunTest(const FilePath& test_case, const std::string& query) { | |
| 46 scoped_refptr<TabProxy> tab(GetActiveTab()); | |
| 47 ASSERT_TRUE(tab.get()); | |
| 48 | |
| 49 FilePath test_file_path = ui_test_utils::GetTestFilePath( | |
| 50 FilePath(kTestDir), test_case); | |
| 51 GURL url = ui_test_utils::GetFileUrlWithQuery(test_file_path, query); | |
| 52 ASSERT_TRUE(tab->NavigateToURL(url)); | |
| 53 | |
| 54 std::string value = WaitUntilCookieNonEmpty(tab.get(), url, | |
| 55 kTestCompleteCookie, TestTimeouts::action_max_timeout_ms()); | |
| 56 ASSERT_STREQ(kTestCompleteSuccess, value.c_str()); | |
| 57 } | |
| 58 | |
| 59 void RunIncognitoTest(const FilePath& test_case) { | |
| 60 scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); | |
| 61 ASSERT_TRUE(browser.get()); | |
| 62 | |
| 63 // Open an Incognito window. | |
| 64 ASSERT_TRUE(browser->RunCommand(IDC_NEW_INCOGNITO_WINDOW)); | |
| 65 scoped_refptr<BrowserProxy> incognito(automation()->GetBrowserWindow(1)); | |
| 66 ASSERT_TRUE(incognito.get()); | |
| 67 int window_count; | |
| 68 ASSERT_TRUE(automation()->GetBrowserWindowCount(&window_count)); | |
| 69 ASSERT_EQ(2, window_count); | |
| 70 | |
| 71 scoped_refptr<TabProxy> tab(incognito->GetTab(0)); | |
| 72 ASSERT_TRUE(tab.get()); | |
| 73 | |
| 74 GURL url = ui_test_utils::GetTestUrl(FilePath(kTestDir), test_case); | |
| 75 ASSERT_TRUE(tab->NavigateToURL(url)); | |
| 76 | |
| 77 std::string value = WaitUntilCookieNonEmpty(tab.get(), url, | |
| 78 kTestCompleteCookie, TestTimeouts::action_max_timeout_ms()); | |
| 79 | |
| 80 // Close the incognito window | |
| 81 ASSERT_TRUE(incognito->RunCommand(IDC_CLOSE_WINDOW)); | |
| 82 ASSERT_TRUE(automation()->GetBrowserWindowCount(&window_count)); | |
| 83 ASSERT_EQ(1, window_count); | |
| 84 | |
| 85 ASSERT_STREQ(kTestCompleteSuccess, value.c_str()); | |
| 86 } | |
| 87 | |
| 88 bool WaitForProcessCountToBeAtLeast(int tabs, int workers) { | |
| 89 // The 1 is for the browser process. | |
| 90 int number_of_processes = 1 + workers + tabs; | |
| 91 #if defined(OS_POSIX) && !defined(OS_MACOSX) | |
| 92 // On Unix, we also have a zygote process and a sandbox host process. | |
| 93 number_of_processes += 2; | |
| 94 #endif | |
| 95 | |
| 96 int cur_process_count; | |
| 97 for (int i = 0; i < 100; ++i) { | |
| 98 cur_process_count = 0; | |
| 99 if (!GetBrowserProcessCount(&cur_process_count)) | |
| 100 return false; | |
| 101 if (cur_process_count >= number_of_processes) | |
| 102 return true; | |
| 103 | |
| 104 // Sometimes the worker processes can take a while to shut down on the | |
| 105 // bots, so use a longer timeout period to avoid spurious failures. | |
| 106 base::PlatformThread::Sleep(TestTimeouts::action_max_timeout() / 100); | |
| 107 } | |
| 108 | |
| 109 EXPECT_GE(cur_process_count, number_of_processes); | |
| 110 return false; | |
| 111 } | |
| 112 | |
| 113 void RunWorkerFastLayoutTest(const std::string& test_case_file_name) { | |
| 114 FilePath fast_test_dir; | |
| 115 fast_test_dir = fast_test_dir.AppendASCII("fast"); | |
| 116 | |
| 117 FilePath worker_test_dir; | |
| 118 worker_test_dir = worker_test_dir.AppendASCII("workers"); | |
| 119 InitializeForLayoutTest(fast_test_dir, worker_test_dir, kNoHttpPort); | |
| 120 | |
| 121 // Worker tests also rely on common files in js/resources. | |
| 122 FilePath js_dir = fast_test_dir.AppendASCII("js"); | |
| 123 FilePath resource_dir; | |
| 124 resource_dir = resource_dir.AppendASCII("resources"); | |
| 125 AddResourceForLayoutTest(js_dir, resource_dir); | |
| 126 | |
| 127 printf("Test: %s\n", test_case_file_name.c_str()); | |
| 128 RunLayoutTest(test_case_file_name, kNoHttpPort); | |
| 129 | |
| 130 // Navigate to a blank page so that any workers are cleaned up. | |
| 131 // This helps leaks trackers do a better job of reporting. | |
| 132 scoped_refptr<TabProxy> tab(GetActiveTab()); | |
| 133 GURL about_url(chrome::kAboutBlankURL); | |
| 134 EXPECT_EQ(AUTOMATION_MSG_NAVIGATION_SUCCESS, tab->NavigateToURL(about_url)); | |
| 135 } | |
| 136 | |
| 137 void RunWorkerStorageLayoutTest(const std::string& test_case_file_name) { | |
| 138 FilePath worker_test_dir; | |
| 139 worker_test_dir = worker_test_dir.AppendASCII("fast"); | |
| 140 worker_test_dir = worker_test_dir.AppendASCII("workers"); | |
| 141 | |
| 142 FilePath storage_test_dir; | |
| 143 storage_test_dir = storage_test_dir.AppendASCII("storage"); | |
| 144 InitializeForLayoutTest(worker_test_dir, storage_test_dir, kNoHttpPort); | |
| 145 | |
| 146 // Storage worker tests also rely on common files in 'resources'. | |
| 147 FilePath resource_dir; | |
| 148 resource_dir = resource_dir.AppendASCII("resources"); | |
| 149 AddResourceForLayoutTest(worker_test_dir.Append(storage_test_dir), | |
| 150 resource_dir); | |
| 151 | |
| 152 printf("Test: %s\n", test_case_file_name.c_str()); | |
| 153 RunLayoutTest(test_case_file_name, kNoHttpPort); | |
| 154 | |
| 155 // Navigate to a blank page so that any workers are cleaned up. | |
| 156 // This helps leaks trackers do a better job of reporting. | |
| 157 scoped_refptr<TabProxy> tab(GetActiveTab()); | |
| 158 GURL about_url(chrome::kAboutBlankURL); | |
| 159 EXPECT_EQ(AUTOMATION_MSG_NAVIGATION_SUCCESS, tab->NavigateToURL(about_url)); | |
| 160 } | |
| 161 | |
| 162 bool NavigateAndWaitForAuth(TabProxy* tab, const GURL& url) { | |
| 163 // Pass a large number of navigations to tell the tab to block until an auth | |
| 164 // dialog pops up. | |
| 165 EXPECT_EQ(AUTOMATION_MSG_NAVIGATION_AUTH_NEEDED, | |
| 166 tab->NavigateToURLBlockUntilNavigationsComplete(url, 100)); | |
| 167 return tab->NeedsAuth(); | |
| 168 } | |
| 169 }; | |
| 170 | |
| 171 | |
| 172 TEST_F(WorkerTest, SingleWorker) { | |
| 173 RunTest(FilePath(FILE_PATH_LITERAL("single_worker.html")), ""); | |
| 174 } | |
| 175 | |
| 176 TEST_F(WorkerTest, MultipleWorkers) { | |
| 177 RunTest(FilePath(FILE_PATH_LITERAL("multi_worker.html")), ""); | |
| 178 } | |
| 179 | |
| 180 TEST_F(WorkerTest, SingleSharedWorker) { | |
| 181 RunTest(FilePath(FILE_PATH_LITERAL("single_worker.html")), "shared=true"); | |
| 182 } | |
| 183 | |
| 184 // Flaky on Win XP only. http://crbug.com/96435 | |
| 185 #if defined(OS_WIN) | |
| 186 #define MultipleSharedWorkers DISABLED_MultipleSharedWorkers | |
| 187 #endif | |
| 188 TEST_F(WorkerTest, MultipleSharedWorkers) { | |
| 189 RunTest(FilePath(FILE_PATH_LITERAL("multi_worker.html")), "shared=true"); | |
| 190 } | |
| 191 | |
| 192 #if defined(OS_LINUX) || defined(OS_CHROMEOS) | |
| 193 // http://crbug.com/80446 | |
| 194 #define DISABLED_TerminateQueuedWorkers DISABLED_TerminateQueuedWorkers | |
| 195 #endif | |
| 196 TEST_F(WorkerTest, DISABLED_TerminateQueuedWorkers) { | |
| 197 ASSERT_TRUE(WaitForProcessCountToBeAtLeast(1, 0)); | |
| 198 RunTest(FilePath(FILE_PATH_LITERAL("terminate_queued_workers.html")), ""); | |
| 199 // Make sure all workers exit. | |
| 200 ASSERT_TRUE(WaitForProcessCountToBeAtLeast(1, 0)); | |
| 201 } | |
| 202 | |
| 203 #if defined(OS_LINUX) | |
| 204 // http://crbug.com/30021 | |
| 205 #define IncognitoSharedWorkers DISABLED_IncognitoSharedWorkers | |
| 206 #endif | |
| 207 // Incognito windows should not share workers with non-incognito windows | |
| 208 TEST_F(WorkerTest, IncognitoSharedWorkers) { | |
| 209 // Load a non-incognito tab and have it create a shared worker | |
| 210 RunTest(FilePath(FILE_PATH_LITERAL("incognito_worker.html")), ""); | |
| 211 // Incognito worker should not share with non-incognito | |
| 212 RunIncognitoTest(FilePath(FILE_PATH_LITERAL("incognito_worker.html"))); | |
| 213 } | |
| 214 | |
| 215 const FilePath::CharType kDocRoot[] = | |
| 216 FILE_PATH_LITERAL("chrome/test/data/workers"); | |
| 217 | |
| 218 #if defined(OS_WIN) | |
| 219 // http://crbug.com/33344 - NavigateAndWaitForAuth times out on the Windows | |
| 220 // build bots. | |
| 221 #define WorkerHttpAuth DISABLED_WorkerHttpAuth | |
| 222 #endif | |
| 223 // Make sure that auth dialog is displayed from worker context. | |
| 224 TEST_F(WorkerTest, WorkerHttpAuth) { | |
| 225 net::TestServer test_server(net::TestServer::TYPE_HTTP, | |
| 226 net::TestServer::kLocalhost, | |
| 227 FilePath(kDocRoot)); | |
| 228 ASSERT_TRUE(test_server.Start()); | |
| 229 | |
| 230 scoped_refptr<TabProxy> tab(GetActiveTab()); | |
| 231 ASSERT_TRUE(tab.get()); | |
| 232 | |
| 233 GURL url = test_server.GetURL("files/worker_auth.html"); | |
| 234 EXPECT_TRUE(NavigateAndWaitForAuth(tab, url)); | |
| 235 } | |
| 236 | |
| 237 #if defined(OS_WIN) | |
| 238 // http://crbug.com/33344 - NavigateAndWaitForAuth times out on the Windows | |
| 239 // build bots. | |
| 240 #define SharedWorkerHttpAuth DISABLED_SharedWorkerHttpAuth | |
| 241 #endif | |
| 242 // Make sure that auth dialog is displayed from shared worker context. | |
| 243 TEST_F(WorkerTest, DISABLED_SharedWorkerHttpAuth) { | |
| 244 net::TestServer test_server(net::TestServer::TYPE_HTTP, | |
| 245 net::TestServer::kLocalhost, | |
| 246 FilePath(kDocRoot)); | |
| 247 ASSERT_TRUE(test_server.Start()); | |
| 248 | |
| 249 scoped_refptr<TabProxy> tab(GetActiveTab()); | |
| 250 ASSERT_TRUE(tab.get()); | |
| 251 | |
| 252 GURL url = test_server.GetURL("files/shared_worker_auth.html"); | |
| 253 EXPECT_TRUE(NavigateAndWaitForAuth(tab, url)); | |
| 254 // TODO(atwilson): Add support to automation framework to test for auth | |
| 255 // dialogs displayed by non-navigating tabs. | |
| 256 } | |
| 257 | 36 |
| 258 // Crashy, http://crbug.com/35965. | 37 // Crashy, http://crbug.com/35965. |
| 259 // Flaky, http://crbug.com/36555. | 38 // Flaky, http://crbug.com/36555. |
| 260 TEST_F(WorkerTest, DISABLED_WorkerClonePort) { | 39 IN_PROC_BROWSER_TEST_F(WorkerLayoutTest, SLOW_WorkerClonePort) { |
| 261 RunWorkerFastLayoutTest("worker-cloneport.html"); | 40 RunLayoutTest("worker-cloneport.html"); |
| 262 } | 41 } |
| 263 | 42 |
| 264 // http://crbug.com/101996 (started flaking with WebKit roll 98537:98582). | 43 // http://crbug.com/101996 (started flaking with WebKit roll 98537:98582). |
| 265 TEST_F(WorkerTest, DISABLED_WorkerContextMultiPort) { | 44 IN_PROC_BROWSER_TEST_F(WorkerLayoutTest, WorkerContextMultiPort) { |
| 266 RunWorkerFastLayoutTest("worker-context-multi-port.html"); | 45 RunLayoutTest("worker-context-multi-port.html"); |
| 267 } | 46 } |
| 268 | 47 |
| 269 TEST_F(WorkerTest, WorkerMessagePort) { | 48 IN_PROC_BROWSER_TEST_F(WorkerLayoutTest, WorkerMessagePort) { |
| 270 RunWorkerFastLayoutTest("worker-messageport.html"); | 49 RunLayoutTest("worker-messageport.html"); |
| 271 } | 50 } |
| 272 | 51 |
| 273 TEST_F(WorkerTest, WorkerMessagePortGC) { | 52 IN_PROC_BROWSER_TEST_F(WorkerLayoutTest, WorkerMessagePortGC) { |
| 274 RunWorkerFastLayoutTest("worker-messageport-gc.html"); | 53 RunLayoutTest("worker-messageport-gc.html"); |
| 275 } | 54 } |
| 276 | 55 |
| 277 // http://crbug.com/101996 (started flaking with WebKit roll 98537:98582). | 56 // http://crbug.com/101996 (started flaking with WebKit roll 98537:98582). |
| 278 TEST_F(WorkerTest, DISABLED_WorkerMultiPort) { | 57 IN_PROC_BROWSER_TEST_F(WorkerLayoutTest, WorkerMultiPort) { |
| 279 RunWorkerFastLayoutTest("worker-multi-port.html"); | 58 RunLayoutTest("worker-multi-port.html"); |
| 280 } | 59 } |
| 281 | 60 |
| 282 // | 61 // |
| 283 // SharedWorkerFastLayoutTests | 62 // SharedWorkerFastLayoutTests |
| 284 // | 63 // |
| 285 TEST_F(WorkerTest, SharedWorkerFastConstructor) { | 64 IN_PROC_BROWSER_TEST_F(WorkerLayoutTest, SharedWorkerFastConstructor) { |
| 286 RunWorkerFastLayoutTest("shared-worker-constructor.html"); | 65 RunLayoutTest("shared-worker-constructor.html"); |
| 287 } | 66 } |
| 288 | 67 |
| 289 TEST_F(WorkerTest, SharedWorkerFastContextGC) { | 68 IN_PROC_BROWSER_TEST_F(WorkerLayoutTest, SharedWorkerFastContextGC) { |
| 290 RunWorkerFastLayoutTest("shared-worker-context-gc.html"); | 69 RunLayoutTest("shared-worker-context-gc.html"); |
| 291 } | 70 } |
| 292 | 71 |
| 293 TEST_F(WorkerTest, SharedWorkerFastEventListener) { | 72 IN_PROC_BROWSER_TEST_F(WorkerLayoutTest, SharedWorkerFastEventListener) { |
| 294 RunWorkerFastLayoutTest("shared-worker-event-listener.html"); | 73 RunLayoutTest("shared-worker-event-listener.html"); |
| 295 } | 74 } |
| 296 | 75 |
| 297 TEST_F(WorkerTest, SharedWorkerFastException) { | 76 IN_PROC_BROWSER_TEST_F(WorkerLayoutTest, SharedWorkerFastException) { |
| 298 RunWorkerFastLayoutTest("shared-worker-exception.html"); | 77 RunLayoutTest("shared-worker-exception.html"); |
| 299 } | 78 } |
| 300 | 79 |
| 301 TEST_F(WorkerTest, SharedWorkerFastGC) { | 80 IN_PROC_BROWSER_TEST_F(WorkerLayoutTest, SharedWorkerFastGC) { |
| 302 RunWorkerFastLayoutTest("shared-worker-gc.html"); | 81 RunLayoutTest("shared-worker-gc.html"); |
| 303 } | 82 } |
| 304 | 83 |
| 305 TEST_F(WorkerTest, SharedWorkerFastInIframe) { | 84 IN_PROC_BROWSER_TEST_F(WorkerLayoutTest, SharedWorkerFastInIframe) { |
| 306 RunWorkerFastLayoutTest("shared-worker-in-iframe.html"); | 85 RunLayoutTest("shared-worker-in-iframe.html"); |
| 307 } | 86 } |
| 308 | 87 |
| 309 TEST_F(WorkerTest, SharedWorkerFastLoadError) { | 88 IN_PROC_BROWSER_TEST_F(WorkerLayoutTest, SharedWorkerFastLoadError) { |
| 310 RunWorkerFastLayoutTest("shared-worker-load-error.html"); | 89 RunLayoutTest("shared-worker-load-error.html"); |
| 311 } | 90 } |
| 312 | 91 |
| 313 TEST_F(WorkerTest, SharedWorkerFastLocation) { | 92 IN_PROC_BROWSER_TEST_F(WorkerLayoutTest, SharedWorkerFastLocation) { |
| 314 RunWorkerFastLayoutTest("shared-worker-location.html"); | 93 RunLayoutTest("shared-worker-location.html"); |
| 315 } | 94 } |
| 316 | 95 |
| 317 TEST_F(WorkerTest, SharedWorkerFastName) { | 96 IN_PROC_BROWSER_TEST_F(WorkerLayoutTest, SharedWorkerFastName) { |
| 318 RunWorkerFastLayoutTest("shared-worker-name.html"); | 97 RunLayoutTest("shared-worker-name.html"); |
| 319 } | 98 } |
| 320 | 99 |
| 321 TEST_F(WorkerTest, SharedWorkerFastNavigator) { | 100 IN_PROC_BROWSER_TEST_F(WorkerLayoutTest, SharedWorkerFastNavigator) { |
| 322 RunWorkerFastLayoutTest("shared-worker-navigator.html"); | 101 RunLayoutTest("shared-worker-navigator.html"); |
| 323 } | 102 } |
| 324 | 103 |
| 325 TEST_F(WorkerTest, SharedWorkerFastReplaceGlobalConstructor) { | 104 IN_PROC_BROWSER_TEST_F(WorkerLayoutTest, |
| 326 RunWorkerFastLayoutTest("shared-worker-replace-global-constructor.html"); | 105 SharedWorkerFastReplaceGlobalConstructor) { |
| 327 } | 106 RunLayoutTest("shared-worker-replace-global-constructor.html"); |
| 328 | 107 } |
| 329 TEST_F(WorkerTest, SharedWorkerFastReplaceSelf) { | 108 |
| 330 RunWorkerFastLayoutTest("shared-worker-replace-self.html"); | 109 IN_PROC_BROWSER_TEST_F(WorkerLayoutTest, SharedWorkerFastReplaceSelf) { |
| 331 } | 110 RunLayoutTest("shared-worker-replace-self.html"); |
| 332 | 111 } |
| 333 TEST_F(WorkerTest, SharedWorkerFastScriptError) { | 112 |
| 334 RunWorkerFastLayoutTest("shared-worker-script-error.html"); | 113 IN_PROC_BROWSER_TEST_F(WorkerLayoutTest, SharedWorkerFastScriptError) { |
| 335 } | 114 RunLayoutTest("shared-worker-script-error.html"); |
| 336 | 115 } |
| 337 TEST_F(WorkerTest, SharedWorkerFastShared) { | 116 |
| 338 RunWorkerFastLayoutTest("shared-worker-shared.html"); | 117 IN_PROC_BROWSER_TEST_F(WorkerLayoutTest, SharedWorkerFastShared) { |
| 339 } | 118 RunLayoutTest("shared-worker-shared.html"); |
| 340 | 119 } |
| 341 TEST_F(WorkerTest, SharedWorkerFastSimple) { | 120 |
| 342 RunWorkerFastLayoutTest("shared-worker-simple.html"); | 121 IN_PROC_BROWSER_TEST_F(WorkerLayoutTest, SharedWorkerFastSimple) { |
| 343 } | 122 RunLayoutTest("shared-worker-simple.html"); |
| 344 | 123 } |
| 345 // http://crbug.com/16934 | 124 |
| 346 TEST_F(WorkerTest, DISABLED_WorkerHttpLayoutTests) { | 125 class MessagePortTest : public InProcessBrowserLayoutTest { |
| 126 public: |
| 127 MessagePortTest() : InProcessBrowserLayoutTest( |
| 128 FilePath(), FilePath().AppendASCII("fast").AppendASCII("events")) { |
| 129 } |
| 130 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { |
| 131 InProcessBrowserLayoutTest::SetUpInProcessBrowserTestFixture(); |
| 132 AddResourceForLayoutTest( |
| 133 FilePath().AppendASCII("fast").AppendASCII("js"), |
| 134 FilePath().AppendASCII("resources")); |
| 135 } |
| 136 }; |
| 137 |
| 138 // Flaky, http://crbug.com/34996. |
| 139 IN_PROC_BROWSER_TEST_F(MessagePortTest, Tests) { |
| 347 static const char* kLayoutTestFiles[] = { | 140 static const char* kLayoutTestFiles[] = { |
| 348 "shared-worker-importScripts.html", | 141 "message-channel-gc.html", |
| 349 "shared-worker-redirect.html", | 142 "message-channel-gc-2.html", |
| 350 // flakey? BUG 16934 "text-encoding.html", | 143 "message-channel-gc-3.html", |
| 144 "message-channel-gc-4.html", |
| 145 "message-port.html", |
| 146 "message-port-clone.html", |
| 147 "message-port-constructor-for-deleted-document.html", |
| 148 "message-port-deleted-document.html", |
| 149 "message-port-deleted-frame.html", |
| 150 "message-port-inactive-document.html", |
| 151 "message-port-multi.html", |
| 152 "message-port-no-wrapper.html", |
| 153 // Only works with run-webkit-tests --leaks. |
| 154 // "message-channel-listener-circular-ownership.html", |
| 155 }; |
| 156 |
| 157 for (size_t i = 0; i < arraysize(kLayoutTestFiles); ++i) |
| 158 RunLayoutTest(kLayoutTestFiles[i]); |
| 159 } |
| 160 |
| 161 |
| 162 class WorkerHttpLayoutTest : public InProcessBrowserLayoutTest { |
| 163 public: |
| 164 // The resources for these tests hardcode 8000, so must use that here. If |
| 165 // multiple tests which use it run in parallel, then the test will fail but |
| 166 // it'll run again at the end in serial and pass. |
| 167 WorkerHttpLayoutTest() : InProcessBrowserLayoutTest( |
| 168 FilePath().AppendASCII("http").AppendASCII("tests"), |
| 169 FilePath().AppendASCII("workers"), |
| 170 8000) { |
| 171 } |
| 172 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { |
| 173 InProcessBrowserLayoutTest::SetUpInProcessBrowserTestFixture(); |
| 174 AddResourceForLayoutTest( |
| 175 FilePath().AppendASCII("http").AppendASCII("tests"), |
| 176 FilePath().AppendASCII("resources")); |
| 177 } |
| 178 }; |
| 179 |
| 180 IN_PROC_BROWSER_TEST_F(WorkerHttpLayoutTest, Tests) { |
| 181 static const char* kLayoutTestFiles[] = { |
| 182 "shared-worker-importScripts.html", |
| 183 "shared-worker-redirect.html", |
| 184 "text-encoding.html", |
| 351 #if defined(OS_WIN) | 185 #if defined(OS_WIN) |
| 352 // Fails on the mac (and linux?): | 186 // Fails on the mac (and linux?): |
| 353 // http://code.google.com/p/chromium/issues/detail?id=22599 | 187 // http://code.google.com/p/chromium/issues/detail?id=22599 |
| 354 "worker-importScripts.html", | 188 "worker-importScripts.html", |
| 355 #endif | 189 #endif |
| 356 "worker-redirect.html", | 190 "worker-redirect.html", |
| 357 }; | 191 }; |
| 358 | 192 |
| 359 FilePath http_test_dir; | |
| 360 http_test_dir = http_test_dir.AppendASCII("http"); | |
| 361 http_test_dir = http_test_dir.AppendASCII("tests"); | |
| 362 | |
| 363 FilePath worker_test_dir; | |
| 364 worker_test_dir = worker_test_dir.AppendASCII("workers"); | |
| 365 InitializeForLayoutTest(http_test_dir, worker_test_dir, kHttpPort); | |
| 366 | |
| 367 LayoutTestHttpServer http_server(new_http_root_dir_, kHttpPort); | |
| 368 ASSERT_TRUE(http_server.Start()); | |
| 369 for (size_t i = 0; i < arraysize(kLayoutTestFiles); ++i) | 193 for (size_t i = 0; i < arraysize(kLayoutTestFiles); ++i) |
| 370 RunLayoutTest(kLayoutTestFiles[i], kHttpPort); | 194 RunHttpLayoutTest(kLayoutTestFiles[i]); |
| 371 ASSERT_TRUE(http_server.Stop()); | 195 } |
| 372 } | 196 |
| 373 | 197 class WorkerXHRHttpLayoutTest : public InProcessBrowserLayoutTest { |
| 374 TEST_F(WorkerTest, WorkerWebSocketLayoutTests) { | 198 public: |
| 375 static const char* kLayoutTestFiles[] = { | 199 WorkerXHRHttpLayoutTest() : InProcessBrowserLayoutTest( |
| 376 "close-in-onmessage-crash.html", | 200 FilePath().AppendASCII("http").AppendASCII("tests"), |
| 377 "close-in-shared-worker.html", | 201 FilePath().AppendASCII("xmlhttprequest").AppendASCII("workers"), |
| 378 "close-in-worker.html", | 202 -1) { |
| 379 "shared-worker-simple.html", | 203 } |
| 380 "worker-handshake-challenge-randomness.html", | 204 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { |
| 381 "worker-simple.html" | 205 InProcessBrowserLayoutTest::SetUpInProcessBrowserTestFixture(); |
| 382 }; | 206 AddResourceForLayoutTest( |
| 383 | 207 FilePath().AppendASCII("http").AppendASCII("tests"), |
| 384 FilePath websocket_test_dir; | 208 FilePath().AppendASCII("workers").AppendASCII("resources")); |
| 385 websocket_test_dir = websocket_test_dir.AppendASCII("http"); | 209 } |
| 386 websocket_test_dir = websocket_test_dir.AppendASCII("tests"); | 210 }; |
| 387 | 211 |
| 388 FilePath worker_test_dir; | 212 IN_PROC_BROWSER_TEST_F(WorkerXHRHttpLayoutTest, Tests) { |
| 389 worker_test_dir = worker_test_dir.AppendASCII("websocket"); | |
| 390 worker_test_dir = worker_test_dir.AppendASCII("tests"); | |
| 391 worker_test_dir = worker_test_dir.AppendASCII("hybi"); | |
| 392 worker_test_dir = worker_test_dir.AppendASCII("workers"); | |
| 393 InitializeForLayoutTest(websocket_test_dir, worker_test_dir, kHttpPort); | |
| 394 | |
| 395 FilePath websocket_root_dir(temp_test_dir_); | |
| 396 websocket_root_dir = websocket_root_dir.AppendASCII("LayoutTests"); | |
| 397 ui_test_utils::TestWebSocketServer websocket_server; | |
| 398 ASSERT_TRUE(websocket_server.Start(websocket_root_dir)); | |
| 399 | |
| 400 LayoutTestHttpServer http_server(new_http_root_dir_, kHttpPort); | |
| 401 ASSERT_TRUE(http_server.Start()); | |
| 402 for (size_t i = 0; i < arraysize(kLayoutTestFiles); ++i) | |
| 403 RunLayoutTest(kLayoutTestFiles[i], kHttpPort); | |
| 404 ASSERT_TRUE(http_server.Stop()); | |
| 405 } | |
| 406 | |
| 407 TEST_F(WorkerTest, DISABLED_WorkerXhrHttpLayoutTests) { | |
| 408 static const char* kLayoutTestFiles[] = { | 213 static const char* kLayoutTestFiles[] = { |
| 409 "abort-exception-assert.html", | 214 "abort-exception-assert.html", |
| 410 #if defined(OS_WIN) | 215 #if defined(OS_WIN) |
| 411 // Fails on the mac (and linux?): | 216 // Fails on the mac (and linux?): |
| 412 // http://code.google.com/p/chromium/issues/detail?id=22599 | 217 // http://code.google.com/p/chromium/issues/detail?id=22599 |
| 413 "close.html", | 218 "close.html", |
| 414 #endif | 219 #endif |
| 415 // These tests (and the shared-worker versions below) are disabled due to | 220 // These tests (and the shared-worker versions below) are disabled due to |
| 416 // limitations in lighttpd (doesn't handle all of the HTTP methods). | 221 // limitations in lighttpd (doesn't handle all of the HTTP methods). |
| 417 // "methods-async.html", | 222 // "methods-async.html", |
| 418 // "methods.html", | 223 // "methods.html", |
| 419 | 224 |
| 420 "shared-worker-close.html", | 225 "shared-worker-close.html", |
| 421 // Disabled due to limitations in lighttpd (does not handle methods other | 226 // Disabled due to limitations in lighttpd (does not handle methods other |
| 422 // than GET/PUT/POST). | 227 // than GET/PUT/POST). |
| 423 // "shared-worker-methods-async.html", | 228 // "shared-worker-methods-async.html", |
| 424 // "shared-worker-methods.html", | 229 // "shared-worker-methods.html", |
| 425 "shared-worker-xhr-file-not-found.html", | 230 "shared-worker-xhr-file-not-found.html", |
| 426 | 231 |
| 427 "xmlhttprequest-file-not-found.html" | 232 "xmlhttprequest-file-not-found.html" |
| 428 }; | 233 }; |
| 429 | 234 |
| 430 FilePath http_test_dir; | |
| 431 http_test_dir = http_test_dir.AppendASCII("http"); | |
| 432 http_test_dir = http_test_dir.AppendASCII("tests"); | |
| 433 | |
| 434 FilePath worker_test_dir; | |
| 435 worker_test_dir = worker_test_dir.AppendASCII("xmlhttprequest"); | |
| 436 worker_test_dir = worker_test_dir.AppendASCII("workers"); | |
| 437 InitializeForLayoutTest(http_test_dir, worker_test_dir, kHttpPort); | |
| 438 | |
| 439 LayoutTestHttpServer http_server(new_http_root_dir_, kHttpPort); | |
| 440 ASSERT_TRUE(http_server.Start()); | |
| 441 for (size_t i = 0; i < arraysize(kLayoutTestFiles); ++i) | 235 for (size_t i = 0; i < arraysize(kLayoutTestFiles); ++i) |
| 442 RunLayoutTest(kLayoutTestFiles[i], kHttpPort); | 236 RunHttpLayoutTest(kLayoutTestFiles[i]); |
| 443 ASSERT_TRUE(http_server.Stop()); | 237 } |
| 444 } | 238 |
| 445 | 239 class WorkerWebSocketHttpLayoutTest : public InProcessBrowserLayoutTest { |
| 446 // Flaky, http://crbug.com/34996. | 240 public: |
| 447 TEST_F(WorkerTest, DISABLED_MessagePorts) { | 241 WorkerWebSocketHttpLayoutTest() : InProcessBrowserLayoutTest( |
| 242 FilePath(), |
| 243 FilePath().AppendASCII("http").AppendASCII("tests"). |
| 244 AppendASCII("websocket").AppendASCII("tests").AppendASCII("hybi"). |
| 245 AppendASCII("workers"), |
| 246 -1) { |
| 247 } |
| 248 }; |
| 249 |
| 250 IN_PROC_BROWSER_TEST_F(WorkerWebSocketHttpLayoutTest, Tests) { |
| 448 static const char* kLayoutTestFiles[] = { | 251 static const char* kLayoutTestFiles[] = { |
| 449 "message-channel-gc.html", | 252 "close-in-onmessage-crash.html", |
| 450 "message-channel-gc-2.html", | 253 "close-in-shared-worker.html", |
| 451 "message-channel-gc-3.html", | 254 "close-in-worker.html", |
| 452 "message-channel-gc-4.html", | 255 "shared-worker-simple.html", |
| 453 "message-port.html", | 256 "worker-handshake-challenge-randomness.html", |
| 454 "message-port-clone.html", | 257 "worker-simple.html" |
| 455 "message-port-constructor-for-deleted-document.html", | |
| 456 "message-port-deleted-document.html", | |
| 457 "message-port-deleted-frame.html", | |
| 458 "message-port-inactive-document.html", | |
| 459 "message-port-multi.html", | |
| 460 "message-port-no-wrapper.html", | |
| 461 // Only works with run-webkit-tests --leaks. | |
| 462 // "message-channel-listener-circular-ownership.html", | |
| 463 }; | 258 }; |
| 464 | 259 |
| 465 FilePath fast_test_dir; | 260 FilePath websocket_test_dir; |
| 466 fast_test_dir = fast_test_dir.AppendASCII("fast"); | 261 ASSERT_TRUE(PathService::Get(content::DIR_LAYOUT_TESTS, &websocket_test_dir)); |
| 467 | 262 |
| 468 FilePath worker_test_dir; | 263 ui_test_utils::TestWebSocketServer websocket_server; |
| 469 worker_test_dir = worker_test_dir.AppendASCII("events"); | 264 ASSERT_TRUE(websocket_server.Start(websocket_test_dir)); |
| 470 InitializeForLayoutTest(fast_test_dir, worker_test_dir, kNoHttpPort); | |
| 471 | |
| 472 // MessagePort tests also rely on common files in js/resources. | |
| 473 FilePath js_dir = fast_test_dir.AppendASCII("js"); | |
| 474 FilePath resource_dir; | |
| 475 resource_dir = resource_dir.AppendASCII("resources"); | |
| 476 AddResourceForLayoutTest(js_dir, resource_dir); | |
| 477 | 265 |
| 478 for (size_t i = 0; i < arraysize(kLayoutTestFiles); ++i) | 266 for (size_t i = 0; i < arraysize(kLayoutTestFiles); ++i) |
| 479 RunLayoutTest(kLayoutTestFiles[i], kNoHttpPort); | 267 RunHttpLayoutTest(kLayoutTestFiles[i]); |
| 480 } | 268 } |
| 481 | 269 |
| 482 TEST_F(WorkerTest, LimitPerPage) { | 270 class WorkerTest : public InProcessBrowserTest { |
| 483 int max_workers_per_tab = WorkerServiceImpl::kMaxWorkersPerTabWhenSeparate; | 271 public: |
| 484 GURL url = ui_test_utils::GetTestUrl(FilePath(kTestDir), | 272 WorkerTest() {} |
| 485 FilePath(kManySharedWorkersFile)); | 273 |
| 486 url = GURL(url.spec() + StringPrintf("?count=%d", max_workers_per_tab + 1)); | 274 GURL GetTestURL(const std::string& test_case, const std::string& query) { |
| 487 | 275 FilePath test_file_path = ui_test_utils::GetTestFilePath( |
| 488 NavigateToURL(url); | 276 FilePath(FILE_PATH_LITERAL("workers")), |
| 489 ASSERT_TRUE(WaitForProcessCountToBeAtLeast(1, max_workers_per_tab)); | 277 FilePath().AppendASCII(test_case)); |
| 278 return ui_test_utils::GetFileUrlWithQuery(test_file_path, query); |
| 279 } |
| 280 |
| 281 void RunTest(Browser* browser, |
| 282 const std::string& test_case, |
| 283 const std::string& query) { |
| 284 GURL url = GetTestURL(test_case, query); |
| 285 const string16 expected_title = ASCIIToUTF16("OK"); |
| 286 ui_test_utils::TitleWatcher title_watcher( |
| 287 browser->GetSelectedWebContents(), expected_title); |
| 288 ui_test_utils::NavigateToURL(browser, url); |
| 289 string16 final_title = title_watcher.WaitAndGetTitle(); |
| 290 EXPECT_EQ(expected_title, final_title); |
| 291 } |
| 292 |
| 293 void RunTest(const std::string& test_case, const std::string& query) { |
| 294 RunTest(browser(), test_case, query); |
| 295 } |
| 296 |
| 297 static void CountWorkerProcesses(int *cur_process_count) { |
| 298 *cur_process_count = 0; |
| 299 for (WorkerProcessHostIterator iter; !iter.Done(); ++iter) |
| 300 (*cur_process_count)++; |
| 301 BrowserThread::PostTask( |
| 302 BrowserThread::UI, FROM_HERE, MessageLoop::QuitClosure()); |
| 303 } |
| 304 |
| 305 bool WaitForWorkerProcessCount(int count) { |
| 306 int cur_process_count; |
| 307 for (int i = 0; i < 100; ++i) { |
| 308 BrowserThread::PostTask( |
| 309 BrowserThread::IO, FROM_HERE, |
| 310 base::Bind(&CountWorkerProcesses, &cur_process_count)); |
| 311 ui_test_utils::RunMessageLoop(); |
| 312 if (cur_process_count == count) |
| 313 return true; |
| 314 |
| 315 // Sometimes the worker processes can take a while to shut down on the |
| 316 // bots, so use a longer timeout period to avoid spurious failures. |
| 317 base::PlatformThread::Sleep(TestTimeouts::action_max_timeout() / 100); |
| 318 } |
| 319 |
| 320 EXPECT_EQ(cur_process_count, count); |
| 321 return false; |
| 322 } |
| 323 }; |
| 324 |
| 325 IN_PROC_BROWSER_TEST_F(WorkerTest, SingleWorker) { |
| 326 RunTest("single_worker.html", ""); |
| 327 } |
| 328 |
| 329 IN_PROC_BROWSER_TEST_F(WorkerTest, MultipleWorkers) { |
| 330 RunTest("multi_worker.html", ""); |
| 331 } |
| 332 |
| 333 IN_PROC_BROWSER_TEST_F(WorkerTest, SingleSharedWorker) { |
| 334 RunTest("single_worker.html", "shared=true"); |
| 335 } |
| 336 |
| 337 // http://crbug.com/96435 |
| 338 IN_PROC_BROWSER_TEST_F(WorkerTest, MultipleSharedWorkers) { |
| 339 RunTest("multi_worker.html", "shared=true"); |
| 340 } |
| 341 |
| 342 // http://crbug.com/80446 |
| 343 IN_PROC_BROWSER_TEST_F(WorkerTest, TerminateQueuedWorkers) { |
| 344 ASSERT_TRUE(WaitForWorkerProcessCount(0)); |
| 345 RunTest("terminate_queued_workers.html", ""); |
| 346 // Make sure all workers exit. |
| 347 ASSERT_TRUE(WaitForWorkerProcessCount(0)); |
| 348 } |
| 349 |
| 350 // Incognito windows should not share workers with non-incognito windows |
| 351 // http://crbug.com/30021 |
| 352 IN_PROC_BROWSER_TEST_F(WorkerTest, IncognitoSharedWorkers) { |
| 353 // Load a non-incognito tab and have it create a shared worker |
| 354 RunTest("incognito_worker.html", ""); |
| 355 |
| 356 // Incognito worker should not share with non-incognito |
| 357 RunTest(CreateIncognitoBrowser(), "incognito_worker.html", ""); |
| 358 } |
| 359 |
| 360 // Make sure that auth dialog is displayed from worker context. |
| 361 // http://crbug.com/33344 |
| 362 IN_PROC_BROWSER_TEST_F(WorkerTest, WorkerHttpAuth) { |
| 363 ASSERT_TRUE(test_server()->Start()); |
| 364 GURL url = test_server()->GetURL("files/workers/worker_auth.html"); |
| 365 |
| 366 ui_test_utils::NavigateToURLWithDisposition( |
| 367 browser(), url, CURRENT_TAB, ui_test_utils::BROWSER_TEST_WAIT_FOR_AUTH); |
| 368 } |
| 369 |
| 370 // Make sure that auth dialog is displayed from shared worker context. |
| 371 // http://crbug.com/33344 |
| 372 IN_PROC_BROWSER_TEST_F(WorkerTest, SharedWorkerHttpAuth) { |
| 373 ASSERT_TRUE(test_server()->Start()); |
| 374 GURL url = test_server()->GetURL("files/workers/shared_worker_auth.html"); |
| 375 ui_test_utils::NavigateToURLWithDisposition( |
| 376 browser(), url, CURRENT_TAB, ui_test_utils::BROWSER_TEST_WAIT_FOR_AUTH); |
| 377 } |
| 378 |
| 379 IN_PROC_BROWSER_TEST_F(WorkerTest, LimitPerPage) { |
| 380 int max_workers_per_tab = WorkerServiceImpl::kMaxWorkersPerTabWhenSeparate; |
| 381 std::string query = StringPrintf("?count=%d", max_workers_per_tab + 1); |
| 382 |
| 383 GURL url = GetTestURL("many_shared_workers.html", query); |
| 384 ui_test_utils::NavigateToURL(browser(), url); |
| 385 ASSERT_TRUE(WaitForWorkerProcessCount(max_workers_per_tab)); |
| 490 } | 386 } |
| 491 | 387 |
| 492 // http://crbug.com/36800 | 388 // http://crbug.com/36800 |
| 493 #if defined(OS_WIN) | 389 IN_PROC_BROWSER_TEST_F(WorkerTest, LimitTotal) { |
| 494 #define MAYBE_LimitTotal DISABLED_LimitTotal | |
| 495 #else | |
| 496 #define MAYBE_LimitTotal LimitTotal | |
| 497 #endif // defined(OS_WIN) | |
| 498 TEST_F(WorkerTest, MAYBE_LimitTotal) { | |
| 499 int max_workers_per_tab = WorkerServiceImpl::kMaxWorkersPerTabWhenSeparate; | 390 int max_workers_per_tab = WorkerServiceImpl::kMaxWorkersPerTabWhenSeparate; |
| 500 int total_workers = WorkerServiceImpl::kMaxWorkersWhenSeparate; | 391 int total_workers = WorkerServiceImpl::kMaxWorkersWhenSeparate; |
| 501 | 392 |
| 393 std::string query = StringPrintf("?count=%d", max_workers_per_tab); |
| 394 GURL url = GetTestURL("many_shared_workers.html", query); |
| 395 ui_test_utils::NavigateToURL( |
| 396 browser(), GURL(url.spec() + StringPrintf("&client_id=0"))); |
| 397 |
| 502 // Adding 1 so that we cause some workers to be queued. | 398 // Adding 1 so that we cause some workers to be queued. |
| 503 int tab_count = (total_workers / max_workers_per_tab) + 1; | 399 int tab_count = (total_workers / max_workers_per_tab) + 1; |
| 504 GURL url = ui_test_utils::GetTestUrl(FilePath(kTestDir), | |
| 505 FilePath(kManySharedWorkersFile)); | |
| 506 url = GURL(url.spec() + StringPrintf("?count=%d", max_workers_per_tab)); | |
| 507 | |
| 508 scoped_refptr<TabProxy> tab(GetActiveTab()); | |
| 509 ASSERT_TRUE(tab.get()); | |
| 510 ASSERT_TRUE(tab->NavigateToURL( | |
| 511 GURL(url.spec() + StringPrintf("&client_id=%d", 0)))); | |
| 512 scoped_refptr<BrowserProxy> window(automation()->GetBrowserWindow(0)); | |
| 513 ASSERT_TRUE(window.get()); | |
| 514 for (int i = 1; i < tab_count; ++i) { | 400 for (int i = 1; i < tab_count; ++i) { |
| 515 ASSERT_TRUE(window->AppendTab(GURL( | 401 ui_test_utils::NavigateToURLWithDisposition( |
| 516 url.spec() + StringPrintf("&client_id=%d", i)))); | 402 browser(), GURL(url.spec() + StringPrintf("&client_id=%d", i)), |
| 403 NEW_FOREGROUND_TAB, |
| 404 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
| 517 } | 405 } |
| 518 | 406 |
| 519 // Check that we didn't create more than the max number of workers. | 407 // Check that we didn't create more than the max number of workers. |
| 520 ASSERT_TRUE(WaitForProcessCountToBeAtLeast(tab_count, total_workers)); | 408 ASSERT_TRUE(WaitForWorkerProcessCount(total_workers)); |
| 521 | 409 |
| 522 // Now close a page and check that the queued workers were started. | 410 // Now close a page and check that the queued workers were started. |
| 523 const FilePath::CharType* kGoogleDir = FILE_PATH_LITERAL("google"); | 411 const FilePath kGoogleDir(FILE_PATH_LITERAL("google")); |
| 524 const FilePath::CharType* kGoogleFile = FILE_PATH_LITERAL("google.html"); | 412 const FilePath kGoogleFile(FILE_PATH_LITERAL("google.html")); |
| 525 ASSERT_EQ(AUTOMATION_MSG_NAVIGATION_SUCCESS, | 413 url = GURL(ui_test_utils::GetTestUrl(kGoogleDir, kGoogleFile)); |
| 526 tab->NavigateToURL(ui_test_utils::GetTestUrl(FilePath(kGoogleDir), | 414 ui_test_utils::NavigateToURL(browser(), url); |
| 527 FilePath(kGoogleFile)))); | 415 |
| 528 | 416 ASSERT_TRUE(WaitForWorkerProcessCount(total_workers)); |
| 529 ASSERT_TRUE(WaitForProcessCountToBeAtLeast(tab_count, total_workers)); | |
| 530 } | 417 } |
| 531 | 418 |
| 532 // Flaky, http://crbug.com/59786. | 419 // Flaky, http://crbug.com/59786. |
| 533 TEST_F(WorkerTest, DISABLED_WorkerClose) { | 420 IN_PROC_BROWSER_TEST_F(WorkerTest, WorkerClose) { |
| 534 scoped_refptr<TabProxy> tab(GetActiveTab()); | 421 RunTest("worker_close.html", ""); |
| 535 ASSERT_TRUE(tab.get()); | 422 ASSERT_TRUE(WaitForWorkerProcessCount(0)); |
| 536 GURL url = ui_test_utils::GetTestUrl(FilePath(kTestDir), | |
| 537 FilePath(kWorkerClose)); | |
| 538 ASSERT_TRUE(tab->NavigateToURL(url)); | |
| 539 std::string value = WaitUntilCookieNonEmpty(tab.get(), url, | |
| 540 kTestCompleteCookie, TestTimeouts::action_max_timeout_ms()); | |
| 541 ASSERT_STREQ(kTestCompleteSuccess, value.c_str()); | |
| 542 ASSERT_TRUE(WaitForProcessCountToBeAtLeast(1, 0)); | |
| 543 } | 423 } |
| 544 | 424 |
| 545 // Flaky, http://crbug.com/70861. | 425 // Flaky, http://crbug.com/70861. |
| 546 TEST_F(WorkerTest, DISABLED_QueuedSharedWorkerShutdown) { | 426 IN_PROC_BROWSER_TEST_F(WorkerTest, QueuedSharedWorkerShutdown) { |
| 547 // Tests to make sure that queued shared workers are started up when | 427 // Tests to make sure that queued shared workers are started up when shared |
| 548 // shared workers shut down. | 428 // workers shut down. |
| 549 int max_workers_per_tab = WorkerServiceImpl::kMaxWorkersPerTabWhenSeparate; | 429 int max_workers_per_tab = WorkerServiceImpl::kMaxWorkersPerTabWhenSeparate; |
| 550 GURL url = ui_test_utils::GetTestUrl(FilePath(kTestDir), | 430 std::string query = StringPrintf("?count=%d", max_workers_per_tab); |
| 551 FilePath(kQuerySharedWorkerShutdownFile)); | 431 RunTest("queued_shared_worker_shutdown.html", query); |
| 552 url = GURL(url.spec() + StringPrintf("?count=%d", max_workers_per_tab)); | 432 ASSERT_TRUE(WaitForWorkerProcessCount(max_workers_per_tab)); |
| 553 | |
| 554 scoped_refptr<TabProxy> tab(GetActiveTab()); | |
| 555 ASSERT_TRUE(tab.get()); | |
| 556 ASSERT_TRUE(tab->NavigateToURL(url)); | |
| 557 std::string value = WaitUntilCookieNonEmpty(tab.get(), url, | |
| 558 kTestCompleteCookie, TestTimeouts::action_max_timeout_ms()); | |
| 559 ASSERT_STREQ(kTestCompleteSuccess, value.c_str()); | |
| 560 ASSERT_TRUE(WaitForProcessCountToBeAtLeast(1, max_workers_per_tab)); | |
| 561 } | 433 } |
| 562 | 434 |
| 563 // Flaky, http://crbug.com/69881. | 435 // Flaky, http://crbug.com/69881. |
| 564 TEST_F(WorkerTest, DISABLED_MultipleTabsQueuedSharedWorker) { | 436 IN_PROC_BROWSER_TEST_F(WorkerTest, MultipleTabsQueuedSharedWorker) { |
| 565 // Tests to make sure that only one instance of queued shared workers are | 437 // Tests to make sure that only one instance of queued shared workers are |
| 566 // started up even when those instances are on multiple tabs. | 438 // started up even when those instances are on multiple tabs. |
| 567 int max_workers_per_tab = WorkerServiceImpl::kMaxWorkersPerTabWhenSeparate; | 439 int max_workers_per_tab = WorkerServiceImpl::kMaxWorkersPerTabWhenSeparate; |
| 568 GURL url = ui_test_utils::GetTestUrl(FilePath(kTestDir), | 440 std::string query = StringPrintf("?count=%d", max_workers_per_tab + 1); |
| 569 FilePath(kManySharedWorkersFile)); | 441 GURL url = GetTestURL("many_shared_workers.html", query); |
| 570 url = GURL(url.spec() + StringPrintf("?count=%d", max_workers_per_tab+1)); | 442 ui_test_utils::NavigateToURL(browser(), url); |
| 571 | 443 ASSERT_TRUE(WaitForWorkerProcessCount(max_workers_per_tab)); |
| 572 scoped_refptr<TabProxy> tab(GetActiveTab()); | |
| 573 ASSERT_TRUE(tab.get()); | |
| 574 ASSERT_TRUE(tab->NavigateToURL(url)); | |
| 575 ASSERT_TRUE(WaitForProcessCountToBeAtLeast(1, max_workers_per_tab)); | |
| 576 | 444 |
| 577 // Create same set of workers in new tab (leaves one worker queued from this | 445 // Create same set of workers in new tab (leaves one worker queued from this |
| 578 // tab). | 446 // tab). |
| 579 scoped_refptr<BrowserProxy> window(automation()->GetBrowserWindow(0)); | 447 url = GetTestURL("many_shared_workers.html", query); |
| 580 ASSERT_TRUE(window.get()); | 448 ui_test_utils::NavigateToURLWithDisposition( |
| 581 ASSERT_TRUE(window->AppendTab(url)); | 449 browser(), url, NEW_FOREGROUND_TAB, |
| 582 ASSERT_TRUE(WaitForProcessCountToBeAtLeast(2, max_workers_per_tab)); | 450 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
| 451 ASSERT_TRUE(WaitForWorkerProcessCount(max_workers_per_tab)); |
| 583 | 452 |
| 584 // Now shutdown one of the shared workers - this will fire both queued | 453 // Now shutdown one of the shared workers - this will fire both queued |
| 585 // workers, but only one instance should be started | 454 // workers, but only one instance should be started. |
| 586 GURL url2 = ui_test_utils::GetTestUrl(FilePath(kTestDir), | 455 url = GetTestURL("shutdown_shared_worker.html", "?id=0"); |
| 587 FilePath(kShutdownSharedWorkerFile)); | 456 ui_test_utils::NavigateToURLWithDisposition( |
| 588 url2 = GURL(url2.spec() + "?id=0"); | 457 browser(), url, NEW_FOREGROUND_TAB, |
| 589 ASSERT_TRUE(window->AppendTab(url2)); | 458 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); |
| 590 | 459 ASSERT_TRUE(WaitForWorkerProcessCount(max_workers_per_tab)); |
| 591 std::string value = WaitUntilCookieNonEmpty(tab.get(), url, | |
| 592 kTestCompleteCookie, TestTimeouts::action_max_timeout_ms()); | |
| 593 ASSERT_STREQ(kTestCompleteSuccess, value.c_str()); | |
| 594 ASSERT_TRUE(WaitForProcessCountToBeAtLeast(3, max_workers_per_tab)); | |
| 595 } | 460 } |
| 596 | 461 |
| 597 // Flaky: http://crbug.com/48148 | 462 // Flaky: http://crbug.com/48148 |
| 598 TEST_F(WorkerTest, DISABLED_QueuedSharedWorkerStartedFromOtherTab) { | 463 IN_PROC_BROWSER_TEST_F(WorkerTest, QueuedSharedWorkerStartedFromOtherTab) { |
| 599 // Tests to make sure that queued shared workers are started up when | 464 // Tests to make sure that queued shared workers are started up when |
| 600 // an instance is launched from another tab. | 465 // an instance is launched from another tab. |
| 601 int max_workers_per_tab = WorkerServiceImpl::kMaxWorkersPerTabWhenSeparate; | 466 int max_workers_per_tab = WorkerServiceImpl::kMaxWorkersPerTabWhenSeparate; |
| 602 GURL url = ui_test_utils::GetTestUrl(FilePath(kTestDir), | 467 std::string query = StringPrintf("?count=%d", max_workers_per_tab + 1); |
| 603 FilePath(kManySharedWorkersFile)); | 468 GURL url = GetTestURL("many_shared_workers.html", query); |
| 604 url = GURL(url.spec() + StringPrintf("?count=%d", max_workers_per_tab+1)); | 469 ui_test_utils::NavigateToURL(browser(), url); |
| 605 | 470 ASSERT_TRUE(WaitForWorkerProcessCount(max_workers_per_tab)); |
| 606 scoped_refptr<TabProxy> tab(GetActiveTab()); | 471 |
| 607 ASSERT_TRUE(tab.get()); | |
| 608 ASSERT_TRUE(tab->NavigateToURL(url)); | |
| 609 ASSERT_TRUE(WaitForProcessCountToBeAtLeast(1, max_workers_per_tab)); | |
| 610 // First window has hit its limit. Now launch second window which creates | 472 // First window has hit its limit. Now launch second window which creates |
| 611 // the same worker that was queued in the first window, to ensure it gets | 473 // the same worker that was queued in the first window, to ensure it gets |
| 612 // connected to the first window too. | 474 // connected to the first window too. |
| 613 scoped_refptr<BrowserProxy> window(automation()->GetBrowserWindow(0)); | 475 query = StringPrintf("?id=%d", max_workers_per_tab); |
| 614 ASSERT_TRUE(window.get()); | 476 url = GetTestURL("single_shared_worker.html", query); |
| 615 GURL url2 = ui_test_utils::GetTestUrl(FilePath(kTestDir), | 477 ui_test_utils::NavigateToURLWithDisposition( |
| 616 FilePath(kSingleSharedWorkersFile)); | 478 browser(), url, NEW_FOREGROUND_TAB, |
| 617 url2 = GURL(url2.spec() + StringPrintf("?id=%d", max_workers_per_tab)); | 479 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); |
| 618 ASSERT_TRUE(window->AppendTab(url2)); | 480 |
| 619 | 481 ASSERT_TRUE(WaitForWorkerProcessCount(max_workers_per_tab + 1)); |
| 620 std::string value = WaitUntilCookieNonEmpty(tab.get(), url, | 482 } |
| 621 kTestCompleteCookie, TestTimeouts::action_max_timeout_ms()); | |
| 622 ASSERT_STREQ(kTestCompleteSuccess, value.c_str()); | |
| 623 ASSERT_TRUE(WaitForProcessCountToBeAtLeast(2, max_workers_per_tab+1)); | |
| 624 } | |
| OLD | NEW |