OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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/string_util.h" | 6 #include "base/string_util.h" |
7 #include "base/test/test_timeouts.h" | 7 #include "base/test/test_timeouts.h" |
8 #include "base/threading/platform_thread.h" | 8 #include "base/threading/platform_thread.h" |
9 #include "chrome/app/chrome_command_ids.h" | 9 #include "chrome/app/chrome_command_ids.h" |
10 #include "chrome/test/automation/automation_proxy.h" | 10 #include "chrome/test/automation/automation_proxy.h" |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 kTestCompleteCookie, TestTimeouts::action_max_timeout_ms()); | 78 kTestCompleteCookie, TestTimeouts::action_max_timeout_ms()); |
79 | 79 |
80 // Close the incognito window | 80 // Close the incognito window |
81 ASSERT_TRUE(incognito->RunCommand(IDC_CLOSE_WINDOW)); | 81 ASSERT_TRUE(incognito->RunCommand(IDC_CLOSE_WINDOW)); |
82 ASSERT_TRUE(automation()->GetBrowserWindowCount(&window_count)); | 82 ASSERT_TRUE(automation()->GetBrowserWindowCount(&window_count)); |
83 ASSERT_EQ(1, window_count); | 83 ASSERT_EQ(1, window_count); |
84 | 84 |
85 ASSERT_STREQ(kTestCompleteSuccess, value.c_str()); | 85 ASSERT_STREQ(kTestCompleteSuccess, value.c_str()); |
86 } | 86 } |
87 | 87 |
88 bool WaitForProcessCountToBe(int tabs, int workers) { | 88 bool WaitForProcessCountToBeAtLeast(int tabs, int workers) { |
89 // The 1 is for the browser process. | 89 // The 1 is for the browser process. |
90 int number_of_processes = 1 + workers + tabs; | 90 int number_of_processes = 1 + workers + tabs; |
91 #if defined(OS_POSIX) && !defined(OS_MACOSX) | 91 #if defined(OS_POSIX) && !defined(OS_MACOSX) |
92 // On Unix, we also have a zygote process and a sandbox host process. | 92 // On Unix, we also have a zygote process and a sandbox host process. |
93 number_of_processes += 2; | 93 number_of_processes += 2; |
94 #endif | 94 #endif |
95 | 95 |
96 int cur_process_count; | 96 int cur_process_count; |
97 for (int i = 0; i < 100; ++i) { | 97 for (int i = 0; i < 100; ++i) { |
98 cur_process_count = 0; | 98 cur_process_count = 0; |
99 if (!GetBrowserProcessCount(&cur_process_count)) | 99 if (!GetBrowserProcessCount(&cur_process_count)) |
100 return false; | 100 return false; |
101 if (cur_process_count == number_of_processes) | 101 if (cur_process_count >= number_of_processes) |
102 return true; | 102 return true; |
103 | 103 |
104 // Sometimes the worker processes can take a while to shut down on the | 104 // Sometimes the worker processes can take a while to shut down on the |
105 // bots, so use a longer timeout period to avoid spurious failures. | 105 // bots, so use a longer timeout period to avoid spurious failures. |
106 base::PlatformThread::Sleep(TestTimeouts::action_max_timeout() / 100); | 106 base::PlatformThread::Sleep(TestTimeouts::action_max_timeout() / 100); |
107 } | 107 } |
108 | 108 |
109 EXPECT_EQ(number_of_processes, cur_process_count); | 109 EXPECT_GE(cur_process_count, number_of_processes); |
110 return false; | 110 return false; |
111 } | 111 } |
112 | 112 |
113 void RunWorkerFastLayoutTest(const std::string& test_case_file_name) { | 113 void RunWorkerFastLayoutTest(const std::string& test_case_file_name) { |
114 FilePath fast_test_dir; | 114 FilePath fast_test_dir; |
115 fast_test_dir = fast_test_dir.AppendASCII("fast"); | 115 fast_test_dir = fast_test_dir.AppendASCII("fast"); |
116 | 116 |
117 FilePath worker_test_dir; | 117 FilePath worker_test_dir; |
118 worker_test_dir = worker_test_dir.AppendASCII("workers"); | 118 worker_test_dir = worker_test_dir.AppendASCII("workers"); |
119 InitializeForLayoutTest(fast_test_dir, worker_test_dir, kNoHttpPort); | 119 InitializeForLayoutTest(fast_test_dir, worker_test_dir, kNoHttpPort); |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 #endif | 187 #endif |
188 TEST_F(WorkerTest, MultipleSharedWorkers) { | 188 TEST_F(WorkerTest, MultipleSharedWorkers) { |
189 RunTest(FilePath(FILE_PATH_LITERAL("multi_worker.html")), "shared=true"); | 189 RunTest(FilePath(FILE_PATH_LITERAL("multi_worker.html")), "shared=true"); |
190 } | 190 } |
191 | 191 |
192 #if defined(OS_LINUX) || defined(OS_CHROMEOS) | 192 #if defined(OS_LINUX) || defined(OS_CHROMEOS) |
193 // http://crbug.com/80446 | 193 // http://crbug.com/80446 |
194 #define DISABLED_TerminateQueuedWorkers DISABLED_TerminateQueuedWorkers | 194 #define DISABLED_TerminateQueuedWorkers DISABLED_TerminateQueuedWorkers |
195 #endif | 195 #endif |
196 TEST_F(WorkerTest, DISABLED_TerminateQueuedWorkers) { | 196 TEST_F(WorkerTest, DISABLED_TerminateQueuedWorkers) { |
197 ASSERT_TRUE(WaitForProcessCountToBe(1, 0)); | 197 ASSERT_TRUE(WaitForProcessCountToBeAtLeast(1, 0)); |
198 RunTest(FilePath(FILE_PATH_LITERAL("terminate_queued_workers.html")), ""); | 198 RunTest(FilePath(FILE_PATH_LITERAL("terminate_queued_workers.html")), ""); |
199 // Make sure all workers exit. | 199 // Make sure all workers exit. |
200 ASSERT_TRUE(WaitForProcessCountToBe(1, 0)); | 200 ASSERT_TRUE(WaitForProcessCountToBeAtLeast(1, 0)); |
201 } | 201 } |
202 | 202 |
203 #if defined(OS_LINUX) | 203 #if defined(OS_LINUX) |
204 // http://crbug.com/30021 | 204 // http://crbug.com/30021 |
205 #define IncognitoSharedWorkers DISABLED_IncognitoSharedWorkers | 205 #define IncognitoSharedWorkers DISABLED_IncognitoSharedWorkers |
206 #endif | 206 #endif |
207 // Incognito windows should not share workers with non-incognito windows | 207 // Incognito windows should not share workers with non-incognito windows |
208 TEST_F(WorkerTest, IncognitoSharedWorkers) { | 208 TEST_F(WorkerTest, IncognitoSharedWorkers) { |
209 // Load a non-incognito tab and have it create a shared worker | 209 // Load a non-incognito tab and have it create a shared worker |
210 RunTest(FilePath(FILE_PATH_LITERAL("incognito_worker.html")), ""); | 210 RunTest(FilePath(FILE_PATH_LITERAL("incognito_worker.html")), ""); |
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
479 RunLayoutTest(kLayoutTestFiles[i], kNoHttpPort); | 479 RunLayoutTest(kLayoutTestFiles[i], kNoHttpPort); |
480 } | 480 } |
481 | 481 |
482 TEST_F(WorkerTest, LimitPerPage) { | 482 TEST_F(WorkerTest, LimitPerPage) { |
483 int max_workers_per_tab = WorkerServiceImpl::kMaxWorkersPerTabWhenSeparate; | 483 int max_workers_per_tab = WorkerServiceImpl::kMaxWorkersPerTabWhenSeparate; |
484 GURL url = ui_test_utils::GetTestUrl(FilePath(kTestDir), | 484 GURL url = ui_test_utils::GetTestUrl(FilePath(kTestDir), |
485 FilePath(kManySharedWorkersFile)); | 485 FilePath(kManySharedWorkersFile)); |
486 url = GURL(url.spec() + StringPrintf("?count=%d", max_workers_per_tab + 1)); | 486 url = GURL(url.spec() + StringPrintf("?count=%d", max_workers_per_tab + 1)); |
487 | 487 |
488 NavigateToURL(url); | 488 NavigateToURL(url); |
489 ASSERT_TRUE(WaitForProcessCountToBe(1, max_workers_per_tab)); | 489 ASSERT_TRUE(WaitForProcessCountToBeAtLeast(1, max_workers_per_tab)); |
490 } | 490 } |
491 | 491 |
492 // http://crbug.com/36800 | 492 // http://crbug.com/36800 |
493 #if defined(OS_WIN) | 493 #if defined(OS_WIN) |
494 #define MAYBE_LimitTotal DISABLED_LimitTotal | 494 #define MAYBE_LimitTotal DISABLED_LimitTotal |
495 #else | 495 #else |
496 #define MAYBE_LimitTotal LimitTotal | 496 #define MAYBE_LimitTotal LimitTotal |
497 #endif // defined(OS_WIN) | 497 #endif // defined(OS_WIN) |
498 TEST_F(WorkerTest, MAYBE_LimitTotal) { | 498 TEST_F(WorkerTest, MAYBE_LimitTotal) { |
499 int max_workers_per_tab = WorkerServiceImpl::kMaxWorkersPerTabWhenSeparate; | 499 int max_workers_per_tab = WorkerServiceImpl::kMaxWorkersPerTabWhenSeparate; |
(...skipping 10 matching lines...) Expand all Loading... |
510 ASSERT_TRUE(tab->NavigateToURL( | 510 ASSERT_TRUE(tab->NavigateToURL( |
511 GURL(url.spec() + StringPrintf("&client_id=%d", 0)))); | 511 GURL(url.spec() + StringPrintf("&client_id=%d", 0)))); |
512 scoped_refptr<BrowserProxy> window(automation()->GetBrowserWindow(0)); | 512 scoped_refptr<BrowserProxy> window(automation()->GetBrowserWindow(0)); |
513 ASSERT_TRUE(window.get()); | 513 ASSERT_TRUE(window.get()); |
514 for (int i = 1; i < tab_count; ++i) { | 514 for (int i = 1; i < tab_count; ++i) { |
515 ASSERT_TRUE(window->AppendTab(GURL( | 515 ASSERT_TRUE(window->AppendTab(GURL( |
516 url.spec() + StringPrintf("&client_id=%d", i)))); | 516 url.spec() + StringPrintf("&client_id=%d", i)))); |
517 } | 517 } |
518 | 518 |
519 // Check that we didn't create more than the max number of workers. | 519 // Check that we didn't create more than the max number of workers. |
520 ASSERT_TRUE(WaitForProcessCountToBe(tab_count, total_workers)); | 520 ASSERT_TRUE(WaitForProcessCountToBeAtLeast(tab_count, total_workers)); |
521 | 521 |
522 // Now close a page and check that the queued workers were started. | 522 // Now close a page and check that the queued workers were started. |
523 const FilePath::CharType* kGoogleDir = FILE_PATH_LITERAL("google"); | 523 const FilePath::CharType* kGoogleDir = FILE_PATH_LITERAL("google"); |
524 const FilePath::CharType* kGoogleFile = FILE_PATH_LITERAL("google.html"); | 524 const FilePath::CharType* kGoogleFile = FILE_PATH_LITERAL("google.html"); |
525 ASSERT_EQ(AUTOMATION_MSG_NAVIGATION_SUCCESS, | 525 ASSERT_EQ(AUTOMATION_MSG_NAVIGATION_SUCCESS, |
526 tab->NavigateToURL(ui_test_utils::GetTestUrl(FilePath(kGoogleDir), | 526 tab->NavigateToURL(ui_test_utils::GetTestUrl(FilePath(kGoogleDir), |
527 FilePath(kGoogleFile)))); | 527 FilePath(kGoogleFile)))); |
528 | 528 |
529 ASSERT_TRUE(WaitForProcessCountToBe(tab_count, total_workers)); | 529 ASSERT_TRUE(WaitForProcessCountToBeAtLeast(tab_count, total_workers)); |
530 } | 530 } |
531 | 531 |
532 // Flaky, http://crbug.com/59786. | 532 // Flaky, http://crbug.com/59786. |
533 TEST_F(WorkerTest, DISABLED_WorkerClose) { | 533 TEST_F(WorkerTest, DISABLED_WorkerClose) { |
534 scoped_refptr<TabProxy> tab(GetActiveTab()); | 534 scoped_refptr<TabProxy> tab(GetActiveTab()); |
535 ASSERT_TRUE(tab.get()); | 535 ASSERT_TRUE(tab.get()); |
536 GURL url = ui_test_utils::GetTestUrl(FilePath(kTestDir), | 536 GURL url = ui_test_utils::GetTestUrl(FilePath(kTestDir), |
537 FilePath(kWorkerClose)); | 537 FilePath(kWorkerClose)); |
538 ASSERT_TRUE(tab->NavigateToURL(url)); | 538 ASSERT_TRUE(tab->NavigateToURL(url)); |
539 std::string value = WaitUntilCookieNonEmpty(tab.get(), url, | 539 std::string value = WaitUntilCookieNonEmpty(tab.get(), url, |
540 kTestCompleteCookie, TestTimeouts::action_max_timeout_ms()); | 540 kTestCompleteCookie, TestTimeouts::action_max_timeout_ms()); |
541 ASSERT_STREQ(kTestCompleteSuccess, value.c_str()); | 541 ASSERT_STREQ(kTestCompleteSuccess, value.c_str()); |
542 ASSERT_TRUE(WaitForProcessCountToBe(1, 0)); | 542 ASSERT_TRUE(WaitForProcessCountToBeAtLeast(1, 0)); |
543 } | 543 } |
544 | 544 |
545 // Flaky, http://crbug.com/70861. | 545 // Flaky, http://crbug.com/70861. |
546 TEST_F(WorkerTest, DISABLED_QueuedSharedWorkerShutdown) { | 546 TEST_F(WorkerTest, DISABLED_QueuedSharedWorkerShutdown) { |
547 // Tests to make sure that queued shared workers are started up when | 547 // Tests to make sure that queued shared workers are started up when |
548 // shared workers shut down. | 548 // shared workers shut down. |
549 int max_workers_per_tab = WorkerServiceImpl::kMaxWorkersPerTabWhenSeparate; | 549 int max_workers_per_tab = WorkerServiceImpl::kMaxWorkersPerTabWhenSeparate; |
550 GURL url = ui_test_utils::GetTestUrl(FilePath(kTestDir), | 550 GURL url = ui_test_utils::GetTestUrl(FilePath(kTestDir), |
551 FilePath(kQuerySharedWorkerShutdownFile)); | 551 FilePath(kQuerySharedWorkerShutdownFile)); |
552 url = GURL(url.spec() + StringPrintf("?count=%d", max_workers_per_tab)); | 552 url = GURL(url.spec() + StringPrintf("?count=%d", max_workers_per_tab)); |
553 | 553 |
554 scoped_refptr<TabProxy> tab(GetActiveTab()); | 554 scoped_refptr<TabProxy> tab(GetActiveTab()); |
555 ASSERT_TRUE(tab.get()); | 555 ASSERT_TRUE(tab.get()); |
556 ASSERT_TRUE(tab->NavigateToURL(url)); | 556 ASSERT_TRUE(tab->NavigateToURL(url)); |
557 std::string value = WaitUntilCookieNonEmpty(tab.get(), url, | 557 std::string value = WaitUntilCookieNonEmpty(tab.get(), url, |
558 kTestCompleteCookie, TestTimeouts::action_max_timeout_ms()); | 558 kTestCompleteCookie, TestTimeouts::action_max_timeout_ms()); |
559 ASSERT_STREQ(kTestCompleteSuccess, value.c_str()); | 559 ASSERT_STREQ(kTestCompleteSuccess, value.c_str()); |
560 ASSERT_TRUE(WaitForProcessCountToBe(1, max_workers_per_tab)); | 560 ASSERT_TRUE(WaitForProcessCountToBeAtLeast(1, max_workers_per_tab)); |
561 } | 561 } |
562 | 562 |
563 // Flaky, http://crbug.com/69881. | 563 // Flaky, http://crbug.com/69881. |
564 TEST_F(WorkerTest, DISABLED_MultipleTabsQueuedSharedWorker) { | 564 TEST_F(WorkerTest, DISABLED_MultipleTabsQueuedSharedWorker) { |
565 // Tests to make sure that only one instance of queued shared workers are | 565 // Tests to make sure that only one instance of queued shared workers are |
566 // started up even when those instances are on multiple tabs. | 566 // started up even when those instances are on multiple tabs. |
567 int max_workers_per_tab = WorkerServiceImpl::kMaxWorkersPerTabWhenSeparate; | 567 int max_workers_per_tab = WorkerServiceImpl::kMaxWorkersPerTabWhenSeparate; |
568 GURL url = ui_test_utils::GetTestUrl(FilePath(kTestDir), | 568 GURL url = ui_test_utils::GetTestUrl(FilePath(kTestDir), |
569 FilePath(kManySharedWorkersFile)); | 569 FilePath(kManySharedWorkersFile)); |
570 url = GURL(url.spec() + StringPrintf("?count=%d", max_workers_per_tab+1)); | 570 url = GURL(url.spec() + StringPrintf("?count=%d", max_workers_per_tab+1)); |
571 | 571 |
572 scoped_refptr<TabProxy> tab(GetActiveTab()); | 572 scoped_refptr<TabProxy> tab(GetActiveTab()); |
573 ASSERT_TRUE(tab.get()); | 573 ASSERT_TRUE(tab.get()); |
574 ASSERT_TRUE(tab->NavigateToURL(url)); | 574 ASSERT_TRUE(tab->NavigateToURL(url)); |
575 ASSERT_TRUE(WaitForProcessCountToBe(1, max_workers_per_tab)); | 575 ASSERT_TRUE(WaitForProcessCountToBeAtLeast(1, max_workers_per_tab)); |
576 | 576 |
577 // Create same set of workers in new tab (leaves one worker queued from this | 577 // Create same set of workers in new tab (leaves one worker queued from this |
578 // tab). | 578 // tab). |
579 scoped_refptr<BrowserProxy> window(automation()->GetBrowserWindow(0)); | 579 scoped_refptr<BrowserProxy> window(automation()->GetBrowserWindow(0)); |
580 ASSERT_TRUE(window.get()); | 580 ASSERT_TRUE(window.get()); |
581 ASSERT_TRUE(window->AppendTab(url)); | 581 ASSERT_TRUE(window->AppendTab(url)); |
582 ASSERT_TRUE(WaitForProcessCountToBe(2, max_workers_per_tab)); | 582 ASSERT_TRUE(WaitForProcessCountToBeAtLeast(2, max_workers_per_tab)); |
583 | 583 |
584 // Now shutdown one of the shared workers - this will fire both queued | 584 // Now shutdown one of the shared workers - this will fire both queued |
585 // workers, but only one instance should be started | 585 // workers, but only one instance should be started |
586 GURL url2 = ui_test_utils::GetTestUrl(FilePath(kTestDir), | 586 GURL url2 = ui_test_utils::GetTestUrl(FilePath(kTestDir), |
587 FilePath(kShutdownSharedWorkerFile)); | 587 FilePath(kShutdownSharedWorkerFile)); |
588 url2 = GURL(url2.spec() + "?id=0"); | 588 url2 = GURL(url2.spec() + "?id=0"); |
589 ASSERT_TRUE(window->AppendTab(url2)); | 589 ASSERT_TRUE(window->AppendTab(url2)); |
590 | 590 |
591 std::string value = WaitUntilCookieNonEmpty(tab.get(), url, | 591 std::string value = WaitUntilCookieNonEmpty(tab.get(), url, |
592 kTestCompleteCookie, TestTimeouts::action_max_timeout_ms()); | 592 kTestCompleteCookie, TestTimeouts::action_max_timeout_ms()); |
593 ASSERT_STREQ(kTestCompleteSuccess, value.c_str()); | 593 ASSERT_STREQ(kTestCompleteSuccess, value.c_str()); |
594 ASSERT_TRUE(WaitForProcessCountToBe(3, max_workers_per_tab)); | 594 ASSERT_TRUE(WaitForProcessCountToBeAtLeast(3, max_workers_per_tab)); |
595 } | 595 } |
596 | 596 |
597 // Flaky: http://crbug.com/48148 | 597 // Flaky: http://crbug.com/48148 |
598 TEST_F(WorkerTest, DISABLED_QueuedSharedWorkerStartedFromOtherTab) { | 598 TEST_F(WorkerTest, DISABLED_QueuedSharedWorkerStartedFromOtherTab) { |
599 // Tests to make sure that queued shared workers are started up when | 599 // Tests to make sure that queued shared workers are started up when |
600 // an instance is launched from another tab. | 600 // an instance is launched from another tab. |
601 int max_workers_per_tab = WorkerServiceImpl::kMaxWorkersPerTabWhenSeparate; | 601 int max_workers_per_tab = WorkerServiceImpl::kMaxWorkersPerTabWhenSeparate; |
602 GURL url = ui_test_utils::GetTestUrl(FilePath(kTestDir), | 602 GURL url = ui_test_utils::GetTestUrl(FilePath(kTestDir), |
603 FilePath(kManySharedWorkersFile)); | 603 FilePath(kManySharedWorkersFile)); |
604 url = GURL(url.spec() + StringPrintf("?count=%d", max_workers_per_tab+1)); | 604 url = GURL(url.spec() + StringPrintf("?count=%d", max_workers_per_tab+1)); |
605 | 605 |
606 scoped_refptr<TabProxy> tab(GetActiveTab()); | 606 scoped_refptr<TabProxy> tab(GetActiveTab()); |
607 ASSERT_TRUE(tab.get()); | 607 ASSERT_TRUE(tab.get()); |
608 ASSERT_TRUE(tab->NavigateToURL(url)); | 608 ASSERT_TRUE(tab->NavigateToURL(url)); |
609 ASSERT_TRUE(WaitForProcessCountToBe(1, max_workers_per_tab)); | 609 ASSERT_TRUE(WaitForProcessCountToBeAtLeast(1, max_workers_per_tab)); |
610 // First window has hit its limit. Now launch second window which creates | 610 // First window has hit its limit. Now launch second window which creates |
611 // the same worker that was queued in the first window, to ensure it gets | 611 // the same worker that was queued in the first window, to ensure it gets |
612 // connected to the first window too. | 612 // connected to the first window too. |
613 scoped_refptr<BrowserProxy> window(automation()->GetBrowserWindow(0)); | 613 scoped_refptr<BrowserProxy> window(automation()->GetBrowserWindow(0)); |
614 ASSERT_TRUE(window.get()); | 614 ASSERT_TRUE(window.get()); |
615 GURL url2 = ui_test_utils::GetTestUrl(FilePath(kTestDir), | 615 GURL url2 = ui_test_utils::GetTestUrl(FilePath(kTestDir), |
616 FilePath(kSingleSharedWorkersFile)); | 616 FilePath(kSingleSharedWorkersFile)); |
617 url2 = GURL(url2.spec() + StringPrintf("?id=%d", max_workers_per_tab)); | 617 url2 = GURL(url2.spec() + StringPrintf("?id=%d", max_workers_per_tab)); |
618 ASSERT_TRUE(window->AppendTab(url2)); | 618 ASSERT_TRUE(window->AppendTab(url2)); |
619 | 619 |
620 std::string value = WaitUntilCookieNonEmpty(tab.get(), url, | 620 std::string value = WaitUntilCookieNonEmpty(tab.get(), url, |
621 kTestCompleteCookie, TestTimeouts::action_max_timeout_ms()); | 621 kTestCompleteCookie, TestTimeouts::action_max_timeout_ms()); |
622 ASSERT_STREQ(kTestCompleteSuccess, value.c_str()); | 622 ASSERT_STREQ(kTestCompleteSuccess, value.c_str()); |
623 ASSERT_TRUE(WaitForProcessCountToBe(2, max_workers_per_tab+1)); | 623 ASSERT_TRUE(WaitForProcessCountToBeAtLeast(2, max_workers_per_tab+1)); |
624 } | 624 } |
OLD | NEW |