diff options
author | phajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-02-10 09:33:21 +0000 |
---|---|---|
committer | phajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-02-10 09:33:21 +0000 |
commit | 84466968475088bf0f7ea837a215dec061d5eb41 (patch) | |
tree | 335808d3950114731f4dbc7c1ea8b618d76b581c | |
parent | 1eb175082bf16c5f7d92972f5d20277cb665d8e8 (diff) | |
download | chromium_src-84466968475088bf0f7ea837a215dec061d5eb41.zip chromium_src-84466968475088bf0f7ea837a215dec061d5eb41.tar.gz chromium_src-84466968475088bf0f7ea837a215dec061d5eb41.tar.bz2 |
Make several tests more snappy, less sleepy.
Some also say it's good for reducing flakiness.
TEST=Changing ui_tests.
BUG=none
Review URL: http://codereview.chromium.org/593018
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@38605 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/browser_uitest.cc | 17 | ||||
-rw-r--r-- | chrome/browser/renderer_host/resource_dispatcher_host_uitest.cc | 49 | ||||
-rw-r--r-- | chrome/browser/session_history_uitest.cc | 15 | ||||
-rw-r--r-- | chrome/browser/tab_contents/view_source_uitest.cc | 1 | ||||
-rw-r--r-- | chrome/browser/unload_uitest.cc | 21 | ||||
-rw-r--r-- | chrome/test/data/cross-origin-redirect-blocked.html | 17 | ||||
-rw-r--r-- | chrome/test/data/window.close.html | 114 |
7 files changed, 96 insertions, 138 deletions
diff --git a/chrome/browser/browser_uitest.cc b/chrome/browser/browser_uitest.cc index abfecd9..5ceb55f 100644 --- a/chrome/browser/browser_uitest.cc +++ b/chrome/browser/browser_uitest.cc @@ -222,20 +222,9 @@ TEST_F(VisibleBrowserTest, WindowOpenClose) { FilePath test_file(test_data_directory_); test_file = test_file.AppendASCII("window.close.html"); - NavigateToURL(net::FilePathToFileURL(test_file)); - - int i; - for (i = 0; i < 10; ++i) { - PlatformThread::Sleep(action_max_timeout_ms() / 10); - std::wstring title = GetActiveTabTitle(); - if (title == L"PASSED") { - // Success, bail out. - break; - } - } - - if (i == 10) - FAIL() << "failed to get error page title"; + NavigateToURLBlockUntilNavigationsComplete( + net::FilePathToFileURL(test_file), 2); + EXPECT_EQ(L"Title Of Awesomeness", GetActiveTabTitle()); } class ShowModalDialogTest : public UITest { diff --git a/chrome/browser/renderer_host/resource_dispatcher_host_uitest.cc b/chrome/browser/renderer_host/resource_dispatcher_host_uitest.cc index 58f6591..469dba7 100644 --- a/chrome/browser/renderer_host/resource_dispatcher_host_uitest.cc +++ b/chrome/browser/renderer_host/resource_dispatcher_host_uitest.cc @@ -23,18 +23,11 @@ namespace { class ResourceDispatcherTest : public UITest { public: void CheckTitleTest(const std::wstring& file, - const std::wstring& expected_title) { - NavigateToURL(URLRequestMockHTTPJob::GetMockUrl( - FilePath::FromWStringHack(file))); - const int kCheckDelayMs = 100; - int max_wait_time = 5000; - while (max_wait_time > 0) { - max_wait_time -= kCheckDelayMs; - PlatformThread::Sleep(kCheckDelayMs); - if (expected_title == GetActiveTabTitle()) - break; - } - + const std::wstring& expected_title, + int expected_navigations) { + NavigateToURLBlockUntilNavigationsComplete( + URLRequestMockHTTPJob::GetMockUrl(FilePath::FromWStringHack(file)), + expected_navigations); EXPECT_EQ(expected_title, GetActiveTabTitle()); } @@ -46,25 +39,24 @@ class ResourceDispatcherTest : public UITest { TEST_F(ResourceDispatcherTest, SniffHTMLWithNoContentType) { CheckTitleTest(L"content-sniffer-test0.html", - L"Content Sniffer Test 0"); + L"Content Sniffer Test 0", 1); } TEST_F(ResourceDispatcherTest, RespectNoSniffDirective) { - CheckTitleTest(L"nosniff-test.html", L""); + CheckTitleTest(L"nosniff-test.html", L"", 1); } TEST_F(ResourceDispatcherTest, DoNotSniffHTMLFromTextPlain) { - CheckTitleTest(L"content-sniffer-test1.html", L""); + CheckTitleTest(L"content-sniffer-test1.html", L"", 1); } TEST_F(ResourceDispatcherTest, DoNotSniffHTMLFromImageGIF) { - CheckTitleTest(L"content-sniffer-test2.html", L""); + CheckTitleTest(L"content-sniffer-test2.html", L"", 1); } TEST_F(ResourceDispatcherTest, SniffNoContentTypeNoData) { CheckTitleTest(L"content-sniffer-test3.html", - L"Content Sniffer Test 3"); - PlatformThread::Sleep(sleep_timeout_ms() * 2); + L"Content Sniffer Test 3", 1); EXPECT_EQ(1, GetTabCount()); // Make sure the download shelf is not showing. @@ -75,11 +67,11 @@ TEST_F(ResourceDispatcherTest, SniffNoContentTypeNoData) { } TEST_F(ResourceDispatcherTest, ContentDispositionEmpty) { - CheckTitleTest(L"content-disposition-empty.html", L"success"); + CheckTitleTest(L"content-disposition-empty.html", L"success", 1); } TEST_F(ResourceDispatcherTest, ContentDispositionInline) { - CheckTitleTest(L"content-disposition-inline.html", L"success"); + CheckTitleTest(L"content-disposition-inline.html", L"success", 1); } // Test for bug #1091358. @@ -184,7 +176,7 @@ TEST_F(ResourceDispatcherTest, CrossSiteOnunloadCookie) { // Navigate to a new cross-site page, to dispatch unload event and set the // cookie. CheckTitleTest(L"content-sniffer-test0.html", - L"Content Sniffer Test 0"); + L"Content Sniffer Test 0", 1); // Check that the cookie was set. std::string value_result; @@ -229,7 +221,7 @@ TEST_F(ResourceDispatcherTest, CrossSiteAfterCrash) { // Navigate to a new cross-site page. The browser should not wait around for // the old renderer's on{before}unload handlers to run. CheckTitleTest(L"content-sniffer-test0.html", - L"Content Sniffer Test 0"); + L"Content Sniffer Test 0", 1); } #endif // !defined(OS_MACOSX) @@ -243,7 +235,7 @@ TEST_F(ResourceDispatcherTest, CrossSiteNavigationNonBuffered) { // Start with an HTTP page. CheckTitleTest(L"content-sniffer-test0.html", - L"Content Sniffer Test 0"); + L"Content Sniffer Test 0", 1); // Now load a file:// page, which does not use the BufferedEventHandler. // Make sure that the page loads and displays a title, and doesn't get stuck. @@ -304,20 +296,15 @@ TEST_F(ResourceDispatcherTest, CrossSiteNavigationErrorPage) { } TEST_F(ResourceDispatcherTest, CrossOriginRedirectBlocked) { - int before = automation()->GetFilteredInetHitCount(); - CheckTitleTest(L"cross-origin-redirect-blocked.html", - L"done"); - int after = automation()->GetFilteredInetHitCount(); - // // We expect the following URL requests from this test: // 1- http://mock.http/cross-origin-redirect-blocked.html // 2- http://mock.http/redirect-to-title2.html // 3- http://mock.http/title2.html // // If the redirect in #2 were not blocked, we'd also see a request - // for http://mock.http:4000/title2.html. - // - EXPECT_EQ(3, after - before); + // for http://mock.http:4000/title2.html, and the title would be different. + CheckTitleTest(L"cross-origin-redirect-blocked.html", + L"Title Of More Awesomeness", 2); } } // namespace diff --git a/chrome/browser/session_history_uitest.cc b/chrome/browser/session_history_uitest.cc index fe06d8b..d2bbc84 100644 --- a/chrome/browser/session_history_uitest.cc +++ b/chrome/browser/session_history_uitest.cc @@ -72,21 +72,6 @@ class SessionHistoryTest : public UITest { return title; } - // Try 10 times to get the right tab title. - wstring TestTabTitle(const wstring& value) { - // Error pages load separately, but the UI automation system does not wait - // for error pages to load before returning after a navigation request. - // So, we need to sleep a little. - const int kWaitForErrorPageMsec = 200; - - for (int i = 0; i < 10; ++i) { - if (value.compare(GetTabTitle()) == 0) - return value; - PlatformThread::Sleep(kWaitForErrorPageMsec); - } - return GetTabTitle(); - } - GURL GetTabURL() { GURL url; EXPECT_TRUE(tab_->GetCurrentURL(&url)); diff --git a/chrome/browser/tab_contents/view_source_uitest.cc b/chrome/browser/tab_contents/view_source_uitest.cc index 4ee078d..60af8d6 100644 --- a/chrome/browser/tab_contents/view_source_uitest.cc +++ b/chrome/browser/tab_contents/view_source_uitest.cc @@ -48,7 +48,6 @@ TEST_F(ViewSourceTest, DoesBrowserRenderInViewSource) { scoped_refptr<TabProxy> tab(GetActiveTab()); ASSERT_TRUE(tab.get()); tab->NavigateToURL(url); - PlatformThread::Sleep(sleep_timeout_ms()); // Try to retrieve the cookie that the page sets // It should not be there (because we are in view-source mode diff --git a/chrome/browser/unload_uitest.cc b/chrome/browser/unload_uitest.cc index 86d0a82..2bbe357 100644 --- a/chrome/browser/unload_uitest.cc +++ b/chrome/browser/unload_uitest.cc @@ -103,32 +103,19 @@ class UnloadTest : public UITest { } } - void CheckTitle(const std::wstring& expected_title) { - const int kCheckDelayMs = 100; - int max_wait_time = 5000; - while (max_wait_time > 0) { - max_wait_time -= kCheckDelayMs; - PlatformThread::Sleep(kCheckDelayMs); - if (expected_title == GetActiveTabTitle()) - break; - } - - EXPECT_EQ(expected_title, GetActiveTabTitle()); - } - void NavigateToDataURL(const std::string& html_content, const std::wstring& expected_title) { NavigateToURL(GURL("data:text/html," + html_content)); - CheckTitle(expected_title); + EXPECT_EQ(expected_title, GetActiveTabTitle()); } void NavigateToNolistenersFileTwice() { NavigateToURL(URLRequestMockHTTPJob::GetMockUrl( FilePath(FILE_PATH_LITERAL("title2.html")))); - CheckTitle(L"Title Of Awesomeness"); + EXPECT_EQ(L"Title Of Awesomeness", GetActiveTabTitle()); NavigateToURL(URLRequestMockHTTPJob::GetMockUrl( FilePath(FILE_PATH_LITERAL("title2.html")))); - CheckTitle(L"Title Of Awesomeness"); + EXPECT_EQ(L"Title Of Awesomeness", GetActiveTabTitle()); } // Navigates to a URL asynchronously, then again synchronously. The first @@ -146,7 +133,7 @@ class UnloadTest : public UITest { URLRequestMockHTTPJob::GetMockUrl( FilePath(FILE_PATH_LITERAL("title2.html")))); - CheckTitle(L"Title Of Awesomeness"); + EXPECT_EQ(L"Title Of Awesomeness", GetActiveTabTitle()); } void LoadUrlAndQuitBrowser(const std::string& html_content, diff --git a/chrome/test/data/cross-origin-redirect-blocked.html b/chrome/test/data/cross-origin-redirect-blocked.html index 3e9cdd4..d0e8ee9 100644 --- a/chrome/test/data/cross-origin-redirect-blocked.html +++ b/chrome/test/data/cross-origin-redirect-blocked.html @@ -1,7 +1,6 @@ <html> <head> -<!-- avoid an automatically generated favicon reqeuest --> -<link rel="icon" type="image/vnd.microsoft.icon" href="data:,"> + <title></title> </head> <body> <script> @@ -12,13 +11,17 @@ function NewXHR(url) { return r; } -function SignalDone() { - document.title = "done"; +function SignalSuccess() { + document.location = "title3.html"; +} + +function SignalFailure() { + document.location = "title1.html"; } function CreateDummyRequest() { dummy_request = NewXHR("http://mock.http/title2.html"); - dummy_request.onload = SignalDone; + dummy_request.onload = SignalSuccess; dummy_request.send(null); } @@ -28,7 +31,7 @@ function RedirectFailed() { // We also care that the underlying network stack does not send the redirect. // We cannot detect that from JS, but our test harness is designed to detect // that (see ResourceDispatcherTest::CrossOriginRedirectBlocked). Before - // calling SignalDone, we want to allow the browser time to notice a request + // calling SignalSuccess, we want to allow the browser time to notice a request // to follow the redirect if one should exist. To do that, we just need to // make another network request. // @@ -39,7 +42,7 @@ function RedirectFailed() { function RedirectSucceeded() { // Oops, the redirect should have been denied! - SignalDone(); + SignalFailure(); } // Kick off a request that will attempt a cross-origin redirect. diff --git a/chrome/test/data/window.close.html b/chrome/test/data/window.close.html index ebe16868..333851f 100644 --- a/chrome/test/data/window.close.html +++ b/chrome/test/data/window.close.html @@ -1,53 +1,61 @@ -<script> -var popup, popup2, popup3, popup4; - -// window.open, window.close should be synchronous -function test1() { - popup = window.open('title1.html', 'name'); - popup.close(); - - popup = window.open('title2.html', 'name', 'width=200,height=200'); - popup.close(); -} - -// Try opening/closing a few windows. -function test2() { - openPopups(); - closePopups(); -} - -function test3() { - openPopups(); - setTimeout(closePopups, 0); - setTimeout(test4, 1); -} - -function test4() { - openPopups(); - setTimeout(closePopupsAndDone, 250); -} - -function openPopups() { - popup = window.open('title1.html', 'name'); - popup2 = window.open('title1.html', 'name2'); - popup3 = window.open('title1.html', 'name3'); - popup4 = window.open('title1.html', 'name4'); -} - -function closePopups() { - popup.close(); - popup2.close(); - popup3.close(); - popup4.close(); -} - -function closePopupsAndDone() { - closePopups(); - document.title = "PASSED"; -} - -test1(); -test2(); -test3(); - -</script> +<html> +<head> + <title>initial title</title> + <script> + var popup, popup2, popup3, popup4; + + // window.open, window.close should be synchronous + function test1() { + popup = window.open('title1.html', 'name'); + popup.close(); + + popup = window.open('title2.html', 'name', 'width=200,height=200'); + popup.close(); + } + + // Try opening/closing a few windows. + function test2() { + openPopups(); + closePopups(); + } + + function test3() { + openPopups(); + setTimeout(closePopups, 0); + setTimeout(test4, 1); + } + + function test4() { + openPopups(); + setTimeout(closePopupsAndDone, 250); + } + + function openPopups() { + popup = window.open('title1.html', 'name'); + popup2 = window.open('title1.html', 'name2'); + popup3 = window.open('title1.html', 'name3'); + popup4 = window.open('title1.html', 'name4'); + } + + function closePopups() { + popup.close(); + popup2.close(); + popup3.close(); + popup4.close(); + } + + function closePopupsAndDone() { + closePopups(); + document.location = 'title2.html' + } + + function startTheTest() { + test1(); + test2(); + test3(); + } + </script> +</head> +<body onload="startTheTest()"> +</body> +</html> |