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

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

Issue 6794056: Revert 80472 - GTTF: Detect browser crashes on shutdown in UI tests.Previously the automation fra... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 8 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 | « chrome/test/ui/ui_test.h ('k') | chrome_frame/test/perf/chrome_frame_perftest.cc » ('j') | 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 279 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 scoped_refptr<BrowserProxy> window = 290 scoped_refptr<BrowserProxy> window =
291 automation()->GetBrowserWindow(window_index); 291 automation()->GetBrowserWindow(window_index);
292 ASSERT_TRUE(window.get()); 292 ASSERT_TRUE(window.get());
293 scoped_refptr<TabProxy> tab_proxy(window->GetTab(tab_index)); 293 scoped_refptr<TabProxy> tab_proxy(window->GetTab(tab_index));
294 ASSERT_TRUE(tab_proxy.get()); 294 ASSERT_TRUE(tab_proxy.get());
295 EXPECT_EQ(AUTOMATION_MSG_NAVIGATION_SUCCESS, 295 EXPECT_EQ(AUTOMATION_MSG_NAVIGATION_SUCCESS,
296 tab_proxy->NavigateToURLBlockUntilNavigationsComplete( 296 tab_proxy->NavigateToURLBlockUntilNavigationsComplete(
297 url, number_of_navigations)) << url.spec(); 297 url, number_of_navigations)) << url.spec();
298 } 298 }
299 299
300 bool UITestBase::WaitForBrowserProcessToQuit(int timeout) {
301 return launcher_->WaitForBrowserProcessToQuit(timeout);
302 }
303
300 bool UITestBase::WaitForBookmarkBarVisibilityChange(BrowserProxy* browser, 304 bool UITestBase::WaitForBookmarkBarVisibilityChange(BrowserProxy* browser,
301 bool wait_for_open) { 305 bool wait_for_open) {
302 const int kCycles = 10; 306 const int kCycles = 10;
303 for (int i = 0; i < kCycles; i++) { 307 for (int i = 0; i < kCycles; i++) {
304 bool visible = false; 308 bool visible = false;
305 bool animating = true; 309 bool animating = true;
306 if (!browser->GetBookmarkBarVisibility(&visible, &animating)) 310 if (!browser->GetBookmarkBarVisibility(&visible, &animating))
307 return false; // Some error. 311 return false; // Some error.
308 if (visible == wait_for_open && !animating) 312 if (visible == wait_for_open && !animating)
309 return true; // Bookmark bar visibility change complete. 313 return true; // Bookmark bar visibility change complete.
310 314
311 // Give it a chance to catch up. 315 // Give it a chance to catch up.
312 base::PlatformThread::Sleep(TestTimeouts::action_timeout_ms() / kCycles); 316 bool browser_survived = CrashAwareSleep(
317 TestTimeouts::action_timeout_ms() / kCycles);
318 EXPECT_TRUE(browser_survived);
319 if (!browser_survived)
320 return false;
313 } 321 }
314 322
315 ADD_FAILURE() << "Timeout reached in WaitForBookmarkBarVisibilityChange"; 323 ADD_FAILURE() << "Timeout reached in WaitForBookmarkBarVisibilityChange";
316 return false; 324 return false;
317 } 325 }
318 326
319 GURL UITestBase::GetActiveTabURL(int window_index) { 327 GURL UITestBase::GetActiveTabURL(int window_index) {
320 scoped_refptr<TabProxy> tab_proxy(GetActiveTab(window_index)); 328 scoped_refptr<TabProxy> tab_proxy(GetActiveTab(window_index));
321 EXPECT_TRUE(tab_proxy.get()); 329 EXPECT_TRUE(tab_proxy.get());
322 if (!tab_proxy.get()) 330 if (!tab_proxy.get())
(...skipping 27 matching lines...) Expand all
350 358
351 int active_tab_index = -1; 359 int active_tab_index = -1;
352 EXPECT_TRUE(window_proxy->GetActiveTabIndex(&active_tab_index)); 360 EXPECT_TRUE(window_proxy->GetActiveTabIndex(&active_tab_index));
353 return active_tab_index; 361 return active_tab_index;
354 } 362 }
355 363
356 bool UITestBase::IsBrowserRunning() { 364 bool UITestBase::IsBrowserRunning() {
357 return launcher_->IsBrowserRunning(); 365 return launcher_->IsBrowserRunning();
358 } 366 }
359 367
368 bool UITestBase::CrashAwareSleep(int timeout_ms) {
369 return launcher_->CrashAwareSleep(timeout_ms);
370 }
371
360 int UITestBase::GetTabCount() { 372 int UITestBase::GetTabCount() {
361 return GetTabCount(0); 373 return GetTabCount(0);
362 } 374 }
363 375
364 int UITestBase::GetTabCount(int window_index) { 376 int UITestBase::GetTabCount(int window_index) {
365 scoped_refptr<BrowserProxy> window( 377 scoped_refptr<BrowserProxy> window(
366 automation()->GetBrowserWindow(window_index)); 378 automation()->GetBrowserWindow(window_index));
367 EXPECT_TRUE(window.get()); 379 EXPECT_TRUE(window.get());
368 if (!window.get()) 380 if (!window.get())
369 return 0; 381 return 0;
370 382
371 int result = 0; 383 int result = 0;
372 EXPECT_TRUE(window->GetTabCount(&result)); 384 EXPECT_TRUE(window->GetTabCount(&result));
373 385
374 return result; 386 return result;
375 } 387 }
376 388
377 void UITestBase::WaitUntilTabCount(int tab_count) { 389 void UITestBase::WaitUntilTabCount(int tab_count) {
378 const int kMaxIntervals = 10; 390 const int kMaxIntervals = 10;
379 const int kIntervalMs = TestTimeouts::action_timeout_ms() / kMaxIntervals; 391 const int kIntervalMs = TestTimeouts::action_timeout_ms() / kMaxIntervals;
380 392
381 for (int i = 0; i < kMaxIntervals; ++i) { 393 for (int i = 0; i < kMaxIntervals; ++i) {
394 bool browser_survived = CrashAwareSleep(kIntervalMs);
395 EXPECT_TRUE(browser_survived);
396 if (!browser_survived)
397 return;
382 if (GetTabCount() == tab_count) 398 if (GetTabCount() == tab_count)
383 return; 399 return;
384
385 base::PlatformThread::Sleep(kIntervalMs);
386 } 400 }
387 401
388 ADD_FAILURE() << "Timeout reached in WaitUntilTabCount"; 402 ADD_FAILURE() << "Timeout reached in WaitUntilTabCount";
389 } 403 }
390 404
391 FilePath UITestBase::GetDownloadDirectory() { 405 FilePath UITestBase::GetDownloadDirectory() {
392 scoped_refptr<TabProxy> tab_proxy(GetActiveTab()); 406 scoped_refptr<TabProxy> tab_proxy(GetActiveTab());
393 EXPECT_TRUE(tab_proxy.get()); 407 EXPECT_TRUE(tab_proxy.get());
394 if (!tab_proxy.get()) 408 if (!tab_proxy.get())
395 return FilePath(); 409 return FilePath();
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after
706 720
707 bool UITest::WaitUntilJavaScriptCondition(TabProxy* tab, 721 bool UITest::WaitUntilJavaScriptCondition(TabProxy* tab,
708 const std::wstring& frame_xpath, 722 const std::wstring& frame_xpath,
709 const std::wstring& jscript, 723 const std::wstring& jscript,
710 int timeout_ms) { 724 int timeout_ms) {
711 const int kIntervalMs = 250; 725 const int kIntervalMs = 250;
712 const int kMaxIntervals = timeout_ms / kIntervalMs; 726 const int kMaxIntervals = timeout_ms / kIntervalMs;
713 727
714 // Wait until the test signals it has completed. 728 // Wait until the test signals it has completed.
715 for (int i = 0; i < kMaxIntervals; ++i) { 729 for (int i = 0; i < kMaxIntervals; ++i) {
730 bool browser_survived = CrashAwareSleep(kIntervalMs);
731 EXPECT_TRUE(browser_survived);
732 if (!browser_survived)
733 return false;
734
716 bool done_value = false; 735 bool done_value = false;
717 bool success = tab->ExecuteAndExtractBool(frame_xpath, jscript, 736 bool success = tab->ExecuteAndExtractBool(frame_xpath, jscript,
718 &done_value); 737 &done_value);
719 EXPECT_TRUE(success); 738 EXPECT_TRUE(success);
720 if (!success) 739 if (!success)
721 return false; 740 return false;
722 if (done_value) 741 if (done_value)
723 return true; 742 return true;
724
725 base::PlatformThread::Sleep(kIntervalMs);
726 } 743 }
727 744
728 ADD_FAILURE() << "Timeout reached in WaitUntilJavaScriptCondition"; 745 ADD_FAILURE() << "Timeout reached in WaitUntilJavaScriptCondition";
729 return false; 746 return false;
730 } 747 }
731 748
732 bool UITest::WaitUntilCookieValue(TabProxy* tab, 749 bool UITest::WaitUntilCookieValue(TabProxy* tab,
733 const GURL& url, 750 const GURL& url,
734 const char* cookie_name, 751 const char* cookie_name,
735 int timeout_ms, 752 int timeout_ms,
736 const char* expected_value) { 753 const char* expected_value) {
737 const int kIntervalMs = 250; 754 const int kIntervalMs = 250;
738 const int kMaxIntervals = timeout_ms / kIntervalMs; 755 const int kMaxIntervals = timeout_ms / kIntervalMs;
739 756
740 std::string cookie_value; 757 std::string cookie_value;
741 for (int i = 0; i < kMaxIntervals; ++i) { 758 for (int i = 0; i < kMaxIntervals; ++i) {
759 bool browser_survived = CrashAwareSleep(kIntervalMs);
760 EXPECT_TRUE(browser_survived);
761 if (!browser_survived)
762 return false;
763
742 EXPECT_TRUE(tab->GetCookieByName(url, cookie_name, &cookie_value)); 764 EXPECT_TRUE(tab->GetCookieByName(url, cookie_name, &cookie_value));
743 if (cookie_value == expected_value) 765 if (cookie_value == expected_value)
744 return true; 766 return true;
745
746 base::PlatformThread::Sleep(kIntervalMs);
747 } 767 }
748 768
749 ADD_FAILURE() << "Timeout reached in WaitUntilCookieValue"; 769 ADD_FAILURE() << "Timeout reached in WaitUntilCookieValue";
750 return false; 770 return false;
751 } 771 }
752 772
753 std::string UITest::WaitUntilCookieNonEmpty(TabProxy* tab, 773 std::string UITest::WaitUntilCookieNonEmpty(TabProxy* tab,
754 const GURL& url, 774 const GURL& url,
755 const char* cookie_name, 775 const char* cookie_name,
756 int timeout_ms) { 776 int timeout_ms) {
757 const int kIntervalMs = 250; 777 const int kIntervalMs = 250;
758 const int kMaxIntervals = timeout_ms / kIntervalMs; 778 const int kMaxIntervals = timeout_ms / kIntervalMs;
759 779
760 for (int i = 0; i < kMaxIntervals; ++i) { 780 for (int i = 0; i < kMaxIntervals; ++i) {
781 bool browser_survived = CrashAwareSleep(kIntervalMs);
782 EXPECT_TRUE(browser_survived);
783 if (!browser_survived)
784 return std::string();
785
761 std::string cookie_value; 786 std::string cookie_value;
762 EXPECT_TRUE(tab->GetCookieByName(url, cookie_name, &cookie_value)); 787 EXPECT_TRUE(tab->GetCookieByName(url, cookie_name, &cookie_value));
763 if (!cookie_value.empty()) 788 if (!cookie_value.empty())
764 return cookie_value; 789 return cookie_value;
765
766 base::PlatformThread::Sleep(kIntervalMs);
767 } 790 }
768 791
769 ADD_FAILURE() << "Timeout reached in WaitUntilCookieNonEmpty"; 792 ADD_FAILURE() << "Timeout reached in WaitUntilCookieNonEmpty";
770 return std::string(); 793 return std::string();
771 } 794 }
772 795
773 bool UITest::WaitForDownloadShelfVisible(BrowserProxy* browser) { 796 bool UITest::WaitForDownloadShelfVisible(BrowserProxy* browser) {
774 return WaitForDownloadShelfVisibilityChange(browser, true); 797 return WaitForDownloadShelfVisibilityChange(browser, true);
775 } 798 }
776 799
777 bool UITest::WaitForDownloadShelfInvisible(BrowserProxy* browser) { 800 bool UITest::WaitForDownloadShelfInvisible(BrowserProxy* browser) {
778 return WaitForDownloadShelfVisibilityChange(browser, false); 801 return WaitForDownloadShelfVisibilityChange(browser, false);
779 } 802 }
780 803
781 bool UITest::WaitForFindWindowVisibilityChange(BrowserProxy* browser, 804 bool UITest::WaitForFindWindowVisibilityChange(BrowserProxy* browser,
782 bool wait_for_open) { 805 bool wait_for_open) {
783 const int kCycles = 10; 806 const int kCycles = 10;
784 for (int i = 0; i < kCycles; i++) { 807 for (int i = 0; i < kCycles; i++) {
785 bool visible = false; 808 bool visible = false;
786 if (!browser->IsFindWindowFullyVisible(&visible)) 809 if (!browser->IsFindWindowFullyVisible(&visible))
787 return false; // Some error. 810 return false; // Some error.
788 if (visible == wait_for_open) 811 if (visible == wait_for_open)
789 return true; // Find window visibility change complete. 812 return true; // Find window visibility change complete.
790 813
791 // Give it a chance to catch up. 814 // Give it a chance to catch up.
792 base::PlatformThread::Sleep(TestTimeouts::action_timeout_ms() / kCycles); 815 bool browser_survived = CrashAwareSleep(
816 TestTimeouts::action_timeout_ms() / kCycles);
817 EXPECT_TRUE(browser_survived);
818 if (!browser_survived)
819 return false;
793 } 820 }
794 821
795 ADD_FAILURE() << "Timeout reached in WaitForFindWindowVisibilityChange"; 822 ADD_FAILURE() << "Timeout reached in WaitForFindWindowVisibilityChange";
796 return false; 823 return false;
797 } 824 }
798 825
799 void UITest::TerminateBrowser() { 826 void UITest::TerminateBrowser() {
800 launcher_->TerminateBrowser(); 827 launcher_->TerminateBrowser();
801 } 828 }
802 829
803 void UITest::NavigateToURLAsync(const GURL& url) { 830 void UITest::NavigateToURLAsync(const GURL& url) {
804 scoped_refptr<TabProxy> tab_proxy(GetActiveTab()); 831 scoped_refptr<TabProxy> tab_proxy(GetActiveTab());
805 ASSERT_TRUE(tab_proxy.get()); 832 ASSERT_TRUE(tab_proxy.get());
806 ASSERT_TRUE(tab_proxy->NavigateToURLAsync(url)); 833 ASSERT_TRUE(tab_proxy->NavigateToURLAsync(url));
807 } 834 }
808 835
809 bool UITest::WaitForDownloadShelfVisibilityChange(BrowserProxy* browser, 836 bool UITest::WaitForDownloadShelfVisibilityChange(BrowserProxy* browser,
810 bool wait_for_open) { 837 bool wait_for_open) {
811 const int kCycles = 10; 838 const int kCycles = 10;
812 int fail_count = 0; 839 int fail_count = 0;
813 int incorrect_state_count = 0; 840 int incorrect_state_count = 0;
814 base::Time start = base::Time::Now(); 841 base::Time start = base::Time::Now();
815 for (int i = 0; i < kCycles; i++) { 842 for (int i = 0; i < kCycles; i++) {
843 // Give it a chance to catch up.
844 bool browser_survived = CrashAwareSleep(
845 TestTimeouts::action_timeout_ms() / kCycles);
846 EXPECT_TRUE(browser_survived);
847 if (!browser_survived) {
848 LOG(INFO) << "Elapsed time: " << (base::Time::Now() - start).InSecondsF()
849 << " seconds"
850 << " call failed " << fail_count << " times"
851 << " state was incorrect " << incorrect_state_count << " times";
852 ADD_FAILURE() << "Browser failed in " << __FUNCTION__;
853 return false;
854 }
855
816 bool visible = !wait_for_open; 856 bool visible = !wait_for_open;
817 if (!browser->IsShelfVisible(&visible)) { 857 if (!browser->IsShelfVisible(&visible)) {
818 fail_count++; 858 fail_count++;
819 continue; 859 continue;
820 } 860 }
821 if (visible == wait_for_open) { 861 if (visible == wait_for_open) {
822 LOG(INFO) << "Elapsed time: " << (base::Time::Now() - start).InSecondsF() 862 LOG(INFO) << "Elapsed time: " << (base::Time::Now() - start).InSecondsF()
823 << " seconds" 863 << " seconds"
824 << " call failed " << fail_count << " times" 864 << " call failed " << fail_count << " times"
825 << " state was incorrect " << incorrect_state_count << " times"; 865 << " state was incorrect " << incorrect_state_count << " times";
826 return true; // Got the download shelf. 866 return true; // Got the download shelf.
827 } 867 }
828 incorrect_state_count++; 868 incorrect_state_count++;
829
830 // Give it a chance to catch up.
831 base::PlatformThread::Sleep(TestTimeouts::action_timeout_ms() / kCycles);
832 } 869 }
833 870
834 LOG(INFO) << "Elapsed time: " << (base::Time::Now() - start).InSecondsF() 871 LOG(INFO) << "Elapsed time: " << (base::Time::Now() - start).InSecondsF()
835 << " seconds" 872 << " seconds"
836 << " call failed " << fail_count << " times" 873 << " call failed " << fail_count << " times"
837 << " state was incorrect " << incorrect_state_count << " times"; 874 << " state was incorrect " << incorrect_state_count << " times";
838 ADD_FAILURE() << "Timeout reached in " << __FUNCTION__; 875 ADD_FAILURE() << "Timeout reached in " << __FUNCTION__;
839 return false; 876 return false;
840 } 877 }
OLDNEW
« no previous file with comments | « chrome/test/ui/ui_test.h ('k') | chrome_frame/test/perf/chrome_frame_perftest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698