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

Side by Side Diff: chrome/browser/errorpage_browsertest.cc

Issue 238783003: Merge 262846 "Revert 255617, due to it not tracking use of the link doctor page." (Closed) Base URL: svn://svn.chromium.org/chrome/branches/1916/src/
Patch Set: Created 6 years, 8 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/bind.h" 5 #include "base/bind.h"
6 #include "base/command_line.h" 6 #include "base/command_line.h"
7 #include "base/compiler_specific.h" 7 #include "base/compiler_specific.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/path_service.h"
11 #include "base/prefs/pref_service.h" 10 #include "base/prefs/pref_service.h"
12 #include "base/strings/stringprintf.h" 11 #include "base/strings/stringprintf.h"
13 #include "base/strings/utf_string_conversions.h" 12 #include "base/strings/utf_string_conversions.h"
14 #include "chrome/browser/browsing_data/browsing_data_helper.h" 13 #include "chrome/browser/browsing_data/browsing_data_helper.h"
15 #include "chrome/browser/browsing_data/browsing_data_remover.h" 14 #include "chrome/browser/browsing_data/browsing_data_remover.h"
16 #include "chrome/browser/google/google_util.h" 15 #include "chrome/browser/google/google_util.h"
17 #include "chrome/browser/net/url_request_mock_util.h" 16 #include "chrome/browser/net/url_request_mock_util.h"
18 #include "chrome/browser/profiles/profile.h" 17 #include "chrome/browser/profiles/profile.h"
19 #include "chrome/browser/ui/browser.h" 18 #include "chrome/browser/ui/browser.h"
20 #include "chrome/browser/ui/browser_commands.h" 19 #include "chrome/browser/ui/browser_commands.h"
21 #include "chrome/browser/ui/tabs/tab_strip_model.h" 20 #include "chrome/browser/ui/tabs/tab_strip_model.h"
22 #include "chrome/common/chrome_paths.h"
23 #include "chrome/common/chrome_switches.h" 21 #include "chrome/common/chrome_switches.h"
24 #include "chrome/common/pref_names.h" 22 #include "chrome/common/pref_names.h"
25 #include "chrome/test/base/in_process_browser_test.h" 23 #include "chrome/test/base/in_process_browser_test.h"
26 #include "chrome/test/base/ui_test_utils.h" 24 #include "chrome/test/base/ui_test_utils.h"
27 #include "content/public/browser/browser_thread.h" 25 #include "content/public/browser/browser_thread.h"
28 #include "content/public/browser/notification_service.h" 26 #include "content/public/browser/notification_service.h"
29 #include "content/public/browser/render_frame_host.h" 27 #include "content/public/browser/render_frame_host.h"
30 #include "content/public/browser/render_view_host.h" 28 #include "content/public/browser/render_view_host.h"
31 #include "content/public/browser/web_contents.h" 29 #include "content/public/browser/web_contents.h"
32 #include "content/public/browser/web_contents_observer.h" 30 #include "content/public/browser/web_contents_observer.h"
(...skipping 15 matching lines...) Expand all
48 #include "net/url_request/url_request_test_util.h" 46 #include "net/url_request/url_request_test_util.h"
49 47
50 using content::BrowserThread; 48 using content::BrowserThread;
51 using content::NavigationController; 49 using content::NavigationController;
52 using content::URLRequestFailedJob; 50 using content::URLRequestFailedJob;
53 using net::URLRequestJobFactory; 51 using net::URLRequestJobFactory;
54 using net::URLRequestTestJob; 52 using net::URLRequestTestJob;
55 53
56 namespace { 54 namespace {
57 55
58 // Returns true if |text| is displayed on the page |browser| is currently
59 // displaying. Uses "innerText", so will miss hidden text, and whitespace
60 // space handling may be weird.
61 bool WARN_UNUSED_RESULT IsDisplayingText(Browser* browser,
62 const std::string& text) {
63 std::string command = base::StringPrintf(
64 "var textContent = document.body.innerText;"
65 "var hasText = textContent.indexOf('%s') >= 0;"
66 "domAutomationController.send(hasText);",
67 text.c_str());
68 bool result = false;
69 EXPECT_TRUE(content::ExecuteScriptAndExtractBool(
70 browser->tab_strip_model()->GetActiveWebContents(), command, &result));
71 return result;
72 }
73
74 // Expands the more box on the currently displayed error page.
75 void ToggleHelpBox(Browser* browser) {
76 EXPECT_TRUE(content::ExecuteScript(
77 browser->tab_strip_model()->GetActiveWebContents(),
78 "document.getElementById('more-less-button').click();"));
79 }
80
81 // Returns true if |browser| is displaying the text representation of
82 // |error_code| on the current page.
83 bool WARN_UNUSED_RESULT IsDisplayingNetError(Browser* browser,
84 net::Error error_code) {
85 // Get the error as a string, and remove the leading "net::", which is not
86 // included on error pages.
87 std::string error_string = net::ErrorToString(error_code);
88 base::RemoveChars(error_string, "net:", &error_string);
89
90 return IsDisplayingText(browser, error_string);
91 }
92
93 // Checks that the local error page is being displayed, without remotely
94 // retrieved navigation corrections, and with the specified error code.
95 void ExpectDisplayingLocalErrorPage(Browser* browser, net::Error error_code) {
96 // Expand the help box so innerText will include text below the fold.
97 ToggleHelpBox(browser);
98
99 EXPECT_TRUE(IsDisplayingNetError(browser, error_code));
100
101 // Locally generated error pages should not have navigation corrections.
102 EXPECT_FALSE(IsDisplayingText(browser, "http://correction1/"));
103 EXPECT_FALSE(IsDisplayingText(browser, "http://correction2/"));
104
105 // Locally generated error pages should not have a populated search box.
106 bool search_box_populated = false;
107 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
108 browser->tab_strip_model()->GetActiveWebContents(),
109 "var searchText = document.getElementById('search-box').value;"
110 "domAutomationController.send(searchText == 'search query');",
111 &search_box_populated));
112 EXPECT_FALSE(search_box_populated);
113 }
114
115 // Checks that an error page with information retrieved from the navigation
116 // correction service is being displayed, with the specified specified error
117 // code.
118 void ExpectDisplayingNavigationCorrections(Browser* browser,
119 net::Error error_code) {
120 // Expand the help box so innerText will include text below the fold.
121 ToggleHelpBox(browser);
122
123 EXPECT_TRUE(IsDisplayingNetError(browser, error_code));
124
125 // Check that the mock navigation corrections are displayed.
126 EXPECT_TRUE(IsDisplayingText(browser, "http://correction1/"));
127 EXPECT_TRUE(IsDisplayingText(browser, "http://correction2/"));
128
129 // Check that the search box is populated correctly.
130 bool search_box_populated = false;
131 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
132 browser->tab_strip_model()->GetActiveWebContents(),
133 "var searchText = document.getElementById('search-box').value;"
134 "domAutomationController.send(searchText == 'search query');",
135 &search_box_populated));
136 EXPECT_TRUE(search_box_populated);
137 }
138
139 // A protocol handler that fails a configurable number of requests, then 56 // A protocol handler that fails a configurable number of requests, then
140 // succeeds all requests after that, keeping count of failures and successes. 57 // succeeds all requests after that, keeping count of failures and successes.
141 class FailFirstNRequestsProtocolHandler 58 class FailFirstNRequestsProtocolHandler
142 : public URLRequestJobFactory::ProtocolHandler { 59 : public URLRequestJobFactory::ProtocolHandler {
143 public: 60 public:
144 FailFirstNRequestsProtocolHandler(const GURL& url, int requests_to_fail) 61 FailFirstNRequestsProtocolHandler(const GURL& url, int requests_to_fail)
145 : url_(url), requests_(0), failures_(0), 62 : url_(url), requests_(0), failures_(0),
146 requests_to_fail_(requests_to_fail) {} 63 requests_to_fail_(requests_to_fail) {}
147 virtual ~FailFirstNRequestsProtocolHandler() {} 64 virtual ~FailFirstNRequestsProtocolHandler() {}
148 65
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 150
234 // Navigates forward in the history and waits for |num_navigations| to occur, 151 // Navigates forward in the history and waits for |num_navigations| to occur,
235 // and the title to change to |expected_title|. 152 // and the title to change to |expected_title|.
236 void GoForwardAndWaitForTitle(const std::string& expected_title, 153 void GoForwardAndWaitForTitle(const std::string& expected_title,
237 int num_navigations) { 154 int num_navigations) {
238 NavigateHistoryAndWaitForTitle(expected_title, 155 NavigateHistoryAndWaitForTitle(expected_title,
239 num_navigations, 156 num_navigations,
240 HISTORY_NAVIGATE_FORWARD); 157 HISTORY_NAVIGATE_FORWARD);
241 } 158 }
242 159
243 void GoBackAndWaitForNavigations(int num_navigations) {
244 NavigateHistory(num_navigations, HISTORY_NAVIGATE_BACK);
245 }
246
247 void GoForwardAndWaitForNavigations(int num_navigations) {
248 NavigateHistory(num_navigations, HISTORY_NAVIGATE_FORWARD);
249 }
250
251 // Confirms that the javascript variable indicating whether or not we have 160 // Confirms that the javascript variable indicating whether or not we have
252 // a stale copy in the cache has been set to |expected|. 161 // a stale copy in the cache has been set to |expected|.
253 bool ProbeStaleCopyValue(bool expected) { 162 bool ProbeStaleCopyValue(bool expected) {
254 const char* js_cache_probe = 163 const char* js_cache_probe =
255 "try {\n" 164 "try {\n"
256 " domAutomationController.send(\n" 165 " domAutomationController.send(\n"
257 " templateData.staleCopyInCache ? 'yes' : 'no');\n" 166 " templateData.staleCopyInCache ? 'yes' : 'no');\n"
258 "} catch (e) {\n" 167 "} catch (e) {\n"
259 " domAutomationController.send(e.message);\n" 168 " domAutomationController.send(e.message);\n"
260 "}\n"; 169 "}\n";
(...skipping 26 matching lines...) Expand all
287 js_reload_script, 196 js_reload_script,
288 &result); 197 &result);
289 EXPECT_TRUE(ret); 198 EXPECT_TRUE(ret);
290 if (!ret) 199 if (!ret)
291 return testing::AssertionFailure(); 200 return testing::AssertionFailure();
292 return ("success" == result ? testing::AssertionSuccess() : 201 return ("success" == result ? testing::AssertionSuccess() :
293 (testing::AssertionFailure() << "Exception message is " << result)); 202 (testing::AssertionFailure() << "Exception message is " << result));
294 } 203 }
295 204
296 protected: 205 protected:
297 static void EnableMocks(const GURL& search_url) {
298 chrome_browser_net::SetUrlRequestMocksEnabled(true);
299
300 // Add a mock for the search engine the error page will use.
301 base::FilePath root_http;
302 PathService::Get(chrome::DIR_TEST_DATA, &root_http);
303 content::URLRequestMockHTTPJob::AddHostnameToFileHandler(
304 search_url.host(), root_http.AppendASCII("title3.html"));
305 }
306
307 virtual void SetUpOnMainThread() OVERRIDE { 206 virtual void SetUpOnMainThread() OVERRIDE {
308 BrowserThread::PostTask( 207 BrowserThread::PostTask(
309 BrowserThread::IO, FROM_HERE, 208 BrowserThread::IO, FROM_HERE,
310 base::Bind(&ErrorPageTest::EnableMocks, 209 base::Bind(&chrome_browser_net::SetUrlRequestMocksEnabled, true));
311 google_util::GetGoogleSearchURL(browser()->profile())));
312 } 210 }
313 211
314 // Returns a GURL that results in a DNS error. 212 // Returns a GURL that results in a DNS error.
315 GURL GetDnsErrorURL() const { 213 GURL GetDnsErrorURL() const {
316 return URLRequestFailedJob::GetMockHttpUrl(net::ERR_NAME_NOT_RESOLVED); 214 return URLRequestFailedJob::GetMockHttpUrl(net::ERR_NAME_NOT_RESOLVED);
317 } 215 }
318 216
319 private: 217 private:
320 // Navigates the browser the indicated direction in the history and waits for 218 // Navigates the browser the indicated direction in the history and waits for
321 // |num_navigations| to occur and the title to change to |expected_title|. 219 // |num_navigations| to occur and the title to change to |expected_title|.
322 void NavigateHistoryAndWaitForTitle(const std::string& expected_title, 220 void NavigateHistoryAndWaitForTitle(const std::string& expected_title,
323 int num_navigations, 221 int num_navigations,
324 HistoryNavigationDirection direction) { 222 HistoryNavigationDirection direction) {
325 content::TitleWatcher title_watcher( 223 content::TitleWatcher title_watcher(
326 browser()->tab_strip_model()->GetActiveWebContents(), 224 browser()->tab_strip_model()->GetActiveWebContents(),
327 base::ASCIIToUTF16(expected_title)); 225 base::ASCIIToUTF16(expected_title));
328 226
329 NavigateHistory(num_navigations, direction);
330
331 EXPECT_EQ(title_watcher.WaitAndGetTitle(),
332 base::ASCIIToUTF16(expected_title));
333 }
334
335 void NavigateHistory(int num_navigations,
336 HistoryNavigationDirection direction) {
337 content::TestNavigationObserver test_navigation_observer( 227 content::TestNavigationObserver test_navigation_observer(
338 browser()->tab_strip_model()->GetActiveWebContents(), 228 browser()->tab_strip_model()->GetActiveWebContents(),
339 num_navigations); 229 num_navigations);
340 if (direction == HISTORY_NAVIGATE_BACK) { 230 if (direction == HISTORY_NAVIGATE_BACK) {
341 chrome::GoBack(browser(), CURRENT_TAB); 231 chrome::GoBack(browser(), CURRENT_TAB);
342 } else if (direction == HISTORY_NAVIGATE_FORWARD) { 232 } else if (direction == HISTORY_NAVIGATE_FORWARD) {
343 chrome::GoForward(browser(), CURRENT_TAB); 233 chrome::GoForward(browser(), CURRENT_TAB);
344 } else { 234 } else {
345 FAIL(); 235 FAIL();
346 } 236 }
347 test_navigation_observer.Wait(); 237 test_navigation_observer.Wait();
238
239 EXPECT_EQ(title_watcher.WaitAndGetTitle(),
240 base::ASCIIToUTF16(expected_title));
348 } 241 }
349 }; 242 };
350 243
351 class TestFailProvisionalLoadObserver : public content::WebContentsObserver { 244 class TestFailProvisionalLoadObserver : public content::WebContentsObserver {
352 public: 245 public:
353 explicit TestFailProvisionalLoadObserver(content::WebContents* contents) 246 explicit TestFailProvisionalLoadObserver(content::WebContents* contents)
354 : content::WebContentsObserver(contents) {} 247 : content::WebContentsObserver(contents) {}
355 virtual ~TestFailProvisionalLoadObserver() {} 248 virtual ~TestFailProvisionalLoadObserver() {}
356 249
357 // This method is invoked when the provisional load failed. 250 // This method is invoked when the provisional load failed.
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
390 // See crbug.com/109669 283 // See crbug.com/109669
391 #if defined(USE_AURA) || defined(OS_WIN) 284 #if defined(USE_AURA) || defined(OS_WIN)
392 #define MAYBE_DNSError_Basic DISABLED_DNSError_Basic 285 #define MAYBE_DNSError_Basic DISABLED_DNSError_Basic
393 #else 286 #else
394 #define MAYBE_DNSError_Basic DNSError_Basic 287 #define MAYBE_DNSError_Basic DNSError_Basic
395 #endif 288 #endif
396 // Test that a DNS error occuring in the main frame redirects to an error page. 289 // Test that a DNS error occuring in the main frame redirects to an error page.
397 IN_PROC_BROWSER_TEST_F(ErrorPageTest, MAYBE_DNSError_Basic) { 290 IN_PROC_BROWSER_TEST_F(ErrorPageTest, MAYBE_DNSError_Basic) {
398 // The first navigation should fail, and the second one should be the error 291 // The first navigation should fail, and the second one should be the error
399 // page. 292 // page.
400 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( 293 NavigateToURLAndWaitForTitle(GetDnsErrorURL(), "Mock Link Doctor", 2);
401 browser(), GetDnsErrorURL(), 2);
402 ExpectDisplayingNavigationCorrections(browser(), net::ERR_NAME_NOT_RESOLVED);
403 } 294 }
404 295
405 // See crbug.com/109669 296 // See crbug.com/109669
406 #if defined(USE_AURA) 297 #if defined(USE_AURA)
407 #define MAYBE_DNSError_GoBack1 DISABLED_DNSError_GoBack1 298 #define MAYBE_DNSError_GoBack1 DISABLED_DNSError_GoBack1
408 #else 299 #else
409 #define MAYBE_DNSError_GoBack1 DNSError_GoBack1 300 #define MAYBE_DNSError_GoBack1 DNSError_GoBack1
410 #endif 301 #endif
411 302
412 // Test that a DNS error occuring in the main frame does not result in an 303 // Test that a DNS error occuring in the main frame does not result in an
413 // additional session history entry. 304 // additional session history entry.
414 IN_PROC_BROWSER_TEST_F(ErrorPageTest, MAYBE_DNSError_GoBack1) { 305 IN_PROC_BROWSER_TEST_F(ErrorPageTest, MAYBE_DNSError_GoBack1) {
415 NavigateToFileURL(FILE_PATH_LITERAL("title2.html")); 306 NavigateToFileURL(FILE_PATH_LITERAL("title2.html"));
416 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( 307 NavigateToURLAndWaitForTitle(GetDnsErrorURL(), "Mock Link Doctor", 2);
417 browser(), GetDnsErrorURL(), 2);
418 ExpectDisplayingNavigationCorrections(browser(), net::ERR_NAME_NOT_RESOLVED);
419 GoBackAndWaitForTitle("Title Of Awesomeness", 1); 308 GoBackAndWaitForTitle("Title Of Awesomeness", 1);
420 } 309 }
421 310
422 // See crbug.com/109669 311 // See crbug.com/109669
423 #if defined(USE_AURA) 312 #if defined(USE_AURA)
424 #define MAYBE_DNSError_GoBack2 DISABLED_DNSError_GoBack2 313 #define MAYBE_DNSError_GoBack2 DISABLED_DNSError_GoBack2
425 #else 314 #else
426 #define MAYBE_DNSError_GoBack2 DNSError_GoBack2 315 #define MAYBE_DNSError_GoBack2 DNSError_GoBack2
427 #endif 316 #endif
428 // Test that a DNS error occuring in the main frame does not result in an 317 // Test that a DNS error occuring in the main frame does not result in an
429 // additional session history entry. 318 // additional session history entry.
430 IN_PROC_BROWSER_TEST_F(ErrorPageTest, DNSError_GoBack2) { 319 IN_PROC_BROWSER_TEST_F(ErrorPageTest, DNSError_GoBack2) {
431 NavigateToFileURL(FILE_PATH_LITERAL("title2.html")); 320 NavigateToFileURL(FILE_PATH_LITERAL("title2.html"));
432 321
433 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( 322 NavigateToURLAndWaitForTitle(GetDnsErrorURL(), "Mock Link Doctor", 2);
434 browser(), GetDnsErrorURL(), 2);
435 ExpectDisplayingNavigationCorrections(browser(), net::ERR_NAME_NOT_RESOLVED);
436
437 NavigateToFileURL(FILE_PATH_LITERAL("title3.html")); 323 NavigateToFileURL(FILE_PATH_LITERAL("title3.html"));
438 324
439 GoBackAndWaitForNavigations(2); 325 GoBackAndWaitForTitle("Mock Link Doctor", 2);
440 ExpectDisplayingNavigationCorrections(browser(), net::ERR_NAME_NOT_RESOLVED);
441
442 GoBackAndWaitForTitle("Title Of Awesomeness", 1); 326 GoBackAndWaitForTitle("Title Of Awesomeness", 1);
443 } 327 }
444 328
445 // See crbug.com/109669 329 // See crbug.com/109669
446 #if defined(USE_AURA) 330 #if defined(USE_AURA)
447 #define MAYBE_DNSError_GoBack2AndForward DISABLED_DNSError_GoBack2AndForward 331 #define MAYBE_DNSError_GoBack2AndForward DISABLED_DNSError_GoBack2AndForward
448 #else 332 #else
449 #define MAYBE_DNSError_GoBack2AndForward DNSError_GoBack2AndForward 333 #define MAYBE_DNSError_GoBack2AndForward DNSError_GoBack2AndForward
450 #endif 334 #endif
451 // Test that a DNS error occuring in the main frame does not result in an 335 // Test that a DNS error occuring in the main frame does not result in an
452 // additional session history entry. 336 // additional session history entry.
453 IN_PROC_BROWSER_TEST_F(ErrorPageTest, DNSError_GoBack2AndForward) { 337 IN_PROC_BROWSER_TEST_F(ErrorPageTest, DNSError_GoBack2AndForward) {
454 NavigateToFileURL(FILE_PATH_LITERAL("title2.html")); 338 NavigateToFileURL(FILE_PATH_LITERAL("title2.html"));
455 339
456 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( 340 NavigateToURLAndWaitForTitle(GetDnsErrorURL(), "Mock Link Doctor", 2);
457 browser(), GetDnsErrorURL(), 2);
458 ExpectDisplayingNavigationCorrections(browser(), net::ERR_NAME_NOT_RESOLVED);
459
460 NavigateToFileURL(FILE_PATH_LITERAL("title3.html")); 341 NavigateToFileURL(FILE_PATH_LITERAL("title3.html"));
461 342
462 GoBackAndWaitForNavigations(2); 343 GoBackAndWaitForTitle("Mock Link Doctor", 2);
463 ExpectDisplayingNavigationCorrections(browser(), net::ERR_NAME_NOT_RESOLVED);
464
465 GoBackAndWaitForTitle("Title Of Awesomeness", 1); 344 GoBackAndWaitForTitle("Title Of Awesomeness", 1);
466 345
467 GoForwardAndWaitForNavigations(2); 346 GoForwardAndWaitForTitle("Mock Link Doctor", 2);
468 ExpectDisplayingNavigationCorrections(browser(), net::ERR_NAME_NOT_RESOLVED);
469 } 347 }
470 348
471 // See crbug.com/109669 349 // See crbug.com/109669
472 #if defined(USE_AURA) 350 #if defined(USE_AURA)
473 #define MAYBE_DNSError_GoBack2Forward2 DISABLED_DNSError_GoBack2Forward2 351 #define MAYBE_DNSError_GoBack2Forward2 DISABLED_DNSError_GoBack2Forward2
474 #else 352 #else
475 #define MAYBE_DNSError_GoBack2Forward2 DNSError_GoBack2Forward2 353 #define MAYBE_DNSError_GoBack2Forward2 DNSError_GoBack2Forward2
476 #endif 354 #endif
477 // Test that a DNS error occuring in the main frame does not result in an 355 // Test that a DNS error occuring in the main frame does not result in an
478 // additional session history entry. 356 // additional session history entry.
479 IN_PROC_BROWSER_TEST_F(ErrorPageTest, DNSError_GoBack2Forward2) { 357 IN_PROC_BROWSER_TEST_F(ErrorPageTest, DNSError_GoBack2Forward2) {
480 NavigateToFileURL(FILE_PATH_LITERAL("title3.html")); 358 NavigateToFileURL(FILE_PATH_LITERAL("title3.html"));
481 359
482 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( 360 NavigateToURLAndWaitForTitle(GetDnsErrorURL(), "Mock Link Doctor", 2);
483 browser(), GetDnsErrorURL(), 2);
484 ExpectDisplayingNavigationCorrections(browser(), net::ERR_NAME_NOT_RESOLVED);
485
486 NavigateToFileURL(FILE_PATH_LITERAL("title2.html")); 361 NavigateToFileURL(FILE_PATH_LITERAL("title2.html"));
487 362
488 GoBackAndWaitForNavigations(2); 363 GoBackAndWaitForTitle("Mock Link Doctor", 2);
489 ExpectDisplayingNavigationCorrections(browser(), net::ERR_NAME_NOT_RESOLVED);
490
491 GoBackAndWaitForTitle("Title Of More Awesomeness", 1); 364 GoBackAndWaitForTitle("Title Of More Awesomeness", 1);
492 365
493 GoForwardAndWaitForNavigations(2); 366 GoForwardAndWaitForTitle("Mock Link Doctor", 2);
494 ExpectDisplayingNavigationCorrections(browser(), net::ERR_NAME_NOT_RESOLVED);
495
496 GoForwardAndWaitForTitle("Title Of Awesomeness", 1); 367 GoForwardAndWaitForTitle("Title Of Awesomeness", 1);
497 } 368 }
498 369
499 // See crbug.com/109669 370 // Test that a DNS error occuring in an iframe.
500 #if defined(USE_AURA)
501 #define MAYBE_DNSError_DoSearch DNSError_DoSearch
502 #else
503 #define MAYBE_DNSError_DoSearch DNSError_DoSearch
504 #endif
505 // Test that the search button on a DNS error page works.
506 IN_PROC_BROWSER_TEST_F(ErrorPageTest, MAYBE_DNSError_DoSearch) {
507 // The first navigation should fail, and the second one should be the error
508 // page.
509 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(
510 browser(), GetDnsErrorURL(), 2);
511 ExpectDisplayingNavigationCorrections(browser(), net::ERR_NAME_NOT_RESOLVED);
512
513 // Do a search and make sure the browser ends up at the right page.
514 content::TestNavigationObserver nav_observer(
515 browser()->tab_strip_model()->GetActiveWebContents(),
516 1);
517 content::TitleWatcher title_watcher(
518 browser()->tab_strip_model()->GetActiveWebContents(),
519 base::ASCIIToUTF16("Title Of More Awesomeness"));
520 ASSERT_TRUE(content::ExecuteScript(
521 browser()->tab_strip_model()->GetActiveWebContents(),
522 "document.getElementById('search-button').click();"));
523 nav_observer.Wait();
524 EXPECT_EQ(base::ASCIIToUTF16("Title Of More Awesomeness"),
525 title_watcher.WaitAndGetTitle());
526
527 // Check the path and query string.
528 std::string url;
529 ASSERT_TRUE(content::ExecuteScriptAndExtractString(
530 browser()->tab_strip_model()->GetActiveWebContents(),
531 "domAutomationController.send(window.location.href);",
532 &url));
533 EXPECT_EQ("/search", GURL(url).path());
534 EXPECT_EQ("q=search%20query", GURL(url).query());
535
536 // Go back to the error page, to make sure the history is correct.
537 GoBackAndWaitForNavigations(2);
538 ExpectDisplayingNavigationCorrections(browser(), net::ERR_NAME_NOT_RESOLVED);
539 }
540
541 // Test that a DNS error occuring in an iframe does not result in showing
542 // navigation corrections.
543 IN_PROC_BROWSER_TEST_F(ErrorPageTest, IFrameDNSError_Basic) { 371 IN_PROC_BROWSER_TEST_F(ErrorPageTest, IFrameDNSError_Basic) {
544 NavigateToURLAndWaitForTitle( 372 NavigateToURLAndWaitForTitle(
545 content::URLRequestMockHTTPJob::GetMockUrl( 373 content::URLRequestMockHTTPJob::GetMockUrl(
546 base::FilePath(FILE_PATH_LITERAL("iframe_dns_error.html"))), 374 base::FilePath(FILE_PATH_LITERAL("iframe_dns_error.html"))),
547 "Blah", 375 "Blah",
548 1); 376 1);
549 // We expect to have two history entries, since we started off with navigation 377 // We expect to have two history entries, since we started off with navigation
550 // to "about:blank" and then navigated to "iframe_dns_error.html". 378 // to "about:blank" and then navigated to "iframe_dns_error.html".
551 EXPECT_EQ(2, 379 EXPECT_EQ(2,
552 browser()->tab_strip_model()->GetActiveWebContents()-> 380 browser()->tab_strip_model()->GetActiveWebContents()->
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
641 content::NOTIFICATION_LOAD_STOP, 469 content::NOTIFICATION_LOAD_STOP,
642 content::Source<NavigationController>(&wc->GetController())); 470 content::Source<NavigationController>(&wc->GetController()));
643 wc->GetMainFrame()->ExecuteJavaScript(base::ASCIIToUTF16(script)); 471 wc->GetMainFrame()->ExecuteJavaScript(base::ASCIIToUTF16(script));
644 load_observer.Wait(); 472 load_observer.Wait();
645 473
646 EXPECT_EQ(fail_url, fail_observer.fail_url()); 474 EXPECT_EQ(fail_url, fail_observer.fail_url());
647 EXPECT_EQ(2, wc->GetController().GetEntryCount()); 475 EXPECT_EQ(2, wc->GetController().GetEntryCount());
648 } 476 }
649 } 477 }
650 478
651 // Checks that navigation corrections are not loaded when we receive an actual 479 // Checks that the Link Doctor is not loaded when we receive an actual 404 page.
652 // 404 page.
653 IN_PROC_BROWSER_TEST_F(ErrorPageTest, Page404) { 480 IN_PROC_BROWSER_TEST_F(ErrorPageTest, Page404) {
654 NavigateToURLAndWaitForTitle( 481 NavigateToURLAndWaitForTitle(
655 content::URLRequestMockHTTPJob::GetMockUrl( 482 content::URLRequestMockHTTPJob::GetMockUrl(
656 base::FilePath(FILE_PATH_LITERAL("page404.html"))), 483 base::FilePath(FILE_PATH_LITERAL("page404.html"))),
657 "SUCCESS", 484 "SUCCESS",
658 1); 485 1);
659 } 486 }
660 487
661 // Checks that when an error occurs, the stale cache status of the page 488 // Checks that when an error occurs, the stale cache status of the page
662 // is correctly transferred, and that stale cached copied can be loaded 489 // is correctly transferred, and that stale cached copied can be loaded
663 // from the javascript. 490 // from the javascript.
664 IN_PROC_BROWSER_TEST_F(ErrorPageTest, StaleCacheStatus) { 491 IN_PROC_BROWSER_TEST_F(ErrorPageTest, StaleCacheStatus) {
665 ASSERT_TRUE(test_server()->Start()); 492 ASSERT_TRUE(test_server()->Start());
666 // Load cache with entry with "nocache" set, to create stale 493 // Load cache with entry with "nocache" set, to create stale
667 // cache. 494 // cache.
668 GURL test_url(test_server()->GetURL("files/nocache.html")); 495 GURL test_url(test_server()->GetURL("files/nocache.html"));
669 NavigateToURLAndWaitForTitle(test_url, "Nocache Test Page", 1); 496 NavigateToURLAndWaitForTitle(test_url, "Nocache Test Page", 1);
670 497
671 // Reload same URL after forcing an error from the the network layer; 498 // Reload same URL after forcing an error from the the network layer;
672 // confirm that the error page is told the cached copy exists. 499 // confirm that the error page is told the cached copy exists.
673 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter = 500 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter =
674 browser()->profile()->GetRequestContext(); 501 browser()->profile()->GetRequestContext();
675 BrowserThread::PostTask( 502 BrowserThread::PostTask(
676 BrowserThread::IO, FROM_HERE, 503 BrowserThread::IO, FROM_HERE,
677 base::Bind(&InterceptNetworkTransactions, url_request_context_getter, 504 base::Bind(&InterceptNetworkTransactions, url_request_context_getter,
505 // Note that we can't use an error that'll invoke the link
506 // doctor. In normal network error conditions that would
507 // work (because the link doctor fetch would also fail,
508 // putting us back in the main offline path), but
509 // SetUrlRequestMocksEnabled() has also specfied a link
510 // doctor mock, which will be accessible because it
511 // won't go through the network cache.
678 net::ERR_FAILED)); 512 net::ERR_FAILED));
679 513
680 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( 514 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(
681 // With no navigation corrections to load, there's only one navigation. 515 // With no link doctor load, there's only one navigation.
682 browser(), test_url, 1); 516 browser(), test_url, 1);
683 EXPECT_TRUE(ProbeStaleCopyValue(true)); 517 EXPECT_TRUE(ProbeStaleCopyValue(true));
684 EXPECT_NE(base::ASCIIToUTF16("Nocache Test Page"), 518 EXPECT_NE(base::ASCIIToUTF16("Nocache Test Page"),
685 browser()->tab_strip_model()->GetActiveWebContents()->GetTitle()); 519 browser()->tab_strip_model()->GetActiveWebContents()->GetTitle());
686 520
687 // Confirm that loading the stale copy from the cache works. 521 // Confirm that loading the stale copy from the cache works.
688 content::TestNavigationObserver same_tab_observer( 522 content::TestNavigationObserver same_tab_observer(
689 browser()->tab_strip_model()->GetActiveWebContents(), 1); 523 browser()->tab_strip_model()->GetActiveWebContents(), 1);
690 ASSERT_TRUE(ReloadStaleCopyFromCache()); 524 ASSERT_TRUE(ReloadStaleCopyFromCache());
691 same_tab_observer.Wait(); 525 same_tab_observer.Wait();
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
759 InstallProtocolHandler(test_url, kRequestsToFail); 593 InstallProtocolHandler(test_url, kRequestsToFail);
760 NavigateToURLAndWaitForTitle(test_url, "Test One", kRequestsToFail + 1); 594 NavigateToURLAndWaitForTitle(test_url, "Test One", kRequestsToFail + 1);
761 // Note that the protocol handler updates these variables on the IO thread, 595 // Note that the protocol handler updates these variables on the IO thread,
762 // but this function reads them on the main thread. The requests have to be 596 // but this function reads them on the main thread. The requests have to be
763 // created (on the IO thread) before NavigateToURLAndWaitForTitle returns or 597 // created (on the IO thread) before NavigateToURLAndWaitForTitle returns or
764 // this becomes racey. 598 // this becomes racey.
765 EXPECT_EQ(kRequestsToFail, protocol_handler()->failures()); 599 EXPECT_EQ(kRequestsToFail, protocol_handler()->failures());
766 EXPECT_EQ(kRequestsToFail + 1, protocol_handler()->requests()); 600 EXPECT_EQ(kRequestsToFail + 1, protocol_handler()->requests());
767 } 601 }
768 602
603 // Returns Javascript code that executes plain text search for the page.
604 // Pass into content::ExecuteScriptAndExtractBool as |script| parameter.
605 std::string GetTextContentContainsStringScript(
606 const std::string& value_to_search) {
607 return base::StringPrintf(
608 "var textContent = document.body.textContent;"
609 "var hasError = textContent.indexOf('%s') >= 0;"
610 "domAutomationController.send(hasError);",
611 value_to_search.c_str());
612 }
613
769 // Protocol handler that fails all requests with net::ERR_ADDRESS_UNREACHABLE. 614 // Protocol handler that fails all requests with net::ERR_ADDRESS_UNREACHABLE.
770 class AddressUnreachableProtocolHandler 615 class AddressUnreachableProtocolHandler
771 : public net::URLRequestJobFactory::ProtocolHandler { 616 : public net::URLRequestJobFactory::ProtocolHandler {
772 public: 617 public:
773 AddressUnreachableProtocolHandler() {} 618 AddressUnreachableProtocolHandler() {}
774 virtual ~AddressUnreachableProtocolHandler() {} 619 virtual ~AddressUnreachableProtocolHandler() {}
775 620
776 // net::URLRequestJobFactory::ProtocolHandler: 621 // net::URLRequestJobFactory::ProtocolHandler:
777 virtual net::URLRequestJob* MaybeCreateJob( 622 virtual net::URLRequestJob* MaybeCreateJob(
778 net::URLRequest* request, 623 net::URLRequest* request,
779 net::NetworkDelegate* network_delegate) const OVERRIDE { 624 net::NetworkDelegate* network_delegate) const OVERRIDE {
780 return new URLRequestFailedJob(request, 625 return new URLRequestFailedJob(request,
781 network_delegate, 626 network_delegate,
782 net::ERR_ADDRESS_UNREACHABLE); 627 net::ERR_ADDRESS_UNREACHABLE);
783 } 628 }
784 629
785 private: 630 private:
786 DISALLOW_COPY_AND_ASSIGN(AddressUnreachableProtocolHandler); 631 DISALLOW_COPY_AND_ASSIGN(AddressUnreachableProtocolHandler);
787 }; 632 };
788 633
789 // A test fixture that returns ERR_ADDRESS_UNREACHABLE for all navigation 634 // A test fixture that returns ERR_ADDRESS_UNREACHABLE for all Link Doctor
790 // correction requests. ERR_NAME_NOT_RESOLVED is more typical, but need to use 635 // requests. ERR_NAME_NOT_RESOLVED is more typical, but need to use a different
791 // a different error for the correction service and the original page to 636 // error for the Link Doctor and the original page to validate the right page
792 // validate the right page is being displayed. 637 // is being displayed.
793 class ErrorPageNavigationCorrectionsFailTest : public ErrorPageTest { 638 class ErrorPageLinkDoctorFailTest : public ErrorPageTest {
794 public: 639 public:
795 // InProcessBrowserTest: 640 // InProcessBrowserTest:
796 virtual void SetUpOnMainThread() OVERRIDE { 641 virtual void SetUpOnMainThread() OVERRIDE {
797 BrowserThread::PostTask( 642 BrowserThread::PostTask(
798 BrowserThread::IO, FROM_HERE, 643 BrowserThread::IO, FROM_HERE,
799 base::Bind(&ErrorPageNavigationCorrectionsFailTest::AddFilters)); 644 base::Bind(&ErrorPageLinkDoctorFailTest::AddFilters));
800 } 645 }
801 646
802 virtual void CleanUpOnMainThread() OVERRIDE { 647 virtual void CleanUpOnMainThread() OVERRIDE {
803 BrowserThread::PostTask( 648 BrowserThread::PostTask(
804 BrowserThread::IO, FROM_HERE, 649 BrowserThread::IO, FROM_HERE,
805 base::Bind(&ErrorPageNavigationCorrectionsFailTest::RemoveFilters)); 650 base::Bind(&ErrorPageLinkDoctorFailTest::RemoveFilters));
806 } 651 }
807 652
808 private: 653 private:
809 // Adds a filter that causes all correction service requests to fail with 654 // Adds a filter that causes all requests for the Link Doctor's scheme and
810 // ERR_ADDRESS_UNREACHABLE. 655 // host to fail with ERR_ADDRESS_UNREACHABLE. Since the Link Doctor adds
656 // query strings, it's not enough to just fail exact matches.
811 // 657 //
812 // Also adds the content::URLRequestFailedJob filter. 658 // Also adds the content::URLRequestFailedJob filter.
813 static void AddFilters() { 659 static void AddFilters() {
814 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 660 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
815 content::URLRequestFailedJob::AddUrlHandler(); 661 content::URLRequestFailedJob::AddUrlHandler();
816 662
817 net::URLRequestFilter::GetInstance()->AddUrlProtocolHandler( 663 net::URLRequestFilter::GetInstance()->AddHostnameProtocolHandler(
818 google_util::LinkDoctorBaseURL(), 664 google_util::LinkDoctorBaseURL().scheme(),
665 google_util::LinkDoctorBaseURL().host(),
819 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler>( 666 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler>(
820 new AddressUnreachableProtocolHandler())); 667 new AddressUnreachableProtocolHandler()));
821 } 668 }
822 669
823 static void RemoveFilters() { 670 static void RemoveFilters() {
824 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 671 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
825 net::URLRequestFilter::GetInstance()->ClearHandlers(); 672 net::URLRequestFilter::GetInstance()->ClearHandlers();
826 } 673 }
827 }; 674 };
828 675
829 // Make sure that when corrections fail to load, the network error page is 676 // Make sure that when the Link Doctor fails to load, the network error page is
830 // successfully loaded. 677 // successfully loaded.
831 IN_PROC_BROWSER_TEST_F(ErrorPageNavigationCorrectionsFailTest, 678 IN_PROC_BROWSER_TEST_F(ErrorPageLinkDoctorFailTest, LinkDoctorFail) {
832 FetchCorrectionsFails) {
833 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( 679 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(
834 browser(), 680 browser(),
835 URLRequestFailedJob::GetMockHttpUrl(net::ERR_NAME_NOT_RESOLVED), 681 URLRequestFailedJob::GetMockHttpUrl(net::ERR_NAME_NOT_RESOLVED),
836 2); 682 2);
837 683
838 // Verify that the expected error page is being displayed. 684 // Verify that the expected error page is being displayed. Do this by making
839 ExpectDisplayingLocalErrorPage(browser(), net::ERR_NAME_NOT_RESOLVED); 685 // sure the original error code (ERR_NAME_NOT_RESOLVED) is displayed.
686 bool result = false;
687 EXPECT_TRUE(content::ExecuteScriptAndExtractBool(
688 browser()->tab_strip_model()->GetActiveWebContents(),
689 GetTextContentContainsStringScript("ERR_NAME_NOT_RESOLVED"),
690 &result));
691 EXPECT_TRUE(result);
840 } 692 }
841 693
842 // Checks that when an error occurs and a corrections fail to load, the stale 694 // Checks that when an error occurs and a link doctor load fails, the stale
843 // cache status of the page is correctly transferred, and we can load the 695 // cache status of the page is correctly transferred, and we can load the
844 // stale copy from the javascript. Most logic copied from StaleCacheStatus 696 // stale copy from the javascript. Most logic copied from StaleCacheStatus
845 // above. 697 // above.
846 IN_PROC_BROWSER_TEST_F(ErrorPageNavigationCorrectionsFailTest, 698 IN_PROC_BROWSER_TEST_F(ErrorPageLinkDoctorFailTest,
847 StaleCacheStatusFailedCorrections) { 699 StaleCacheStatusFailedLinkDoctor) {
848 ASSERT_TRUE(test_server()->Start()); 700 ASSERT_TRUE(test_server()->Start());
849 // Load cache with entry with "nocache" set, to create stale 701 // Load cache with entry with "nocache" set, to create stale
850 // cache. 702 // cache.
851 GURL test_url(test_server()->GetURL("files/nocache.html")); 703 GURL test_url(test_server()->GetURL("files/nocache.html"));
852 NavigateToURLAndWaitForTitle(test_url, "Nocache Test Page", 1); 704 NavigateToURLAndWaitForTitle(test_url, "Nocache Test Page", 1);
853 705
854 // Reload same URL after forcing an error from the the network layer; 706 // Reload same URL after forcing an error from the the network layer;
855 // confirm that the error page is told the cached copy exists. 707 // confirm that the error page is told the cached copy exists.
856 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter = 708 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter =
857 browser()->profile()->GetRequestContext(); 709 browser()->profile()->GetRequestContext();
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
919 }; 771 };
920 772
921 const char ErrorPageForIDNTest::kHostname[] = 773 const char ErrorPageForIDNTest::kHostname[] =
922 "xn--d1abbgf6aiiy.xn--p1ai"; 774 "xn--d1abbgf6aiiy.xn--p1ai";
923 const char ErrorPageForIDNTest::kHostnameJSUnicode[] = 775 const char ErrorPageForIDNTest::kHostnameJSUnicode[] =
924 "\\u043f\\u0440\\u0435\\u0437\\u0438\\u0434\\u0435\\u043d\\u0442." 776 "\\u043f\\u0440\\u0435\\u0437\\u0438\\u0434\\u0435\\u043d\\u0442."
925 "\\u0440\\u0444"; 777 "\\u0440\\u0444";
926 778
927 // Make sure error page shows correct unicode for IDN. 779 // Make sure error page shows correct unicode for IDN.
928 IN_PROC_BROWSER_TEST_F(ErrorPageForIDNTest, IDN) { 780 IN_PROC_BROWSER_TEST_F(ErrorPageForIDNTest, IDN) {
929 // ERR_UNSAFE_PORT will not trigger navigation corrections. 781 // ERR_UNSAFE_PORT will not trigger the link doctor.
930 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( 782 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(
931 browser(), 783 browser(),
932 URLRequestFailedJob::GetMockHttpUrlForHostname(net::ERR_UNSAFE_PORT, 784 URLRequestFailedJob::GetMockHttpUrlForHostname(net::ERR_UNSAFE_PORT,
933 kHostname), 785 kHostname),
934 1); 786 1);
935 787
936 ToggleHelpBox(browser()); 788 bool result = false;
937 EXPECT_TRUE(IsDisplayingText(browser(), kHostnameJSUnicode)); 789 EXPECT_TRUE(content::ExecuteScriptAndExtractBool(
790 browser()->tab_strip_model()->GetActiveWebContents(),
791 GetTextContentContainsStringScript(kHostnameJSUnicode),
792 &result));
793 EXPECT_TRUE(result);
938 } 794 }
939 795
940 } // namespace 796 } // namespace
OLDNEW
« 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