Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(28)

Side by Side Diff: chrome/test/ui/ui_test.cc

Issue 2903012: Output some error text if one of these Wait functions should timeout.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 10 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 #if defined(OS_POSIX) 7 #if defined(OS_POSIX)
8 #include <signal.h> 8 #include <signal.h>
9 #include <sys/types.h> 9 #include <sys/types.h>
10 #endif 10 #endif
(...skipping 602 matching lines...) Expand 10 before | Expand all | Expand 10 after
613 613
614 bool UITestBase::WaitForDownloadShelfInvisible(BrowserProxy* browser) { 614 bool UITestBase::WaitForDownloadShelfInvisible(BrowserProxy* browser) {
615 return WaitForDownloadShelfVisibilityChange(browser, false); 615 return WaitForDownloadShelfVisibilityChange(browser, false);
616 } 616 }
617 617
618 bool UITestBase::WaitForDownloadShelfVisibilityChange(BrowserProxy* browser, 618 bool UITestBase::WaitForDownloadShelfVisibilityChange(BrowserProxy* browser,
619 bool wait_for_open) { 619 bool wait_for_open) {
620 const int kCycles = 10; 620 const int kCycles = 10;
621 for (int i = 0; i < kCycles; i++) { 621 for (int i = 0; i < kCycles; i++) {
622 // Give it a chance to catch up. 622 // Give it a chance to catch up.
623 PlatformThread::Sleep(sleep_timeout_ms() / kCycles); 623 bool browser_survived = CrashAwareSleep(sleep_timeout_ms() / kCycles);
624 EXPECT_TRUE(browser_survived);
625 if (!browser_survived)
626 return false;
624 627
625 bool visible = !wait_for_open; 628 bool visible = !wait_for_open;
626 if (!browser->IsShelfVisible(&visible)) 629 if (!browser->IsShelfVisible(&visible))
627 continue; 630 continue;
628 if (visible == wait_for_open) 631 if (visible == wait_for_open)
629 return true; // Got the download shelf. 632 return true; // Got the download shelf.
630 } 633 }
634
635 ADD_FAILURE() << "Timeout reached in WaitForDownloadShelfVisibilityChange";
Paweł Hajdan Jr. 2010/07/14 00:16:58 You might want to add another log message in the o
631 return false; 636 return false;
632 } 637 }
633 638
634 bool UITestBase::WaitForFindWindowVisibilityChange(BrowserProxy* browser, 639 bool UITestBase::WaitForFindWindowVisibilityChange(BrowserProxy* browser,
635 bool wait_for_open) { 640 bool wait_for_open) {
636 const int kCycles = 10; 641 const int kCycles = 10;
637 for (int i = 0; i < kCycles; i++) { 642 for (int i = 0; i < kCycles; i++) {
638 bool visible = false; 643 bool visible = false;
639 if (!browser->IsFindWindowFullyVisible(&visible)) 644 if (!browser->IsFindWindowFullyVisible(&visible))
640 return false; // Some error. 645 return false; // Some error.
641 if (visible == wait_for_open) 646 if (visible == wait_for_open)
642 return true; // Find window visibility change complete. 647 return true; // Find window visibility change complete.
643 648
644 // Give it a chance to catch up. 649 // Give it a chance to catch up.
645 PlatformThread::Sleep(sleep_timeout_ms() / kCycles); 650 bool browser_survived = CrashAwareSleep(sleep_timeout_ms() / kCycles);
651 EXPECT_TRUE(browser_survived);
652 if (!browser_survived)
653 return false;
646 } 654 }
655
656 ADD_FAILURE() << "Timeout reached in WaitForFindWindowVisibilityChange";
647 return false; 657 return false;
648 } 658 }
649 659
650 bool UITestBase::WaitForBookmarkBarVisibilityChange(BrowserProxy* browser, 660 bool UITestBase::WaitForBookmarkBarVisibilityChange(BrowserProxy* browser,
651 bool wait_for_open) { 661 bool wait_for_open) {
652 const int kCycles = 10; 662 const int kCycles = 10;
653 for (int i = 0; i < kCycles; i++) { 663 for (int i = 0; i < kCycles; i++) {
654 bool visible = false; 664 bool visible = false;
655 bool animating = true; 665 bool animating = true;
656 if (!browser->GetBookmarkBarVisibility(&visible, &animating)) 666 if (!browser->GetBookmarkBarVisibility(&visible, &animating))
657 return false; // Some error. 667 return false; // Some error.
658 if (visible == wait_for_open && !animating) 668 if (visible == wait_for_open && !animating)
659 return true; // Bookmark bar visibility change complete. 669 return true; // Bookmark bar visibility change complete.
660 670
661 // Give it a chance to catch up. 671 // Give it a chance to catch up.
662 PlatformThread::Sleep(sleep_timeout_ms() / kCycles); 672 bool browser_survived = CrashAwareSleep(sleep_timeout_ms() / kCycles);
673 EXPECT_TRUE(browser_survived);
674 if (!browser_survived)
675 return false;
663 } 676 }
677
678 ADD_FAILURE() << "Timeout reached in WaitForBookmarkBarVisibilityChange";
664 return false; 679 return false;
665 } 680 }
666 681
667 GURL UITestBase::GetActiveTabURL(int window_index) { 682 GURL UITestBase::GetActiveTabURL(int window_index) {
668 scoped_refptr<TabProxy> tab_proxy(GetActiveTab(window_index)); 683 scoped_refptr<TabProxy> tab_proxy(GetActiveTab(window_index));
669 EXPECT_TRUE(tab_proxy.get()); 684 EXPECT_TRUE(tab_proxy.get());
670 if (!tab_proxy.get()) 685 if (!tab_proxy.get())
671 return GURL(); 686 return GURL();
672 687
673 GURL url; 688 GURL url;
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
768 bool browser_survived = CrashAwareSleep(kIntervalMs); 783 bool browser_survived = CrashAwareSleep(kIntervalMs);
769 EXPECT_TRUE(browser_survived); 784 EXPECT_TRUE(browser_survived);
770 if (!browser_survived) 785 if (!browser_survived)
771 return false; 786 return false;
772 787
773 EXPECT_TRUE(tab->GetCookieByName(url, cookie_name, &cookie_value)); 788 EXPECT_TRUE(tab->GetCookieByName(url, cookie_name, &cookie_value));
774 if (cookie_value == expected_value) 789 if (cookie_value == expected_value)
775 return true; 790 return true;
776 } 791 }
777 792
793 ADD_FAILURE() << "Timeout reached in WaitUntilCookieValue";
778 return false; 794 return false;
779 } 795 }
780 796
781 std::string UITestBase::WaitUntilCookieNonEmpty(TabProxy* tab, 797 std::string UITestBase::WaitUntilCookieNonEmpty(TabProxy* tab,
782 const GURL& url, 798 const GURL& url,
783 const char* cookie_name, 799 const char* cookie_name,
784 int time_out_ms) { 800 int time_out_ms) {
785 const int kIntervalMs = 250; 801 const int kIntervalMs = 250;
786 const int kMaxIntervals = time_out_ms / kIntervalMs; 802 const int kMaxIntervals = time_out_ms / kIntervalMs;
787 803
788 for (int i = 0; i < kMaxIntervals; ++i) { 804 for (int i = 0; i < kMaxIntervals; ++i) {
789 bool browser_survived = CrashAwareSleep(kIntervalMs); 805 bool browser_survived = CrashAwareSleep(kIntervalMs);
790 EXPECT_TRUE(browser_survived); 806 EXPECT_TRUE(browser_survived);
791 if (!browser_survived) 807 if (!browser_survived)
792 return std::string(); 808 return std::string();
793 809
794 std::string cookie_value; 810 std::string cookie_value;
795 EXPECT_TRUE(tab->GetCookieByName(url, cookie_name, &cookie_value)); 811 EXPECT_TRUE(tab->GetCookieByName(url, cookie_name, &cookie_value));
796 if (!cookie_value.empty()) 812 if (!cookie_value.empty())
797 return cookie_value; 813 return cookie_value;
798 } 814 }
799 815
816 ADD_FAILURE() << "Timeout reached in WaitUntilCookieNonEmpty";
800 return std::string(); 817 return std::string();
801 } 818 }
802 819
803 bool UITestBase::WaitUntilJavaScriptCondition(TabProxy* tab, 820 bool UITestBase::WaitUntilJavaScriptCondition(TabProxy* tab,
804 const std::wstring& frame_xpath, 821 const std::wstring& frame_xpath,
805 const std::wstring& jscript, 822 const std::wstring& jscript,
806 int time_out_ms) { 823 int time_out_ms) {
807 const int kIntervalMs = 250; 824 const int kIntervalMs = 250;
808 const int kMaxIntervals = time_out_ms / kIntervalMs; 825 const int kMaxIntervals = time_out_ms / kIntervalMs;
809 826
810 // Wait until the test signals it has completed. 827 // Wait until the test signals it has completed.
811 for (int i = 0; i < kMaxIntervals; ++i) { 828 for (int i = 0; i < kMaxIntervals; ++i) {
812 bool browser_survived = CrashAwareSleep(kIntervalMs); 829 bool browser_survived = CrashAwareSleep(kIntervalMs);
813 EXPECT_TRUE(browser_survived); 830 EXPECT_TRUE(browser_survived);
814 if (!browser_survived) 831 if (!browser_survived)
815 return false; 832 return false;
816 833
817 bool done_value = false; 834 bool done_value = false;
818 bool success = tab->ExecuteAndExtractBool(frame_xpath, jscript, 835 bool success = tab->ExecuteAndExtractBool(frame_xpath, jscript,
819 &done_value); 836 &done_value);
820 EXPECT_TRUE(success); 837 EXPECT_TRUE(success);
821 if (!success) 838 if (!success)
822 return false; 839 return false;
823 if (done_value) 840 if (done_value)
824 return true; 841 return true;
825 } 842 }
826 843
844 ADD_FAILURE() << "Timeout reached in WaitUntilJavaScriptCondition";
827 return false; 845 return false;
828 } 846 }
829 847
830 void UITestBase::WaitUntilTabCount(int tab_count) { 848 void UITestBase::WaitUntilTabCount(int tab_count) {
831 for (int i = 0; i < 10; ++i) { 849 const int kMaxIntervals = 10;
832 PlatformThread::Sleep(sleep_timeout_ms() / 10); 850 const int kIntervalMs = sleep_timeout_ms() / kMaxIntervals;
851
852 for (int i = 0; i < kMaxIntervals; ++i) {
853 bool browser_survived = CrashAwareSleep(kIntervalMs);
854 EXPECT_TRUE(browser_survived);
855 if (!browser_survived)
856 return;
833 if (GetTabCount() == tab_count) 857 if (GetTabCount() == tab_count)
834 break; 858 return;
835 } 859 }
836 EXPECT_EQ(tab_count, GetTabCount()); 860
861 ADD_FAILURE() << "Timeout reached in WaitUntilTabCount";
837 } 862 }
838 863
839 FilePath UITestBase::GetDownloadDirectory() { 864 FilePath UITestBase::GetDownloadDirectory() {
840 scoped_refptr<TabProxy> tab_proxy(GetActiveTab()); 865 scoped_refptr<TabProxy> tab_proxy(GetActiveTab());
841 EXPECT_TRUE(tab_proxy.get()); 866 EXPECT_TRUE(tab_proxy.get());
842 if (!tab_proxy.get()) 867 if (!tab_proxy.get())
843 return FilePath(); 868 return FilePath();
844 869
845 FilePath download_directory; 870 FilePath download_directory;
846 EXPECT_TRUE(tab_proxy->GetDownloadDirectory(&download_directory)); 871 EXPECT_TRUE(tab_proxy->GetDownloadDirectory(&download_directory));
(...skipping 651 matching lines...) Expand 10 before | Expand all | Expand 10 after
1498 set_ui_test_name(ASCIIToWide(test_name)); 1523 set_ui_test_name(ASCIIToWide(test_name));
1499 } 1524 }
1500 UITestBase::SetUp(); 1525 UITestBase::SetUp();
1501 PlatformTest::SetUp(); 1526 PlatformTest::SetUp();
1502 } 1527 }
1503 1528
1504 void UITest::TearDown() { 1529 void UITest::TearDown() {
1505 UITestBase::TearDown(); 1530 UITestBase::TearDown();
1506 PlatformTest::TearDown(); 1531 PlatformTest::TearDown();
1507 } 1532 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698