summaryrefslogtreecommitdiffstats
path: root/chrome/browser/errorpage_browsertest.cc
diff options
context:
space:
mode:
authormmenke@chromium.org <mmenke@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-04-09 22:49:33 +0000
committermmenke@chromium.org <mmenke@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-04-09 22:49:33 +0000
commitee7d24ed35647b9c41dca4791a01db8097d9b08e (patch)
tree9e8bebdcde8a4454eced4da8318ebba647fe2d71 /chrome/browser/errorpage_browsertest.cc
parentf65bf17a74cb083be28a5f5f550a676efbd98370 (diff)
downloadchromium_src-ee7d24ed35647b9c41dca4791a01db8097d9b08e.zip
chromium_src-ee7d24ed35647b9c41dca4791a01db8097d9b08e.tar.gz
chromium_src-ee7d24ed35647b9c41dca4791a01db8097d9b08e.tar.bz2
Revert 255617, due to it not tracking use of the link doctor page properly.
Not reverting the string changes, because the new strings work with the old file, and we've passed string freeze. > Switch to using the new Link Doctor API. > > The new API allows Link Doctor results to be integrated into Chrome's > own error pages. BUG=64832, 260709 TBR=mmenke@chromium.org Originally Landed: https://src.chromium.org/viewvc/chrome?view=rev&revision=255617 Review URL: https://codereview.chromium.org/228803002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@262846 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/errorpage_browsertest.cc')
-rw-r--r--chrome/browser/errorpage_browsertest.cc280
1 files changed, 68 insertions, 212 deletions
diff --git a/chrome/browser/errorpage_browsertest.cc b/chrome/browser/errorpage_browsertest.cc
index a82698f..cc95ab7 100644
--- a/chrome/browser/errorpage_browsertest.cc
+++ b/chrome/browser/errorpage_browsertest.cc
@@ -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 @@ using net::URLRequestTestJob;
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 @@ class ErrorPageTest : public InProcessBrowserTest {
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 @@ class ErrorPageTest : public InProcessBrowserTest {
}
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 @@ class ErrorPageTest : public InProcessBrowserTest {
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 @@ class ErrorPageTest : public InProcessBrowserTest {
FAIL();
}
test_navigation_observer.Wait();
+
+ EXPECT_EQ(title_watcher.WaitAndGetTitle(),
+ base::ASCIIToUTF16(expected_title));
}
};
@@ -397,9 +290,7 @@ void InterceptNetworkTransactions(net::URLRequestContextGetter* getter,
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 @@ IN_PROC_BROWSER_TEST_F(ErrorPageTest, MAYBE_DNSError_Basic) {
// 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, MAYBE_DNSError_GoBack1) {
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_GoBack2) {
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_GoBack2AndForward) {
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 @@ IN_PROC_BROWSER_TEST_F(ErrorPageTest, IFrameDNSError_JavaScript) {
}
}
-// 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 @@ IN_PROC_BROWSER_TEST_F(ErrorPageTest, StaleCacheStatus) {
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 @@ IN_PROC_BROWSER_TEST_F(ErrorPageAutoReloadTest, AutoReload) {
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 @@ class AddressUnreachableProtocolHandler
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 @@ class ErrorPageNavigationCorrectionsFailTest : public ErrorPageTest {
}
};
-// 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 @@ const char ErrorPageForIDNTest::kHostnameJSUnicode[] =
// 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