summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormmenke@chromium.org <mmenke@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-09-12 16:22:44 +0000
committermmenke@chromium.org <mmenke@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-09-12 16:22:44 +0000
commit7ad40225da25437f7cf000c0848ab2102767209c (patch)
tree0a97d3a25bddf632cae963d4f383005a1d8493c3
parent58291cf8f3232fdfe8da0d87d653cb9330c7cfb5 (diff)
downloadchromium_src-7ad40225da25437f7cf000c0848ab2102767209c.zip
chromium_src-7ad40225da25437f7cf000c0848ab2102767209c.tar.gz
chromium_src-7ad40225da25437f7cf000c0848ab2102767209c.tar.bz2
Switch the ErrorPageTest from ui tests to browser tests,
and declare them no longer flaky under Linux. These tests have a long and storied history of having varying degrees of flake. I'm hoping that switching them over to browser tests will fix most of it, particularly getting rid of the timer in "WaitForTitleMatching". It should also make any future flake a little easier to debug. TEST=ErrorPageTest.* BUG=79412 Review URL: http://codereview.chromium.org/7837043 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@100701 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/errorpage_browsertest.cc183
-rw-r--r--chrome/browser/errorpage_uitest.cc192
-rw-r--r--chrome/chrome_tests.gypi2
-rw-r--r--chrome/test/base/ui_test_utils.cc28
-rw-r--r--chrome/test/base/ui_test_utils.h2
5 files changed, 207 insertions, 200 deletions
diff --git a/chrome/browser/errorpage_browsertest.cc b/chrome/browser/errorpage_browsertest.cc
new file mode 100644
index 0000000..4badd95
--- /dev/null
+++ b/chrome/browser/errorpage_browsertest.cc
@@ -0,0 +1,183 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/utf_string_conversions.h"
+#include "chrome/browser/ui/browser.h"
+#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
+#include "chrome/test/base/in_process_browser_test.h"
+#include "chrome/test/base/ui_test_utils.h"
+#include "chrome/test/test_navigation_observer.h"
+#include "content/browser/net/url_request_failed_dns_job.h"
+#include "content/browser/net/url_request_mock_http_job.h"
+
+class ErrorPageTest : public InProcessBrowserTest {
+ public:
+ enum HistoryNavigationDirection {
+ HISTORY_NAVIGATE_BACK,
+ HISTORY_NAVIGATE_FORWARD,
+ };
+
+ // Navigates the active tab to a mock url created for the file at |file_path|.
+ void NavigateToFileURL(const FilePath::StringType& file_path) {
+ ui_test_utils::NavigateToURL(
+ browser(),
+ URLRequestMockHTTPJob::GetMockUrl(FilePath(file_path)));
+ }
+
+ // Navigates to the given URL and waits for |num_navigations| to occur, and
+ // the title to change to |expected_title|.
+ void NavigateToURLAndWaitForTitle(const GURL& url,
+ const std::string& expected_title,
+ int num_navigations) {
+ ui_test_utils::TitleWatcher title_watcher(
+ browser()->GetSelectedTabContents(),
+ ASCIIToUTF16(expected_title));
+
+ ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(
+ browser(), url, num_navigations);
+
+ EXPECT_EQ(title_watcher.WaitAndGetTitle(), ASCIIToUTF16(expected_title));
+ }
+
+ // Navigates back in the history and waits for |num_navigations| to occur, and
+ // the title to change to |expected_title|.
+ void GoBackAndWaitForTitle(const std::string& expected_title,
+ int num_navigations) {
+ NavigateHistoryAndWaitForTitle(expected_title,
+ num_navigations,
+ HISTORY_NAVIGATE_BACK);
+ }
+
+ // Navigates forward in the history and waits for |num_navigations| to occur,
+ // and the title to change to |expected_title|.
+ void GoForwardAndWaitForTitle(const std::string& expected_title,
+ int num_navigations) {
+ NavigateHistoryAndWaitForTitle(expected_title,
+ num_navigations,
+ HISTORY_NAVIGATE_FORWARD);
+ }
+
+ private:
+ // Navigates the browser the indicated direction in the history and waits for
+ // |num_navigations| to occur and the title to change to |expected_title|.
+ void NavigateHistoryAndWaitForTitle(const std::string& expected_title,
+ int num_navigations,
+ HistoryNavigationDirection direction) {
+ ui_test_utils::TitleWatcher title_watcher(
+ browser()->GetSelectedTabContents(),
+ ASCIIToUTF16(expected_title));
+
+ TestNavigationObserver test_navigation_observer(
+ Source<NavigationController>(
+ &browser()->GetSelectedTabContentsWrapper()->controller()),
+ NULL,
+ num_navigations);
+ if (direction == HISTORY_NAVIGATE_BACK) {
+ browser()->GoBack(CURRENT_TAB);
+ } else if (direction == HISTORY_NAVIGATE_FORWARD) {
+ browser()->GoForward(CURRENT_TAB);
+ } else {
+ FAIL();
+ }
+ test_navigation_observer.WaitForObservation();
+
+ EXPECT_EQ(title_watcher.WaitAndGetTitle(), ASCIIToUTF16(expected_title));
+ }
+};
+
+// Test that a DNS error occuring in the main frame redirects to an error page.
+IN_PROC_BROWSER_TEST_F(ErrorPageTest, DNSError_Basic) {
+ GURL test_url(URLRequestFailedDnsJob::kTestUrl);
+ // The first navigation should fail, and the second one should be the error
+ // page.
+ NavigateToURLAndWaitForTitle(test_url, "Mock Link Doctor", 2);
+}
+
+// Test that a DNS error occuring in the main frame does not result in an
+// additional session history entry.
+IN_PROC_BROWSER_TEST_F(ErrorPageTest, DNSError_GoBack1) {
+ GURL test_url(URLRequestFailedDnsJob::kTestUrl);
+ NavigateToFileURL(FILE_PATH_LITERAL("title2.html"));
+ NavigateToURLAndWaitForTitle(test_url, "Mock Link Doctor", 2);
+ GoBackAndWaitForTitle("Title Of Awesomeness", 1);
+}
+
+// Test that a DNS error occuring in the main frame does not result in an
+// additional session history entry.
+IN_PROC_BROWSER_TEST_F(ErrorPageTest, DNSError_GoBack2) {
+ GURL test_url(URLRequestFailedDnsJob::kTestUrl);
+ NavigateToFileURL(FILE_PATH_LITERAL("title2.html"));
+
+ NavigateToURLAndWaitForTitle(test_url, "Mock Link Doctor", 2);
+ NavigateToFileURL(FILE_PATH_LITERAL("title3.html"));
+
+ GoBackAndWaitForTitle("Mock Link Doctor", 2);
+ GoBackAndWaitForTitle("Title Of Awesomeness", 1);
+}
+
+// Test that a DNS error occuring in the main frame does not result in an
+// additional session history entry.
+IN_PROC_BROWSER_TEST_F(ErrorPageTest, DNSError_GoBack2AndForward) {
+ GURL test_url(URLRequestFailedDnsJob::kTestUrl);
+ NavigateToFileURL(FILE_PATH_LITERAL("title2.html"));
+
+ NavigateToURLAndWaitForTitle(test_url, "Mock Link Doctor", 2);
+ NavigateToFileURL(FILE_PATH_LITERAL("title3.html"));
+
+ GoBackAndWaitForTitle("Mock Link Doctor", 2);
+ GoBackAndWaitForTitle("Title Of Awesomeness", 1);
+
+ GoForwardAndWaitForTitle("Mock Link Doctor", 2);
+}
+
+// Test that a DNS error occuring in the main frame does not result in an
+// additional session history entry.
+IN_PROC_BROWSER_TEST_F(ErrorPageTest, DNSError_GoBack2Forward2) {
+ GURL test_url(URLRequestFailedDnsJob::kTestUrl);
+ NavigateToFileURL(FILE_PATH_LITERAL("title3.html"));
+
+ NavigateToURLAndWaitForTitle(test_url, "Mock Link Doctor", 2);
+ NavigateToFileURL(FILE_PATH_LITERAL("title2.html"));
+
+ GoBackAndWaitForTitle("Mock Link Doctor", 2);
+ GoBackAndWaitForTitle("Title Of More Awesomeness", 1);
+
+ GoForwardAndWaitForTitle("Mock Link Doctor", 2);
+ GoForwardAndWaitForTitle("Title Of Awesomeness", 1);
+}
+
+// Test that a DNS error occuring in an iframe.
+IN_PROC_BROWSER_TEST_F(ErrorPageTest, IFrameDNSError_Basic) {
+ NavigateToURLAndWaitForTitle(
+ URLRequestMockHTTPJob::GetMockUrl(
+ FilePath(FILE_PATH_LITERAL("iframe_dns_error.html"))),
+ "Blah",
+ 1);
+}
+
+// Test that a DNS error occuring in an iframe does not result in an
+// additional session history entry.
+IN_PROC_BROWSER_TEST_F(ErrorPageTest, IFrameDNSError_GoBack) {
+ NavigateToFileURL(FILE_PATH_LITERAL("title2.html"));
+ NavigateToFileURL(FILE_PATH_LITERAL("iframe_dns_error.html"));
+ GoBackAndWaitForTitle("Title Of Awesomeness", 1);
+}
+
+// Test that a DNS error occuring in an iframe does not result in an
+// additional session history entry.
+IN_PROC_BROWSER_TEST_F(ErrorPageTest, IFrameDNSError_GoBackAndForward) {
+ NavigateToFileURL(FILE_PATH_LITERAL("title2.html"));
+ NavigateToFileURL(FILE_PATH_LITERAL("iframe_dns_error.html"));
+ GoBackAndWaitForTitle("Title Of Awesomeness", 1);
+ GoForwardAndWaitForTitle("Blah", 1);
+}
+
+// Checks that the Link Doctor is not loaded when we receive an actual 404 page.
+IN_PROC_BROWSER_TEST_F(ErrorPageTest, Page404) {
+ NavigateToURLAndWaitForTitle(
+ URLRequestMockHTTPJob::GetMockUrl(
+ FilePath(FILE_PATH_LITERAL("page404.html"))),
+ "SUCCESS",
+ 1);
+}
diff --git a/chrome/browser/errorpage_uitest.cc b/chrome/browser/errorpage_uitest.cc
index fe82efb..e69de29 100644
--- a/chrome/browser/errorpage_uitest.cc
+++ b/chrome/browser/errorpage_uitest.cc
@@ -1,192 +0,0 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "base/string_util.h"
-#include "base/test/test_timeouts.h"
-#include "base/threading/platform_thread.h"
-#include "chrome/test/automation/tab_proxy.h"
-#include "chrome/test/ui/ui_test.h"
-#include "content/browser/net/url_request_failed_dns_job.h"
-#include "content/browser/net/url_request_mock_http_job.h"
-#include "net/test/test_server.h"
-
-class ErrorPageTest : public UITest {
- protected:
- bool WaitForTitleMatching(const std::wstring& title) {
- for (int i = 0; i < 10; ++i) {
- if (GetActiveTabTitle() == title)
- return true;
- base::PlatformThread::Sleep(TestTimeouts::action_timeout_ms());
- }
- EXPECT_EQ(title, GetActiveTabTitle());
- return false;
- }
-};
-
-TEST_F(ErrorPageTest, DNSError_Basic) {
- GURL test_url(URLRequestFailedDnsJob::kTestUrl);
-
- // The first navigation should fail, and the second one should be the error
- // page.
- NavigateToURLBlockUntilNavigationsComplete(test_url, 2);
-
- EXPECT_TRUE(WaitForTitleMatching(L"Mock Link Doctor"));
-}
-
-TEST_F(ErrorPageTest, DNSError_GoBack1) {
- // Test that a DNS error occuring in the main frame does not result in an
- // additional session history entry.
- GURL test_url(URLRequestFailedDnsJob::kTestUrl);
-
- NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(
- FilePath(FILE_PATH_LITERAL("title2.html"))));
- // The first navigation should fail, and the second one should be the error
- // page.
- NavigateToURLBlockUntilNavigationsComplete(test_url, 2);
- EXPECT_TRUE(WaitForTitleMatching(L"Mock Link Doctor"));
-
- EXPECT_TRUE(GetActiveTab()->GoBack());
-
- EXPECT_TRUE(WaitForTitleMatching(L"Title Of Awesomeness"));
-}
-
-// Flaky on Linux, see http://crbug.com/79412
-#if defined(OS_LINUX)
-#define MAYBE_DNSError_GoBack2 FLAKY_DNSError_GoBack2
-#else
-#define MAYBE_DNSError_GoBack2 DNSError_GoBack2
-#endif
-TEST_F(ErrorPageTest, MAYBE_DNSError_GoBack2) {
- // Test that a DNS error occuring in the main frame does not result in an
- // additional session history entry.
- GURL test_url(URLRequestFailedDnsJob::kTestUrl);
-
- NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(
- FilePath(FILE_PATH_LITERAL("title2.html"))));
- // The first navigation should fail, and the second one should be the error
- // page.
- NavigateToURLBlockUntilNavigationsComplete(test_url, 2);
- EXPECT_TRUE(WaitForTitleMatching(L"Mock Link Doctor"));
- NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(
- FilePath(FILE_PATH_LITERAL("title3.html"))));
-
- // The first navigation should fail, and the second one should be the error
- // page.
- EXPECT_TRUE(GetActiveTab()->GoBackBlockUntilNavigationsComplete(2));
- EXPECT_TRUE(WaitForTitleMatching(L"Mock Link Doctor"));
- EXPECT_TRUE(GetActiveTab()->GoBack());
-
- EXPECT_TRUE(WaitForTitleMatching(L"Title Of Awesomeness"));
-}
-
-// Flaky on Linux, see http://crbug.com/79412
-#if defined(OS_LINUX)
-#define MAYBE_DNSError_GoBack2AndForward FLAKY_DNSError_GoBack2AndForward
-#else
-#define MAYBE_DNSError_GoBack2AndForward DNSError_GoBack2AndForward
-#endif
-TEST_F(ErrorPageTest, MAYBE_DNSError_GoBack2AndForward) {
- // Test that a DNS error occuring in the main frame does not result in an
- // additional session history entry.
-
- GURL test_url(URLRequestFailedDnsJob::kTestUrl);
-
- NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(
- FilePath(FILE_PATH_LITERAL("title2.html"))));
- // The first navigation should fail, and the second one should be the error
- // page.
- NavigateToURLBlockUntilNavigationsComplete(test_url, 2);
- EXPECT_TRUE(WaitForTitleMatching(L"Mock Link Doctor"));
- NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(
- FilePath(FILE_PATH_LITERAL("title3.html"))));
-
- // The first navigation should fail, and the second one should be the error
- // page.
- EXPECT_TRUE(GetActiveTab()->GoBackBlockUntilNavigationsComplete(2));
- EXPECT_TRUE(WaitForTitleMatching(L"Mock Link Doctor"));
- EXPECT_TRUE(GetActiveTab()->GoBack());
- // The first navigation should fail, and the second one should be the error
- // page.
- EXPECT_TRUE(GetActiveTab()->GoForwardBlockUntilNavigationsComplete(2));
-
- EXPECT_TRUE(WaitForTitleMatching(L"Mock Link Doctor"));
-}
-
-// Flaky on Linux, see http://crbug.com/79412
-#if defined(OS_LINUX)
-#define MAYBE_DNSError_GoBack2Forward2 FLAKY_DNSError_GoBack2Forward2
-#else
-#define MAYBE_DNSError_GoBack2Forward2 DNSError_GoBack2Forward2
-#endif
-TEST_F(ErrorPageTest, MAYBE_DNSError_GoBack2Forward2) {
- // Test that a DNS error occuring in the main frame does not result in an
- // additional session history entry.
-
- GURL test_url(URLRequestFailedDnsJob::kTestUrl);
-
- NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(
- FilePath(FILE_PATH_LITERAL("title3.html"))));
- // The first navigation should fail, and the second one should be the error
- // page.
- NavigateToURLBlockUntilNavigationsComplete(test_url, 2);
- EXPECT_TRUE(WaitForTitleMatching(L"Mock Link Doctor"));
- NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(
- FilePath(FILE_PATH_LITERAL("title2.html"))));
-
- // The first navigation should fail, and the second one should be the error
- // page.
- EXPECT_TRUE(GetActiveTab()->GoBackBlockUntilNavigationsComplete(2));
- EXPECT_TRUE(WaitForTitleMatching(L"Mock Link Doctor"));
- EXPECT_TRUE(GetActiveTab()->GoBack());
- // The first navigation should fail, and the second one should be the error
- // page.
- EXPECT_TRUE(GetActiveTab()->GoForwardBlockUntilNavigationsComplete(2));
- EXPECT_TRUE(WaitForTitleMatching(L"Mock Link Doctor"));
- EXPECT_TRUE(GetActiveTab()->GoForward());
-
- EXPECT_TRUE(WaitForTitleMatching(L"Title Of Awesomeness"));
-}
-
-TEST_F(ErrorPageTest, IFrameDNSError_Basic) {
- NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(
- FilePath(FILE_PATH_LITERAL("iframe_dns_error.html"))));
- EXPECT_TRUE(WaitForTitleMatching(L"Blah"));
-}
-
-TEST_F(ErrorPageTest, IFrameDNSError_GoBack) {
- // Test that a DNS error occuring in an iframe does not result in an
- // additional session history entry.
-
- NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(
- FilePath(FILE_PATH_LITERAL("title2.html"))));
- NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(
- FilePath(FILE_PATH_LITERAL("iframe_dns_error.html"))));
-
- EXPECT_TRUE(GetActiveTab()->GoBack());
-
- EXPECT_TRUE(WaitForTitleMatching(L"Title Of Awesomeness"));
-}
-
-TEST_F(ErrorPageTest, IFrameDNSError_GoBackAndForward) {
- // Test that a DNS error occuring in an iframe does not result in an
- // additional session history entry.
-
- NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(
- FilePath(FILE_PATH_LITERAL("title2.html"))));
- NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(
- FilePath(FILE_PATH_LITERAL("iframe_dns_error.html"))));
-
- EXPECT_TRUE(GetActiveTab()->GoBack());
- EXPECT_TRUE(GetActiveTab()->GoForward());
-
- EXPECT_TRUE(WaitForTitleMatching(L"Blah"));
-}
-
-// Checks that the Link Doctor is not loaded when we receive an actual 404 page.
-TEST_F(ErrorPageTest, Page404) {
- NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(
- FilePath(FILE_PATH_LITERAL("page404.html"))));
-
- EXPECT_TRUE(WaitForTitleMatching(L"SUCCESS"));
-}
diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi
index a247e3d..74ad1bf 100644
--- a/chrome/chrome_tests.gypi
+++ b/chrome/chrome_tests.gypi
@@ -670,7 +670,6 @@
'browser/browser_encoding_uitest.cc',
'browser/custom_handlers/custom_handlers_uitest.cc',
'browser/download/save_page_uitest.cc',
- 'browser/errorpage_uitest.cc',
'browser/default_plugin_uitest.cc',
'browser/fast_shutdown_uitest.cc',
'browser/gpu_uitest.cc',
@@ -2237,6 +2236,7 @@
'browser/custom_handlers/protocol_handler_registry_browsertest.cc',
'browser/download/download_browsertest.cc',
'browser/download/save_page_browsertest.cc',
+ 'browser/errorpage_browsertest.cc',
'browser/extensions/alert_apitest.cc',
'browser/extensions/all_urls_apitest.cc',
'browser/extensions/app_background_page_apitest.cc',
diff --git a/chrome/test/base/ui_test_utils.cc b/chrome/test/base/ui_test_utils.cc
index d087e68..9a2a006 100644
--- a/chrome/test/base/ui_test_utils.cc
+++ b/chrome/test/base/ui_test_utils.cc
@@ -811,7 +811,7 @@ void WindowedNotificationObserver::Observe(int type,
TitleWatcher::TitleWatcher(TabContents* tab_contents,
const string16& expected_title)
- : expected_tab_(tab_contents),
+ : tab_contents_(tab_contents),
expected_title_observed_(false),
quit_loop_on_observation_(false) {
EXPECT_TRUE(tab_contents != NULL);
@@ -819,6 +819,16 @@ TitleWatcher::TitleWatcher(TabContents* tab_contents,
notification_registrar_.Add(this,
content::NOTIFICATION_TAB_CONTENTS_TITLE_UPDATED,
Source<TabContents>(tab_contents));
+
+ // When navigating through the history, the restored NavigationEntry's title
+ // will be used. If the entry ends up having the same title after we return
+ // to it, as will usually be the case, the
+ // NOTIFICATION_TAB_CONTENTS_TITLE_UPDATED will then be suppressed, since the
+ // NavigationEntry's title hasn't changed.
+ notification_registrar_.Add(
+ this,
+ content::NOTIFICATION_LOAD_STOP,
+ Source<NavigationController>(&tab_contents->controller()));
}
void TitleWatcher::AlsoWaitForTitle(const string16& expected_title) {
@@ -839,15 +849,21 @@ const string16& TitleWatcher::WaitAndGetTitle() {
void TitleWatcher::Observe(int type,
const NotificationSource& source,
const NotificationDetails& details) {
- if (type != content::NOTIFICATION_TAB_CONTENTS_TITLE_UPDATED)
- return;
+ if (type == content::NOTIFICATION_TAB_CONTENTS_TITLE_UPDATED) {
+ TabContents* source_contents = Source<TabContents>(source).ptr();
+ ASSERT_EQ(tab_contents_, source_contents);
+ } else if (type == content::NOTIFICATION_LOAD_STOP) {
+ NavigationController* controller =
+ Source<NavigationController>(source).ptr();
+ ASSERT_EQ(&tab_contents_->controller(), controller);
+ } else {
+ FAIL() << "Unexpected notification received.";
+ }
- TabContents* source_contents = Source<TabContents>(source).ptr();
- ASSERT_EQ(expected_tab_, source_contents);
std::vector<string16>::const_iterator it =
std::find(expected_titles_.begin(),
expected_titles_.end(),
- source_contents->GetTitle());
+ tab_contents_->GetTitle());
if (it == expected_titles_.end())
return;
observed_title_ = *it;
diff --git a/chrome/test/base/ui_test_utils.h b/chrome/test/base/ui_test_utils.h
index 07a4311..551959f 100644
--- a/chrome/test/base/ui_test_utils.h
+++ b/chrome/test/base/ui_test_utils.h
@@ -475,7 +475,7 @@ class TitleWatcher : public NotificationObserver {
const NotificationSource& source,
const NotificationDetails& details) OVERRIDE;
- TabContents* expected_tab_;
+ TabContents* tab_contents_;
std::vector<string16> expected_titles_;
NotificationRegistrar notification_registrar_;