OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "base/file_path.h" | |
6 #include "base/string_util.h" | |
7 #include "base/test/test_timeouts.h" | |
8 #include "base/threading/platform_thread.h" | |
9 #include "chrome/app/chrome_command_ids.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" | |
15 #include "chrome/test/ui/ui_layout_test.h" | |
16 #include "content/browser/worker_host/worker_service_impl.h" | |
17 #include "content/public/common/url_constants.h" | |
18 #include "net/test/test_server.h" | |
19 | |
20 using content::WorkerServiceImpl; | |
21 | |
22 namespace { | |
23 | |
24 const char kTestCompleteCookie[] = "status"; | |
25 const char kTestCompleteSuccess[] = "OK"; | |
26 const FilePath::CharType* kTestDir = | |
27 FILE_PATH_LITERAL("workers"); | |
28 const FilePath::CharType* kManySharedWorkersFile = | |
29 FILE_PATH_LITERAL("many_shared_workers.html"); | |
30 const FilePath::CharType* kQuerySharedWorkerShutdownFile = | |
31 FILE_PATH_LITERAL("queued_shared_worker_shutdown.html"); | |
32 const FilePath::CharType* kShutdownSharedWorkerFile = | |
33 FILE_PATH_LITERAL("shutdown_shared_worker.html"); | |
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 | |
258 // Crashy, http://crbug.com/35965. | |
259 // Flaky, http://crbug.com/36555. | |
260 TEST_F(WorkerTest, DISABLED_WorkerClonePort) { | |
261 RunWorkerFastLayoutTest("worker-cloneport.html"); | |
262 } | |
263 | |
264 // http://crbug.com/101996 (started flaking with WebKit roll 98537:98582). | |
265 TEST_F(WorkerTest, DISABLED_WorkerContextMultiPort) { | |
266 RunWorkerFastLayoutTest("worker-context-multi-port.html"); | |
267 } | |
268 | |
269 TEST_F(WorkerTest, WorkerMessagePort) { | |
270 RunWorkerFastLayoutTest("worker-messageport.html"); | |
271 } | |
272 | |
273 TEST_F(WorkerTest, WorkerMessagePortGC) { | |
274 RunWorkerFastLayoutTest("worker-messageport-gc.html"); | |
275 } | |
276 | |
277 // http://crbug.com/101996 (started flaking with WebKit roll 98537:98582). | |
278 TEST_F(WorkerTest, DISABLED_WorkerMultiPort) { | |
279 RunWorkerFastLayoutTest("worker-multi-port.html"); | |
280 } | |
281 | |
282 // | |
283 // SharedWorkerFastLayoutTests | |
284 // | |
285 TEST_F(WorkerTest, SharedWorkerFastConstructor) { | |
286 RunWorkerFastLayoutTest("shared-worker-constructor.html"); | |
287 } | |
288 | |
289 TEST_F(WorkerTest, SharedWorkerFastContextGC) { | |
290 RunWorkerFastLayoutTest("shared-worker-context-gc.html"); | |
291 } | |
292 | |
293 TEST_F(WorkerTest, SharedWorkerFastEventListener) { | |
294 RunWorkerFastLayoutTest("shared-worker-event-listener.html"); | |
295 } | |
296 | |
297 TEST_F(WorkerTest, SharedWorkerFastException) { | |
298 RunWorkerFastLayoutTest("shared-worker-exception.html"); | |
299 } | |
300 | |
301 TEST_F(WorkerTest, SharedWorkerFastGC) { | |
302 RunWorkerFastLayoutTest("shared-worker-gc.html"); | |
303 } | |
304 | |
305 TEST_F(WorkerTest, SharedWorkerFastInIframe) { | |
306 RunWorkerFastLayoutTest("shared-worker-in-iframe.html"); | |
307 } | |
308 | |
309 TEST_F(WorkerTest, SharedWorkerFastLoadError) { | |
310 RunWorkerFastLayoutTest("shared-worker-load-error.html"); | |
311 } | |
312 | |
313 TEST_F(WorkerTest, SharedWorkerFastLocation) { | |
314 RunWorkerFastLayoutTest("shared-worker-location.html"); | |
315 } | |
316 | |
317 TEST_F(WorkerTest, SharedWorkerFastName) { | |
318 RunWorkerFastLayoutTest("shared-worker-name.html"); | |
319 } | |
320 | |
321 TEST_F(WorkerTest, SharedWorkerFastNavigator) { | |
322 RunWorkerFastLayoutTest("shared-worker-navigator.html"); | |
323 } | |
324 | |
325 TEST_F(WorkerTest, SharedWorkerFastReplaceGlobalConstructor) { | |
326 RunWorkerFastLayoutTest("shared-worker-replace-global-constructor.html"); | |
327 } | |
328 | |
329 TEST_F(WorkerTest, SharedWorkerFastReplaceSelf) { | |
330 RunWorkerFastLayoutTest("shared-worker-replace-self.html"); | |
331 } | |
332 | |
333 TEST_F(WorkerTest, SharedWorkerFastScriptError) { | |
334 RunWorkerFastLayoutTest("shared-worker-script-error.html"); | |
335 } | |
336 | |
337 TEST_F(WorkerTest, SharedWorkerFastShared) { | |
338 RunWorkerFastLayoutTest("shared-worker-shared.html"); | |
339 } | |
340 | |
341 TEST_F(WorkerTest, SharedWorkerFastSimple) { | |
342 RunWorkerFastLayoutTest("shared-worker-simple.html"); | |
343 } | |
344 | |
345 // http://crbug.com/16934 | |
346 TEST_F(WorkerTest, DISABLED_WorkerHttpLayoutTests) { | |
347 static const char* kLayoutTestFiles[] = { | |
348 "shared-worker-importScripts.html", | |
349 "shared-worker-redirect.html", | |
350 // flakey? BUG 16934 "text-encoding.html", | |
351 #if defined(OS_WIN) | |
352 // Fails on the mac (and linux?): | |
353 // http://code.google.com/p/chromium/issues/detail?id=22599 | |
354 "worker-importScripts.html", | |
355 #endif | |
356 "worker-redirect.html", | |
357 }; | |
358 | |
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) | |
370 RunLayoutTest(kLayoutTestFiles[i], kHttpPort); | |
371 ASSERT_TRUE(http_server.Stop()); | |
372 } | |
373 | |
374 TEST_F(WorkerTest, WorkerWebSocketLayoutTests) { | |
375 static const char* kLayoutTestFiles[] = { | |
376 "close-in-onmessage-crash.html", | |
377 "close-in-shared-worker.html", | |
378 "close-in-worker.html", | |
379 "shared-worker-simple.html", | |
380 "worker-handshake-challenge-randomness.html", | |
381 "worker-simple.html" | |
382 }; | |
383 | |
384 FilePath websocket_test_dir; | |
385 websocket_test_dir = websocket_test_dir.AppendASCII("http"); | |
386 websocket_test_dir = websocket_test_dir.AppendASCII("tests"); | |
387 | |
388 FilePath worker_test_dir; | |
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[] = { | |
409 "abort-exception-assert.html", | |
410 #if defined(OS_WIN) | |
411 // Fails on the mac (and linux?): | |
412 // http://code.google.com/p/chromium/issues/detail?id=22599 | |
413 "close.html", | |
414 #endif | |
415 // These tests (and the shared-worker versions below) are disabled due to | |
416 // limitations in lighttpd (doesn't handle all of the HTTP methods). | |
417 // "methods-async.html", | |
418 // "methods.html", | |
419 | |
420 "shared-worker-close.html", | |
421 // Disabled due to limitations in lighttpd (does not handle methods other | |
422 // than GET/PUT/POST). | |
423 // "shared-worker-methods-async.html", | |
424 // "shared-worker-methods.html", | |
425 "shared-worker-xhr-file-not-found.html", | |
426 | |
427 "xmlhttprequest-file-not-found.html" | |
428 }; | |
429 | |
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) | |
442 RunLayoutTest(kLayoutTestFiles[i], kHttpPort); | |
443 ASSERT_TRUE(http_server.Stop()); | |
444 } | |
445 | |
446 // Flaky, http://crbug.com/34996. | |
447 TEST_F(WorkerTest, DISABLED_MessagePorts) { | |
448 static const char* kLayoutTestFiles[] = { | |
449 "message-channel-gc.html", | |
450 "message-channel-gc-2.html", | |
451 "message-channel-gc-3.html", | |
452 "message-channel-gc-4.html", | |
453 "message-port.html", | |
454 "message-port-clone.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 }; | |
464 | |
465 FilePath fast_test_dir; | |
466 fast_test_dir = fast_test_dir.AppendASCII("fast"); | |
467 | |
468 FilePath worker_test_dir; | |
469 worker_test_dir = worker_test_dir.AppendASCII("events"); | |
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 | |
478 for (size_t i = 0; i < arraysize(kLayoutTestFiles); ++i) | |
479 RunLayoutTest(kLayoutTestFiles[i], kNoHttpPort); | |
480 } | |
481 | |
482 TEST_F(WorkerTest, LimitPerPage) { | |
483 int max_workers_per_tab = WorkerServiceImpl::kMaxWorkersPerTabWhenSeparate; | |
484 GURL url = ui_test_utils::GetTestUrl(FilePath(kTestDir), | |
485 FilePath(kManySharedWorkersFile)); | |
486 url = GURL(url.spec() + StringPrintf("?count=%d", max_workers_per_tab + 1)); | |
487 | |
488 NavigateToURL(url); | |
489 ASSERT_TRUE(WaitForProcessCountToBeAtLeast(1, max_workers_per_tab)); | |
490 } | |
491 | |
492 // http://crbug.com/36800 | |
493 #if defined(OS_WIN) | |
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; | |
500 int total_workers = WorkerServiceImpl::kMaxWorkersWhenSeparate; | |
501 | |
502 // Adding 1 so that we cause some workers to be queued. | |
503 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) { | |
515 ASSERT_TRUE(window->AppendTab(GURL( | |
516 url.spec() + StringPrintf("&client_id=%d", i)))); | |
517 } | |
518 | |
519 // Check that we didn't create more than the max number of workers. | |
520 ASSERT_TRUE(WaitForProcessCountToBeAtLeast(tab_count, total_workers)); | |
521 | |
522 // Now close a page and check that the queued workers were started. | |
523 const FilePath::CharType* kGoogleDir = FILE_PATH_LITERAL("google"); | |
524 const FilePath::CharType* kGoogleFile = FILE_PATH_LITERAL("google.html"); | |
525 ASSERT_EQ(AUTOMATION_MSG_NAVIGATION_SUCCESS, | |
526 tab->NavigateToURL(ui_test_utils::GetTestUrl(FilePath(kGoogleDir), | |
527 FilePath(kGoogleFile)))); | |
528 | |
529 ASSERT_TRUE(WaitForProcessCountToBeAtLeast(tab_count, total_workers)); | |
530 } | |
531 | |
532 // Flaky, http://crbug.com/59786. | |
533 TEST_F(WorkerTest, DISABLED_WorkerClose) { | |
534 scoped_refptr<TabProxy> tab(GetActiveTab()); | |
535 ASSERT_TRUE(tab.get()); | |
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 } | |
544 | |
545 // Flaky, http://crbug.com/70861. | |
546 TEST_F(WorkerTest, DISABLED_QueuedSharedWorkerShutdown) { | |
547 // Tests to make sure that queued shared workers are started up when | |
548 // shared workers shut down. | |
549 int max_workers_per_tab = WorkerServiceImpl::kMaxWorkersPerTabWhenSeparate; | |
550 GURL url = ui_test_utils::GetTestUrl(FilePath(kTestDir), | |
551 FilePath(kQuerySharedWorkerShutdownFile)); | |
552 url = GURL(url.spec() + StringPrintf("?count=%d", 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 } | |
562 | |
563 // Flaky, http://crbug.com/69881. | |
564 TEST_F(WorkerTest, DISABLED_MultipleTabsQueuedSharedWorker) { | |
565 // Tests to make sure that only one instance of queued shared workers are | |
566 // started up even when those instances are on multiple tabs. | |
567 int max_workers_per_tab = WorkerServiceImpl::kMaxWorkersPerTabWhenSeparate; | |
568 GURL url = ui_test_utils::GetTestUrl(FilePath(kTestDir), | |
569 FilePath(kManySharedWorkersFile)); | |
570 url = GURL(url.spec() + StringPrintf("?count=%d", max_workers_per_tab+1)); | |
571 | |
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 | |
577 // Create same set of workers in new tab (leaves one worker queued from this | |
578 // tab). | |
579 scoped_refptr<BrowserProxy> window(automation()->GetBrowserWindow(0)); | |
580 ASSERT_TRUE(window.get()); | |
581 ASSERT_TRUE(window->AppendTab(url)); | |
582 ASSERT_TRUE(WaitForProcessCountToBeAtLeast(2, max_workers_per_tab)); | |
583 | |
584 // Now shutdown one of the shared workers - this will fire both queued | |
585 // workers, but only one instance should be started | |
586 GURL url2 = ui_test_utils::GetTestUrl(FilePath(kTestDir), | |
587 FilePath(kShutdownSharedWorkerFile)); | |
588 url2 = GURL(url2.spec() + "?id=0"); | |
589 ASSERT_TRUE(window->AppendTab(url2)); | |
590 | |
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 } | |
596 | |
597 // Flaky: http://crbug.com/48148 | |
598 TEST_F(WorkerTest, DISABLED_QueuedSharedWorkerStartedFromOtherTab) { | |
599 // Tests to make sure that queued shared workers are started up when | |
600 // an instance is launched from another tab. | |
601 int max_workers_per_tab = WorkerServiceImpl::kMaxWorkersPerTabWhenSeparate; | |
602 GURL url = ui_test_utils::GetTestUrl(FilePath(kTestDir), | |
603 FilePath(kManySharedWorkersFile)); | |
604 url = GURL(url.spec() + StringPrintf("?count=%d", max_workers_per_tab+1)); | |
605 | |
606 scoped_refptr<TabProxy> tab(GetActiveTab()); | |
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 | |
611 // the same worker that was queued in the first window, to ensure it gets | |
612 // connected to the first window too. | |
613 scoped_refptr<BrowserProxy> window(automation()->GetBrowserWindow(0)); | |
614 ASSERT_TRUE(window.get()); | |
615 GURL url2 = ui_test_utils::GetTestUrl(FilePath(kTestDir), | |
616 FilePath(kSingleSharedWorkersFile)); | |
617 url2 = GURL(url2.spec() + StringPrintf("?id=%d", max_workers_per_tab)); | |
618 ASSERT_TRUE(window->AppendTab(url2)); | |
619 | |
620 std::string value = WaitUntilCookieNonEmpty(tab.get(), url, | |
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 |