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/file_path.h" | 5 #include "base/file_path.h" |
6 #include "base/file_util.h" | 6 #include "base/file_util.h" |
7 #include "base/path_service.h" | 7 #include "base/path_service.h" |
8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
9 #include "chrome/browser/worker_host/worker_service.h" | 9 #include "chrome/browser/worker_host/worker_service.h" |
10 #include "chrome/common/chrome_paths.h" | 10 #include "chrome/common/chrome_paths.h" |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 : UITest(), initialized_for_layout_test_(false), test_count_(0) { | 62 : UITest(), initialized_for_layout_test_(false), test_count_(0) { |
63 } | 63 } |
64 | 64 |
65 WorkerTest::~WorkerTest() { | 65 WorkerTest::~WorkerTest() { |
66 if (!temp_test_dir_.empty()) | 66 if (!temp_test_dir_.empty()) |
67 file_util::Delete(temp_test_dir_, true); | 67 file_util::Delete(temp_test_dir_, true); |
68 } | 68 } |
69 | 69 |
70 void WorkerTest::RunTest(const std::wstring& test_case) { | 70 void WorkerTest::RunTest(const std::wstring& test_case) { |
71 scoped_refptr<TabProxy> tab(GetActiveTab()); | 71 scoped_refptr<TabProxy> tab(GetActiveTab()); |
| 72 ASSERT_TRUE(tab.get()); |
72 | 73 |
73 GURL url = GetTestUrl(L"workers", test_case); | 74 GURL url = GetTestUrl(L"workers", test_case); |
74 ASSERT_TRUE(tab->NavigateToURL(url)); | 75 ASSERT_TRUE(tab->NavigateToURL(url)); |
75 | 76 |
76 std::string value = WaitUntilCookieNonEmpty(tab.get(), url, | 77 std::string value = WaitUntilCookieNonEmpty(tab.get(), url, |
77 kTestCompleteCookie, kTestIntervalMs, kTestWaitTimeoutMs); | 78 kTestCompleteCookie, kTestIntervalMs, kTestWaitTimeoutMs); |
78 ASSERT_STREQ(kTestCompleteSuccess, value.c_str()); | 79 ASSERT_STREQ(kTestCompleteSuccess, value.c_str()); |
79 } | 80 } |
80 | 81 |
81 void WorkerTest::InitializeForLayoutTest(const FilePath& test_parent_dir, | 82 void WorkerTest::InitializeForLayoutTest(const FilePath& test_parent_dir, |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
199 new_test_url.reset(new GURL( | 200 new_test_url.reset(new GURL( |
200 std::string("http://localhost:8080/") + | 201 std::string("http://localhost:8080/") + |
201 UTF16ToUTF8(test_case_dir_.ToWStringHack()) + | 202 UTF16ToUTF8(test_case_dir_.ToWStringHack()) + |
202 "/" + | 203 "/" + |
203 test_case_file_name)); | 204 test_case_file_name)); |
204 else | 205 else |
205 new_test_url.reset(new GURL(net::FilePathToFileURL(new_test_file_path))); | 206 new_test_url.reset(new GURL(net::FilePathToFileURL(new_test_file_path))); |
206 | 207 |
207 // Runs the new layout test. | 208 // Runs the new layout test. |
208 scoped_refptr<TabProxy> tab(GetActiveTab()); | 209 scoped_refptr<TabProxy> tab(GetActiveTab()); |
| 210 ASSERT_TRUE(tab.get()); |
209 ASSERT_TRUE(tab->NavigateToURL(*new_test_url.get())); | 211 ASSERT_TRUE(tab->NavigateToURL(*new_test_url.get())); |
210 std::string escaped_value = | 212 std::string escaped_value = |
211 WaitUntilCookieNonEmpty(tab.get(), *new_test_url.get(), | 213 WaitUntilCookieNonEmpty(tab.get(), *new_test_url.get(), |
212 status_cookie.c_str(), kTestIntervalMs, kTestWaitTimeoutMs); | 214 status_cookie.c_str(), kTestIntervalMs, kTestWaitTimeoutMs); |
213 | 215 |
214 // Unescapes and normalizes the actual result. | 216 // Unescapes and normalizes the actual result. |
215 std::string value = UnescapeURLComponent(escaped_value, | 217 std::string value = UnescapeURLComponent(escaped_value, |
216 UnescapeRule::NORMAL | UnescapeRule::SPACES | | 218 UnescapeRule::NORMAL | UnescapeRule::SPACES | |
217 UnescapeRule::URL_SPECIAL_CHARS | UnescapeRule::CONTROL_CHARS); | 219 UnescapeRule::URL_SPECIAL_CHARS | UnescapeRule::CONTROL_CHARS); |
218 value += "\n"; | 220 value += "\n"; |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
332 RunLayoutTest(kLayoutTestFiles[i], true); | 334 RunLayoutTest(kLayoutTestFiles[i], true); |
333 StopHttpServer(); | 335 StopHttpServer(); |
334 } | 336 } |
335 | 337 |
336 TEST_F(WorkerTest, LimitPerPage) { | 338 TEST_F(WorkerTest, LimitPerPage) { |
337 int max_workers_per_tab = WorkerService::kMaxWorkersPerTabWhenSeparate; | 339 int max_workers_per_tab = WorkerService::kMaxWorkersPerTabWhenSeparate; |
338 GURL url = GetTestUrl(L"workers", L"many_workers.html"); | 340 GURL url = GetTestUrl(L"workers", L"many_workers.html"); |
339 url = GURL(url.spec() + StringPrintf("?count=%d", max_workers_per_tab + 1)); | 341 url = GURL(url.spec() + StringPrintf("?count=%d", max_workers_per_tab + 1)); |
340 | 342 |
341 scoped_refptr<TabProxy> tab(GetActiveTab()); | 343 scoped_refptr<TabProxy> tab(GetActiveTab()); |
| 344 ASSERT_TRUE(tab.get()); |
342 ASSERT_TRUE(tab->NavigateToURL(url)); | 345 ASSERT_TRUE(tab->NavigateToURL(url)); |
343 | 346 |
344 EXPECT_EQ(max_workers_per_tab + 1 + (UITest::in_process_renderer() ? 0 : 1), | 347 EXPECT_EQ(max_workers_per_tab + 1 + (UITest::in_process_renderer() ? 0 : 1), |
345 UITest::GetBrowserProcessCount()); | 348 UITest::GetBrowserProcessCount()); |
346 } | 349 } |
347 | 350 |
348 TEST_F(WorkerTest, LimitTotal) { | 351 TEST_F(WorkerTest, LimitTotal) { |
349 int max_workers_per_tab = WorkerService::kMaxWorkersPerTabWhenSeparate; | 352 int max_workers_per_tab = WorkerService::kMaxWorkersPerTabWhenSeparate; |
350 int total_workers = WorkerService::kMaxWorkersWhenSeparate; | 353 int total_workers = WorkerService::kMaxWorkersWhenSeparate; |
351 | 354 |
352 int tab_count = (total_workers / max_workers_per_tab) + 1; | 355 int tab_count = (total_workers / max_workers_per_tab) + 1; |
353 GURL url = GetTestUrl(L"workers", L"many_workers.html"); | 356 GURL url = GetTestUrl(L"workers", L"many_workers.html"); |
354 url = GURL(url.spec() + StringPrintf("?count=%d", max_workers_per_tab)); | 357 url = GURL(url.spec() + StringPrintf("?count=%d", max_workers_per_tab)); |
355 | 358 |
356 scoped_refptr<TabProxy> tab(GetActiveTab()); | 359 scoped_refptr<TabProxy> tab(GetActiveTab()); |
| 360 ASSERT_TRUE(tab.get()); |
357 ASSERT_TRUE(tab->NavigateToURL(url)); | 361 ASSERT_TRUE(tab->NavigateToURL(url)); |
358 scoped_refptr<BrowserProxy> window(automation()->GetBrowserWindow(0)); | 362 scoped_refptr<BrowserProxy> window(automation()->GetBrowserWindow(0)); |
359 for (int i = 1; i < tab_count; ++i) | 363 for (int i = 1; i < tab_count; ++i) |
360 window->AppendTab(url); | 364 window->AppendTab(url); |
361 | 365 |
362 // Check that we didn't create more than the max number of workers. | 366 // Check that we didn't create more than the max number of workers. |
363 EXPECT_EQ(total_workers + 1 + (UITest::in_process_renderer() ? 0 : tab_count), | 367 EXPECT_EQ(total_workers + 1 + (UITest::in_process_renderer() ? 0 : tab_count), |
364 UITest::GetBrowserProcessCount()); | 368 UITest::GetBrowserProcessCount()); |
365 | 369 |
366 // Now close the first tab and check that the queued workers were started. | 370 // Now close the first tab and check that the queued workers were started. |
367 tab->Close(true); | 371 tab->Close(true); |
368 tab->NavigateToURL(GetTestUrl(L"google", L"google.html")); | 372 tab->NavigateToURL(GetTestUrl(L"google", L"google.html")); |
369 | 373 |
370 EXPECT_EQ(total_workers + 1 + (UITest::in_process_renderer() ? 0 : tab_count), | 374 EXPECT_EQ(total_workers + 1 + (UITest::in_process_renderer() ? 0 : tab_count), |
371 UITest::GetBrowserProcessCount()); | 375 UITest::GetBrowserProcessCount()); |
372 } | 376 } |
OLD | NEW |