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

Unified Diff: chrome/browser/errorpage_browsertest.cc

Issue 137623011: Switch to using the new Link Doctor API. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Remove bonus line from a merge conflict Created 6 years, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/chromeos/offline/offline_load_page.cc ('k') | chrome/browser/google/google_util.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/errorpage_browsertest.cc
===================================================================
--- chrome/browser/errorpage_browsertest.cc (revision 253247)
+++ chrome/browser/errorpage_browsertest.cc (working copy)
@@ -3,6 +3,8 @@
// found in the LICENSE file.
#include "base/bind.h"
+#include "base/compiler_specific.h"
+#include "base/path_service.h"
#include "base/prefs/pref_service.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
@@ -14,6 +16,7 @@
#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/pref_names.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/ui_test_utils.h"
@@ -41,6 +44,87 @@
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);
+}
+
class ErrorPageTest : public InProcessBrowserTest {
public:
enum HistoryNavigationDirection {
@@ -89,6 +173,14 @@
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) {
@@ -116,10 +208,21 @@
}
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(&chrome_browser_net::SetUrlRequestMocksEnabled, true));
+ base::Bind(&ErrorPageTest::EnableMocks,
+ google_util::GetGoogleSearchURL(browser()->profile())));
}
// Returns a GURL that results in a DNS error.
@@ -137,6 +240,14 @@
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);
@@ -148,9 +259,6 @@
FAIL();
}
test_navigation_observer.Wait();
-
- EXPECT_EQ(title_watcher.WaitAndGetTitle(),
- base::ASCIIToUTF16(expected_title));
}
};
@@ -203,7 +311,9 @@
IN_PROC_BROWSER_TEST_F(ErrorPageTest, MAYBE_DNSError_Basic) {
// The first navigation should fail, and the second one should be the error
// page.
- NavigateToURLAndWaitForTitle(GetDnsErrorURL(), "Mock Link Doctor", 2);
+ ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(
+ browser(), GetDnsErrorURL(), 2);
+ ExpectDisplayingNavigationCorrections(browser(), net::ERR_NAME_NOT_RESOLVED);
}
// See crbug.com/109669
@@ -217,7 +327,9 @@
// additional session history entry.
IN_PROC_BROWSER_TEST_F(ErrorPageTest, MAYBE_DNSError_GoBack1) {
NavigateToFileURL(FILE_PATH_LITERAL("title2.html"));
- NavigateToURLAndWaitForTitle(GetDnsErrorURL(), "Mock Link Doctor", 2);
+ ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(
+ browser(), GetDnsErrorURL(), 2);
+ ExpectDisplayingNavigationCorrections(browser(), net::ERR_NAME_NOT_RESOLVED);
GoBackAndWaitForTitle("Title Of Awesomeness", 1);
}
@@ -232,10 +344,15 @@
IN_PROC_BROWSER_TEST_F(ErrorPageTest, DNSError_GoBack2) {
NavigateToFileURL(FILE_PATH_LITERAL("title2.html"));
- NavigateToURLAndWaitForTitle(GetDnsErrorURL(), "Mock Link Doctor", 2);
+ ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(
+ browser(), GetDnsErrorURL(), 2);
+ ExpectDisplayingNavigationCorrections(browser(), net::ERR_NAME_NOT_RESOLVED);
+
NavigateToFileURL(FILE_PATH_LITERAL("title3.html"));
- GoBackAndWaitForTitle("Mock Link Doctor", 2);
+ GoBackAndWaitForNavigations(2);
+ ExpectDisplayingNavigationCorrections(browser(), net::ERR_NAME_NOT_RESOLVED);
+
GoBackAndWaitForTitle("Title Of Awesomeness", 1);
}
@@ -250,13 +367,19 @@
IN_PROC_BROWSER_TEST_F(ErrorPageTest, DNSError_GoBack2AndForward) {
NavigateToFileURL(FILE_PATH_LITERAL("title2.html"));
- NavigateToURLAndWaitForTitle(GetDnsErrorURL(), "Mock Link Doctor", 2);
+ ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(
+ browser(), GetDnsErrorURL(), 2);
+ ExpectDisplayingNavigationCorrections(browser(), net::ERR_NAME_NOT_RESOLVED);
+
NavigateToFileURL(FILE_PATH_LITERAL("title3.html"));
- GoBackAndWaitForTitle("Mock Link Doctor", 2);
+ GoBackAndWaitForNavigations(2);
+ ExpectDisplayingNavigationCorrections(browser(), net::ERR_NAME_NOT_RESOLVED);
+
GoBackAndWaitForTitle("Title Of Awesomeness", 1);
- GoForwardAndWaitForTitle("Mock Link Doctor", 2);
+ GoForwardAndWaitForNavigations(2);
+ ExpectDisplayingNavigationCorrections(browser(), net::ERR_NAME_NOT_RESOLVED);
}
// See crbug.com/109669
@@ -270,17 +393,67 @@
IN_PROC_BROWSER_TEST_F(ErrorPageTest, DNSError_GoBack2Forward2) {
NavigateToFileURL(FILE_PATH_LITERAL("title3.html"));
- NavigateToURLAndWaitForTitle(GetDnsErrorURL(), "Mock Link Doctor", 2);
+ ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(
+ browser(), GetDnsErrorURL(), 2);
+ ExpectDisplayingNavigationCorrections(browser(), net::ERR_NAME_NOT_RESOLVED);
+
NavigateToFileURL(FILE_PATH_LITERAL("title2.html"));
- GoBackAndWaitForTitle("Mock Link Doctor", 2);
+ GoBackAndWaitForNavigations(2);
+ ExpectDisplayingNavigationCorrections(browser(), net::ERR_NAME_NOT_RESOLVED);
+
GoBackAndWaitForTitle("Title Of More Awesomeness", 1);
- GoForwardAndWaitForTitle("Mock Link Doctor", 2);
+ GoForwardAndWaitForNavigations(2);
+ ExpectDisplayingNavigationCorrections(browser(), net::ERR_NAME_NOT_RESOLVED);
+
GoForwardAndWaitForTitle("Title Of Awesomeness", 1);
}
-// Test that a DNS error occuring in an iframe.
+// 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.
IN_PROC_BROWSER_TEST_F(ErrorPageTest, IFrameDNSError_Basic) {
NavigateToURLAndWaitForTitle(
content::URLRequestMockHTTPJob::GetMockUrl(
@@ -392,7 +565,8 @@
}
}
-// Checks that the Link Doctor is not loaded when we receive an actual 404 page.
+// Checks that navigation corrections are not loaded when we receive an actual
+// 404 page.
IN_PROC_BROWSER_TEST_F(ErrorPageTest, Page404) {
NavigateToURLAndWaitForTitle(
content::URLRequestMockHTTPJob::GetMockUrl(
@@ -417,17 +591,10 @@
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 link doctor load, there's only one navigation.
+ // With no navigation corrections to load, there's only one navigation.
browser(), test_url, 1);
EXPECT_TRUE(ProbeStaleCopyValue(true));
@@ -442,17 +609,6 @@
EXPECT_TRUE(ProbeStaleCopyValue(false));
}
-// 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 {
@@ -473,38 +629,36 @@
DISALLOW_COPY_AND_ASSIGN(AddressUnreachableProtocolHandler);
};
-// 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 {
+// 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 {
public:
// InProcessBrowserTest:
virtual void SetUpOnMainThread() OVERRIDE {
BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE,
- base::Bind(&ErrorPageLinkDoctorFailTest::AddFilters));
+ base::Bind(&ErrorPageNavigationCorrectionsFailTest::AddFilters));
}
virtual void CleanUpOnMainThread() OVERRIDE {
BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE,
- base::Bind(&ErrorPageLinkDoctorFailTest::RemoveFilters));
+ base::Bind(&ErrorPageNavigationCorrectionsFailTest::RemoveFilters));
}
private:
- // 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.
+ // Adds a filter that causes all correction service requests to fail with
+ // ERR_ADDRESS_UNREACHABLE.
//
// Also adds the content::URLRequestFailedJob filter.
static void AddFilters() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
content::URLRequestFailedJob::AddUrlHandler();
- net::URLRequestFilter::GetInstance()->AddHostnameProtocolHandler(
- google_util::LinkDoctorBaseURL().scheme(),
- google_util::LinkDoctorBaseURL().host(),
+ net::URLRequestFilter::GetInstance()->AddUrlProtocolHandler(
+ google_util::LinkDoctorBaseURL(),
scoped_ptr<net::URLRequestJobFactory::ProtocolHandler>(
new AddressUnreachableProtocolHandler()));
}
@@ -515,29 +669,24 @@
}
};
-// Make sure that when the Link Doctor fails to load, the network error page is
+// Make sure that when corrections fail to load, the network error page is
// successfully loaded.
-IN_PROC_BROWSER_TEST_F(ErrorPageLinkDoctorFailTest, LinkDoctorFail) {
+IN_PROC_BROWSER_TEST_F(ErrorPageNavigationCorrectionsFailTest,
+ FetchCorrectionsFails) {
ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(
browser(),
URLRequestFailedJob::GetMockHttpUrl(net::ERR_NAME_NOT_RESOLVED),
2);
- // 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);
+ // Verify that the expected error page is being displayed.
+ ExpectDisplayingLocalErrorPage(browser(), net::ERR_NAME_NOT_RESOLVED);
}
-// Checks that when an error occurs and a link doctor load fails, the stale
+// Checks that when an error occurs and a corrections fail to load, the stale
// cache status of the page is correctly transferred. Most logic copied
// from StaleCacheStatus above.
-IN_PROC_BROWSER_TEST_F(ErrorPageLinkDoctorFailTest,
- StaleCacheStatusFailedLinkDoctor) {
+IN_PROC_BROWSER_TEST_F(ErrorPageNavigationCorrectionsFailTest,
+ StaleCacheStatusFailedCorrections) {
ASSERT_TRUE(test_server()->Start());
// Load cache with entry with "nocache" set, to create stale
// cache.
@@ -611,19 +760,15 @@
// Make sure error page shows correct unicode for IDN.
IN_PROC_BROWSER_TEST_F(ErrorPageForIDNTest, IDN) {
- // ERR_UNSAFE_PORT will not trigger the link doctor.
+ // ERR_UNSAFE_PORT will not trigger navigation corrections.
ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(
browser(),
URLRequestFailedJob::GetMockHttpUrlForHostname(net::ERR_UNSAFE_PORT,
kHostname),
1);
- bool result = false;
- EXPECT_TRUE(content::ExecuteScriptAndExtractBool(
- browser()->tab_strip_model()->GetActiveWebContents(),
- GetTextContentContainsStringScript(kHostnameJSUnicode),
- &result));
- EXPECT_TRUE(result);
+ ToggleHelpBox(browser());
+ EXPECT_TRUE(IsDisplayingText(browser(), kHostnameJSUnicode));
}
} // namespace
« no previous file with comments | « chrome/browser/chromeos/offline/offline_load_page.cc ('k') | chrome/browser/google/google_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698