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

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

Issue 235883010: Revert 262846, as the revert has now been merged to M35. (Closed) Base URL: svn://svn.chromium.org/chrome/
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"
10 #include "base/prefs/pref_service.h" 11 #include "base/prefs/pref_service.h"
11 #include "base/strings/stringprintf.h" 12 #include "base/strings/stringprintf.h"
12 #include "base/strings/utf_string_conversions.h" 13 #include "base/strings/utf_string_conversions.h"
13 #include "chrome/browser/browsing_data/browsing_data_helper.h" 14 #include "chrome/browser/browsing_data/browsing_data_helper.h"
14 #include "chrome/browser/browsing_data/browsing_data_remover.h" 15 #include "chrome/browser/browsing_data/browsing_data_remover.h"
15 #include "chrome/browser/google/google_util.h" 16 #include "chrome/browser/google/google_util.h"
16 #include "chrome/browser/net/url_request_mock_util.h" 17 #include "chrome/browser/net/url_request_mock_util.h"
17 #include "chrome/browser/profiles/profile.h" 18 #include "chrome/browser/profiles/profile.h"
18 #include "chrome/browser/ui/browser.h" 19 #include "chrome/browser/ui/browser.h"
19 #include "chrome/browser/ui/browser_commands.h" 20 #include "chrome/browser/ui/browser_commands.h"
20 #include "chrome/browser/ui/tabs/tab_strip_model.h" 21 #include "chrome/browser/ui/tabs/tab_strip_model.h"
22 #include "chrome/common/chrome_paths.h"
21 #include "chrome/common/chrome_switches.h" 23 #include "chrome/common/chrome_switches.h"
22 #include "chrome/common/pref_names.h" 24 #include "chrome/common/pref_names.h"
23 #include "chrome/test/base/in_process_browser_test.h" 25 #include "chrome/test/base/in_process_browser_test.h"
24 #include "chrome/test/base/ui_test_utils.h" 26 #include "chrome/test/base/ui_test_utils.h"
25 #include "content/public/browser/browser_thread.h" 27 #include "content/public/browser/browser_thread.h"
26 #include "content/public/browser/notification_service.h" 28 #include "content/public/browser/notification_service.h"
27 #include "content/public/browser/render_frame_host.h" 29 #include "content/public/browser/render_frame_host.h"
28 #include "content/public/browser/render_view_host.h" 30 #include "content/public/browser/render_view_host.h"
29 #include "content/public/browser/web_contents.h" 31 #include "content/public/browser/web_contents.h"
30 #include "content/public/browser/web_contents_observer.h" 32 #include "content/public/browser/web_contents_observer.h"
(...skipping 15 matching lines...) Expand all
46 #include "net/url_request/url_request_test_util.h" 48 #include "net/url_request/url_request_test_util.h"
47 49
48 using content::BrowserThread; 50 using content::BrowserThread;
49 using content::NavigationController; 51 using content::NavigationController;
50 using content::URLRequestFailedJob; 52 using content::URLRequestFailedJob;
51 using net::URLRequestJobFactory; 53 using net::URLRequestJobFactory;
52 using net::URLRequestTestJob; 54 using net::URLRequestTestJob;
53 55
54 namespace { 56 namespace {
55 57
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
56 // A protocol handler that fails a configurable number of requests, then 139 // A protocol handler that fails a configurable number of requests, then
57 // succeeds all requests after that, keeping count of failures and successes. 140 // succeeds all requests after that, keeping count of failures and successes.
58 class FailFirstNRequestsProtocolHandler 141 class FailFirstNRequestsProtocolHandler
59 : public URLRequestJobFactory::ProtocolHandler { 142 : public URLRequestJobFactory::ProtocolHandler {
60 public: 143 public:
61 FailFirstNRequestsProtocolHandler(const GURL& url, int requests_to_fail) 144 FailFirstNRequestsProtocolHandler(const GURL& url, int requests_to_fail)
62 : url_(url), requests_(0), failures_(0), 145 : url_(url), requests_(0), failures_(0),
63 requests_to_fail_(requests_to_fail) {} 146 requests_to_fail_(requests_to_fail) {}
64 virtual ~FailFirstNRequestsProtocolHandler() {} 147 virtual ~FailFirstNRequestsProtocolHandler() {}
65 148
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 233
151 // Navigates forward in the history and waits for |num_navigations| to occur, 234 // Navigates forward in the history and waits for |num_navigations| to occur,
152 // and the title to change to |expected_title|. 235 // and the title to change to |expected_title|.
153 void GoForwardAndWaitForTitle(const std::string& expected_title, 236 void GoForwardAndWaitForTitle(const std::string& expected_title,
154 int num_navigations) { 237 int num_navigations) {
155 NavigateHistoryAndWaitForTitle(expected_title, 238 NavigateHistoryAndWaitForTitle(expected_title,
156 num_navigations, 239 num_navigations,
157 HISTORY_NAVIGATE_FORWARD); 240 HISTORY_NAVIGATE_FORWARD);
158 } 241 }
159 242
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
160 // Confirms that the javascript variable indicating whether or not we have 251 // Confirms that the javascript variable indicating whether or not we have
161 // a stale copy in the cache has been set to |expected|. 252 // a stale copy in the cache has been set to |expected|.
162 bool ProbeStaleCopyValue(bool expected) { 253 bool ProbeStaleCopyValue(bool expected) {
163 const char* js_cache_probe = 254 const char* js_cache_probe =
164 "try {\n" 255 "try {\n"
165 " domAutomationController.send(\n" 256 " domAutomationController.send(\n"
166 " templateData.staleCopyInCache ? 'yes' : 'no');\n" 257 " templateData.staleCopyInCache ? 'yes' : 'no');\n"
167 "} catch (e) {\n" 258 "} catch (e) {\n"
168 " domAutomationController.send(e.message);\n" 259 " domAutomationController.send(e.message);\n"
169 "}\n"; 260 "}\n";
(...skipping 26 matching lines...) Expand all
196 js_reload_script, 287 js_reload_script,
197 &result); 288 &result);
198 EXPECT_TRUE(ret); 289 EXPECT_TRUE(ret);
199 if (!ret) 290 if (!ret)
200 return testing::AssertionFailure(); 291 return testing::AssertionFailure();
201 return ("success" == result ? testing::AssertionSuccess() : 292 return ("success" == result ? testing::AssertionSuccess() :
202 (testing::AssertionFailure() << "Exception message is " << result)); 293 (testing::AssertionFailure() << "Exception message is " << result));
203 } 294 }
204 295
205 protected: 296 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
206 virtual void SetUpOnMainThread() OVERRIDE { 307 virtual void SetUpOnMainThread() OVERRIDE {
207 BrowserThread::PostTask( 308 BrowserThread::PostTask(
208 BrowserThread::IO, FROM_HERE, 309 BrowserThread::IO, FROM_HERE,
209 base::Bind(&chrome_browser_net::SetUrlRequestMocksEnabled, true)); 310 base::Bind(&ErrorPageTest::EnableMocks,
311 google_util::GetGoogleSearchURL(browser()->profile())));
210 } 312 }
211 313
212 // Returns a GURL that results in a DNS error. 314 // Returns a GURL that results in a DNS error.
213 GURL GetDnsErrorURL() const { 315 GURL GetDnsErrorURL() const {
214 return URLRequestFailedJob::GetMockHttpUrl(net::ERR_NAME_NOT_RESOLVED); 316 return URLRequestFailedJob::GetMockHttpUrl(net::ERR_NAME_NOT_RESOLVED);
215 } 317 }
216 318
217 private: 319 private:
218 // Navigates the browser the indicated direction in the history and waits for 320 // Navigates the browser the indicated direction in the history and waits for
219 // |num_navigations| to occur and the title to change to |expected_title|. 321 // |num_navigations| to occur and the title to change to |expected_title|.
220 void NavigateHistoryAndWaitForTitle(const std::string& expected_title, 322 void NavigateHistoryAndWaitForTitle(const std::string& expected_title,
221 int num_navigations, 323 int num_navigations,
222 HistoryNavigationDirection direction) { 324 HistoryNavigationDirection direction) {
223 content::TitleWatcher title_watcher( 325 content::TitleWatcher title_watcher(
224 browser()->tab_strip_model()->GetActiveWebContents(), 326 browser()->tab_strip_model()->GetActiveWebContents(),
225 base::ASCIIToUTF16(expected_title)); 327 base::ASCIIToUTF16(expected_title));
226 328
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) {
227 content::TestNavigationObserver test_navigation_observer( 337 content::TestNavigationObserver test_navigation_observer(
228 browser()->tab_strip_model()->GetActiveWebContents(), 338 browser()->tab_strip_model()->GetActiveWebContents(),
229 num_navigations); 339 num_navigations);
230 if (direction == HISTORY_NAVIGATE_BACK) { 340 if (direction == HISTORY_NAVIGATE_BACK) {
231 chrome::GoBack(browser(), CURRENT_TAB); 341 chrome::GoBack(browser(), CURRENT_TAB);
232 } else if (direction == HISTORY_NAVIGATE_FORWARD) { 342 } else if (direction == HISTORY_NAVIGATE_FORWARD) {
233 chrome::GoForward(browser(), CURRENT_TAB); 343 chrome::GoForward(browser(), CURRENT_TAB);
234 } else { 344 } else {
235 FAIL(); 345 FAIL();
236 } 346 }
237 test_navigation_observer.Wait(); 347 test_navigation_observer.Wait();
238
239 EXPECT_EQ(title_watcher.WaitAndGetTitle(),
240 base::ASCIIToUTF16(expected_title));
241 } 348 }
242 }; 349 };
243 350
244 class TestFailProvisionalLoadObserver : public content::WebContentsObserver { 351 class TestFailProvisionalLoadObserver : public content::WebContentsObserver {
245 public: 352 public:
246 explicit TestFailProvisionalLoadObserver(content::WebContents* contents) 353 explicit TestFailProvisionalLoadObserver(content::WebContents* contents)
247 : content::WebContentsObserver(contents) {} 354 : content::WebContentsObserver(contents) {}
248 virtual ~TestFailProvisionalLoadObserver() {} 355 virtual ~TestFailProvisionalLoadObserver() {}
249 356
250 // This method is invoked when the provisional load failed. 357 // This method is invoked when the provisional load failed.
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 // See crbug.com/109669 390 // See crbug.com/109669
284 #if defined(USE_AURA) 391 #if defined(USE_AURA)
285 #define MAYBE_DNSError_Basic DISABLED_DNSError_Basic 392 #define MAYBE_DNSError_Basic DISABLED_DNSError_Basic
286 #else 393 #else
287 #define MAYBE_DNSError_Basic DNSError_Basic 394 #define MAYBE_DNSError_Basic DNSError_Basic
288 #endif 395 #endif
289 // Test that a DNS error occuring in the main frame redirects to an error page. 396 // Test that a DNS error occuring in the main frame redirects to an error page.
290 IN_PROC_BROWSER_TEST_F(ErrorPageTest, MAYBE_DNSError_Basic) { 397 IN_PROC_BROWSER_TEST_F(ErrorPageTest, MAYBE_DNSError_Basic) {
291 // The first navigation should fail, and the second one should be the error 398 // The first navigation should fail, and the second one should be the error
292 // page. 399 // page.
293 NavigateToURLAndWaitForTitle(GetDnsErrorURL(), "Mock Link Doctor", 2); 400 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(
401 browser(), GetDnsErrorURL(), 2);
402 ExpectDisplayingNavigationCorrections(browser(), net::ERR_NAME_NOT_RESOLVED);
294 } 403 }
295 404
296 // See crbug.com/109669 405 // See crbug.com/109669
297 #if defined(USE_AURA) 406 #if defined(USE_AURA)
298 #define MAYBE_DNSError_GoBack1 DISABLED_DNSError_GoBack1 407 #define MAYBE_DNSError_GoBack1 DISABLED_DNSError_GoBack1
299 #else 408 #else
300 #define MAYBE_DNSError_GoBack1 DNSError_GoBack1 409 #define MAYBE_DNSError_GoBack1 DNSError_GoBack1
301 #endif 410 #endif
302 411
303 // Test that a DNS error occuring in the main frame does not result in an 412 // Test that a DNS error occuring in the main frame does not result in an
304 // additional session history entry. 413 // additional session history entry.
305 IN_PROC_BROWSER_TEST_F(ErrorPageTest, MAYBE_DNSError_GoBack1) { 414 IN_PROC_BROWSER_TEST_F(ErrorPageTest, MAYBE_DNSError_GoBack1) {
306 NavigateToFileURL(FILE_PATH_LITERAL("title2.html")); 415 NavigateToFileURL(FILE_PATH_LITERAL("title2.html"));
307 NavigateToURLAndWaitForTitle(GetDnsErrorURL(), "Mock Link Doctor", 2); 416 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(
417 browser(), GetDnsErrorURL(), 2);
418 ExpectDisplayingNavigationCorrections(browser(), net::ERR_NAME_NOT_RESOLVED);
308 GoBackAndWaitForTitle("Title Of Awesomeness", 1); 419 GoBackAndWaitForTitle("Title Of Awesomeness", 1);
309 } 420 }
310 421
311 // See crbug.com/109669 422 // See crbug.com/109669
312 #if defined(USE_AURA) 423 #if defined(USE_AURA)
313 #define MAYBE_DNSError_GoBack2 DISABLED_DNSError_GoBack2 424 #define MAYBE_DNSError_GoBack2 DISABLED_DNSError_GoBack2
314 #else 425 #else
315 #define MAYBE_DNSError_GoBack2 DNSError_GoBack2 426 #define MAYBE_DNSError_GoBack2 DNSError_GoBack2
316 #endif 427 #endif
317 // Test that a DNS error occuring in the main frame does not result in an 428 // Test that a DNS error occuring in the main frame does not result in an
318 // additional session history entry. 429 // additional session history entry.
319 IN_PROC_BROWSER_TEST_F(ErrorPageTest, DNSError_GoBack2) { 430 IN_PROC_BROWSER_TEST_F(ErrorPageTest, DNSError_GoBack2) {
320 NavigateToFileURL(FILE_PATH_LITERAL("title2.html")); 431 NavigateToFileURL(FILE_PATH_LITERAL("title2.html"));
321 432
322 NavigateToURLAndWaitForTitle(GetDnsErrorURL(), "Mock Link Doctor", 2); 433 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(
434 browser(), GetDnsErrorURL(), 2);
435 ExpectDisplayingNavigationCorrections(browser(), net::ERR_NAME_NOT_RESOLVED);
436
323 NavigateToFileURL(FILE_PATH_LITERAL("title3.html")); 437 NavigateToFileURL(FILE_PATH_LITERAL("title3.html"));
324 438
325 GoBackAndWaitForTitle("Mock Link Doctor", 2); 439 GoBackAndWaitForNavigations(2);
440 ExpectDisplayingNavigationCorrections(browser(), net::ERR_NAME_NOT_RESOLVED);
441
326 GoBackAndWaitForTitle("Title Of Awesomeness", 1); 442 GoBackAndWaitForTitle("Title Of Awesomeness", 1);
327 } 443 }
328 444
329 // See crbug.com/109669 445 // See crbug.com/109669
330 #if defined(USE_AURA) 446 #if defined(USE_AURA)
331 #define MAYBE_DNSError_GoBack2AndForward DISABLED_DNSError_GoBack2AndForward 447 #define MAYBE_DNSError_GoBack2AndForward DISABLED_DNSError_GoBack2AndForward
332 #else 448 #else
333 #define MAYBE_DNSError_GoBack2AndForward DNSError_GoBack2AndForward 449 #define MAYBE_DNSError_GoBack2AndForward DNSError_GoBack2AndForward
334 #endif 450 #endif
335 // Test that a DNS error occuring in the main frame does not result in an 451 // Test that a DNS error occuring in the main frame does not result in an
336 // additional session history entry. 452 // additional session history entry.
337 IN_PROC_BROWSER_TEST_F(ErrorPageTest, DNSError_GoBack2AndForward) { 453 IN_PROC_BROWSER_TEST_F(ErrorPageTest, DNSError_GoBack2AndForward) {
338 NavigateToFileURL(FILE_PATH_LITERAL("title2.html")); 454 NavigateToFileURL(FILE_PATH_LITERAL("title2.html"));
339 455
340 NavigateToURLAndWaitForTitle(GetDnsErrorURL(), "Mock Link Doctor", 2); 456 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(
457 browser(), GetDnsErrorURL(), 2);
458 ExpectDisplayingNavigationCorrections(browser(), net::ERR_NAME_NOT_RESOLVED);
459
341 NavigateToFileURL(FILE_PATH_LITERAL("title3.html")); 460 NavigateToFileURL(FILE_PATH_LITERAL("title3.html"));
342 461
343 GoBackAndWaitForTitle("Mock Link Doctor", 2); 462 GoBackAndWaitForNavigations(2);
463 ExpectDisplayingNavigationCorrections(browser(), net::ERR_NAME_NOT_RESOLVED);
464
344 GoBackAndWaitForTitle("Title Of Awesomeness", 1); 465 GoBackAndWaitForTitle("Title Of Awesomeness", 1);
345 466
346 GoForwardAndWaitForTitle("Mock Link Doctor", 2); 467 GoForwardAndWaitForNavigations(2);
468 ExpectDisplayingNavigationCorrections(browser(), net::ERR_NAME_NOT_RESOLVED);
347 } 469 }
348 470
349 // See crbug.com/109669 471 // See crbug.com/109669
350 #if defined(USE_AURA) 472 #if defined(USE_AURA)
351 #define MAYBE_DNSError_GoBack2Forward2 DISABLED_DNSError_GoBack2Forward2 473 #define MAYBE_DNSError_GoBack2Forward2 DISABLED_DNSError_GoBack2Forward2
352 #else 474 #else
353 #define MAYBE_DNSError_GoBack2Forward2 DNSError_GoBack2Forward2 475 #define MAYBE_DNSError_GoBack2Forward2 DNSError_GoBack2Forward2
354 #endif 476 #endif
355 // Test that a DNS error occuring in the main frame does not result in an 477 // Test that a DNS error occuring in the main frame does not result in an
356 // additional session history entry. 478 // additional session history entry.
357 IN_PROC_BROWSER_TEST_F(ErrorPageTest, DNSError_GoBack2Forward2) { 479 IN_PROC_BROWSER_TEST_F(ErrorPageTest, DNSError_GoBack2Forward2) {
358 NavigateToFileURL(FILE_PATH_LITERAL("title3.html")); 480 NavigateToFileURL(FILE_PATH_LITERAL("title3.html"));
359 481
360 NavigateToURLAndWaitForTitle(GetDnsErrorURL(), "Mock Link Doctor", 2); 482 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(
483 browser(), GetDnsErrorURL(), 2);
484 ExpectDisplayingNavigationCorrections(browser(), net::ERR_NAME_NOT_RESOLVED);
485
361 NavigateToFileURL(FILE_PATH_LITERAL("title2.html")); 486 NavigateToFileURL(FILE_PATH_LITERAL("title2.html"));
362 487
363 GoBackAndWaitForTitle("Mock Link Doctor", 2); 488 GoBackAndWaitForNavigations(2);
489 ExpectDisplayingNavigationCorrections(browser(), net::ERR_NAME_NOT_RESOLVED);
490
364 GoBackAndWaitForTitle("Title Of More Awesomeness", 1); 491 GoBackAndWaitForTitle("Title Of More Awesomeness", 1);
365 492
366 GoForwardAndWaitForTitle("Mock Link Doctor", 2); 493 GoForwardAndWaitForNavigations(2);
494 ExpectDisplayingNavigationCorrections(browser(), net::ERR_NAME_NOT_RESOLVED);
495
367 GoForwardAndWaitForTitle("Title Of Awesomeness", 1); 496 GoForwardAndWaitForTitle("Title Of Awesomeness", 1);
368 } 497 }
369 498
370 // Test that a DNS error occuring in an iframe. 499 // See crbug.com/109669
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.
371 IN_PROC_BROWSER_TEST_F(ErrorPageTest, IFrameDNSError_Basic) { 543 IN_PROC_BROWSER_TEST_F(ErrorPageTest, IFrameDNSError_Basic) {
372 NavigateToURLAndWaitForTitle( 544 NavigateToURLAndWaitForTitle(
373 content::URLRequestMockHTTPJob::GetMockUrl( 545 content::URLRequestMockHTTPJob::GetMockUrl(
374 base::FilePath(FILE_PATH_LITERAL("iframe_dns_error.html"))), 546 base::FilePath(FILE_PATH_LITERAL("iframe_dns_error.html"))),
375 "Blah", 547 "Blah",
376 1); 548 1);
377 // We expect to have two history entries, since we started off with navigation 549 // We expect to have two history entries, since we started off with navigation
378 // to "about:blank" and then navigated to "iframe_dns_error.html". 550 // to "about:blank" and then navigated to "iframe_dns_error.html".
379 EXPECT_EQ(2, 551 EXPECT_EQ(2,
380 browser()->tab_strip_model()->GetActiveWebContents()-> 552 browser()->tab_strip_model()->GetActiveWebContents()->
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
469 content::NOTIFICATION_LOAD_STOP, 641 content::NOTIFICATION_LOAD_STOP,
470 content::Source<NavigationController>(&wc->GetController())); 642 content::Source<NavigationController>(&wc->GetController()));
471 wc->GetMainFrame()->ExecuteJavaScript(base::ASCIIToUTF16(script)); 643 wc->GetMainFrame()->ExecuteJavaScript(base::ASCIIToUTF16(script));
472 load_observer.Wait(); 644 load_observer.Wait();
473 645
474 EXPECT_EQ(fail_url, fail_observer.fail_url()); 646 EXPECT_EQ(fail_url, fail_observer.fail_url());
475 EXPECT_EQ(2, wc->GetController().GetEntryCount()); 647 EXPECT_EQ(2, wc->GetController().GetEntryCount());
476 } 648 }
477 } 649 }
478 650
479 // Checks that the Link Doctor is not loaded when we receive an actual 404 page. 651 // Checks that navigation corrections are not loaded when we receive an actual
652 // 404 page.
480 IN_PROC_BROWSER_TEST_F(ErrorPageTest, Page404) { 653 IN_PROC_BROWSER_TEST_F(ErrorPageTest, Page404) {
481 NavigateToURLAndWaitForTitle( 654 NavigateToURLAndWaitForTitle(
482 content::URLRequestMockHTTPJob::GetMockUrl( 655 content::URLRequestMockHTTPJob::GetMockUrl(
483 base::FilePath(FILE_PATH_LITERAL("page404.html"))), 656 base::FilePath(FILE_PATH_LITERAL("page404.html"))),
484 "SUCCESS", 657 "SUCCESS",
485 1); 658 1);
486 } 659 }
487 660
488 // Checks that when an error occurs, the stale cache status of the page 661 // Checks that when an error occurs, the stale cache status of the page
489 // is correctly transferred, and that stale cached copied can be loaded 662 // is correctly transferred, and that stale cached copied can be loaded
490 // from the javascript. 663 // from the javascript.
491 IN_PROC_BROWSER_TEST_F(ErrorPageTest, StaleCacheStatus) { 664 IN_PROC_BROWSER_TEST_F(ErrorPageTest, StaleCacheStatus) {
492 ASSERT_TRUE(test_server()->Start()); 665 ASSERT_TRUE(test_server()->Start());
493 // Load cache with entry with "nocache" set, to create stale 666 // Load cache with entry with "nocache" set, to create stale
494 // cache. 667 // cache.
495 GURL test_url(test_server()->GetURL("files/nocache.html")); 668 GURL test_url(test_server()->GetURL("files/nocache.html"));
496 NavigateToURLAndWaitForTitle(test_url, "Nocache Test Page", 1); 669 NavigateToURLAndWaitForTitle(test_url, "Nocache Test Page", 1);
497 670
498 // Reload same URL after forcing an error from the the network layer; 671 // Reload same URL after forcing an error from the the network layer;
499 // confirm that the error page is told the cached copy exists. 672 // confirm that the error page is told the cached copy exists.
500 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter = 673 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter =
501 browser()->profile()->GetRequestContext(); 674 browser()->profile()->GetRequestContext();
502 BrowserThread::PostTask( 675 BrowserThread::PostTask(
503 BrowserThread::IO, FROM_HERE, 676 BrowserThread::IO, FROM_HERE,
504 base::Bind(&InterceptNetworkTransactions, url_request_context_getter, 677 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.
512 net::ERR_FAILED)); 678 net::ERR_FAILED));
513 679
514 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( 680 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(
515 // With no link doctor load, there's only one navigation. 681 // With no navigation corrections to load, there's only one navigation.
516 browser(), test_url, 1); 682 browser(), test_url, 1);
517 EXPECT_TRUE(ProbeStaleCopyValue(true)); 683 EXPECT_TRUE(ProbeStaleCopyValue(true));
518 EXPECT_NE(base::ASCIIToUTF16("Nocache Test Page"), 684 EXPECT_NE(base::ASCIIToUTF16("Nocache Test Page"),
519 browser()->tab_strip_model()->GetActiveWebContents()->GetTitle()); 685 browser()->tab_strip_model()->GetActiveWebContents()->GetTitle());
520 686
521 // Confirm that loading the stale copy from the cache works. 687 // Confirm that loading the stale copy from the cache works.
522 content::TestNavigationObserver same_tab_observer( 688 content::TestNavigationObserver same_tab_observer(
523 browser()->tab_strip_model()->GetActiveWebContents(), 1); 689 browser()->tab_strip_model()->GetActiveWebContents(), 1);
524 ASSERT_TRUE(ReloadStaleCopyFromCache()); 690 ASSERT_TRUE(ReloadStaleCopyFromCache());
525 same_tab_observer.Wait(); 691 same_tab_observer.Wait();
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
593 InstallProtocolHandler(test_url, kRequestsToFail); 759 InstallProtocolHandler(test_url, kRequestsToFail);
594 NavigateToURLAndWaitForTitle(test_url, "Test One", kRequestsToFail + 1); 760 NavigateToURLAndWaitForTitle(test_url, "Test One", kRequestsToFail + 1);
595 // Note that the protocol handler updates these variables on the IO thread, 761 // Note that the protocol handler updates these variables on the IO thread,
596 // but this function reads them on the main thread. The requests have to be 762 // but this function reads them on the main thread. The requests have to be
597 // created (on the IO thread) before NavigateToURLAndWaitForTitle returns or 763 // created (on the IO thread) before NavigateToURLAndWaitForTitle returns or
598 // this becomes racey. 764 // this becomes racey.
599 EXPECT_EQ(kRequestsToFail, protocol_handler()->failures()); 765 EXPECT_EQ(kRequestsToFail, protocol_handler()->failures());
600 EXPECT_EQ(kRequestsToFail + 1, protocol_handler()->requests()); 766 EXPECT_EQ(kRequestsToFail + 1, protocol_handler()->requests());
601 } 767 }
602 768
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
614 // Protocol handler that fails all requests with net::ERR_ADDRESS_UNREACHABLE. 769 // Protocol handler that fails all requests with net::ERR_ADDRESS_UNREACHABLE.
615 class AddressUnreachableProtocolHandler 770 class AddressUnreachableProtocolHandler
616 : public net::URLRequestJobFactory::ProtocolHandler { 771 : public net::URLRequestJobFactory::ProtocolHandler {
617 public: 772 public:
618 AddressUnreachableProtocolHandler() {} 773 AddressUnreachableProtocolHandler() {}
619 virtual ~AddressUnreachableProtocolHandler() {} 774 virtual ~AddressUnreachableProtocolHandler() {}
620 775
621 // net::URLRequestJobFactory::ProtocolHandler: 776 // net::URLRequestJobFactory::ProtocolHandler:
622 virtual net::URLRequestJob* MaybeCreateJob( 777 virtual net::URLRequestJob* MaybeCreateJob(
623 net::URLRequest* request, 778 net::URLRequest* request,
624 net::NetworkDelegate* network_delegate) const OVERRIDE { 779 net::NetworkDelegate* network_delegate) const OVERRIDE {
625 return new URLRequestFailedJob(request, 780 return new URLRequestFailedJob(request,
626 network_delegate, 781 network_delegate,
627 net::ERR_ADDRESS_UNREACHABLE); 782 net::ERR_ADDRESS_UNREACHABLE);
628 } 783 }
629 784
630 private: 785 private:
631 DISALLOW_COPY_AND_ASSIGN(AddressUnreachableProtocolHandler); 786 DISALLOW_COPY_AND_ASSIGN(AddressUnreachableProtocolHandler);
632 }; 787 };
633 788
634 // A test fixture that returns ERR_ADDRESS_UNREACHABLE for all Link Doctor 789 // A test fixture that returns ERR_ADDRESS_UNREACHABLE for all navigation
635 // requests. ERR_NAME_NOT_RESOLVED is more typical, but need to use a different 790 // correction requests. ERR_NAME_NOT_RESOLVED is more typical, but need to use
636 // error for the Link Doctor and the original page to validate the right page 791 // a different error for the correction service and the original page to
637 // is being displayed. 792 // validate the right page is being displayed.
638 class ErrorPageLinkDoctorFailTest : public ErrorPageTest { 793 class ErrorPageNavigationCorrectionsFailTest : public ErrorPageTest {
639 public: 794 public:
640 // InProcessBrowserTest: 795 // InProcessBrowserTest:
641 virtual void SetUpOnMainThread() OVERRIDE { 796 virtual void SetUpOnMainThread() OVERRIDE {
642 BrowserThread::PostTask( 797 BrowserThread::PostTask(
643 BrowserThread::IO, FROM_HERE, 798 BrowserThread::IO, FROM_HERE,
644 base::Bind(&ErrorPageLinkDoctorFailTest::AddFilters)); 799 base::Bind(&ErrorPageNavigationCorrectionsFailTest::AddFilters));
645 } 800 }
646 801
647 virtual void CleanUpOnMainThread() OVERRIDE { 802 virtual void CleanUpOnMainThread() OVERRIDE {
648 BrowserThread::PostTask( 803 BrowserThread::PostTask(
649 BrowserThread::IO, FROM_HERE, 804 BrowserThread::IO, FROM_HERE,
650 base::Bind(&ErrorPageLinkDoctorFailTest::RemoveFilters)); 805 base::Bind(&ErrorPageNavigationCorrectionsFailTest::RemoveFilters));
651 } 806 }
652 807
653 private: 808 private:
654 // Adds a filter that causes all requests for the Link Doctor's scheme and 809 // Adds a filter that causes all correction service requests to fail with
655 // host to fail with ERR_ADDRESS_UNREACHABLE. Since the Link Doctor adds 810 // ERR_ADDRESS_UNREACHABLE.
656 // query strings, it's not enough to just fail exact matches.
657 // 811 //
658 // Also adds the content::URLRequestFailedJob filter. 812 // Also adds the content::URLRequestFailedJob filter.
659 static void AddFilters() { 813 static void AddFilters() {
660 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 814 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
661 content::URLRequestFailedJob::AddUrlHandler(); 815 content::URLRequestFailedJob::AddUrlHandler();
662 816
663 net::URLRequestFilter::GetInstance()->AddHostnameProtocolHandler( 817 net::URLRequestFilter::GetInstance()->AddUrlProtocolHandler(
664 google_util::LinkDoctorBaseURL().scheme(), 818 google_util::LinkDoctorBaseURL(),
665 google_util::LinkDoctorBaseURL().host(),
666 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler>( 819 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler>(
667 new AddressUnreachableProtocolHandler())); 820 new AddressUnreachableProtocolHandler()));
668 } 821 }
669 822
670 static void RemoveFilters() { 823 static void RemoveFilters() {
671 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 824 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
672 net::URLRequestFilter::GetInstance()->ClearHandlers(); 825 net::URLRequestFilter::GetInstance()->ClearHandlers();
673 } 826 }
674 }; 827 };
675 828
676 // Make sure that when the Link Doctor fails to load, the network error page is 829 // Make sure that when corrections fail to load, the network error page is
677 // successfully loaded. 830 // successfully loaded.
678 IN_PROC_BROWSER_TEST_F(ErrorPageLinkDoctorFailTest, LinkDoctorFail) { 831 IN_PROC_BROWSER_TEST_F(ErrorPageNavigationCorrectionsFailTest,
832 FetchCorrectionsFails) {
679 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( 833 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(
680 browser(), 834 browser(),
681 URLRequestFailedJob::GetMockHttpUrl(net::ERR_NAME_NOT_RESOLVED), 835 URLRequestFailedJob::GetMockHttpUrl(net::ERR_NAME_NOT_RESOLVED),
682 2); 836 2);
683 837
684 // Verify that the expected error page is being displayed. Do this by making 838 // Verify that the expected error page is being displayed.
685 // sure the original error code (ERR_NAME_NOT_RESOLVED) is displayed. 839 ExpectDisplayingLocalErrorPage(browser(), net::ERR_NAME_NOT_RESOLVED);
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);
692 } 840 }
693 841
694 // Checks that when an error occurs and a link doctor load fails, the stale 842 // Checks that when an error occurs and a corrections fail to load, the stale
695 // cache status of the page is correctly transferred, and we can load the 843 // cache status of the page is correctly transferred, and we can load the
696 // stale copy from the javascript. Most logic copied from StaleCacheStatus 844 // stale copy from the javascript. Most logic copied from StaleCacheStatus
697 // above. 845 // above.
698 IN_PROC_BROWSER_TEST_F(ErrorPageLinkDoctorFailTest, 846 IN_PROC_BROWSER_TEST_F(ErrorPageNavigationCorrectionsFailTest,
699 StaleCacheStatusFailedLinkDoctor) { 847 StaleCacheStatusFailedCorrections) {
700 ASSERT_TRUE(test_server()->Start()); 848 ASSERT_TRUE(test_server()->Start());
701 // Load cache with entry with "nocache" set, to create stale 849 // Load cache with entry with "nocache" set, to create stale
702 // cache. 850 // cache.
703 GURL test_url(test_server()->GetURL("files/nocache.html")); 851 GURL test_url(test_server()->GetURL("files/nocache.html"));
704 NavigateToURLAndWaitForTitle(test_url, "Nocache Test Page", 1); 852 NavigateToURLAndWaitForTitle(test_url, "Nocache Test Page", 1);
705 853
706 // Reload same URL after forcing an error from the the network layer; 854 // Reload same URL after forcing an error from the the network layer;
707 // confirm that the error page is told the cached copy exists. 855 // confirm that the error page is told the cached copy exists.
708 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter = 856 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter =
709 browser()->profile()->GetRequestContext(); 857 browser()->profile()->GetRequestContext();
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
771 }; 919 };
772 920
773 const char ErrorPageForIDNTest::kHostname[] = 921 const char ErrorPageForIDNTest::kHostname[] =
774 "xn--d1abbgf6aiiy.xn--p1ai"; 922 "xn--d1abbgf6aiiy.xn--p1ai";
775 const char ErrorPageForIDNTest::kHostnameJSUnicode[] = 923 const char ErrorPageForIDNTest::kHostnameJSUnicode[] =
776 "\\u043f\\u0440\\u0435\\u0437\\u0438\\u0434\\u0435\\u043d\\u0442." 924 "\\u043f\\u0440\\u0435\\u0437\\u0438\\u0434\\u0435\\u043d\\u0442."
777 "\\u0440\\u0444"; 925 "\\u0440\\u0444";
778 926
779 // Make sure error page shows correct unicode for IDN. 927 // Make sure error page shows correct unicode for IDN.
780 IN_PROC_BROWSER_TEST_F(ErrorPageForIDNTest, IDN) { 928 IN_PROC_BROWSER_TEST_F(ErrorPageForIDNTest, IDN) {
781 // ERR_UNSAFE_PORT will not trigger the link doctor. 929 // ERR_UNSAFE_PORT will not trigger navigation corrections.
782 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( 930 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(
783 browser(), 931 browser(),
784 URLRequestFailedJob::GetMockHttpUrlForHostname(net::ERR_UNSAFE_PORT, 932 URLRequestFailedJob::GetMockHttpUrlForHostname(net::ERR_UNSAFE_PORT,
785 kHostname), 933 kHostname),
786 1); 934 1);
787 935
788 bool result = false; 936 ToggleHelpBox(browser());
789 EXPECT_TRUE(content::ExecuteScriptAndExtractBool( 937 EXPECT_TRUE(IsDisplayingText(browser(), kHostnameJSUnicode));
790 browser()->tab_strip_model()->GetActiveWebContents(),
791 GetTextContentContainsStringScript(kHostnameJSUnicode),
792 &result));
793 EXPECT_TRUE(result);
794 } 938 }
795 939
796 } // namespace 940 } // namespace
OLDNEW
« no previous file with comments | « trunk/src/chrome/browser/chromeos/offline/offline_load_page.cc ('k') | trunk/src/chrome/browser/google/google_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698