OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/string_util.h" | 5 #include "base/string_util.h" |
6 #include "chrome/app/chrome_dll_resource.h" | 6 #include "chrome/app/chrome_dll_resource.h" |
7 #include "chrome/browser/worker_host/worker_service.h" | 7 #include "chrome/browser/worker_host/worker_service.h" |
8 #include "chrome/common/chrome_switches.h" | 8 #include "chrome/common/chrome_switches.h" |
9 #include "chrome/test/automation/browser_proxy.h" | 9 #include "chrome/test/automation/browser_proxy.h" |
10 #include "chrome/test/automation/tab_proxy.h" | 10 #include "chrome/test/automation/tab_proxy.h" |
11 #include "chrome/test/ui/ui_layout_test.h" | 11 #include "chrome/test/ui/ui_layout_test.h" |
12 | 12 |
13 static const char kTestCompleteCookie[] = "status"; | 13 static const char kTestCompleteCookie[] = "status"; |
14 static const char kTestCompleteSuccess[] = "OK"; | 14 static const char kTestCompleteSuccess[] = "OK"; |
15 | 15 |
| 16 // Layout test files for WorkerFastLayoutTest for the WorkerFastLayoutTest |
| 17 // shards. |
| 18 static const char* kWorkerFastLayoutTestFiles[] = { |
| 19 "stress-js-execution.html", |
| 20 "use-machine-stack.html", |
| 21 "worker-call.html", |
| 22 #if defined(OS_WIN) |
| 23 // This test occasionally fails on valgrind (http://crbug.com/30212). |
| 24 "worker-cloneport.html", |
| 25 #endif |
| 26 "worker-close.html", |
| 27 "worker-constructor.html", |
| 28 "worker-context-gc.html", |
| 29 "worker-context-multi-port.html", |
| 30 "worker-event-listener.html", |
| 31 "worker-gc.html", |
| 32 // worker-lifecycle.html relies on layoutTestController.workerThreadCount |
| 33 // which is not currently implemented. |
| 34 // "worker-lifecycle.html", |
| 35 "worker-location.html", |
| 36 "worker-messageport.html", |
| 37 // Disabled after r27089 (WebKit merge), http://crbug.com/22947 |
| 38 // "worker-messageport-gc.html", |
| 39 "worker-multi-port.html", |
| 40 "worker-navigator.html", |
| 41 "worker-replace-global-constructor.html", |
| 42 "worker-replace-self.html", |
| 43 "worker-script-error.html", |
| 44 "worker-terminate.html", |
| 45 "worker-timeout.html" |
| 46 }; |
| 47 static const int kWorkerFastLayoutTestShards = 3; |
| 48 |
16 class WorkerTest : public UILayoutTest { | 49 class WorkerTest : public UILayoutTest { |
17 protected: | 50 protected: |
18 virtual ~WorkerTest() { } | 51 virtual ~WorkerTest() { } |
19 | 52 |
20 void RunTest(const std::wstring& test_case) { | 53 void RunTest(const std::wstring& test_case) { |
21 scoped_refptr<TabProxy> tab(GetActiveTab()); | 54 scoped_refptr<TabProxy> tab(GetActiveTab()); |
22 ASSERT_TRUE(tab.get()); | 55 ASSERT_TRUE(tab.get()); |
23 | 56 |
24 GURL url = GetTestUrl(L"workers", test_case); | 57 GURL url = GetTestUrl(L"workers", test_case); |
25 ASSERT_TRUE(tab->NavigateToURL(url)); | 58 ASSERT_TRUE(tab->NavigateToURL(url)); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 cur_process_count = GetBrowserProcessCount(); | 100 cur_process_count = GetBrowserProcessCount(); |
68 if (cur_process_count == number_of_processes) | 101 if (cur_process_count == number_of_processes) |
69 return true; | 102 return true; |
70 | 103 |
71 PlatformThread::Sleep(sleep_timeout_ms() / 10); | 104 PlatformThread::Sleep(sleep_timeout_ms() / 10); |
72 } | 105 } |
73 | 106 |
74 EXPECT_EQ(number_of_processes, cur_process_count); | 107 EXPECT_EQ(number_of_processes, cur_process_count); |
75 return false; | 108 return false; |
76 } | 109 } |
| 110 |
| 111 void RunWorkerFastLayoutTests(size_t shard) { |
| 112 FilePath fast_test_dir; |
| 113 fast_test_dir = fast_test_dir.AppendASCII("LayoutTests"); |
| 114 fast_test_dir = fast_test_dir.AppendASCII("fast"); |
| 115 |
| 116 FilePath worker_test_dir; |
| 117 worker_test_dir = worker_test_dir.AppendASCII("workers"); |
| 118 InitializeForLayoutTest(fast_test_dir, worker_test_dir, false); |
| 119 |
| 120 // Worker tests also rely on common files in js/resources. |
| 121 FilePath js_dir = fast_test_dir.AppendASCII("js"); |
| 122 FilePath resource_dir; |
| 123 resource_dir = resource_dir.AppendASCII("resources"); |
| 124 AddResourceForLayoutTest(js_dir, resource_dir); |
| 125 |
| 126 for (size_t i = 0; i < arraysize(kWorkerFastLayoutTestFiles); ++i) { |
| 127 if ((i % kWorkerFastLayoutTestShards) == shard) { |
| 128 printf ("Test: %s\n", kWorkerFastLayoutTestFiles[i]); |
| 129 RunLayoutTest(kWorkerFastLayoutTestFiles[i], false); |
| 130 } |
| 131 } |
| 132 |
| 133 // Navigate away from to a blank page so that any workers are cleaned up. |
| 134 // This helps leaks trackers do a better job of reporting. |
| 135 scoped_refptr<TabProxy> tab(GetActiveTab()); |
| 136 GURL about_url(std::string("file://localhost/")); |
| 137 EXPECT_EQ(AUTOMATION_MSG_NAVIGATION_SUCCESS, tab->NavigateToURL(about_url)); |
| 138 } |
77 }; | 139 }; |
78 | 140 |
79 | 141 |
80 TEST_F(WorkerTest, SingleWorker) { | 142 TEST_F(WorkerTest, SingleWorker) { |
81 RunTest(L"single_worker.html"); | 143 RunTest(L"single_worker.html"); |
82 } | 144 } |
83 | 145 |
84 #if defined(OS_LINUX) | 146 #if defined(OS_LINUX) |
85 // MultipleWorkers times out (process hangs, does not exit) occasionally. | 147 // MultipleWorkers times out (process hangs, does not exit) occasionally. |
86 // http://crbug.com/30353 | 148 // http://crbug.com/30353 |
(...skipping 19 matching lines...) Expand all Loading... |
106 // Incognito windows should not share workers with non-incognito windows | 168 // Incognito windows should not share workers with non-incognito windows |
107 TEST_F(WorkerTest, IncognitoSharedWorkers) { | 169 TEST_F(WorkerTest, IncognitoSharedWorkers) { |
108 // Load a non-incognito tab and have it create a shared worker | 170 // Load a non-incognito tab and have it create a shared worker |
109 RunTest(L"incognito_worker.html"); | 171 RunTest(L"incognito_worker.html"); |
110 // Incognito worker should not share with non-incognito | 172 // Incognito worker should not share with non-incognito |
111 RunIncognitoTest(L"incognito_worker.html"); | 173 RunIncognitoTest(L"incognito_worker.html"); |
112 } | 174 } |
113 | 175 |
114 #if defined(OS_LINUX) | 176 #if defined(OS_LINUX) |
115 // Crashes on Linux - http://crbug.com/22898 | 177 // Crashes on Linux - http://crbug.com/22898 |
116 #define WorkerFastLayoutTests DISABLED_WorkerFastLayoutTests | 178 #define WorkerFastLayoutTests0 DISABLED_WorkerFastLayoutTests0 |
117 #elif defined (OS_MACOSX) | 179 #define WorkerFastLayoutTests1 DISABLED_WorkerFastLayoutTests1 |
118 #define WorkerFastLayoutTests FLAKY_WorkerFastLayoutTests | 180 #define WorkerFastLayoutTests2 DISABLED_WorkerFastLayoutTests2 |
119 #endif | 181 #endif |
120 | 182 |
121 TEST_F(WorkerTest, WorkerFastLayoutTests) { | 183 TEST_F(WorkerTest, WorkerFastLayoutTests0) { |
122 static const char* kLayoutTestFiles[] = { | 184 SCOPED_TRACE(""); |
123 "stress-js-execution.html", | 185 RunWorkerFastLayoutTests(0); |
124 "use-machine-stack.html", | 186 } |
125 "worker-call.html", | |
126 #if defined(OS_WIN) | |
127 // This test occasionally fails on valgrind (http://crbug.com/30212). | |
128 "worker-cloneport.html", | |
129 #endif | |
130 "worker-close.html", | |
131 "worker-constructor.html", | |
132 "worker-context-gc.html", | |
133 "worker-context-multi-port.html", | |
134 "worker-event-listener.html", | |
135 "worker-gc.html", | |
136 // worker-lifecycle.html relies on layoutTestController.workerThreadCount | |
137 // which is not currently implemented. | |
138 // "worker-lifecycle.html", | |
139 "worker-location.html", | |
140 "worker-messageport.html", | |
141 // Disabled after r27089 (WebKit merge), http://crbug.com/22947 | |
142 // "worker-messageport-gc.html", | |
143 "worker-multi-port.html", | |
144 "worker-navigator.html", | |
145 "worker-replace-global-constructor.html", | |
146 "worker-replace-self.html", | |
147 "worker-script-error.html", | |
148 "worker-terminate.html", | |
149 "worker-timeout.html" | |
150 }; | |
151 | 187 |
152 FilePath fast_test_dir; | 188 TEST_F(WorkerTest, WorkerFastLayoutTests1) { |
153 fast_test_dir = fast_test_dir.AppendASCII("LayoutTests"); | 189 SCOPED_TRACE(""); |
154 fast_test_dir = fast_test_dir.AppendASCII("fast"); | 190 RunWorkerFastLayoutTests(1); |
| 191 } |
155 | 192 |
156 FilePath worker_test_dir; | 193 TEST_F(WorkerTest, WorkerFastLayoutTests2) { |
157 worker_test_dir = worker_test_dir.AppendASCII("workers"); | 194 SCOPED_TRACE(""); |
158 InitializeForLayoutTest(fast_test_dir, worker_test_dir, false); | 195 RunWorkerFastLayoutTests(2); |
159 | |
160 // Worker tests also rely on common files in js/resources. | |
161 FilePath js_dir = fast_test_dir.AppendASCII("js"); | |
162 FilePath resource_dir; | |
163 resource_dir = resource_dir.AppendASCII("resources"); | |
164 AddResourceForLayoutTest(js_dir, resource_dir); | |
165 | |
166 for (size_t i = 0; i < arraysize(kLayoutTestFiles); ++i) | |
167 RunLayoutTest(kLayoutTestFiles[i], false); | |
168 | |
169 // Navigate away from to a blank page so that any workers are cleaned up. This | |
170 // helps leaks trackers do a better job of reporting. | |
171 scoped_refptr<TabProxy> tab(GetActiveTab()); | |
172 GURL about_url(std::string("file://localhost/")); | |
173 ASSERT_EQ(AUTOMATION_MSG_NAVIGATION_SUCCESS, tab->NavigateToURL(about_url)); | |
174 } | 196 } |
175 | 197 |
176 #if defined(OS_WIN) || defined(OS_MACOSX) | 198 #if defined(OS_WIN) || defined(OS_MACOSX) |
177 // http://crbug.com/27636 - incorrect URL_MISMATCH exceptions sometimes get | 199 // http://crbug.com/27636 - incorrect URL_MISMATCH exceptions sometimes get |
178 // generated on the windows try bots. | 200 // generated on the windows try bots. |
179 // http://crbug.com/28445 - flakiness on mac | 201 // http://crbug.com/28445 - flakiness on mac |
180 #define SharedWorkerFastLayoutTests FLAKY_SharedWorkerFastLayoutTests | 202 #define SharedWorkerFastLayoutTests FLAKY_SharedWorkerFastLayoutTests |
181 #endif | 203 #endif |
182 | 204 |
183 TEST_F(WorkerTest, SharedWorkerFastLayoutTests) { | 205 TEST_F(WorkerTest, SharedWorkerFastLayoutTests) { |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
370 | 392 |
371 // Check that we didn't create more than the max number of workers. | 393 // Check that we didn't create more than the max number of workers. |
372 ASSERT_TRUE(WaitForProcessCountToBe(tab_count, total_workers)); | 394 ASSERT_TRUE(WaitForProcessCountToBe(tab_count, total_workers)); |
373 | 395 |
374 // Now close a page and check that the queued workers were started. | 396 // Now close a page and check that the queued workers were started. |
375 tab->NavigateToURL(GetTestUrl(L"google", L"google.html")); | 397 tab->NavigateToURL(GetTestUrl(L"google", L"google.html")); |
376 | 398 |
377 ASSERT_TRUE(WaitForProcessCountToBe(tab_count, total_workers)); | 399 ASSERT_TRUE(WaitForProcessCountToBe(tab_count, total_workers)); |
378 #endif | 400 #endif |
379 } | 401 } |
OLD | NEW |