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" |
(...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
462 | 462 |
463 // Check that we didn't create more than the max number of workers. | 463 // Check that we didn't create more than the max number of workers. |
464 ASSERT_TRUE(WaitForProcessCountToBe(tab_count, total_workers)); | 464 ASSERT_TRUE(WaitForProcessCountToBe(tab_count, total_workers)); |
465 | 465 |
466 // Now close a page and check that the queued workers were started. | 466 // Now close a page and check that the queued workers were started. |
467 tab->NavigateToURL(GetTestUrl(L"google", L"google.html")); | 467 tab->NavigateToURL(GetTestUrl(L"google", L"google.html")); |
468 | 468 |
469 ASSERT_TRUE(WaitForProcessCountToBe(tab_count, total_workers)); | 469 ASSERT_TRUE(WaitForProcessCountToBe(tab_count, total_workers)); |
470 #endif | 470 #endif |
471 } | 471 } |
| 472 |
| 473 TEST_F(WorkerTest, WorkerClose) { |
| 474 scoped_refptr<TabProxy> tab(GetActiveTab()); |
| 475 ASSERT_TRUE(tab.get()); |
| 476 GURL url = GetTestUrl(L"workers", L"worker_close.html"); |
| 477 ASSERT_TRUE(tab->NavigateToURL(url)); |
| 478 std::string value = WaitUntilCookieNonEmpty(tab.get(), url, |
| 479 kTestCompleteCookie, kTestIntervalMs, kTestWaitTimeoutMs); |
| 480 ASSERT_STREQ(kTestCompleteSuccess, value.c_str()); |
| 481 ASSERT_TRUE(WaitForProcessCountToBe(1, 0)); |
| 482 } |
| 483 |
| 484 TEST_F(WorkerTest, QueuedSharedWorkerShutdown) { |
| 485 // Tests to make sure that queued shared workers are started up when |
| 486 // shared workers shut down. |
| 487 int max_workers_per_tab = WorkerService::kMaxWorkersPerTabWhenSeparate; |
| 488 GURL url = GetTestUrl(L"workers", L"queued_shared_worker_shutdown.html"); |
| 489 url = GURL(url.spec() + StringPrintf("?count=%d", max_workers_per_tab)); |
| 490 |
| 491 scoped_refptr<TabProxy> tab(GetActiveTab()); |
| 492 ASSERT_TRUE(tab.get()); |
| 493 ASSERT_TRUE(tab->NavigateToURL(url)); |
| 494 std::string value = WaitUntilCookieNonEmpty(tab.get(), url, |
| 495 kTestCompleteCookie, kTestIntervalMs, kTestWaitTimeoutMs); |
| 496 ASSERT_STREQ(kTestCompleteSuccess, value.c_str()); |
| 497 ASSERT_TRUE(WaitForProcessCountToBe(1, max_workers_per_tab)); |
| 498 } |
| 499 |
| 500 TEST_F(WorkerTest, MultipleTabsQueuedSharedWorker) { |
| 501 // Tests to make sure that only one instance of queued shared workers are |
| 502 // started up even when those instances are on multiple tabs. |
| 503 int max_workers_per_tab = WorkerService::kMaxWorkersPerTabWhenSeparate; |
| 504 GURL url = GetTestUrl(L"workers", L"many_shared_workers.html"); |
| 505 url = GURL(url.spec() + StringPrintf("?count=%d", max_workers_per_tab+1)); |
| 506 |
| 507 scoped_refptr<TabProxy> tab(GetActiveTab()); |
| 508 ASSERT_TRUE(tab.get()); |
| 509 ASSERT_TRUE(tab->NavigateToURL(url)); |
| 510 ASSERT_TRUE(WaitForProcessCountToBe(1, max_workers_per_tab)); |
| 511 |
| 512 // Create same set of workers in new tab (leaves one worker queued from this |
| 513 // tab). |
| 514 scoped_refptr<BrowserProxy> window(automation()->GetBrowserWindow(0)); |
| 515 ASSERT_TRUE(window->AppendTab(url)); |
| 516 ASSERT_TRUE(WaitForProcessCountToBe(2, max_workers_per_tab)); |
| 517 |
| 518 // Now shutdown one of the shared workers - this will fire both queued |
| 519 // workers, but only one instance should be started |
| 520 GURL url2 = GetTestUrl(L"workers", L"shutdown_shared_worker.html?id=0"); |
| 521 ASSERT_TRUE(window->AppendTab(url2)); |
| 522 |
| 523 std::string value = WaitUntilCookieNonEmpty(tab.get(), url, |
| 524 kTestCompleteCookie, kTestIntervalMs, kTestWaitTimeoutMs); |
| 525 ASSERT_STREQ(kTestCompleteSuccess, value.c_str()); |
| 526 ASSERT_TRUE(WaitForProcessCountToBe(3, max_workers_per_tab)); |
| 527 } |
| 528 |
| 529 TEST_F(WorkerTest, QueuedSharedWorkerStartedFromOtherTab) { |
| 530 // Tests to make sure that queued shared workers are started up when |
| 531 // an instance is launched from another tab. |
| 532 int max_workers_per_tab = WorkerService::kMaxWorkersPerTabWhenSeparate; |
| 533 GURL url = GetTestUrl(L"workers", L"many_shared_workers.html"); |
| 534 url = GURL(url.spec() + StringPrintf("?count=%d", max_workers_per_tab+1)); |
| 535 |
| 536 scoped_refptr<TabProxy> tab(GetActiveTab()); |
| 537 ASSERT_TRUE(tab.get()); |
| 538 ASSERT_TRUE(tab->NavigateToURL(url)); |
| 539 ASSERT_TRUE(WaitForProcessCountToBe(1, max_workers_per_tab)); |
| 540 // First window has hit its limit. Now launch second window which creates |
| 541 // the same worker that was queued in the first window, to ensure it gets |
| 542 // connected to the first window too. |
| 543 scoped_refptr<BrowserProxy> window(automation()->GetBrowserWindow(0)); |
| 544 GURL url2 = GetTestUrl(L"workers", L"single_shared_worker.html"); |
| 545 url2 = GURL(url2.spec() + StringPrintf("?id=%d", max_workers_per_tab)); |
| 546 window->AppendTab(url2); |
| 547 |
| 548 std::string value = WaitUntilCookieNonEmpty(tab.get(), url, |
| 549 kTestCompleteCookie, kTestIntervalMs, kTestWaitTimeoutMs); |
| 550 ASSERT_STREQ(kTestCompleteSuccess, value.c_str()); |
| 551 ASSERT_TRUE(WaitForProcessCountToBe(2, max_workers_per_tab+1)); |
| 552 } |
OLD | NEW |