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

Side by Side Diff: content/browser/worker_host/test/worker_browsertest.cc

Issue 9802025: Rewrite HTML5 workers ui_tests to browser_tests. Compared to ui_tests, browser_tests are faster, le… (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: add directory create call needed on linux Created 8 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
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(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/bind.h"
6 #include "base/file_path.h"
7 #include "base/path_service.h"
8 #include "base/stringprintf.h"
9 #include "base/string_util.h"
10 #include "base/test/test_timeouts.h"
11 #include "base/utf_string_conversions.h"
12 #include "chrome/browser/ui/browser.h"
13 #include "chrome/test/base/ui_test_utils.h"
14 #include "content/browser/worker_host/worker_process_host.h"
15 #include "content/browser/worker_host/worker_service_impl.h"
16 #include "content/public/browser/browser_thread.h"
17 #include "content/public/common/content_paths.h"
18 #include "content/test/layout_browsertest.h"
19 #include "googleurl/src/gurl.h"
20
21 using content::BrowserThread;
22 using content::WorkerServiceImpl;
23
24 class WorkerLayoutTest : public InProcessBrowserLayoutTest {
25 public:
26 WorkerLayoutTest() : InProcessBrowserLayoutTest(
27 FilePath(), FilePath().AppendASCII("fast").AppendASCII("workers")) {
28 }
29 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE {
30 InProcessBrowserLayoutTest::SetUpInProcessBrowserTestFixture();
31 AddResourceForLayoutTest(
32 FilePath().AppendASCII("fast").AppendASCII("js"),
33 FilePath().AppendASCII("resources"));
34 }
35 };
36
37 // Crashy, http://crbug.com/35965.
38 // Flaky, http://crbug.com/36555.
39 IN_PROC_BROWSER_TEST_F(WorkerLayoutTest, SLOW_WorkerClonePort) {
40 RunLayoutTest("worker-cloneport.html");
41 }
42
43 // http://crbug.com/101996 (started flaking with WebKit roll 98537:98582).
Andrew T Wilson (Slow) 2012/03/28 22:44:09 Are these tests no longer flaky now that we're usi
jam 2012/03/28 23:01:27 I haven't seen any flakiness in running these test
44 IN_PROC_BROWSER_TEST_F(WorkerLayoutTest, WorkerContextMultiPort) {
45 RunLayoutTest("worker-context-multi-port.html");
46 }
47
48 IN_PROC_BROWSER_TEST_F(WorkerLayoutTest, WorkerMessagePort) {
49 RunLayoutTest("worker-messageport.html");
50 }
51
52 IN_PROC_BROWSER_TEST_F(WorkerLayoutTest, WorkerMessagePortGC) {
53 RunLayoutTest("worker-messageport-gc.html");
54 }
55
56 // http://crbug.com/101996 (started flaking with WebKit roll 98537:98582).
57 IN_PROC_BROWSER_TEST_F(WorkerLayoutTest, WorkerMultiPort) {
58 RunLayoutTest("worker-multi-port.html");
59 }
60
61 //
62 // SharedWorkerFastLayoutTests
63 //
64 IN_PROC_BROWSER_TEST_F(WorkerLayoutTest, SharedWorkerFastConstructor) {
65 RunLayoutTest("shared-worker-constructor.html");
66 }
67
68 IN_PROC_BROWSER_TEST_F(WorkerLayoutTest, SharedWorkerFastContextGC) {
69 RunLayoutTest("shared-worker-context-gc.html");
70 }
71
72 IN_PROC_BROWSER_TEST_F(WorkerLayoutTest, SharedWorkerFastEventListener) {
73 RunLayoutTest("shared-worker-event-listener.html");
74 }
75
76 IN_PROC_BROWSER_TEST_F(WorkerLayoutTest, SharedWorkerFastException) {
77 RunLayoutTest("shared-worker-exception.html");
78 }
79
80 IN_PROC_BROWSER_TEST_F(WorkerLayoutTest, SharedWorkerFastGC) {
81 RunLayoutTest("shared-worker-gc.html");
82 }
83
84 IN_PROC_BROWSER_TEST_F(WorkerLayoutTest, SharedWorkerFastInIframe) {
85 RunLayoutTest("shared-worker-in-iframe.html");
86 }
87
88 IN_PROC_BROWSER_TEST_F(WorkerLayoutTest, SharedWorkerFastLoadError) {
89 RunLayoutTest("shared-worker-load-error.html");
90 }
91
92 IN_PROC_BROWSER_TEST_F(WorkerLayoutTest, SharedWorkerFastLocation) {
93 RunLayoutTest("shared-worker-location.html");
94 }
95
96 IN_PROC_BROWSER_TEST_F(WorkerLayoutTest, SharedWorkerFastName) {
97 RunLayoutTest("shared-worker-name.html");
98 }
99
100 IN_PROC_BROWSER_TEST_F(WorkerLayoutTest, SharedWorkerFastNavigator) {
101 RunLayoutTest("shared-worker-navigator.html");
102 }
103
104 IN_PROC_BROWSER_TEST_F(WorkerLayoutTest,
105 SharedWorkerFastReplaceGlobalConstructor) {
106 RunLayoutTest("shared-worker-replace-global-constructor.html");
107 }
108
109 IN_PROC_BROWSER_TEST_F(WorkerLayoutTest, SharedWorkerFastReplaceSelf) {
110 RunLayoutTest("shared-worker-replace-self.html");
111 }
112
113 IN_PROC_BROWSER_TEST_F(WorkerLayoutTest, SharedWorkerFastScriptError) {
114 RunLayoutTest("shared-worker-script-error.html");
115 }
116
117 IN_PROC_BROWSER_TEST_F(WorkerLayoutTest, SharedWorkerFastShared) {
118 RunLayoutTest("shared-worker-shared.html");
119 }
120
121 IN_PROC_BROWSER_TEST_F(WorkerLayoutTest, SharedWorkerFastSimple) {
122 RunLayoutTest("shared-worker-simple.html");
123 }
124
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) {
140 static const char* kLayoutTestFiles[] = {
141 "message-channel-gc.html",
142 "message-channel-gc-2.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",
185 #if defined(OS_WIN)
186 // Fails on the mac (and linux?):
187 // http://code.google.com/p/chromium/issues/detail?id=22599
188 "worker-importScripts.html",
189 #endif
190 "worker-redirect.html",
191 };
192
193 for (size_t i = 0; i < arraysize(kLayoutTestFiles); ++i)
194 RunHttpLayoutTest(kLayoutTestFiles[i]);
195 }
196
197 class WorkerXHRHttpLayoutTest : public InProcessBrowserLayoutTest {
198 public:
199 WorkerXHRHttpLayoutTest() : InProcessBrowserLayoutTest(
200 FilePath().AppendASCII("http").AppendASCII("tests"),
201 FilePath().AppendASCII("xmlhttprequest").AppendASCII("workers"),
202 -1) {
203 }
204 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE {
205 InProcessBrowserLayoutTest::SetUpInProcessBrowserTestFixture();
206 AddResourceForLayoutTest(
207 FilePath().AppendASCII("http").AppendASCII("tests"),
208 FilePath().AppendASCII("workers").AppendASCII("resources"));
209 }
210 };
211
212 IN_PROC_BROWSER_TEST_F(WorkerXHRHttpLayoutTest, Tests) {
213 static const char* kLayoutTestFiles[] = {
214 "abort-exception-assert.html",
215 #if defined(OS_WIN)
216 // Fails on the mac (and linux?):
217 // http://code.google.com/p/chromium/issues/detail?id=22599
218 "close.html",
219 #endif
220 // These tests (and the shared-worker versions below) are disabled due to
221 // limitations in lighttpd (doesn't handle all of the HTTP methods).
222 // "methods-async.html",
223 // "methods.html",
224
225 "shared-worker-close.html",
226 // Disabled due to limitations in lighttpd (does not handle methods other
227 // than GET/PUT/POST).
228 // "shared-worker-methods-async.html",
229 // "shared-worker-methods.html",
230 "shared-worker-xhr-file-not-found.html",
231
232 "xmlhttprequest-file-not-found.html"
233 };
234
235 for (size_t i = 0; i < arraysize(kLayoutTestFiles); ++i)
236 RunHttpLayoutTest(kLayoutTestFiles[i]);
237 }
238
239 class WorkerWebSocketHttpLayoutTest : public InProcessBrowserLayoutTest {
240 public:
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) {
251 static const char* kLayoutTestFiles[] = {
252 "close-in-onmessage-crash.html",
253 "close-in-shared-worker.html",
254 "close-in-worker.html",
255 "shared-worker-simple.html",
256 "worker-handshake-challenge-randomness.html",
257 "worker-simple.html"
258 };
259
260 FilePath websocket_test_dir;
261 ASSERT_TRUE(PathService::Get(content::DIR_LAYOUT_TESTS, &websocket_test_dir));
262
263 ui_test_utils::TestWebSocketServer websocket_server;
264 ASSERT_TRUE(websocket_server.Start(websocket_test_dir));
265
266 for (size_t i = 0; i < arraysize(kLayoutTestFiles); ++i)
267 RunHttpLayoutTest(kLayoutTestFiles[i]);
268 }
269
270 class WorkerTest : public InProcessBrowserTest {
271 public:
272 WorkerTest() {}
273
274 GURL GetTestURL(const std::string& test_case, const std::string& query) {
275 FilePath test_file_path = ui_test_utils::GetTestFilePath(
276 FilePath(FILE_PATH_LITERAL("workers")),
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));
386 }
387
388 // http://crbug.com/36800
389 IN_PROC_BROWSER_TEST_F(WorkerTest, LimitTotal) {
390 int max_workers_per_tab = WorkerServiceImpl::kMaxWorkersPerTabWhenSeparate;
391 int total_workers = WorkerServiceImpl::kMaxWorkersWhenSeparate;
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
398 // Adding 1 so that we cause some workers to be queued.
399 int tab_count = (total_workers / max_workers_per_tab) + 1;
400 for (int i = 1; i < tab_count; ++i) {
401 ui_test_utils::NavigateToURLWithDisposition(
402 browser(), GURL(url.spec() + StringPrintf("&client_id=%d", i)),
403 NEW_FOREGROUND_TAB,
404 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
405 }
406
407 // Check that we didn't create more than the max number of workers.
408 ASSERT_TRUE(WaitForWorkerProcessCount(total_workers));
409
410 // Now close a page and check that the queued workers were started.
411 const FilePath kGoogleDir(FILE_PATH_LITERAL("google"));
412 const FilePath kGoogleFile(FILE_PATH_LITERAL("google.html"));
413 url = GURL(ui_test_utils::GetTestUrl(kGoogleDir, kGoogleFile));
414 ui_test_utils::NavigateToURL(browser(), url);
415
416 ASSERT_TRUE(WaitForWorkerProcessCount(total_workers));
417 }
418
419 // Flaky, http://crbug.com/59786.
420 IN_PROC_BROWSER_TEST_F(WorkerTest, WorkerClose) {
421 RunTest("worker_close.html", "");
422 ASSERT_TRUE(WaitForWorkerProcessCount(0));
423 }
424
425 // Flaky, http://crbug.com/70861.
426 IN_PROC_BROWSER_TEST_F(WorkerTest, QueuedSharedWorkerShutdown) {
427 // Tests to make sure that queued shared workers are started up when shared
428 // workers shut down.
429 int max_workers_per_tab = WorkerServiceImpl::kMaxWorkersPerTabWhenSeparate;
430 std::string query = StringPrintf("?count=%d", max_workers_per_tab);
431 RunTest("queued_shared_worker_shutdown.html", query);
432 ASSERT_TRUE(WaitForWorkerProcessCount(max_workers_per_tab));
433 }
434
435 // Flaky, http://crbug.com/69881.
436 IN_PROC_BROWSER_TEST_F(WorkerTest, MultipleTabsQueuedSharedWorker) {
437 // Tests to make sure that only one instance of queued shared workers are
438 // started up even when those instances are on multiple tabs.
439 int max_workers_per_tab = WorkerServiceImpl::kMaxWorkersPerTabWhenSeparate;
440 std::string query = StringPrintf("?count=%d", max_workers_per_tab + 1);
441 GURL url = GetTestURL("many_shared_workers.html", query);
442 ui_test_utils::NavigateToURL(browser(), url);
443 ASSERT_TRUE(WaitForWorkerProcessCount(max_workers_per_tab));
444
445 // Create same set of workers in new tab (leaves one worker queued from this
446 // tab).
447 url = GetTestURL("many_shared_workers.html", query);
448 ui_test_utils::NavigateToURLWithDisposition(
449 browser(), url, NEW_FOREGROUND_TAB,
450 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
451 ASSERT_TRUE(WaitForWorkerProcessCount(max_workers_per_tab));
452
453 // Now shutdown one of the shared workers - this will fire both queued
454 // workers, but only one instance should be started.
455 url = GetTestURL("shutdown_shared_worker.html", "?id=0");
456 ui_test_utils::NavigateToURLWithDisposition(
457 browser(), url, NEW_FOREGROUND_TAB,
458 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB);
459 ASSERT_TRUE(WaitForWorkerProcessCount(max_workers_per_tab));
460 }
461
462 // Flaky: http://crbug.com/48148
463 IN_PROC_BROWSER_TEST_F(WorkerTest, QueuedSharedWorkerStartedFromOtherTab) {
464 // Tests to make sure that queued shared workers are started up when
465 // an instance is launched from another tab.
466 int max_workers_per_tab = WorkerServiceImpl::kMaxWorkersPerTabWhenSeparate;
467 std::string query = StringPrintf("?count=%d", max_workers_per_tab + 1);
468 GURL url = GetTestURL("many_shared_workers.html", query);
469 ui_test_utils::NavigateToURL(browser(), url);
470 ASSERT_TRUE(WaitForWorkerProcessCount(max_workers_per_tab));
471
472 // First window has hit its limit. Now launch second window which creates
473 // the same worker that was queued in the first window, to ensure it gets
474 // connected to the first window too.
475 query = StringPrintf("?id=%d", max_workers_per_tab);
476 url = GetTestURL("single_shared_worker.html", query);
477 ui_test_utils::NavigateToURLWithDisposition(
478 browser(), url, NEW_FOREGROUND_TAB,
479 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB);
480
481 ASSERT_TRUE(WaitForWorkerProcessCount(max_workers_per_tab + 1));
482 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698