| 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 #include "net/url_request/url_request_unittest.h" |
| 12 | 13 |
| 13 static const char kTestCompleteCookie[] = "status"; | 14 static const char kTestCompleteCookie[] = "status"; |
| 14 static const char kTestCompleteSuccess[] = "OK"; | 15 static const char kTestCompleteSuccess[] = "OK"; |
| 15 | 16 |
| 16 // Layout test files for WorkerFastLayoutTest for the WorkerFastLayoutTest | 17 // Layout test files for WorkerFastLayoutTest for the WorkerFastLayoutTest |
| 17 // shards. | 18 // shards. |
| 18 static const char* kWorkerFastLayoutTestFiles[] = { | 19 static const char* kWorkerFastLayoutTestFiles[] = { |
| 19 "stress-js-execution.html", | 20 "stress-js-execution.html", |
| 20 "use-machine-stack.html", | 21 "use-machine-stack.html", |
| 21 "worker-call.html", | 22 "worker-call.html", |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 RunLayoutTest(kWorkerFastLayoutTestFiles[i], kNoHttpPort); | 130 RunLayoutTest(kWorkerFastLayoutTestFiles[i], kNoHttpPort); |
| 130 } | 131 } |
| 131 } | 132 } |
| 132 | 133 |
| 133 // Navigate away from to a blank page so that any workers are cleaned up. | 134 // 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 // This helps leaks trackers do a better job of reporting. |
| 135 scoped_refptr<TabProxy> tab(GetActiveTab()); | 136 scoped_refptr<TabProxy> tab(GetActiveTab()); |
| 136 GURL about_url(std::string("file://localhost/")); | 137 GURL about_url(std::string("file://localhost/")); |
| 137 EXPECT_EQ(AUTOMATION_MSG_NAVIGATION_SUCCESS, tab->NavigateToURL(about_url)); | 138 EXPECT_EQ(AUTOMATION_MSG_NAVIGATION_SUCCESS, tab->NavigateToURL(about_url)); |
| 138 } | 139 } |
| 140 |
| 141 bool NavigateAndWaitForAuth(TabProxy* tab, const GURL& url) { |
| 142 // Pass a large number of navigations to tell the tab to block until an auth |
| 143 // dialog pops up. |
| 144 bool timeout = false; |
| 145 tab->NavigateToURLWithTimeout(url, 100, kTestWaitTimeoutMs, &timeout); |
| 146 EXPECT_FALSE(timeout); |
| 147 return tab->NeedsAuth(); |
| 148 } |
| 139 }; | 149 }; |
| 140 | 150 |
| 141 | 151 |
| 142 TEST_F(WorkerTest, SingleWorker) { | 152 TEST_F(WorkerTest, SingleWorker) { |
| 143 RunTest(L"single_worker.html"); | 153 RunTest(L"single_worker.html"); |
| 144 } | 154 } |
| 145 | 155 |
| 146 #if defined(OS_LINUX) | 156 #if defined(OS_LINUX) |
| 147 // MultipleWorkers times out (process hangs, does not exit) occasionally. | 157 // MultipleWorkers times out (process hangs, does not exit) occasionally. |
| 148 // http://crbug.com/30353 | 158 // http://crbug.com/30353 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 166 #endif | 176 #endif |
| 167 | 177 |
| 168 // Incognito windows should not share workers with non-incognito windows | 178 // Incognito windows should not share workers with non-incognito windows |
| 169 TEST_F(WorkerTest, IncognitoSharedWorkers) { | 179 TEST_F(WorkerTest, IncognitoSharedWorkers) { |
| 170 // Load a non-incognito tab and have it create a shared worker | 180 // Load a non-incognito tab and have it create a shared worker |
| 171 RunTest(L"incognito_worker.html"); | 181 RunTest(L"incognito_worker.html"); |
| 172 // Incognito worker should not share with non-incognito | 182 // Incognito worker should not share with non-incognito |
| 173 RunIncognitoTest(L"incognito_worker.html"); | 183 RunIncognitoTest(L"incognito_worker.html"); |
| 174 } | 184 } |
| 175 | 185 |
| 186 const wchar_t kDocRoot[] = L"chrome/test/data/workers"; |
| 187 |
| 188 // Make sure that auth dialog is displayed from worker context. |
| 189 TEST_F(WorkerTest, WorkerHttpAuth) { |
| 190 scoped_refptr<HTTPTestServer> server = |
| 191 HTTPTestServer::CreateServer(kDocRoot, NULL); |
| 192 |
| 193 ASSERT_TRUE(NULL != server.get()); |
| 194 scoped_refptr<TabProxy> tab(GetActiveTab()); |
| 195 GURL url = server->TestServerPage("files/worker_auth.html"); |
| 196 EXPECT_TRUE(NavigateAndWaitForAuth(tab, url)); |
| 197 } |
| 198 |
| 199 // Make sure that auth dialog is displayed from shared worker context. |
| 200 TEST_F(WorkerTest, SharedWorkerHttpAuth) { |
| 201 scoped_refptr<HTTPTestServer> server = |
| 202 HTTPTestServer::CreateServer(kDocRoot, NULL); |
| 203 ASSERT_TRUE(NULL != server.get()); |
| 204 scoped_refptr<TabProxy> tab(GetActiveTab()); |
| 205 EXPECT_EQ(1, GetTabCount()); |
| 206 GURL url = server->TestServerPage("files/shared_worker_auth.html"); |
| 207 EXPECT_TRUE(NavigateAndWaitForAuth(tab, url)); |
| 208 // TODO(atwilson): Add support to automation framework to test for auth |
| 209 // dialogs displayed by non-navigating tabs. |
| 210 } |
| 211 |
| 176 #if defined(OS_LINUX) | 212 #if defined(OS_LINUX) |
| 177 // Crashes on Linux - http://crbug.com/22898 | 213 // Crashes on Linux - http://crbug.com/22898 |
| 178 #define WorkerFastLayoutTests0 DISABLED_WorkerFastLayoutTests0 | 214 #define WorkerFastLayoutTests0 DISABLED_WorkerFastLayoutTests0 |
| 179 #define WorkerFastLayoutTests1 DISABLED_WorkerFastLayoutTests1 | 215 #define WorkerFastLayoutTests1 DISABLED_WorkerFastLayoutTests1 |
| 180 #define WorkerFastLayoutTests2 DISABLED_WorkerFastLayoutTests2 | 216 #define WorkerFastLayoutTests2 DISABLED_WorkerFastLayoutTests2 |
| 181 #elif defined(OS_MACOSX) | 217 #elif defined(OS_MACOSX) |
| 182 // Flaky on Mac - http://crbug.com/28445 | 218 // Flaky on Mac - http://crbug.com/28445 |
| 183 #define WorkerFastLayoutTests0 FLAKY_WorkerFastLayoutTests0 | 219 #define WorkerFastLayoutTests0 FLAKY_WorkerFastLayoutTests0 |
| 184 #endif | 220 #endif |
| 185 | 221 |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 417 | 453 |
| 418 // Check that we didn't create more than the max number of workers. | 454 // Check that we didn't create more than the max number of workers. |
| 419 ASSERT_TRUE(WaitForProcessCountToBe(tab_count, total_workers)); | 455 ASSERT_TRUE(WaitForProcessCountToBe(tab_count, total_workers)); |
| 420 | 456 |
| 421 // Now close a page and check that the queued workers were started. | 457 // Now close a page and check that the queued workers were started. |
| 422 tab->NavigateToURL(GetTestUrl(L"google", L"google.html")); | 458 tab->NavigateToURL(GetTestUrl(L"google", L"google.html")); |
| 423 | 459 |
| 424 ASSERT_TRUE(WaitForProcessCountToBe(tab_count, total_workers)); | 460 ASSERT_TRUE(WaitForProcessCountToBe(tab_count, total_workers)); |
| 425 #endif | 461 #endif |
| 426 } | 462 } |
| OLD | NEW |