| Index: chrome/browser/errorpage_browsertest.cc
|
| ===================================================================
|
| --- chrome/browser/errorpage_browsertest.cc (revision 263850)
|
| +++ chrome/browser/errorpage_browsertest.cc (working copy)
|
| @@ -7,7 +7,6 @@
|
| #include "base/compiler_specific.h"
|
| #include "base/logging.h"
|
| #include "base/memory/scoped_ptr.h"
|
| -#include "base/path_service.h"
|
| #include "base/prefs/pref_service.h"
|
| #include "base/strings/stringprintf.h"
|
| #include "base/strings/utf_string_conversions.h"
|
| @@ -19,7 +18,6 @@
|
| #include "chrome/browser/ui/browser.h"
|
| #include "chrome/browser/ui/browser_commands.h"
|
| #include "chrome/browser/ui/tabs/tab_strip_model.h"
|
| -#include "chrome/common/chrome_paths.h"
|
| #include "chrome/common/chrome_switches.h"
|
| #include "chrome/common/pref_names.h"
|
| #include "chrome/test/base/in_process_browser_test.h"
|
| @@ -55,87 +53,6 @@
|
|
|
| namespace {
|
|
|
| -// Returns true if |text| is displayed on the page |browser| is currently
|
| -// displaying. Uses "innerText", so will miss hidden text, and whitespace
|
| -// space handling may be weird.
|
| -bool WARN_UNUSED_RESULT IsDisplayingText(Browser* browser,
|
| - const std::string& text) {
|
| - std::string command = base::StringPrintf(
|
| - "var textContent = document.body.innerText;"
|
| - "var hasText = textContent.indexOf('%s') >= 0;"
|
| - "domAutomationController.send(hasText);",
|
| - text.c_str());
|
| - bool result = false;
|
| - EXPECT_TRUE(content::ExecuteScriptAndExtractBool(
|
| - browser->tab_strip_model()->GetActiveWebContents(), command, &result));
|
| - return result;
|
| -}
|
| -
|
| -// Expands the more box on the currently displayed error page.
|
| -void ToggleHelpBox(Browser* browser) {
|
| - EXPECT_TRUE(content::ExecuteScript(
|
| - browser->tab_strip_model()->GetActiveWebContents(),
|
| - "document.getElementById('more-less-button').click();"));
|
| -}
|
| -
|
| -// Returns true if |browser| is displaying the text representation of
|
| -// |error_code| on the current page.
|
| -bool WARN_UNUSED_RESULT IsDisplayingNetError(Browser* browser,
|
| - net::Error error_code) {
|
| - // Get the error as a string, and remove the leading "net::", which is not
|
| - // included on error pages.
|
| - std::string error_string = net::ErrorToString(error_code);
|
| - base::RemoveChars(error_string, "net:", &error_string);
|
| -
|
| - return IsDisplayingText(browser, error_string);
|
| -}
|
| -
|
| -// Checks that the local error page is being displayed, without remotely
|
| -// retrieved navigation corrections, and with the specified error code.
|
| -void ExpectDisplayingLocalErrorPage(Browser* browser, net::Error error_code) {
|
| - // Expand the help box so innerText will include text below the fold.
|
| - ToggleHelpBox(browser);
|
| -
|
| - EXPECT_TRUE(IsDisplayingNetError(browser, error_code));
|
| -
|
| - // Locally generated error pages should not have navigation corrections.
|
| - EXPECT_FALSE(IsDisplayingText(browser, "http://correction1/"));
|
| - EXPECT_FALSE(IsDisplayingText(browser, "http://correction2/"));
|
| -
|
| - // Locally generated error pages should not have a populated search box.
|
| - bool search_box_populated = false;
|
| - ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
|
| - browser->tab_strip_model()->GetActiveWebContents(),
|
| - "var searchText = document.getElementById('search-box').value;"
|
| - "domAutomationController.send(searchText == 'search query');",
|
| - &search_box_populated));
|
| - EXPECT_FALSE(search_box_populated);
|
| -}
|
| -
|
| -// Checks that an error page with information retrieved from the navigation
|
| -// correction service is being displayed, with the specified specified error
|
| -// code.
|
| -void ExpectDisplayingNavigationCorrections(Browser* browser,
|
| - net::Error error_code) {
|
| - // Expand the help box so innerText will include text below the fold.
|
| - ToggleHelpBox(browser);
|
| -
|
| - EXPECT_TRUE(IsDisplayingNetError(browser, error_code));
|
| -
|
| - // Check that the mock navigation corrections are displayed.
|
| - EXPECT_TRUE(IsDisplayingText(browser, "http://correction1/"));
|
| - EXPECT_TRUE(IsDisplayingText(browser, "http://correction2/"));
|
| -
|
| - // Check that the search box is populated correctly.
|
| - bool search_box_populated = false;
|
| - ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
|
| - browser->tab_strip_model()->GetActiveWebContents(),
|
| - "var searchText = document.getElementById('search-box').value;"
|
| - "domAutomationController.send(searchText == 'search query');",
|
| - &search_box_populated));
|
| - EXPECT_TRUE(search_box_populated);
|
| -}
|
| -
|
| // A protocol handler that fails a configurable number of requests, then
|
| // succeeds all requests after that, keeping count of failures and successes.
|
| class FailFirstNRequestsProtocolHandler
|
| @@ -240,14 +157,6 @@
|
| HISTORY_NAVIGATE_FORWARD);
|
| }
|
|
|
| - void GoBackAndWaitForNavigations(int num_navigations) {
|
| - NavigateHistory(num_navigations, HISTORY_NAVIGATE_BACK);
|
| - }
|
| -
|
| - void GoForwardAndWaitForNavigations(int num_navigations) {
|
| - NavigateHistory(num_navigations, HISTORY_NAVIGATE_FORWARD);
|
| - }
|
| -
|
| // Confirms that the javascript variable indicating whether or not we have
|
| // a stale copy in the cache has been set to |expected|.
|
| bool ProbeStaleCopyValue(bool expected) {
|
| @@ -294,21 +203,10 @@
|
| }
|
|
|
| protected:
|
| - static void EnableMocks(const GURL& search_url) {
|
| - chrome_browser_net::SetUrlRequestMocksEnabled(true);
|
| -
|
| - // Add a mock for the search engine the error page will use.
|
| - base::FilePath root_http;
|
| - PathService::Get(chrome::DIR_TEST_DATA, &root_http);
|
| - content::URLRequestMockHTTPJob::AddHostnameToFileHandler(
|
| - search_url.host(), root_http.AppendASCII("title3.html"));
|
| - }
|
| -
|
| virtual void SetUpOnMainThread() OVERRIDE {
|
| BrowserThread::PostTask(
|
| BrowserThread::IO, FROM_HERE,
|
| - base::Bind(&ErrorPageTest::EnableMocks,
|
| - google_util::GetGoogleSearchURL(browser()->profile())));
|
| + base::Bind(&chrome_browser_net::SetUrlRequestMocksEnabled, true));
|
| }
|
|
|
| // Returns a GURL that results in a DNS error.
|
| @@ -326,14 +224,6 @@
|
| browser()->tab_strip_model()->GetActiveWebContents(),
|
| base::ASCIIToUTF16(expected_title));
|
|
|
| - NavigateHistory(num_navigations, direction);
|
| -
|
| - EXPECT_EQ(title_watcher.WaitAndGetTitle(),
|
| - base::ASCIIToUTF16(expected_title));
|
| - }
|
| -
|
| - void NavigateHistory(int num_navigations,
|
| - HistoryNavigationDirection direction) {
|
| content::TestNavigationObserver test_navigation_observer(
|
| browser()->tab_strip_model()->GetActiveWebContents(),
|
| num_navigations);
|
| @@ -345,6 +235,9 @@
|
| FAIL();
|
| }
|
| test_navigation_observer.Wait();
|
| +
|
| + EXPECT_EQ(title_watcher.WaitAndGetTitle(),
|
| + base::ASCIIToUTF16(expected_title));
|
| }
|
| };
|
|
|
| @@ -397,9 +290,7 @@
|
| IN_PROC_BROWSER_TEST_F(ErrorPageTest, MAYBE_DNSError_Basic) {
|
| // The first navigation should fail, and the second one should be the error
|
| // page.
|
| - ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(
|
| - browser(), GetDnsErrorURL(), 2);
|
| - ExpectDisplayingNavigationCorrections(browser(), net::ERR_NAME_NOT_RESOLVED);
|
| + NavigateToURLAndWaitForTitle(GetDnsErrorURL(), "Mock Link Doctor", 2);
|
| }
|
|
|
| // See crbug.com/109669
|
| @@ -413,9 +304,7 @@
|
| // additional session history entry.
|
| IN_PROC_BROWSER_TEST_F(ErrorPageTest, MAYBE_DNSError_GoBack1) {
|
| NavigateToFileURL(FILE_PATH_LITERAL("title2.html"));
|
| - ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(
|
| - browser(), GetDnsErrorURL(), 2);
|
| - ExpectDisplayingNavigationCorrections(browser(), net::ERR_NAME_NOT_RESOLVED);
|
| + NavigateToURLAndWaitForTitle(GetDnsErrorURL(), "Mock Link Doctor", 2);
|
| GoBackAndWaitForTitle("Title Of Awesomeness", 1);
|
| }
|
|
|
| @@ -430,15 +319,10 @@
|
| IN_PROC_BROWSER_TEST_F(ErrorPageTest, DNSError_GoBack2) {
|
| NavigateToFileURL(FILE_PATH_LITERAL("title2.html"));
|
|
|
| - ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(
|
| - browser(), GetDnsErrorURL(), 2);
|
| - ExpectDisplayingNavigationCorrections(browser(), net::ERR_NAME_NOT_RESOLVED);
|
| -
|
| + NavigateToURLAndWaitForTitle(GetDnsErrorURL(), "Mock Link Doctor", 2);
|
| NavigateToFileURL(FILE_PATH_LITERAL("title3.html"));
|
|
|
| - GoBackAndWaitForNavigations(2);
|
| - ExpectDisplayingNavigationCorrections(browser(), net::ERR_NAME_NOT_RESOLVED);
|
| -
|
| + GoBackAndWaitForTitle("Mock Link Doctor", 2);
|
| GoBackAndWaitForTitle("Title Of Awesomeness", 1);
|
| }
|
|
|
| @@ -453,19 +337,13 @@
|
| IN_PROC_BROWSER_TEST_F(ErrorPageTest, DNSError_GoBack2AndForward) {
|
| NavigateToFileURL(FILE_PATH_LITERAL("title2.html"));
|
|
|
| - ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(
|
| - browser(), GetDnsErrorURL(), 2);
|
| - ExpectDisplayingNavigationCorrections(browser(), net::ERR_NAME_NOT_RESOLVED);
|
| -
|
| + NavigateToURLAndWaitForTitle(GetDnsErrorURL(), "Mock Link Doctor", 2);
|
| NavigateToFileURL(FILE_PATH_LITERAL("title3.html"));
|
|
|
| - GoBackAndWaitForNavigations(2);
|
| - ExpectDisplayingNavigationCorrections(browser(), net::ERR_NAME_NOT_RESOLVED);
|
| -
|
| + GoBackAndWaitForTitle("Mock Link Doctor", 2);
|
| GoBackAndWaitForTitle("Title Of Awesomeness", 1);
|
|
|
| - GoForwardAndWaitForNavigations(2);
|
| - ExpectDisplayingNavigationCorrections(browser(), net::ERR_NAME_NOT_RESOLVED);
|
| + GoForwardAndWaitForTitle("Mock Link Doctor", 2);
|
| }
|
|
|
| // See crbug.com/109669
|
| @@ -479,67 +357,17 @@
|
| IN_PROC_BROWSER_TEST_F(ErrorPageTest, DNSError_GoBack2Forward2) {
|
| NavigateToFileURL(FILE_PATH_LITERAL("title3.html"));
|
|
|
| - ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(
|
| - browser(), GetDnsErrorURL(), 2);
|
| - ExpectDisplayingNavigationCorrections(browser(), net::ERR_NAME_NOT_RESOLVED);
|
| -
|
| + NavigateToURLAndWaitForTitle(GetDnsErrorURL(), "Mock Link Doctor", 2);
|
| NavigateToFileURL(FILE_PATH_LITERAL("title2.html"));
|
|
|
| - GoBackAndWaitForNavigations(2);
|
| - ExpectDisplayingNavigationCorrections(browser(), net::ERR_NAME_NOT_RESOLVED);
|
| -
|
| + GoBackAndWaitForTitle("Mock Link Doctor", 2);
|
| GoBackAndWaitForTitle("Title Of More Awesomeness", 1);
|
|
|
| - GoForwardAndWaitForNavigations(2);
|
| - ExpectDisplayingNavigationCorrections(browser(), net::ERR_NAME_NOT_RESOLVED);
|
| -
|
| + GoForwardAndWaitForTitle("Mock Link Doctor", 2);
|
| GoForwardAndWaitForTitle("Title Of Awesomeness", 1);
|
| }
|
|
|
| -// See crbug.com/109669
|
| -#if defined(USE_AURA)
|
| -#define MAYBE_DNSError_DoSearch DNSError_DoSearch
|
| -#else
|
| -#define MAYBE_DNSError_DoSearch DNSError_DoSearch
|
| -#endif
|
| -// Test that the search button on a DNS error page works.
|
| -IN_PROC_BROWSER_TEST_F(ErrorPageTest, MAYBE_DNSError_DoSearch) {
|
| - // The first navigation should fail, and the second one should be the error
|
| - // page.
|
| - ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(
|
| - browser(), GetDnsErrorURL(), 2);
|
| - ExpectDisplayingNavigationCorrections(browser(), net::ERR_NAME_NOT_RESOLVED);
|
| -
|
| - // Do a search and make sure the browser ends up at the right page.
|
| - content::TestNavigationObserver nav_observer(
|
| - browser()->tab_strip_model()->GetActiveWebContents(),
|
| - 1);
|
| - content::TitleWatcher title_watcher(
|
| - browser()->tab_strip_model()->GetActiveWebContents(),
|
| - base::ASCIIToUTF16("Title Of More Awesomeness"));
|
| - ASSERT_TRUE(content::ExecuteScript(
|
| - browser()->tab_strip_model()->GetActiveWebContents(),
|
| - "document.getElementById('search-button').click();"));
|
| - nav_observer.Wait();
|
| - EXPECT_EQ(base::ASCIIToUTF16("Title Of More Awesomeness"),
|
| - title_watcher.WaitAndGetTitle());
|
| -
|
| - // Check the path and query string.
|
| - std::string url;
|
| - ASSERT_TRUE(content::ExecuteScriptAndExtractString(
|
| - browser()->tab_strip_model()->GetActiveWebContents(),
|
| - "domAutomationController.send(window.location.href);",
|
| - &url));
|
| - EXPECT_EQ("/search", GURL(url).path());
|
| - EXPECT_EQ("q=search%20query", GURL(url).query());
|
| -
|
| - // Go back to the error page, to make sure the history is correct.
|
| - GoBackAndWaitForNavigations(2);
|
| - ExpectDisplayingNavigationCorrections(browser(), net::ERR_NAME_NOT_RESOLVED);
|
| -}
|
| -
|
| -// Test that a DNS error occuring in an iframe does not result in showing
|
| -// navigation corrections.
|
| +// Test that a DNS error occuring in an iframe.
|
| IN_PROC_BROWSER_TEST_F(ErrorPageTest, IFrameDNSError_Basic) {
|
| NavigateToURLAndWaitForTitle(
|
| content::URLRequestMockHTTPJob::GetMockUrl(
|
| @@ -648,8 +476,7 @@
|
| }
|
| }
|
|
|
| -// Checks that navigation corrections are not loaded when we receive an actual
|
| -// 404 page.
|
| +// Checks that the Link Doctor is not loaded when we receive an actual 404 page.
|
| IN_PROC_BROWSER_TEST_F(ErrorPageTest, Page404) {
|
| NavigateToURLAndWaitForTitle(
|
| content::URLRequestMockHTTPJob::GetMockUrl(
|
| @@ -675,10 +502,17 @@
|
| BrowserThread::PostTask(
|
| BrowserThread::IO, FROM_HERE,
|
| base::Bind(&InterceptNetworkTransactions, url_request_context_getter,
|
| + // Note that we can't use an error that'll invoke the link
|
| + // doctor. In normal network error conditions that would
|
| + // work (because the link doctor fetch would also fail,
|
| + // putting us back in the main offline path), but
|
| + // SetUrlRequestMocksEnabled() has also specfied a link
|
| + // doctor mock, which will be accessible because it
|
| + // won't go through the network cache.
|
| net::ERR_FAILED));
|
|
|
| ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(
|
| - // With no navigation corrections to load, there's only one navigation.
|
| + // With no link doctor load, there's only one navigation.
|
| browser(), test_url, 1);
|
| EXPECT_TRUE(ProbeStaleCopyValue(true));
|
| EXPECT_NE(base::ASCIIToUTF16("Nocache Test Page"),
|
| @@ -766,6 +600,17 @@
|
| EXPECT_EQ(kRequestsToFail + 1, protocol_handler()->requests());
|
| }
|
|
|
| +// Returns Javascript code that executes plain text search for the page.
|
| +// Pass into content::ExecuteScriptAndExtractBool as |script| parameter.
|
| +std::string GetTextContentContainsStringScript(
|
| + const std::string& value_to_search) {
|
| + return base::StringPrintf(
|
| + "var textContent = document.body.textContent;"
|
| + "var hasError = textContent.indexOf('%s') >= 0;"
|
| + "domAutomationController.send(hasError);",
|
| + value_to_search.c_str());
|
| +}
|
| +
|
| // Protocol handler that fails all requests with net::ERR_ADDRESS_UNREACHABLE.
|
| class AddressUnreachableProtocolHandler
|
| : public net::URLRequestJobFactory::ProtocolHandler {
|
| @@ -786,36 +631,38 @@
|
| DISALLOW_COPY_AND_ASSIGN(AddressUnreachableProtocolHandler);
|
| };
|
|
|
| -// A test fixture that returns ERR_ADDRESS_UNREACHABLE for all navigation
|
| -// correction requests. ERR_NAME_NOT_RESOLVED is more typical, but need to use
|
| -// a different error for the correction service and the original page to
|
| -// validate the right page is being displayed.
|
| -class ErrorPageNavigationCorrectionsFailTest : public ErrorPageTest {
|
| +// A test fixture that returns ERR_ADDRESS_UNREACHABLE for all Link Doctor
|
| +// requests. ERR_NAME_NOT_RESOLVED is more typical, but need to use a different
|
| +// error for the Link Doctor and the original page to validate the right page
|
| +// is being displayed.
|
| +class ErrorPageLinkDoctorFailTest : public ErrorPageTest {
|
| public:
|
| // InProcessBrowserTest:
|
| virtual void SetUpOnMainThread() OVERRIDE {
|
| BrowserThread::PostTask(
|
| BrowserThread::IO, FROM_HERE,
|
| - base::Bind(&ErrorPageNavigationCorrectionsFailTest::AddFilters));
|
| + base::Bind(&ErrorPageLinkDoctorFailTest::AddFilters));
|
| }
|
|
|
| virtual void CleanUpOnMainThread() OVERRIDE {
|
| BrowserThread::PostTask(
|
| BrowserThread::IO, FROM_HERE,
|
| - base::Bind(&ErrorPageNavigationCorrectionsFailTest::RemoveFilters));
|
| + base::Bind(&ErrorPageLinkDoctorFailTest::RemoveFilters));
|
| }
|
|
|
| private:
|
| - // Adds a filter that causes all correction service requests to fail with
|
| - // ERR_ADDRESS_UNREACHABLE.
|
| + // Adds a filter that causes all requests for the Link Doctor's scheme and
|
| + // host to fail with ERR_ADDRESS_UNREACHABLE. Since the Link Doctor adds
|
| + // query strings, it's not enough to just fail exact matches.
|
| //
|
| // Also adds the content::URLRequestFailedJob filter.
|
| static void AddFilters() {
|
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
|
| content::URLRequestFailedJob::AddUrlHandler();
|
|
|
| - net::URLRequestFilter::GetInstance()->AddUrlProtocolHandler(
|
| - google_util::LinkDoctorBaseURL(),
|
| + net::URLRequestFilter::GetInstance()->AddHostnameProtocolHandler(
|
| + google_util::LinkDoctorBaseURL().scheme(),
|
| + google_util::LinkDoctorBaseURL().host(),
|
| scoped_ptr<net::URLRequestJobFactory::ProtocolHandler>(
|
| new AddressUnreachableProtocolHandler()));
|
| }
|
| @@ -826,25 +673,30 @@
|
| }
|
| };
|
|
|
| -// Make sure that when corrections fail to load, the network error page is
|
| +// Make sure that when the Link Doctor fails to load, the network error page is
|
| // successfully loaded.
|
| -IN_PROC_BROWSER_TEST_F(ErrorPageNavigationCorrectionsFailTest,
|
| - FetchCorrectionsFails) {
|
| +IN_PROC_BROWSER_TEST_F(ErrorPageLinkDoctorFailTest, LinkDoctorFail) {
|
| ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(
|
| browser(),
|
| URLRequestFailedJob::GetMockHttpUrl(net::ERR_NAME_NOT_RESOLVED),
|
| 2);
|
|
|
| - // Verify that the expected error page is being displayed.
|
| - ExpectDisplayingLocalErrorPage(browser(), net::ERR_NAME_NOT_RESOLVED);
|
| + // Verify that the expected error page is being displayed. Do this by making
|
| + // sure the original error code (ERR_NAME_NOT_RESOLVED) is displayed.
|
| + bool result = false;
|
| + EXPECT_TRUE(content::ExecuteScriptAndExtractBool(
|
| + browser()->tab_strip_model()->GetActiveWebContents(),
|
| + GetTextContentContainsStringScript("ERR_NAME_NOT_RESOLVED"),
|
| + &result));
|
| + EXPECT_TRUE(result);
|
| }
|
|
|
| -// Checks that when an error occurs and a corrections fail to load, the stale
|
| +// Checks that when an error occurs and a link doctor load fails, the stale
|
| // cache status of the page is correctly transferred, and we can load the
|
| // stale copy from the javascript. Most logic copied from StaleCacheStatus
|
| // above.
|
| -IN_PROC_BROWSER_TEST_F(ErrorPageNavigationCorrectionsFailTest,
|
| - StaleCacheStatusFailedCorrections) {
|
| +IN_PROC_BROWSER_TEST_F(ErrorPageLinkDoctorFailTest,
|
| + StaleCacheStatusFailedLinkDoctor) {
|
| ASSERT_TRUE(test_server()->Start());
|
| // Load cache with entry with "nocache" set, to create stale
|
| // cache.
|
| @@ -926,15 +778,19 @@
|
|
|
| // Make sure error page shows correct unicode for IDN.
|
| IN_PROC_BROWSER_TEST_F(ErrorPageForIDNTest, IDN) {
|
| - // ERR_UNSAFE_PORT will not trigger navigation corrections.
|
| + // ERR_UNSAFE_PORT will not trigger the link doctor.
|
| ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(
|
| browser(),
|
| URLRequestFailedJob::GetMockHttpUrlForHostname(net::ERR_UNSAFE_PORT,
|
| kHostname),
|
| 1);
|
|
|
| - ToggleHelpBox(browser());
|
| - EXPECT_TRUE(IsDisplayingText(browser(), kHostnameJSUnicode));
|
| + bool result = false;
|
| + EXPECT_TRUE(content::ExecuteScriptAndExtractBool(
|
| + browser()->tab_strip_model()->GetActiveWebContents(),
|
| + GetTextContentContainsStringScript(kHostnameJSUnicode),
|
| + &result));
|
| + EXPECT_TRUE(result);
|
| }
|
|
|
| } // namespace
|
|
|