Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(672)

Side by Side Diff: chrome/worker/worker_uitest.cc

Issue 6691004: Move worker code from chrome\worker to content\worker. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/worker/worker_thread.cc ('k') | chrome/worker/worker_webapplicationcachehost_impl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2011 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/common/url_constants.h"
11 #include "chrome/test/automation/browser_proxy.h"
12 #include "chrome/test/automation/tab_proxy.h"
13 #include "chrome/test/ui/ui_layout_test.h"
14 #include "chrome/test/ui_test_utils.h"
15 #include "content/browser/worker_host/worker_service.h"
16 #include "net/test/test_server.h"
17
18 namespace {
19
20 const char kTestCompleteCookie[] = "status";
21 const char kTestCompleteSuccess[] = "OK";
22 const FilePath::CharType* kTestDir =
23 FILE_PATH_LITERAL("workers");
24 const FilePath::CharType* kManySharedWorkersFile =
25 FILE_PATH_LITERAL("many_shared_workers.html");
26 const FilePath::CharType* kManyWorkersFile =
27 FILE_PATH_LITERAL("many_workers.html");
28 const FilePath::CharType* kQuerySharedWorkerShutdownFile =
29 FILE_PATH_LITERAL("queued_shared_worker_shutdown.html");
30 const FilePath::CharType* kShutdownSharedWorkerFile =
31 FILE_PATH_LITERAL("shutdown_shared_worker.html");
32 const FilePath::CharType* kSingleSharedWorkersFile =
33 FILE_PATH_LITERAL("single_shared_worker.html");
34 const FilePath::CharType* kWorkerClose =
35 FILE_PATH_LITERAL("worker_close.html");
36
37 } // anonymous namespace
38
39 class WorkerTest : public UILayoutTest {
40 protected:
41 virtual ~WorkerTest() { }
42
43 void RunTest(const FilePath& test_case) {
44 scoped_refptr<TabProxy> tab(GetActiveTab());
45 ASSERT_TRUE(tab.get());
46
47 GURL url = ui_test_utils::GetTestUrl(FilePath(kTestDir), test_case);
48 ASSERT_TRUE(tab->NavigateToURL(url));
49
50 std::string value = WaitUntilCookieNonEmpty(tab.get(), url,
51 kTestCompleteCookie, TestTimeouts::action_max_timeout_ms());
52 ASSERT_STREQ(kTestCompleteSuccess, value.c_str());
53 }
54
55 void RunIncognitoTest(const FilePath& test_case) {
56 scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0));
57 ASSERT_TRUE(browser.get());
58
59 // Open an Incognito window.
60 ASSERT_TRUE(browser->RunCommand(IDC_NEW_INCOGNITO_WINDOW));
61 scoped_refptr<BrowserProxy> incognito(automation()->GetBrowserWindow(1));
62 ASSERT_TRUE(incognito.get());
63 int window_count;
64 ASSERT_TRUE(automation()->GetBrowserWindowCount(&window_count));
65 ASSERT_EQ(2, window_count);
66
67 scoped_refptr<TabProxy> tab(incognito->GetTab(0));
68 ASSERT_TRUE(tab.get());
69
70 GURL url = ui_test_utils::GetTestUrl(FilePath(kTestDir), test_case);
71 ASSERT_TRUE(tab->NavigateToURL(url));
72
73 std::string value = WaitUntilCookieNonEmpty(tab.get(), url,
74 kTestCompleteCookie, TestTimeouts::action_max_timeout_ms());
75
76 // Close the incognito window
77 ASSERT_TRUE(incognito->RunCommand(IDC_CLOSE_WINDOW));
78 ASSERT_TRUE(automation()->GetBrowserWindowCount(&window_count));
79 ASSERT_EQ(1, window_count);
80
81 ASSERT_STREQ(kTestCompleteSuccess, value.c_str());
82 }
83
84 bool WaitForProcessCountToBe(int tabs, int workers) {
85 // The 1 is for the browser process.
86 int number_of_processes = 1 + workers +
87 (ProxyLauncher::in_process_renderer() ? 0 : tabs);
88 #if defined(OS_LINUX)
89 // On Linux, we also have a zygote process and a sandbox host process.
90 number_of_processes += 2;
91 #endif
92
93 int cur_process_count;
94 for (int i = 0; i < 100; ++i) {
95 cur_process_count = 0;
96 if (!GetBrowserProcessCount(&cur_process_count))
97 return false;
98 if (cur_process_count == number_of_processes)
99 return true;
100
101 // Sometimes the worker processes can take a while to shut down on the
102 // bots, so use a longer timeout period to avoid spurious failures.
103 base::PlatformThread::Sleep(TestTimeouts::action_max_timeout_ms() / 100);
104 }
105
106 EXPECT_EQ(number_of_processes, cur_process_count);
107 return false;
108 }
109
110 void RunWorkerFastLayoutTest(const std::string& test_case_file_name) {
111 FilePath fast_test_dir;
112 fast_test_dir = fast_test_dir.AppendASCII("fast");
113
114 FilePath worker_test_dir;
115 worker_test_dir = worker_test_dir.AppendASCII("workers");
116 InitializeForLayoutTest(fast_test_dir, worker_test_dir, kNoHttpPort);
117
118 // Worker tests also rely on common files in js/resources.
119 FilePath js_dir = fast_test_dir.AppendASCII("js");
120 FilePath resource_dir;
121 resource_dir = resource_dir.AppendASCII("resources");
122 AddResourceForLayoutTest(js_dir, resource_dir);
123
124 printf("Test: %s\n", test_case_file_name.c_str());
125 RunLayoutTest(test_case_file_name, kNoHttpPort);
126
127 // Navigate to a blank page so that any workers are cleaned up.
128 // This helps leaks trackers do a better job of reporting.
129 scoped_refptr<TabProxy> tab(GetActiveTab());
130 GURL about_url(chrome::kAboutBlankURL);
131 EXPECT_EQ(AUTOMATION_MSG_NAVIGATION_SUCCESS, tab->NavigateToURL(about_url));
132 }
133
134 void RunWorkerStorageLayoutTest(const std::string& test_case_file_name) {
135 FilePath worker_test_dir;
136 worker_test_dir = worker_test_dir.AppendASCII("fast");
137 worker_test_dir = worker_test_dir.AppendASCII("workers");
138
139 FilePath storage_test_dir;
140 storage_test_dir = storage_test_dir.AppendASCII("storage");
141 InitializeForLayoutTest(worker_test_dir, storage_test_dir, kNoHttpPort);
142
143 // Storage worker tests also rely on common files in 'resources'.
144 FilePath resource_dir;
145 resource_dir = resource_dir.AppendASCII("resources");
146 AddResourceForLayoutTest(worker_test_dir.Append(storage_test_dir),
147 resource_dir);
148
149 printf("Test: %s\n", test_case_file_name.c_str());
150 RunLayoutTest(test_case_file_name, kNoHttpPort);
151
152 // Navigate to a blank page so that any workers are cleaned up.
153 // This helps leaks trackers do a better job of reporting.
154 scoped_refptr<TabProxy> tab(GetActiveTab());
155 GURL about_url(chrome::kAboutBlankURL);
156 EXPECT_EQ(AUTOMATION_MSG_NAVIGATION_SUCCESS, tab->NavigateToURL(about_url));
157 }
158
159 bool NavigateAndWaitForAuth(TabProxy* tab, const GURL& url) {
160 // Pass a large number of navigations to tell the tab to block until an auth
161 // dialog pops up.
162 EXPECT_EQ(AUTOMATION_MSG_NAVIGATION_AUTH_NEEDED,
163 tab->NavigateToURLBlockUntilNavigationsComplete(url, 100));
164 return tab->NeedsAuth();
165 }
166 };
167
168
169 TEST_F(WorkerTest, SingleWorker) {
170 RunTest(FilePath(FILE_PATH_LITERAL("single_worker.html")));
171 }
172
173 TEST_F(WorkerTest, MultipleWorkers) {
174 RunTest(FilePath(FILE_PATH_LITERAL("multi_worker.html")));
175 }
176
177 TEST_F(WorkerTest, SingleSharedWorker) {
178 RunTest(FilePath(FILE_PATH_LITERAL("single_worker.html?shared=true")));
179 }
180
181 TEST_F(WorkerTest, MultipleSharedWorkers) {
182 RunTest(FilePath(FILE_PATH_LITERAL("multi_worker.html?shared=true")));
183 }
184
185 TEST_F(WorkerTest, TerminateQueuedWorkers) {
186 ASSERT_TRUE(WaitForProcessCountToBe(1, 0));
187 RunTest(FilePath(FILE_PATH_LITERAL("terminate_queued_workers.html")));
188 // Make sure all workers exit.
189 ASSERT_TRUE(WaitForProcessCountToBe(1, 0));
190 }
191
192 #if defined(OS_LINUX)
193 // http://crbug.com/30021
194 #define IncognitoSharedWorkers FLAKY_IncognitoSharedWorkers
195 #endif
196
197 // Incognito windows should not share workers with non-incognito windows
198 TEST_F(WorkerTest, IncognitoSharedWorkers) {
199 // Load a non-incognito tab and have it create a shared worker
200 RunTest(FilePath(FILE_PATH_LITERAL("incognito_worker.html")));
201 // Incognito worker should not share with non-incognito
202 RunIncognitoTest(FilePath(FILE_PATH_LITERAL("incognito_worker.html")));
203 }
204
205 const FilePath::CharType kDocRoot[] =
206 FILE_PATH_LITERAL("chrome/test/data/workers");
207
208 #if defined(OS_WIN)
209 // http://crbug.com/33344 - NavigateAndWaitForAuth times out on the Windows
210 // build bots.
211 #define WorkerHttpAuth DISABLED_WorkerHttpAuth
212 #endif
213 // Make sure that auth dialog is displayed from worker context.
214 TEST_F(WorkerTest, WorkerHttpAuth) {
215 net::TestServer test_server(net::TestServer::TYPE_HTTP, FilePath(kDocRoot));
216 ASSERT_TRUE(test_server.Start());
217
218 scoped_refptr<TabProxy> tab(GetActiveTab());
219 ASSERT_TRUE(tab.get());
220
221 GURL url = test_server.GetURL("files/worker_auth.html");
222 EXPECT_TRUE(NavigateAndWaitForAuth(tab, url));
223 }
224
225 #if defined(OS_WIN)
226 // http://crbug.com/33344 - NavigateAndWaitForAuth times out on the Windows
227 // build bots.
228 #define SharedWorkerHttpAuth DISABLED_SharedWorkerHttpAuth
229 #endif
230 // Make sure that auth dialog is displayed from shared worker context.
231 TEST_F(WorkerTest, SharedWorkerHttpAuth) {
232 net::TestServer test_server(net::TestServer::TYPE_HTTP, FilePath(kDocRoot));
233 ASSERT_TRUE(test_server.Start());
234
235 scoped_refptr<TabProxy> tab(GetActiveTab());
236 ASSERT_TRUE(tab.get());
237
238 GURL url = test_server.GetURL("files/shared_worker_auth.html");
239 EXPECT_TRUE(NavigateAndWaitForAuth(tab, url));
240 // TODO(atwilson): Add support to automation framework to test for auth
241 // dialogs displayed by non-navigating tabs.
242 }
243
244 TEST_F(WorkerTest, StressJSExecution) {
245 RunWorkerFastLayoutTest("stress-js-execution.html");
246 }
247
248 TEST_F(WorkerTest, UseMachineStack) {
249 RunWorkerFastLayoutTest("use-machine-stack.html");
250 }
251
252 TEST_F(WorkerTest, WorkerCall) {
253 RunWorkerFastLayoutTest("worker-call.html");
254 }
255
256 // Crashy, http://crbug.com/35965.
257 // Flaky, http://crbug.com/36555.
258 TEST_F(WorkerTest, DISABLED_WorkerClonePort) {
259 RunWorkerFastLayoutTest("worker-cloneport.html");
260 }
261
262 // Flaky, http://crbug.com/59780.
263 TEST_F(WorkerTest, FLAKY_WorkerCloseFast) {
264 RunWorkerFastLayoutTest("worker-close.html");
265 }
266
267 TEST_F(WorkerTest, WorkerConstructor) {
268 RunWorkerFastLayoutTest("worker-constructor.html");
269 }
270
271 TEST_F(WorkerTest, WorkerContextGc) {
272 RunWorkerFastLayoutTest("worker-context-gc.html");
273 }
274
275 TEST_F(WorkerTest, WorkerContextMultiPort) {
276 RunWorkerFastLayoutTest("worker-context-multi-port.html");
277 }
278
279 TEST_F(WorkerTest, WorkerEventListener) {
280 RunWorkerFastLayoutTest("worker-event-listener.html");
281 }
282
283 TEST_F(WorkerTest, WorkerGC) {
284 RunWorkerFastLayoutTest("worker-gc.html");
285 }
286
287 // worker-lifecycle.html relies on layoutTestController.workerThreadCount
288 // which is not currently implemented. http://crbug.com/45168
289 TEST_F(WorkerTest, DISABLED_WorkerLifecycle) {
290 RunWorkerFastLayoutTest("worker-lifecycle.html");
291 }
292
293 TEST_F(WorkerTest, WorkerLocation) {
294 RunWorkerFastLayoutTest("worker-location.html");
295 }
296
297 // Flaky, http://crbug.com/71518.
298 TEST_F(WorkerTest, FLAKY_WorkerMapGc) {
299 RunWorkerFastLayoutTest("wrapper-map-gc.html");
300 }
301
302 TEST_F(WorkerTest, WorkerMessagePort) {
303 RunWorkerFastLayoutTest("worker-messageport.html");
304 }
305
306 TEST_F(WorkerTest, WorkerMessagePortGC) {
307 RunWorkerFastLayoutTest("worker-messageport-gc.html");
308 }
309
310 TEST_F(WorkerTest, WorkerMultiPort) {
311 RunWorkerFastLayoutTest("worker-multi-port.html");
312 }
313
314 TEST_F(WorkerTest, WorkerNavigator) {
315 RunWorkerFastLayoutTest("worker-navigator.html");
316 }
317
318 TEST_F(WorkerTest, WorkerReplaceGlobalConstructor) {
319 RunWorkerFastLayoutTest("worker-replace-global-constructor.html");
320 }
321
322 TEST_F(WorkerTest, WorkerReplaceSelf) {
323 RunWorkerFastLayoutTest("worker-replace-self.html");
324 }
325
326 // See bug 44457.
327 #if defined(OS_MACOSX)
328 #define WorkerScriptError FLAKY_WorkerScriptError
329 #endif
330
331 TEST_F(WorkerTest, WorkerScriptError) {
332 RunWorkerFastLayoutTest("worker-script-error.html");
333 }
334
335 TEST_F(WorkerTest, WorkerTerminate) {
336 RunWorkerFastLayoutTest("worker-terminate.html");
337 }
338
339 TEST_F(WorkerTest, WorkerTimeout) {
340 RunWorkerFastLayoutTest("worker-timeout.html");
341 }
342
343 //
344 // SharedWorkerFastLayoutTests
345 //
346 // http://crbug.com/27636 - incorrect URL_MISMATCH exceptions sometimes get
347 // generated on the windows try bots. FLAKY on Win.
348 // http://crbug.com/28445 - flakiness on mac
349 TEST_F(WorkerTest, FLAKY_SharedWorkerFastConstructor) {
350 RunWorkerFastLayoutTest("shared-worker-constructor.html");
351 }
352
353 TEST_F(WorkerTest, FLAKY_SharedWorkerFastContextGC) {
354 RunWorkerFastLayoutTest("shared-worker-context-gc.html");
355 }
356
357 TEST_F(WorkerTest, FLAKY_SharedWorkerFastEventListener) {
358 RunWorkerFastLayoutTest("shared-worker-event-listener.html");
359 }
360
361 TEST_F(WorkerTest, FLAKY_SharedWorkerFastException) {
362 RunWorkerFastLayoutTest("shared-worker-exception.html");
363 }
364
365 TEST_F(WorkerTest, FLAKY_SharedWorkerFastGC) {
366 RunWorkerFastLayoutTest("shared-worker-gc.html");
367 }
368
369 TEST_F(WorkerTest, FLAKY_SharedWorkerFastInIframe) {
370 RunWorkerFastLayoutTest("shared-worker-in-iframe.html");
371 }
372
373 TEST_F(WorkerTest, FLAKY_SharedWorkerFastLoadError) {
374 RunWorkerFastLayoutTest("shared-worker-load-error.html");
375 }
376
377 TEST_F(WorkerTest, FLAKY_SharedWorkerFastLocation) {
378 RunWorkerFastLayoutTest("shared-worker-location.html");
379 }
380
381 TEST_F(WorkerTest, FLAKY_SharedWorkerFastName) {
382 RunWorkerFastLayoutTest("shared-worker-name.html");
383 }
384
385 TEST_F(WorkerTest, FLAKY_SharedWorkerFastNavigator) {
386 RunWorkerFastLayoutTest("shared-worker-navigator.html");
387 }
388
389 TEST_F(WorkerTest, FLAKY_SharedWorkerFastReplaceGlobalConstructor) {
390 RunWorkerFastLayoutTest("shared-worker-replace-global-constructor.html");
391 }
392
393 TEST_F(WorkerTest, FLAKY_SharedWorkerFastReplaceSelf) {
394 RunWorkerFastLayoutTest("shared-worker-replace-self.html");
395 }
396
397 TEST_F(WorkerTest, FLAKY_SharedWorkerFastScriptError) {
398 RunWorkerFastLayoutTest("shared-worker-script-error.html");
399 }
400
401 TEST_F(WorkerTest, FLAKY_SharedWorkerFastShared) {
402 RunWorkerFastLayoutTest("shared-worker-shared.html");
403 }
404
405 TEST_F(WorkerTest, FLAKY_SharedWorkerFastSimple) {
406 RunWorkerFastLayoutTest("shared-worker-simple.html");
407 }
408
409 // http://crbug.com/16934
410 TEST_F(WorkerTest, DISABLED_WorkerHttpLayoutTests) {
411 static const char* kLayoutTestFiles[] = {
412 "shared-worker-importScripts.html",
413 "shared-worker-redirect.html",
414 // flakey? BUG 16934 "text-encoding.html",
415 #if defined(OS_WIN)
416 // Fails on the mac (and linux?):
417 // http://code.google.com/p/chromium/issues/detail?id=22599
418 "worker-importScripts.html",
419 #endif
420 "worker-redirect.html",
421 };
422
423 FilePath http_test_dir;
424 http_test_dir = http_test_dir.AppendASCII("http");
425 http_test_dir = http_test_dir.AppendASCII("tests");
426
427 FilePath worker_test_dir;
428 worker_test_dir = worker_test_dir.AppendASCII("workers");
429 InitializeForLayoutTest(http_test_dir, worker_test_dir, kHttpPort);
430
431 StartHttpServer(new_http_root_dir_);
432 for (size_t i = 0; i < arraysize(kLayoutTestFiles); ++i)
433 RunLayoutTest(kLayoutTestFiles[i], kHttpPort);
434 StopHttpServer();
435 }
436
437 TEST_F(WorkerTest, WorkerWebSocketLayoutTests) {
438 static const char* kLayoutTestFiles[] = {
439 "close-in-onmessage-crash.html",
440 "close-in-shared-worker.html",
441 "close-in-worker.html",
442 "shared-worker-simple.html",
443 "worker-handshake-challenge-randomness.html",
444 "worker-simple.html"
445 };
446
447 FilePath websocket_test_dir;
448 websocket_test_dir = websocket_test_dir.AppendASCII("http");
449 websocket_test_dir = websocket_test_dir.AppendASCII("tests");
450
451 FilePath worker_test_dir;
452 worker_test_dir = worker_test_dir.AppendASCII("websocket");
453 worker_test_dir = worker_test_dir.AppendASCII("tests");
454 worker_test_dir = worker_test_dir.AppendASCII("workers");
455 InitializeForLayoutTest(websocket_test_dir, worker_test_dir, kHttpPort);
456
457 FilePath websocket_root_dir(temp_test_dir_);
458 websocket_root_dir = websocket_root_dir.AppendASCII("LayoutTests");
459 ui_test_utils::TestWebSocketServer websocket_server;
460 ASSERT_TRUE(websocket_server.Start(websocket_root_dir));
461
462 StartHttpServer(new_http_root_dir_);
463 for (size_t i = 0; i < arraysize(kLayoutTestFiles); ++i)
464 RunLayoutTest(kLayoutTestFiles[i], kHttpPort);
465 StopHttpServer();
466 }
467
468 TEST_F(WorkerTest, DISABLED_WorkerXhrHttpLayoutTests) {
469 static const char* kLayoutTestFiles[] = {
470 "abort-exception-assert.html",
471 #if defined(OS_WIN)
472 // Fails on the mac (and linux?):
473 // http://code.google.com/p/chromium/issues/detail?id=22599
474 "close.html",
475 #endif
476 // These tests (and the shared-worker versions below) are disabled due to
477 // limitations in lighttpd (doesn't handle all of the HTTP methods).
478 // "methods-async.html",
479 // "methods.html",
480
481 "shared-worker-close.html",
482 // Disabled due to limitations in lighttpd (does not handle methods other
483 // than GET/PUT/POST).
484 // "shared-worker-methods-async.html",
485 // "shared-worker-methods.html",
486 "shared-worker-xhr-file-not-found.html",
487
488 "xmlhttprequest-file-not-found.html"
489 };
490
491 FilePath http_test_dir;
492 http_test_dir = http_test_dir.AppendASCII("http");
493 http_test_dir = http_test_dir.AppendASCII("tests");
494
495 FilePath worker_test_dir;
496 worker_test_dir = worker_test_dir.AppendASCII("xmlhttprequest");
497 worker_test_dir = worker_test_dir.AppendASCII("workers");
498 InitializeForLayoutTest(http_test_dir, worker_test_dir, kHttpPort);
499
500 StartHttpServer(new_http_root_dir_);
501 for (size_t i = 0; i < arraysize(kLayoutTestFiles); ++i)
502 RunLayoutTest(kLayoutTestFiles[i], kHttpPort);
503 StopHttpServer();
504 }
505
506 // Flaky, http://crbug.com/34996.
507 TEST_F(WorkerTest, FLAKY_MessagePorts) {
508 static const char* kLayoutTestFiles[] = {
509 "message-channel-gc.html",
510 "message-channel-gc-2.html",
511 "message-channel-gc-3.html",
512 "message-channel-gc-4.html",
513 "message-port.html",
514 "message-port-clone.html",
515 "message-port-constructor-for-deleted-document.html",
516 "message-port-deleted-document.html",
517 "message-port-deleted-frame.html",
518 "message-port-inactive-document.html",
519 "message-port-multi.html",
520 "message-port-no-wrapper.html",
521 // Only works with run-webkit-tests --leaks.
522 // "message-channel-listener-circular-ownership.html",
523 };
524
525 FilePath fast_test_dir;
526 fast_test_dir = fast_test_dir.AppendASCII("fast");
527
528 FilePath worker_test_dir;
529 worker_test_dir = worker_test_dir.AppendASCII("events");
530 InitializeForLayoutTest(fast_test_dir, worker_test_dir, kNoHttpPort);
531
532 // MessagePort tests also rely on common files in js/resources.
533 FilePath js_dir = fast_test_dir.AppendASCII("js");
534 FilePath resource_dir;
535 resource_dir = resource_dir.AppendASCII("resources");
536 AddResourceForLayoutTest(js_dir, resource_dir);
537
538 for (size_t i = 0; i < arraysize(kLayoutTestFiles); ++i)
539 RunLayoutTest(kLayoutTestFiles[i], kNoHttpPort);
540 }
541
542 // This has been flaky on Windows since r39931. http://crbug.com/36800
543 // And on Mac since r51935. http://crbug.com/48664
544 TEST_F(WorkerTest, FLAKY_LimitPerPage) {
545 int max_workers_per_tab = WorkerService::kMaxWorkersPerTabWhenSeparate;
546 GURL url = ui_test_utils::GetTestUrl(FilePath(kTestDir),
547 FilePath(kManyWorkersFile));
548 url = GURL(url.spec() + StringPrintf("?count=%d", max_workers_per_tab + 1));
549
550 NavigateToURL(url);
551 ASSERT_TRUE(WaitForProcessCountToBe(1, max_workers_per_tab));
552 }
553
554 // Doesn't crash, but on all platforms, it sometimes fails.
555 // Flaky on all platforms: http://crbug.com/28445
556 #if defined(OS_LINUX)
557 // Hangs on Linux: http://30332
558 #define FLAKY_LimitTotal DISABLED_LimitTotal
559 #endif
560 TEST_F(WorkerTest, FLAKY_LimitTotal) {
561 int max_workers_per_tab = WorkerService::kMaxWorkersPerTabWhenSeparate;
562 int total_workers = WorkerService::kMaxWorkersWhenSeparate;
563
564 int tab_count = (total_workers / max_workers_per_tab) + 1;
565 GURL url = ui_test_utils::GetTestUrl(FilePath(kTestDir),
566 FilePath(kManyWorkersFile));
567 url = GURL(url.spec() + StringPrintf("?count=%d", max_workers_per_tab));
568
569 scoped_refptr<TabProxy> tab(GetActiveTab());
570 ASSERT_TRUE(tab.get());
571 ASSERT_TRUE(tab->NavigateToURL(url));
572 scoped_refptr<BrowserProxy> window(automation()->GetBrowserWindow(0));
573 ASSERT_TRUE(window.get());
574 for (int i = 1; i < tab_count; ++i)
575 ASSERT_TRUE(window->AppendTab(url));
576
577 // Check that we didn't create more than the max number of workers.
578 ASSERT_TRUE(WaitForProcessCountToBe(tab_count, total_workers));
579
580 // Now close a page and check that the queued workers were started.
581 const FilePath::CharType* kGoogleDir = FILE_PATH_LITERAL("google");
582 const FilePath::CharType* kGoogleFile = FILE_PATH_LITERAL("google.html");
583 ASSERT_EQ(AUTOMATION_MSG_NAVIGATION_SUCCESS,
584 tab->NavigateToURL(ui_test_utils::GetTestUrl(FilePath(kGoogleDir),
585 FilePath(kGoogleFile))));
586
587 ASSERT_TRUE(WaitForProcessCountToBe(tab_count, total_workers));
588 }
589
590 // Flaky, http://crbug.com/59786.
591 TEST_F(WorkerTest, FLAKY_WorkerClose) {
592 scoped_refptr<TabProxy> tab(GetActiveTab());
593 ASSERT_TRUE(tab.get());
594 GURL url = ui_test_utils::GetTestUrl(FilePath(kTestDir),
595 FilePath(kWorkerClose));
596 ASSERT_TRUE(tab->NavigateToURL(url));
597 std::string value = WaitUntilCookieNonEmpty(tab.get(), url,
598 kTestCompleteCookie, TestTimeouts::action_max_timeout_ms());
599 ASSERT_STREQ(kTestCompleteSuccess, value.c_str());
600 ASSERT_TRUE(WaitForProcessCountToBe(1, 0));
601 }
602
603 // Flaky, http://crbug.com/70861.
604 TEST_F(WorkerTest, FLAKY_QueuedSharedWorkerShutdown) {
605 // Tests to make sure that queued shared workers are started up when
606 // shared workers shut down.
607 int max_workers_per_tab = WorkerService::kMaxWorkersPerTabWhenSeparate;
608 GURL url = ui_test_utils::GetTestUrl(FilePath(kTestDir),
609 FilePath(kQuerySharedWorkerShutdownFile));
610 url = GURL(url.spec() + StringPrintf("?count=%d", max_workers_per_tab));
611
612 scoped_refptr<TabProxy> tab(GetActiveTab());
613 ASSERT_TRUE(tab.get());
614 ASSERT_TRUE(tab->NavigateToURL(url));
615 std::string value = WaitUntilCookieNonEmpty(tab.get(), url,
616 kTestCompleteCookie, TestTimeouts::action_max_timeout_ms());
617 ASSERT_STREQ(kTestCompleteSuccess, value.c_str());
618 ASSERT_TRUE(WaitForProcessCountToBe(1, max_workers_per_tab));
619 }
620
621 // Flaky, http://crbug.com/69881.
622 TEST_F(WorkerTest, FLAKY_MultipleTabsQueuedSharedWorker) {
623 // Tests to make sure that only one instance of queued shared workers are
624 // started up even when those instances are on multiple tabs.
625 int max_workers_per_tab = WorkerService::kMaxWorkersPerTabWhenSeparate;
626 GURL url = ui_test_utils::GetTestUrl(FilePath(kTestDir),
627 FilePath(kManySharedWorkersFile));
628 url = GURL(url.spec() + StringPrintf("?count=%d", max_workers_per_tab+1));
629
630 scoped_refptr<TabProxy> tab(GetActiveTab());
631 ASSERT_TRUE(tab.get());
632 ASSERT_TRUE(tab->NavigateToURL(url));
633 ASSERT_TRUE(WaitForProcessCountToBe(1, max_workers_per_tab));
634
635 // Create same set of workers in new tab (leaves one worker queued from this
636 // tab).
637 scoped_refptr<BrowserProxy> window(automation()->GetBrowserWindow(0));
638 ASSERT_TRUE(window.get());
639 ASSERT_TRUE(window->AppendTab(url));
640 ASSERT_TRUE(WaitForProcessCountToBe(2, max_workers_per_tab));
641
642 // Now shutdown one of the shared workers - this will fire both queued
643 // workers, but only one instance should be started
644 GURL url2 = ui_test_utils::GetTestUrl(FilePath(kTestDir),
645 FilePath(kShutdownSharedWorkerFile));
646 url2 = GURL(url2.spec() + "?id=0");
647 ASSERT_TRUE(window->AppendTab(url2));
648
649 std::string value = WaitUntilCookieNonEmpty(tab.get(), url,
650 kTestCompleteCookie, TestTimeouts::action_max_timeout_ms());
651 ASSERT_STREQ(kTestCompleteSuccess, value.c_str());
652 ASSERT_TRUE(WaitForProcessCountToBe(3, max_workers_per_tab));
653 }
654
655 // Flaky: http://crbug.com/48148
656 TEST_F(WorkerTest, FLAKY_QueuedSharedWorkerStartedFromOtherTab) {
657 // Tests to make sure that queued shared workers are started up when
658 // an instance is launched from another tab.
659 int max_workers_per_tab = WorkerService::kMaxWorkersPerTabWhenSeparate;
660 GURL url = ui_test_utils::GetTestUrl(FilePath(kTestDir),
661 FilePath(kManySharedWorkersFile));
662 url = GURL(url.spec() + StringPrintf("?count=%d", max_workers_per_tab+1));
663
664 scoped_refptr<TabProxy> tab(GetActiveTab());
665 ASSERT_TRUE(tab.get());
666 ASSERT_TRUE(tab->NavigateToURL(url));
667 ASSERT_TRUE(WaitForProcessCountToBe(1, max_workers_per_tab));
668 // First window has hit its limit. Now launch second window which creates
669 // the same worker that was queued in the first window, to ensure it gets
670 // connected to the first window too.
671 scoped_refptr<BrowserProxy> window(automation()->GetBrowserWindow(0));
672 ASSERT_TRUE(window.get());
673 GURL url2 = ui_test_utils::GetTestUrl(FilePath(kTestDir),
674 FilePath(kSingleSharedWorkersFile));
675 url2 = GURL(url2.spec() + StringPrintf("?id=%d", max_workers_per_tab));
676 ASSERT_TRUE(window->AppendTab(url2));
677
678 std::string value = WaitUntilCookieNonEmpty(tab.get(), url,
679 kTestCompleteCookie, TestTimeouts::action_max_timeout_ms());
680 ASSERT_STREQ(kTestCompleteSuccess, value.c_str());
681 ASSERT_TRUE(WaitForProcessCountToBe(2, max_workers_per_tab+1));
682 }
683
684 class WorkerFileSystemTest : public WorkerTest {
685 protected:
686 void RunWorkerFileSystemLayoutTest(const std::string& test_case_file_name) {
687 FilePath worker_test_dir;
688 worker_test_dir = worker_test_dir.AppendASCII("fast");
689
690 FilePath filesystem_test_dir;
691 filesystem_test_dir = filesystem_test_dir.AppendASCII("filesystem");
692 filesystem_test_dir = filesystem_test_dir.AppendASCII("workers");
693 InitializeForLayoutTest(worker_test_dir, filesystem_test_dir, kNoHttpPort);
694
695 FilePath resource_dir;
696 resource_dir = resource_dir.AppendASCII("resources");
697 AddResourceForLayoutTest(worker_test_dir.AppendASCII("filesystem"),
698 resource_dir);
699
700 // FS tests also rely on common files in js/resources.
701 FilePath js_dir = worker_test_dir.AppendASCII("js");
702 FilePath js_resource_dir;
703 js_resource_dir = js_resource_dir.AppendASCII("resources");
704 AddResourceForLayoutTest(js_dir, js_resource_dir);
705
706 RunLayoutTest(test_case_file_name, kNoHttpPort);
707
708 // Navigate to a blank page so that any workers are cleaned up.
709 // This helps leaks trackers do a better job of reporting.
710 scoped_refptr<TabProxy> tab(GetActiveTab());
711 ASSERT_TRUE(tab.get());
712 GURL about_url(chrome::kAboutBlankURL);
713 EXPECT_EQ(AUTOMATION_MSG_NAVIGATION_SUCCESS, tab->NavigateToURL(about_url));
714 }
715 };
716
717 TEST_F(WorkerFileSystemTest, Temporary) {
718 RunWorkerFileSystemLayoutTest("simple-temporary.html");
719 }
720
721 TEST_F(WorkerFileSystemTest, Persistent) {
722 RunWorkerFileSystemLayoutTest("simple-persistent.html");
723 }
724
725 TEST_F(WorkerFileSystemTest, SyncTemporary) {
726 RunWorkerFileSystemLayoutTest("simple-temporary-sync.html");
727 }
728
729 TEST_F(WorkerFileSystemTest, SyncPersistent) {
730 RunWorkerFileSystemLayoutTest("simple-persistent-sync.html");
731 }
732
733 TEST_F(WorkerFileSystemTest, AsyncOperations) {
734 RunWorkerFileSystemLayoutTest("async-operations.html");
735 }
736
737 TEST_F(WorkerFileSystemTest, SyncOperations) {
738 RunWorkerFileSystemLayoutTest("sync-operations.html");
739 }
740
741 TEST_F(WorkerFileSystemTest, FileEntryToURISync) {
742 RunWorkerFileSystemLayoutTest("file-entry-to-uri-sync.html");
743 }
744
745 #if defined(OS_LINUX)
746 // These tests fail on Linux due to an assert in WebKit's RNG.
747 // See http://webkit.org/b/55728.
748 #define FileFromFileEntry DISABLED_FileFromFileEntry
749 #define FileFromFileEntrySync DISABLED_FileFromFileEntrySync
750 #define FileWriterTruncateExtend DISABLED_FileWriterTruncateExtend
751 #define FileWriterSyncTruncateExtend DISABLED_FileWriterSyncTruncateExtend
752 #define FileWriterSyncWriteOverlapped DISABLED_FileWriterSyncWriteOverlapped
753 #endif
754 TEST_F(WorkerFileSystemTest, FileFromFileEntry) {
755 RunWorkerFileSystemLayoutTest("file-from-file-entry.html");
756 }
757
758 TEST_F(WorkerFileSystemTest, FileFromFileEntrySync) {
759 RunWorkerFileSystemLayoutTest("file-from-file-entry-sync.html");
760 }
761
762 TEST_F(WorkerFileSystemTest, FileWriterTruncateExtend) {
763 RunWorkerFileSystemLayoutTest("file-writer-truncate-extend.html");
764 }
765
766 TEST_F(WorkerFileSystemTest, FileWriterSyncTruncateExtend) {
767 RunWorkerFileSystemLayoutTest("file-writer-sync-truncate-extend.html");
768 }
769
770 TEST_F(WorkerFileSystemTest, FileWriterSyncWriteOverlapped) {
771 RunWorkerFileSystemLayoutTest("file-writer-sync-write-overlapped.html");
772 }
OLDNEW
« no previous file with comments | « chrome/worker/worker_thread.cc ('k') | chrome/worker/worker_webapplicationcachehost_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698