Chromium Code Reviews| 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/browser/worker_host/worker_service.h" | 7 #include "chrome/browser/worker_host/worker_service.h" |
| 7 #include "chrome/common/chrome_switches.h" | 8 #include "chrome/common/chrome_switches.h" |
| 8 #include "chrome/test/automation/browser_proxy.h" | 9 #include "chrome/test/automation/browser_proxy.h" |
| 9 #include "chrome/test/automation/tab_proxy.h" | 10 #include "chrome/test/automation/tab_proxy.h" |
| 10 #include "chrome/test/ui/ui_layout_test.h" | 11 #include "chrome/test/ui/ui_layout_test.h" |
| 11 | 12 |
| 12 static const char kTestCompleteCookie[] = "status"; | 13 static const char kTestCompleteCookie[] = "status"; |
| 13 static const char kTestCompleteSuccess[] = "OK"; | 14 static const char kTestCompleteSuccess[] = "OK"; |
| 14 | 15 |
| 15 class WorkerTest : public UILayoutTest { | 16 class WorkerTest : public UILayoutTest { |
| 16 protected: | 17 protected: |
| 17 virtual ~WorkerTest() { } | 18 virtual ~WorkerTest() { } |
| 18 | 19 |
| 19 void RunTest(const std::wstring& test_case) { | 20 void RunTest(const std::wstring& test_case) { |
| 20 scoped_refptr<TabProxy> tab(GetActiveTab()); | 21 scoped_refptr<TabProxy> tab(GetActiveTab()); |
| 21 ASSERT_TRUE(tab.get()); | 22 ASSERT_TRUE(tab.get()); |
| 22 | 23 |
| 23 GURL url = GetTestUrl(L"workers", test_case); | 24 GURL url = GetTestUrl(L"workers", test_case); |
| 24 ASSERT_TRUE(tab->NavigateToURL(url)); | 25 ASSERT_TRUE(tab->NavigateToURL(url)); |
| 25 | 26 |
| 26 std::string value = WaitUntilCookieNonEmpty(tab.get(), url, | 27 std::string value = WaitUntilCookieNonEmpty(tab.get(), url, |
| 27 kTestCompleteCookie, kTestIntervalMs, kTestWaitTimeoutMs); | 28 kTestCompleteCookie, kTestIntervalMs, kTestWaitTimeoutMs); |
| 28 ASSERT_STREQ(kTestCompleteSuccess, value.c_str()); | 29 ASSERT_STREQ(kTestCompleteSuccess, value.c_str()); |
| 29 } | 30 } |
| 30 | 31 |
| 32 void RunIncognitoTest(const std::wstring& test_case) { | |
| 33 scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); | |
| 34 // Open an Incognito window. | |
| 35 int window_count; | |
| 36 ASSERT_TRUE(browser->RunCommand(IDC_NEW_INCOGNITO_WINDOW)); | |
| 37 scoped_refptr<BrowserProxy> incognito(automation()->GetBrowserWindow(1)); | |
| 38 scoped_refptr<TabProxy> tab(incognito->GetTab(0)); | |
| 39 ASSERT_TRUE(automation()->GetBrowserWindowCount(&window_count)); | |
| 40 ASSERT_EQ(2, window_count); | |
| 41 | |
| 42 GURL url = GetTestUrl(L"workers", test_case); | |
| 43 ASSERT_TRUE(tab->NavigateToURL(url)); | |
| 44 | |
| 45 std::string value = WaitUntilCookieNonEmpty(tab.get(), url, | |
| 46 kTestCompleteCookie, kTestIntervalMs, kTestWaitTimeoutMs); | |
| 47 | |
| 48 // Close the incognito window | |
| 49 ASSERT_TRUE(incognito->RunCommand(IDC_CLOSE_WINDOW)); | |
| 50 ASSERT_TRUE(automation()->GetBrowserWindowCount(&window_count)); | |
| 51 ASSERT_EQ(1, window_count); | |
| 52 | |
| 53 ASSERT_STREQ(kTestCompleteSuccess, value.c_str()); | |
| 54 } | |
| 55 | |
| 31 bool WaitForProcessCountToBe(int tabs, int workers) { | 56 bool WaitForProcessCountToBe(int tabs, int workers) { |
| 32 // The 1 is for the browser process. | 57 // The 1 is for the browser process. |
| 33 int number_of_processes = 1 + workers + | 58 int number_of_processes = 1 + workers + |
| 34 (UITest::in_process_renderer() ? 0 : tabs); | 59 (UITest::in_process_renderer() ? 0 : tabs); |
| 35 #if defined(OS_LINUX) | 60 #if defined(OS_LINUX) |
| 36 // On Linux, we also have a zygote process and a sandbox host process. | 61 // On Linux, we also have a zygote process and a sandbox host process. |
| 37 number_of_processes += 2; | 62 number_of_processes += 2; |
| 38 #endif | 63 #endif |
| 39 | 64 |
| 40 int cur_process_count; | 65 int cur_process_count; |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 58 #endif | 83 #endif |
| 59 | 84 |
| 60 TEST_F(WorkerTest, SingleWorker) { | 85 TEST_F(WorkerTest, SingleWorker) { |
| 61 RunTest(L"single_worker.html"); | 86 RunTest(L"single_worker.html"); |
| 62 } | 87 } |
| 63 | 88 |
| 64 TEST_F(WorkerTest, MultipleWorkers) { | 89 TEST_F(WorkerTest, MultipleWorkers) { |
| 65 RunTest(L"multi_worker.html"); | 90 RunTest(L"multi_worker.html"); |
| 66 } | 91 } |
| 67 | 92 |
| 93 // Incognito windows should not share workers with non-incognito windows | |
| 94 // http://crbug.com/27883 | |
|
jam
2009/11/25 23:30:46
nit: no need to mention the bug number, as it'll b
| |
| 95 TEST_F(WorkerTest, IncognitoSharedWorkers) { | |
| 96 // Load a non-incognito tab and have it create a shared worker | |
| 97 RunTest(L"incognito_worker.html"); | |
| 98 // Incognito worker should not share with non-incognito | |
| 99 RunIncognitoTest(L"incognito_worker.html"); | |
| 100 } | |
| 101 | |
| 68 #if defined(OS_LINUX) || defined (OS_MACOSX) | 102 #if defined(OS_LINUX) || defined (OS_MACOSX) |
| 69 #define WorkerFastLayoutTests DISABLED_WorkerFastLayoutTests | 103 #define WorkerFastLayoutTests DISABLED_WorkerFastLayoutTests |
| 70 #endif | 104 #endif |
| 71 | 105 |
| 72 TEST_F(WorkerTest, WorkerFastLayoutTests) { | 106 TEST_F(WorkerTest, WorkerFastLayoutTests) { |
| 73 static const char* kLayoutTestFiles[] = { | 107 static const char* kLayoutTestFiles[] = { |
| 74 "stress-js-execution.html", | 108 "stress-js-execution.html", |
| 75 "use-machine-stack.html", | 109 "use-machine-stack.html", |
| 76 "worker-call.html", | 110 "worker-call.html", |
| 77 "worker-cloneport.html", | 111 "worker-cloneport.html", |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 151 FilePath worker_test_dir; | 185 FilePath worker_test_dir; |
| 152 worker_test_dir = worker_test_dir.AppendASCII("workers"); | 186 worker_test_dir = worker_test_dir.AppendASCII("workers"); |
| 153 InitializeForLayoutTest(fast_test_dir, worker_test_dir, false); | 187 InitializeForLayoutTest(fast_test_dir, worker_test_dir, false); |
| 154 | 188 |
| 155 // Worker tests also rely on common files in js/resources. | 189 // Worker tests also rely on common files in js/resources. |
| 156 FilePath js_dir = fast_test_dir.AppendASCII("js"); | 190 FilePath js_dir = fast_test_dir.AppendASCII("js"); |
| 157 FilePath resource_dir; | 191 FilePath resource_dir; |
| 158 resource_dir = resource_dir.AppendASCII("resources"); | 192 resource_dir = resource_dir.AppendASCII("resources"); |
| 159 AddResourceForLayoutTest(js_dir, resource_dir); | 193 AddResourceForLayoutTest(js_dir, resource_dir); |
| 160 | 194 |
| 161 for (size_t i = 0; i < arraysize(kLayoutTestFiles); ++i) | 195 for (size_t i = 0; i < arraysize(kLayoutTestFiles); ++i) { |
| 162 RunLayoutTest(kLayoutTestFiles[i], false); | 196 RunLayoutTest(kLayoutTestFiles[i], false); |
| 197 // Shared workers will error out if we ever have more than one tab open. | |
| 198 int window_count = 0; | |
| 199 ASSERT_TRUE(automation()->GetBrowserWindowCount(&window_count)); | |
| 200 ASSERT_EQ(1, window_count); | |
| 201 EXPECT_EQ(1, GetTabCount()); | |
| 202 } | |
| 163 } | 203 } |
| 164 | 204 |
| 165 TEST_F(WorkerTest, WorkerHttpLayoutTests) { | 205 TEST_F(WorkerTest, WorkerHttpLayoutTests) { |
| 166 static const char* kLayoutTestFiles[] = { | 206 static const char* kLayoutTestFiles[] = { |
| 167 "shared-worker-importScripts.html", | 207 "shared-worker-importScripts.html", |
| 168 "shared-worker-redirect.html", | 208 "shared-worker-redirect.html", |
| 169 // flakey? BUG 16934 "text-encoding.html", | 209 // flakey? BUG 16934 "text-encoding.html", |
| 170 #if defined(OS_WIN) | 210 #if defined(OS_WIN) |
| 171 // Fails on the mac (and linux?): | 211 // Fails on the mac (and linux?): |
| 172 // http://code.google.com/p/chromium/issues/detail?id=22599 | 212 // http://code.google.com/p/chromium/issues/detail?id=22599 |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 308 window->AppendTab(url); | 348 window->AppendTab(url); |
| 309 | 349 |
| 310 // Check that we didn't create more than the max number of workers. | 350 // Check that we didn't create more than the max number of workers. |
| 311 ASSERT_TRUE(WaitForProcessCountToBe(tab_count, total_workers)); | 351 ASSERT_TRUE(WaitForProcessCountToBe(tab_count, total_workers)); |
| 312 | 352 |
| 313 // Now close a page and check that the queued workers were started. | 353 // Now close a page and check that the queued workers were started. |
| 314 tab->NavigateToURL(GetTestUrl(L"google", L"google.html")); | 354 tab->NavigateToURL(GetTestUrl(L"google", L"google.html")); |
| 315 | 355 |
| 316 ASSERT_TRUE(WaitForProcessCountToBe(tab_count, total_workers)); | 356 ASSERT_TRUE(WaitForProcessCountToBe(tab_count, total_workers)); |
| 317 } | 357 } |
| OLD | NEW |