OLD | NEW |
1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-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 "chrome/test/ui/ui_test.h" | 5 #include "chrome/test/ui/ui_test.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/base_switches.h" | 10 #include "base/base_switches.h" |
(...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
384 } | 384 } |
385 #else | 385 #else |
386 // TODO(port): above code is very Windows-specific; we need to | 386 // TODO(port): above code is very Windows-specific; we need to |
387 // figure out and abstract out how we'll handle finding any existing | 387 // figure out and abstract out how we'll handle finding any existing |
388 // running process, etc. on other platforms. | 388 // running process, etc. on other platforms. |
389 NOTIMPLEMENTED(); | 389 NOTIMPLEMENTED(); |
390 #endif | 390 #endif |
391 } | 391 } |
392 | 392 |
393 void UITest::QuitBrowser() { | 393 void UITest::QuitBrowser() { |
394 typedef std::vector<BrowserProxy*> BrowserVector; | 394 typedef std::vector<scoped_refptr<BrowserProxy> > BrowserVector; |
395 | 395 |
396 // There's nothing to do here if the browser is not running. | 396 // There's nothing to do here if the browser is not running. |
397 if (IsBrowserRunning()) { | 397 if (IsBrowserRunning()) { |
398 automation()->SetFilteredInet(false); | 398 automation()->SetFilteredInet(false); |
399 BrowserVector browsers; | 399 BrowserVector browsers; |
400 | 400 |
401 // Build up a list of HWNDs; we do this as a separate step so that closing | 401 // Build up a list of HWNDs; we do this as a separate step so that closing |
402 // the windows doesn't mess up the iteration. | 402 // the windows doesn't mess up the iteration. |
403 int window_count = 0; | 403 int window_count = 0; |
404 EXPECT_TRUE(automation()->GetBrowserWindowCount(&window_count)); | 404 EXPECT_TRUE(automation()->GetBrowserWindowCount(&window_count)); |
405 | 405 |
406 for (int i = 0; i < window_count; ++i) { | 406 for (int i = 0; i < window_count; ++i) { |
407 BrowserProxy* browser_proxy = automation()->GetBrowserWindow(i); | 407 scoped_refptr<BrowserProxy> browser_proxy = |
| 408 automation()->GetBrowserWindow(i); |
408 browsers.push_back(browser_proxy); | 409 browsers.push_back(browser_proxy); |
409 } | 410 } |
410 | 411 |
411 // This is disabled for now on linux because it causes a crash. See | 412 // This is disabled for now on linux because it causes a crash. See |
412 // http://crbug.com/12334 | 413 // http://crbug.com/12334 |
413 #if !defined(OS_LINUX) | 414 #if !defined(OS_LINUX) |
414 for (BrowserVector::iterator iter = browsers.begin(); | 415 for (BrowserVector::iterator iter = browsers.begin(); |
415 iter != browsers.end(); ++iter) { | 416 iter != browsers.end(); ++iter) { |
416 // Use ApplyAccelerator since it doesn't wait | 417 // Use ApplyAccelerator since it doesn't wait |
417 (*iter)->ApplyAccelerator(IDC_CLOSE_WINDOW); | 418 (*iter)->ApplyAccelerator(IDC_CLOSE_WINDOW); |
418 delete (*iter); | |
419 } | 419 } |
420 #endif | 420 #endif |
421 | 421 |
| 422 browsers.clear(); |
| 423 |
422 // Now, drop the automation IPC channel so that the automation provider in | 424 // Now, drop the automation IPC channel so that the automation provider in |
423 // the browser notices and drops its reference to the browser process. | 425 // the browser notices and drops its reference to the browser process. |
424 server_->Disconnect(); | 426 server_->Disconnect(); |
425 | 427 |
426 // Wait for the browser process to quit. It should quit once all tabs have | 428 // Wait for the browser process to quit. It should quit once all tabs have |
427 // been closed. | 429 // been closed. |
428 int timeout = 5000; | 430 int timeout = 5000; |
429 #ifdef WAIT_FOR_DEBUGGER_ON_OPEN | 431 #ifdef WAIT_FOR_DEBUGGER_ON_OPEN |
430 timeout = 500000; | 432 timeout = 500000; |
431 #endif | 433 #endif |
(...skipping 16 matching lines...) Expand all Loading... |
448 void UITest::CleanupAppProcesses() { | 450 void UITest::CleanupAppProcesses() { |
449 TerminateAllChromeProcesses(user_data_dir()); | 451 TerminateAllChromeProcesses(user_data_dir()); |
450 | 452 |
451 // Suppress spammy failures that seem to be occurring when running | 453 // Suppress spammy failures that seem to be occurring when running |
452 // the UI tests in single-process mode. | 454 // the UI tests in single-process mode. |
453 // TODO(jhughes): figure out why this is necessary at all, and fix it | 455 // TODO(jhughes): figure out why this is necessary at all, and fix it |
454 if (!in_process_renderer_) | 456 if (!in_process_renderer_) |
455 AssertAppNotRunning(L"Unable to quit all browser processes."); | 457 AssertAppNotRunning(L"Unable to quit all browser processes."); |
456 } | 458 } |
457 | 459 |
458 TabProxy* UITest::GetActiveTab(int window_index) { | 460 scoped_refptr<TabProxy> UITest::GetActiveTab(int window_index) { |
459 EXPECT_GE(window_index, 0); | 461 EXPECT_GE(window_index, 0); |
460 int window_count; | 462 int window_count; |
461 // Use EXPECT rather than ASSERT here because ASSERT_* returns void. | 463 // Use EXPECT rather than ASSERT here because ASSERT_* returns void. |
462 EXPECT_TRUE(automation()->GetBrowserWindowCount(&window_count)); | 464 EXPECT_TRUE(automation()->GetBrowserWindowCount(&window_count)); |
463 EXPECT_GT(window_count, window_index); | 465 EXPECT_GT(window_count, window_index); |
464 scoped_ptr<BrowserProxy> window_proxy(automation()-> | 466 scoped_refptr<BrowserProxy> window_proxy(automation()-> |
465 GetBrowserWindow(window_index)); | 467 GetBrowserWindow(window_index)); |
466 if (!window_proxy.get()) | 468 if (!window_proxy.get()) |
467 return NULL; | 469 return NULL; |
468 | 470 |
469 int active_tab_index = -1; | 471 int active_tab_index = -1; |
470 EXPECT_TRUE(window_proxy->GetActiveTabIndex(&active_tab_index)); | 472 EXPECT_TRUE(window_proxy->GetActiveTabIndex(&active_tab_index)); |
471 if (active_tab_index == -1) | 473 if (active_tab_index == -1) |
472 return NULL; | 474 return NULL; |
473 | 475 |
474 return window_proxy->GetTab(active_tab_index); | 476 return window_proxy->GetTab(active_tab_index); |
475 } | 477 } |
476 | 478 |
| 479 scoped_refptr<TabProxy> UITest::GetActiveTab() { |
| 480 return GetActiveTab(0); |
| 481 } |
| 482 |
477 void UITest::NavigateToURLAsync(const GURL& url) { | 483 void UITest::NavigateToURLAsync(const GURL& url) { |
478 scoped_ptr<TabProxy> tab_proxy(GetActiveTab()); | 484 scoped_refptr<TabProxy> tab_proxy(GetActiveTab()); |
479 ASSERT_TRUE(tab_proxy.get()); | 485 ASSERT_TRUE(tab_proxy.get()); |
480 if (!tab_proxy.get()) | 486 if (!tab_proxy.get()) |
481 return; | 487 return; |
482 | 488 |
483 tab_proxy->NavigateToURLAsync(url); | 489 tab_proxy->NavigateToURLAsync(url); |
484 } | 490 } |
485 | 491 |
486 void UITest::NavigateToURL(const GURL& url) { | 492 void UITest::NavigateToURL(const GURL& url) { |
487 scoped_ptr<TabProxy> tab_proxy(GetActiveTab()); | 493 scoped_refptr<TabProxy> tab_proxy(GetActiveTab()); |
488 ASSERT_TRUE(tab_proxy.get()); | 494 ASSERT_TRUE(tab_proxy.get()); |
489 if (!tab_proxy.get()) | 495 if (!tab_proxy.get()) |
490 return; | 496 return; |
491 | 497 |
492 bool is_timeout = true; | 498 bool is_timeout = true; |
493 ASSERT_TRUE(tab_proxy->NavigateToURLWithTimeout( | 499 ASSERT_TRUE(tab_proxy->NavigateToURLWithTimeout( |
494 url, command_execution_timeout_ms(), &is_timeout)) << url.spec(); | 500 url, command_execution_timeout_ms(), &is_timeout)) << url.spec(); |
495 ASSERT_FALSE(is_timeout) << url.spec(); | 501 ASSERT_FALSE(is_timeout) << url.spec(); |
496 } | 502 } |
497 | 503 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
542 return true; // Bookmark bar visibility change complete. | 548 return true; // Bookmark bar visibility change complete. |
543 | 549 |
544 // Give it a chance to catch up. | 550 // Give it a chance to catch up. |
545 PlatformThread::Sleep(sleep_timeout_ms() / kCycles); | 551 PlatformThread::Sleep(sleep_timeout_ms() / kCycles); |
546 } | 552 } |
547 return false; | 553 return false; |
548 } | 554 } |
549 #endif // defined(OS_WIN) | 555 #endif // defined(OS_WIN) |
550 | 556 |
551 GURL UITest::GetActiveTabURL(int window_index) { | 557 GURL UITest::GetActiveTabURL(int window_index) { |
552 scoped_ptr<TabProxy> tab_proxy(GetActiveTab(window_index)); | 558 scoped_refptr<TabProxy> tab_proxy(GetActiveTab(window_index)); |
553 if (!tab_proxy.get()) | 559 if (!tab_proxy.get()) |
554 return GURL(); | 560 return GURL(); |
555 | 561 |
556 GURL url; | 562 GURL url; |
557 if (!tab_proxy->GetCurrentURL(&url)) | 563 if (!tab_proxy->GetCurrentURL(&url)) |
558 return GURL(); | 564 return GURL(); |
559 return url; | 565 return url; |
560 } | 566 } |
561 | 567 |
562 std::wstring UITest::GetActiveTabTitle(int window_index) { | 568 std::wstring UITest::GetActiveTabTitle(int window_index) { |
563 std::wstring title; | 569 std::wstring title; |
564 scoped_ptr<TabProxy> tab_proxy(GetActiveTab(window_index)); | 570 scoped_refptr<TabProxy> tab_proxy(GetActiveTab(window_index)); |
565 if (!tab_proxy.get()) | 571 if (!tab_proxy.get()) |
566 return title; | 572 return title; |
567 | 573 |
568 EXPECT_TRUE(tab_proxy->GetTabTitle(&title)); | 574 EXPECT_TRUE(tab_proxy->GetTabTitle(&title)); |
569 return title; | 575 return title; |
570 } | 576 } |
571 | 577 |
572 int UITest::GetActiveTabIndex(int window_index) { | 578 int UITest::GetActiveTabIndex(int window_index) { |
573 scoped_ptr<TabProxy> tab_proxy(GetActiveTab(window_index)); | 579 scoped_refptr<TabProxy> tab_proxy(GetActiveTab(window_index)); |
574 if (!tab_proxy.get()) | 580 if (!tab_proxy.get()) |
575 return -1; | 581 return -1; |
576 | 582 |
577 int index; | 583 int index; |
578 EXPECT_TRUE(tab_proxy->GetTabIndex(&index)); | 584 EXPECT_TRUE(tab_proxy->GetTabIndex(&index)); |
579 return index; | 585 return index; |
580 } | 586 } |
581 | 587 |
582 bool UITest::IsBrowserRunning() { | 588 bool UITest::IsBrowserRunning() { |
583 return CrashAwareSleep(0); | 589 return CrashAwareSleep(0); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
617 DictionaryValue* UITest::GetDefaultProfilePreferences() { | 623 DictionaryValue* UITest::GetDefaultProfilePreferences() { |
618 std::wstring path; | 624 std::wstring path; |
619 PathService::Get(chrome::DIR_USER_DATA, &path); | 625 PathService::Get(chrome::DIR_USER_DATA, &path); |
620 file_util::AppendToPath(&path, chrome::kNotSignedInProfile); | 626 file_util::AppendToPath(&path, chrome::kNotSignedInProfile); |
621 file_util::AppendToPath(&path, chrome::kPreferencesFilename); | 627 file_util::AppendToPath(&path, chrome::kPreferencesFilename); |
622 return LoadDictionaryValueFromPath(FilePath::FromWStringHack(path)); | 628 return LoadDictionaryValueFromPath(FilePath::FromWStringHack(path)); |
623 } | 629 } |
624 #endif // OS_WIN | 630 #endif // OS_WIN |
625 | 631 |
626 int UITest::GetTabCount() { | 632 int UITest::GetTabCount() { |
627 scoped_ptr<BrowserProxy> first_window(automation()->GetBrowserWindow(0)); | 633 scoped_refptr<BrowserProxy> first_window(automation()->GetBrowserWindow(0)); |
628 if (!first_window.get()) | 634 if (!first_window.get()) |
629 return 0; | 635 return 0; |
630 | 636 |
631 int result = 0; | 637 int result = 0; |
632 EXPECT_TRUE(first_window->GetTabCount(&result)); | 638 EXPECT_TRUE(first_window->GetTabCount(&result)); |
633 | 639 |
634 return result; | 640 return result; |
635 } | 641 } |
636 | 642 |
637 bool UITest::WaitUntilCookieValue(TabProxy* tab, | 643 bool UITest::WaitUntilCookieValue(TabProxy* tab, |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
721 void UITest::WaitUntilTabCount(int tab_count) { | 727 void UITest::WaitUntilTabCount(int tab_count) { |
722 for (int i = 0; i < 10; ++i) { | 728 for (int i = 0; i < 10; ++i) { |
723 PlatformThread::Sleep(sleep_timeout_ms() / 10); | 729 PlatformThread::Sleep(sleep_timeout_ms() / 10); |
724 if (GetTabCount() == tab_count) | 730 if (GetTabCount() == tab_count) |
725 break; | 731 break; |
726 } | 732 } |
727 EXPECT_EQ(tab_count, GetTabCount()); | 733 EXPECT_EQ(tab_count, GetTabCount()); |
728 } | 734 } |
729 | 735 |
730 std::wstring UITest::GetDownloadDirectory() { | 736 std::wstring UITest::GetDownloadDirectory() { |
731 scoped_ptr<TabProxy> tab_proxy(GetActiveTab()); | 737 scoped_refptr<TabProxy> tab_proxy(GetActiveTab()); |
732 if (!tab_proxy.get()) | 738 if (!tab_proxy.get()) |
733 return false; | 739 return false; |
734 | 740 |
735 std::wstring download_directory; | 741 std::wstring download_directory; |
736 EXPECT_TRUE(tab_proxy->GetDownloadDirectory(&download_directory)); | 742 EXPECT_TRUE(tab_proxy->GetDownloadDirectory(&download_directory)); |
737 return download_directory; | 743 return download_directory; |
738 } | 744 } |
739 | 745 |
740 void UITest::CloseBrowserAsync(BrowserProxy* browser) const { | 746 void UITest::CloseBrowserAsync(BrowserProxy* browser) const { |
741 server_->Send( | 747 server_->Send( |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
785 // which signals completion of the test. The cookie name is | 791 // which signals completion of the test. The cookie name is |
786 // a concatenation of the test name and the test id. This allows | 792 // a concatenation of the test name and the test id. This allows |
787 // us to run multiple tests within a single webpage and test | 793 // us to run multiple tests within a single webpage and test |
788 // that they all c | 794 // that they all c |
789 std::string cookie_name = name; | 795 std::string cookie_name = name; |
790 cookie_name.append("."); | 796 cookie_name.append("."); |
791 cookie_name.append(id); | 797 cookie_name.append(id); |
792 cookie_name.append("."); | 798 cookie_name.append("."); |
793 cookie_name.append(test_complete_cookie); | 799 cookie_name.append(test_complete_cookie); |
794 | 800 |
795 scoped_ptr<TabProxy> tab(GetActiveTab()); | 801 scoped_refptr<TabProxy> tab(GetActiveTab()); |
796 | 802 |
797 bool test_result = WaitUntilCookieValue(tab.get(), url, | 803 bool test_result = WaitUntilCookieValue(tab.get(), url, |
798 cookie_name.c_str(), | 804 cookie_name.c_str(), |
799 kIntervalMilliSeconds, wait_time, | 805 kIntervalMilliSeconds, wait_time, |
800 expected_cookie_value.c_str()); | 806 expected_cookie_value.c_str()); |
801 EXPECT_EQ(true, test_result); | 807 EXPECT_EQ(true, test_result); |
802 } | 808 } |
803 | 809 |
804 void UITest::PrintResult(const std::string& measurement, | 810 void UITest::PrintResult(const std::string& measurement, |
805 const std::string& modifier, | 811 const std::string& modifier, |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
859 } | 865 } |
860 | 866 |
861 bool UITest::EvictFileFromSystemCacheWrapper(const FilePath& path) { | 867 bool UITest::EvictFileFromSystemCacheWrapper(const FilePath& path) { |
862 for (int i = 0; i < 10; i++) { | 868 for (int i = 0; i < 10; i++) { |
863 if (file_util::EvictFileFromSystemCache(path)) | 869 if (file_util::EvictFileFromSystemCache(path)) |
864 return true; | 870 return true; |
865 PlatformThread::Sleep(sleep_timeout_ms() / 10); | 871 PlatformThread::Sleep(sleep_timeout_ms() / 10); |
866 } | 872 } |
867 return false; | 873 return false; |
868 } | 874 } |
OLD | NEW |