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

Side by Side 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: Simulate click on more button 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 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/compiler_specific.h"
7 #include "base/path_service.h"
6 #include "base/prefs/pref_service.h" 8 #include "base/prefs/pref_service.h"
7 #include "base/strings/stringprintf.h" 9 #include "base/strings/stringprintf.h"
8 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
9 #include "chrome/browser/google/google_util.h" 11 #include "chrome/browser/google/google_util.h"
10 #include "chrome/browser/net/url_request_mock_util.h" 12 #include "chrome/browser/net/url_request_mock_util.h"
11 #include "chrome/browser/profiles/profile.h" 13 #include "chrome/browser/profiles/profile.h"
12 #include "chrome/browser/ui/browser.h" 14 #include "chrome/browser/ui/browser.h"
13 #include "chrome/browser/ui/browser_commands.h" 15 #include "chrome/browser/ui/browser_commands.h"
14 #include "chrome/browser/ui/tabs/tab_strip_model.h" 16 #include "chrome/browser/ui/tabs/tab_strip_model.h"
17 #include "chrome/common/chrome_paths.h"
15 #include "chrome/common/pref_names.h" 18 #include "chrome/common/pref_names.h"
16 #include "chrome/test/base/in_process_browser_test.h" 19 #include "chrome/test/base/in_process_browser_test.h"
17 #include "chrome/test/base/ui_test_utils.h" 20 #include "chrome/test/base/ui_test_utils.h"
18 #include "content/public/browser/notification_service.h" 21 #include "content/public/browser/notification_service.h"
19 #include "content/public/browser/render_view_host.h" 22 #include "content/public/browser/render_view_host.h"
20 #include "content/public/browser/web_contents.h" 23 #include "content/public/browser/web_contents.h"
21 #include "content/public/browser/web_contents_observer.h" 24 #include "content/public/browser/web_contents_observer.h"
22 #include "content/public/test/browser_test_utils.h" 25 #include "content/public/test/browser_test_utils.h"
23 #include "content/public/test/test_navigation_observer.h" 26 #include "content/public/test/test_navigation_observer.h"
24 #include "content/test/net/url_request_failed_job.h" 27 #include "content/test/net/url_request_failed_job.h"
25 #include "content/test/net/url_request_mock_http_job.h" 28 #include "content/test/net/url_request_mock_http_job.h"
26 #include "net/base/net_errors.h" 29 #include "net/base/net_errors.h"
27 #include "net/base/net_util.h" 30 #include "net/base/net_util.h"
28 #include "net/url_request/url_request_filter.h" 31 #include "net/url_request/url_request_filter.h"
29 #include "net/url_request/url_request_job_factory.h" 32 #include "net/url_request/url_request_job_factory.h"
30 33
31 using content::BrowserThread; 34 using content::BrowserThread;
32 using content::NavigationController; 35 using content::NavigationController;
33 using content::URLRequestFailedJob; 36 using content::URLRequestFailedJob;
34 37
35 namespace { 38 namespace {
36 39
40 // Returns true if |text| is displayed on the page |browser| is currently
41 // displaying. Uses "innerText", so will miss hidden text, and whitespace
42 // space handling may be weird.
43 bool WARN_UNUSED_RESULT IsDisplayingText(Browser* browser,
44 const std::string& text) {
45 std::string command = base::StringPrintf(
46 "var textContent = document.body.innerText;"
47 "var hasText = textContent.indexOf('%s') >= 0;"
48 "domAutomationController.send(hasText);",
49 text.c_str());
50 bool result = false;
51 EXPECT_TRUE(content::ExecuteScriptAndExtractBool(
52 browser->tab_strip_model()->GetActiveWebContents(), command, &result));
53 return result;
54 }
55
56 // Expands the more box on the currently displayed error page.
57 void ToggleHelpBox(Browser* browser) {
58 EXPECT_TRUE(content::ExecuteScript(
59 browser->tab_strip_model()->GetActiveWebContents(), "toggleHelpBox()"));
60 }
61
62 // Returns true if |browser| is displaying the text representation of
63 // |error_code| on the current page.
64 bool WARN_UNUSED_RESULT IsDisplayingNetError(Browser* browser,
65 net::Error error_code) {
66 // Get the error as a string, and remove the leading "net::", which is not
67 // included on error pages.
68 std::string error_string = net::ErrorToString(error_code);
69 base::RemoveChars(error_string, "net:", &error_string);
70
71 return IsDisplayingText(browser, error_string);
72 }
73
74 // Checks that the local error page is being displayed, without remotely
75 // retrieved Link Doctor information, and with the specified error code.
76 void ExpectDisplayingLocalErrorPage(Browser* browser, net::Error error_code) {
77 // Expand the help box so innerText will include text below the fold.
78 ToggleHelpBox(browser);
79
80 EXPECT_TRUE(IsDisplayingNetError(browser, error_code));
81
82 // Locally generated error pages should not have Link Doctor suggestions.
83 EXPECT_FALSE(IsDisplayingText(browser, "http://correction1/"));
84 EXPECT_FALSE(IsDisplayingText(browser, "http://correction2/"));
85
86 // Locally generated error pages should not have a populated search box.
87 bool search_box_populated = false;
88 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
89 browser->tab_strip_model()->GetActiveWebContents(),
90 "var searchText = document.getElementById('search-box').value;"
91 "domAutomationController.send(searchText == 'search query');",
92 &search_box_populated));
93 EXPECT_FALSE(search_box_populated);
94 }
95
96 // Checks that an error page with information retrieved from the Link Doctor
97 // is being displayed, with the specified specified error code.
98 void ExpectDisplayingLinkDoctor(Browser* browser, net::Error error_code) {
99 // Expand the help box so innerText will include text below the fold.
100 ToggleHelpBox(browser);
101
102 EXPECT_TRUE(IsDisplayingNetError(browser, error_code));
103
104 // Check that suggestions from the mock Link Doctor results are displayed.
105 EXPECT_TRUE(IsDisplayingText(browser, "http://correction1/"));
106 EXPECT_TRUE(IsDisplayingText(browser, "http://correction2/"));
107
108 // Check that the search box is populated correctly.
109 bool search_box_populated = false;
110 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
111 browser->tab_strip_model()->GetActiveWebContents(),
112 "var searchText = document.getElementById('search-box').value;"
113 "domAutomationController.send(searchText == 'search query');",
114 &search_box_populated));
115 EXPECT_TRUE(search_box_populated);
116 }
117
37 class ErrorPageTest : public InProcessBrowserTest { 118 class ErrorPageTest : public InProcessBrowserTest {
38 public: 119 public:
39 enum HistoryNavigationDirection { 120 enum HistoryNavigationDirection {
40 HISTORY_NAVIGATE_BACK, 121 HISTORY_NAVIGATE_BACK,
41 HISTORY_NAVIGATE_FORWARD, 122 HISTORY_NAVIGATE_FORWARD,
42 }; 123 };
43 124
44 // Navigates the active tab to a mock url created for the file at |file_path|. 125 // Navigates the active tab to a mock url created for the file at |file_path|.
45 void NavigateToFileURL(const base::FilePath::StringType& file_path) { 126 void NavigateToFileURL(const base::FilePath::StringType& file_path) {
46 ui_test_utils::NavigateToURL( 127 ui_test_utils::NavigateToURL(
(...skipping 28 matching lines...) Expand all
75 156
76 // Navigates forward in the history and waits for |num_navigations| to occur, 157 // Navigates forward in the history and waits for |num_navigations| to occur,
77 // and the title to change to |expected_title|. 158 // and the title to change to |expected_title|.
78 void GoForwardAndWaitForTitle(const std::string& expected_title, 159 void GoForwardAndWaitForTitle(const std::string& expected_title,
79 int num_navigations) { 160 int num_navigations) {
80 NavigateHistoryAndWaitForTitle(expected_title, 161 NavigateHistoryAndWaitForTitle(expected_title,
81 num_navigations, 162 num_navigations,
82 HISTORY_NAVIGATE_FORWARD); 163 HISTORY_NAVIGATE_FORWARD);
83 } 164 }
84 165
166 void GoBackAndWaitForNavigations(int num_navigations) {
167 NavigateHistory(num_navigations, HISTORY_NAVIGATE_BACK);
168 }
169
170 void GoForwardAndWaitForNavigations(int num_navigations) {
171 NavigateHistory(num_navigations, HISTORY_NAVIGATE_FORWARD);
172 }
173
85 protected: 174 protected:
175 static void EnableMocks(const GURL& search_url) {
176 chrome_browser_net::SetUrlRequestMocksEnabled(true);
177
178 // Add a mock for the search engine the error page will use.
179 base::FilePath root_http;
180 PathService::Get(chrome::DIR_TEST_DATA, &root_http);
181 content::URLRequestMockHTTPJob::AddHostnameToFileHandler(
182 search_url.host(), root_http.AppendASCII("title3.html"));
183 }
184
86 virtual void SetUpOnMainThread() OVERRIDE { 185 virtual void SetUpOnMainThread() OVERRIDE {
87 BrowserThread::PostTask( 186 BrowserThread::PostTask(
88 BrowserThread::IO, FROM_HERE, 187 BrowserThread::IO, FROM_HERE,
89 base::Bind(&chrome_browser_net::SetUrlRequestMocksEnabled, true)); 188 base::Bind(&ErrorPageTest::EnableMocks,
189 google_util::GetGoogleSearchURL(browser()->profile())));
90 } 190 }
91 191
92 // Returns a GURL that results in a DNS error. 192 // Returns a GURL that results in a DNS error.
93 GURL GetDnsErrorURL() const { 193 GURL GetDnsErrorURL() const {
94 return URLRequestFailedJob::GetMockHttpUrl(net::ERR_NAME_NOT_RESOLVED); 194 return URLRequestFailedJob::GetMockHttpUrl(net::ERR_NAME_NOT_RESOLVED);
95 } 195 }
96 196
97 private: 197 private:
98 // Navigates the browser the indicated direction in the history and waits for 198 // Navigates the browser the indicated direction in the history and waits for
99 // |num_navigations| to occur and the title to change to |expected_title|. 199 // |num_navigations| to occur and the title to change to |expected_title|.
100 void NavigateHistoryAndWaitForTitle(const std::string& expected_title, 200 void NavigateHistoryAndWaitForTitle(const std::string& expected_title,
101 int num_navigations, 201 int num_navigations,
102 HistoryNavigationDirection direction) { 202 HistoryNavigationDirection direction) {
103 content::TitleWatcher title_watcher( 203 content::TitleWatcher title_watcher(
104 browser()->tab_strip_model()->GetActiveWebContents(), 204 browser()->tab_strip_model()->GetActiveWebContents(),
105 base::ASCIIToUTF16(expected_title)); 205 base::ASCIIToUTF16(expected_title));
106 206
207 NavigateHistory(num_navigations, direction);
208
209 EXPECT_EQ(title_watcher.WaitAndGetTitle(),
210 base::ASCIIToUTF16(expected_title));
211 }
212
213 void NavigateHistory(int num_navigations,
214 HistoryNavigationDirection direction) {
107 content::TestNavigationObserver test_navigation_observer( 215 content::TestNavigationObserver test_navigation_observer(
108 browser()->tab_strip_model()->GetActiveWebContents(), 216 browser()->tab_strip_model()->GetActiveWebContents(),
109 num_navigations); 217 num_navigations);
110 if (direction == HISTORY_NAVIGATE_BACK) { 218 if (direction == HISTORY_NAVIGATE_BACK) {
111 chrome::GoBack(browser(), CURRENT_TAB); 219 chrome::GoBack(browser(), CURRENT_TAB);
112 } else if (direction == HISTORY_NAVIGATE_FORWARD) { 220 } else if (direction == HISTORY_NAVIGATE_FORWARD) {
113 chrome::GoForward(browser(), CURRENT_TAB); 221 chrome::GoForward(browser(), CURRENT_TAB);
114 } else { 222 } else {
115 FAIL(); 223 FAIL();
116 } 224 }
117 test_navigation_observer.Wait(); 225 test_navigation_observer.Wait();
118
119 EXPECT_EQ(title_watcher.WaitAndGetTitle(),
120 base::ASCIIToUTF16(expected_title));
121 } 226 }
122 }; 227 };
123 228
124 229
125 class TestFailProvisionalLoadObserver : public content::WebContentsObserver { 230 class TestFailProvisionalLoadObserver : public content::WebContentsObserver {
126 public: 231 public:
127 explicit TestFailProvisionalLoadObserver(content::WebContents* contents) 232 explicit TestFailProvisionalLoadObserver(content::WebContents* contents)
128 : content::WebContentsObserver(contents) {} 233 : content::WebContentsObserver(contents) {}
129 virtual ~TestFailProvisionalLoadObserver() {} 234 virtual ~TestFailProvisionalLoadObserver() {}
130 235
(...skipping 20 matching lines...) Expand all
151 // See crbug.com/109669 256 // See crbug.com/109669
152 #if defined(USE_AURA) || defined(OS_WIN) 257 #if defined(USE_AURA) || defined(OS_WIN)
153 #define MAYBE_DNSError_Basic DISABLED_DNSError_Basic 258 #define MAYBE_DNSError_Basic DISABLED_DNSError_Basic
154 #else 259 #else
155 #define MAYBE_DNSError_Basic DNSError_Basic 260 #define MAYBE_DNSError_Basic DNSError_Basic
156 #endif 261 #endif
157 // Test that a DNS error occuring in the main frame redirects to an error page. 262 // Test that a DNS error occuring in the main frame redirects to an error page.
158 IN_PROC_BROWSER_TEST_F(ErrorPageTest, MAYBE_DNSError_Basic) { 263 IN_PROC_BROWSER_TEST_F(ErrorPageTest, MAYBE_DNSError_Basic) {
159 // The first navigation should fail, and the second one should be the error 264 // The first navigation should fail, and the second one should be the error
160 // page. 265 // page.
161 NavigateToURLAndWaitForTitle(GetDnsErrorURL(), "Mock Link Doctor", 2); 266 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(
267 browser(), GetDnsErrorURL(), 2);
268 ExpectDisplayingLinkDoctor(browser(), net::ERR_NAME_NOT_RESOLVED);
162 } 269 }
163 270
164 // See crbug.com/109669 271 // See crbug.com/109669
165 #if defined(USE_AURA) 272 #if defined(USE_AURA)
166 #define MAYBE_DNSError_GoBack1 DISABLED_DNSError_GoBack1 273 #define MAYBE_DNSError_GoBack1 DISABLED_DNSError_GoBack1
167 #else 274 #else
168 #define MAYBE_DNSError_GoBack1 DNSError_GoBack1 275 #define MAYBE_DNSError_GoBack1 DNSError_GoBack1
169 #endif 276 #endif
170 277
171 // Test that a DNS error occuring in the main frame does not result in an 278 // Test that a DNS error occuring in the main frame does not result in an
172 // additional session history entry. 279 // additional session history entry.
173 IN_PROC_BROWSER_TEST_F(ErrorPageTest, MAYBE_DNSError_GoBack1) { 280 IN_PROC_BROWSER_TEST_F(ErrorPageTest, MAYBE_DNSError_GoBack1) {
174 NavigateToFileURL(FILE_PATH_LITERAL("title2.html")); 281 NavigateToFileURL(FILE_PATH_LITERAL("title2.html"));
175 NavigateToURLAndWaitForTitle(GetDnsErrorURL(), "Mock Link Doctor", 2); 282 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(
283 browser(), GetDnsErrorURL(), 2);
284 ExpectDisplayingLinkDoctor(browser(), net::ERR_NAME_NOT_RESOLVED);
176 GoBackAndWaitForTitle("Title Of Awesomeness", 1); 285 GoBackAndWaitForTitle("Title Of Awesomeness", 1);
177 } 286 }
178 287
179 // See crbug.com/109669 288 // See crbug.com/109669
180 #if defined(USE_AURA) 289 #if defined(USE_AURA)
181 #define MAYBE_DNSError_GoBack2 DISABLED_DNSError_GoBack2 290 #define MAYBE_DNSError_GoBack2 DISABLED_DNSError_GoBack2
182 #else 291 #else
183 #define MAYBE_DNSError_GoBack2 DNSError_GoBack2 292 #define MAYBE_DNSError_GoBack2 DNSError_GoBack2
184 #endif 293 #endif
185 // Test that a DNS error occuring in the main frame does not result in an 294 // Test that a DNS error occuring in the main frame does not result in an
186 // additional session history entry. 295 // additional session history entry.
187 IN_PROC_BROWSER_TEST_F(ErrorPageTest, DNSError_GoBack2) { 296 IN_PROC_BROWSER_TEST_F(ErrorPageTest, DNSError_GoBack2) {
188 NavigateToFileURL(FILE_PATH_LITERAL("title2.html")); 297 NavigateToFileURL(FILE_PATH_LITERAL("title2.html"));
189 298
190 NavigateToURLAndWaitForTitle(GetDnsErrorURL(), "Mock Link Doctor", 2); 299 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(
300 browser(), GetDnsErrorURL(), 2);
301 ExpectDisplayingLinkDoctor(browser(), net::ERR_NAME_NOT_RESOLVED);
302
191 NavigateToFileURL(FILE_PATH_LITERAL("title3.html")); 303 NavigateToFileURL(FILE_PATH_LITERAL("title3.html"));
192 304
193 GoBackAndWaitForTitle("Mock Link Doctor", 2); 305 GoBackAndWaitForNavigations(2);
306 ExpectDisplayingLinkDoctor(browser(), net::ERR_NAME_NOT_RESOLVED);
307
194 GoBackAndWaitForTitle("Title Of Awesomeness", 1); 308 GoBackAndWaitForTitle("Title Of Awesomeness", 1);
195 } 309 }
196 310
197 // See crbug.com/109669 311 // See crbug.com/109669
198 #if defined(USE_AURA) 312 #if defined(USE_AURA)
199 #define MAYBE_DNSError_GoBack2AndForward DISABLED_DNSError_GoBack2AndForward 313 #define MAYBE_DNSError_GoBack2AndForward DISABLED_DNSError_GoBack2AndForward
200 #else 314 #else
201 #define MAYBE_DNSError_GoBack2AndForward DNSError_GoBack2AndForward 315 #define MAYBE_DNSError_GoBack2AndForward DNSError_GoBack2AndForward
202 #endif 316 #endif
203 // 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
204 // additional session history entry. 318 // additional session history entry.
205 IN_PROC_BROWSER_TEST_F(ErrorPageTest, DNSError_GoBack2AndForward) { 319 IN_PROC_BROWSER_TEST_F(ErrorPageTest, DNSError_GoBack2AndForward) {
206 NavigateToFileURL(FILE_PATH_LITERAL("title2.html")); 320 NavigateToFileURL(FILE_PATH_LITERAL("title2.html"));
207 321
208 NavigateToURLAndWaitForTitle(GetDnsErrorURL(), "Mock Link Doctor", 2); 322 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(
323 browser(), GetDnsErrorURL(), 2);
324 ExpectDisplayingLinkDoctor(browser(), net::ERR_NAME_NOT_RESOLVED);
325
209 NavigateToFileURL(FILE_PATH_LITERAL("title3.html")); 326 NavigateToFileURL(FILE_PATH_LITERAL("title3.html"));
210 327
211 GoBackAndWaitForTitle("Mock Link Doctor", 2); 328 GoBackAndWaitForNavigations(2);
329 ExpectDisplayingLinkDoctor(browser(), net::ERR_NAME_NOT_RESOLVED);
330
212 GoBackAndWaitForTitle("Title Of Awesomeness", 1); 331 GoBackAndWaitForTitle("Title Of Awesomeness", 1);
213 332
214 GoForwardAndWaitForTitle("Mock Link Doctor", 2); 333 GoForwardAndWaitForNavigations(2);
334 ExpectDisplayingLinkDoctor(browser(), net::ERR_NAME_NOT_RESOLVED);
215 } 335 }
216 336
217 // See crbug.com/109669 337 // See crbug.com/109669
218 #if defined(USE_AURA) 338 #if defined(USE_AURA)
219 #define MAYBE_DNSError_GoBack2Forward2 DISABLED_DNSError_GoBack2Forward2 339 #define MAYBE_DNSError_GoBack2Forward2 DISABLED_DNSError_GoBack2Forward2
220 #else 340 #else
221 #define MAYBE_DNSError_GoBack2Forward2 DNSError_GoBack2Forward2 341 #define MAYBE_DNSError_GoBack2Forward2 DNSError_GoBack2Forward2
222 #endif 342 #endif
223 // Test that a DNS error occuring in the main frame does not result in an 343 // Test that a DNS error occuring in the main frame does not result in an
224 // additional session history entry. 344 // additional session history entry.
225 IN_PROC_BROWSER_TEST_F(ErrorPageTest, DNSError_GoBack2Forward2) { 345 IN_PROC_BROWSER_TEST_F(ErrorPageTest, DNSError_GoBack2Forward2) {
226 NavigateToFileURL(FILE_PATH_LITERAL("title3.html")); 346 NavigateToFileURL(FILE_PATH_LITERAL("title3.html"));
227 347
228 NavigateToURLAndWaitForTitle(GetDnsErrorURL(), "Mock Link Doctor", 2); 348 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(
349 browser(), GetDnsErrorURL(), 2);
350 ExpectDisplayingLinkDoctor(browser(), net::ERR_NAME_NOT_RESOLVED);
351
229 NavigateToFileURL(FILE_PATH_LITERAL("title2.html")); 352 NavigateToFileURL(FILE_PATH_LITERAL("title2.html"));
230 353
231 GoBackAndWaitForTitle("Mock Link Doctor", 2); 354 GoBackAndWaitForNavigations(2);
355 ExpectDisplayingLinkDoctor(browser(), net::ERR_NAME_NOT_RESOLVED);
356
232 GoBackAndWaitForTitle("Title Of More Awesomeness", 1); 357 GoBackAndWaitForTitle("Title Of More Awesomeness", 1);
233 358
234 GoForwardAndWaitForTitle("Mock Link Doctor", 2); 359 GoForwardAndWaitForNavigations(2);
360 ExpectDisplayingLinkDoctor(browser(), net::ERR_NAME_NOT_RESOLVED);
361
235 GoForwardAndWaitForTitle("Title Of Awesomeness", 1); 362 GoForwardAndWaitForTitle("Title Of Awesomeness", 1);
236 } 363 }
237 364
238 // Test that a DNS error occuring in an iframe. 365 // See crbug.com/109669
366 #if defined(USE_AURA)
367 #define MAYBE_DNSError_DoSearch DISABLED_DNSError_DoSearch
368 #else
369 #define MAYBE_DNSError_DoSearch DNSError_DoSearch
370 #endif
371 // Test that the search button on a DNS error page works.
372 IN_PROC_BROWSER_TEST_F(ErrorPageTest, MAYBE_DNSError_DoSearch) {
373 // The first navigation should fail, and the second one should be the error
374 // page.
375 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(
376 browser(), GetDnsErrorURL(), 2);
377 ExpectDisplayingLinkDoctor(browser(), net::ERR_NAME_NOT_RESOLVED);
378
379 // Do a search and make sure the browser ends up at the right page.
380 content::TestNavigationObserver nav_observer(
381 browser()->tab_strip_model()->GetActiveWebContents(),
382 1);
383 content::TitleWatcher title_watcher(
384 browser()->tab_strip_model()->GetActiveWebContents(),
385 base::ASCIIToUTF16("Title Of More Awesomeness"));
386 ASSERT_TRUE(content::ExecuteScript(
387 browser()->tab_strip_model()->GetActiveWebContents(),
388 "document.getElementById('search-button').click();"));
389 nav_observer.Wait();
390 EXPECT_EQ(base::ASCIIToUTF16("Title Of More Awesomeness"),
391 title_watcher.WaitAndGetTitle());
392
393 // Check the path and query string.
394 std::string url;
395 ASSERT_TRUE(content::ExecuteScriptAndExtractString(
396 browser()->tab_strip_model()->GetActiveWebContents(),
397 "domAutomationController.send(window.location.href);",
398 &url));
399 EXPECT_EQ("/search", GURL(url).path());
400 EXPECT_EQ("q=search+query", GURL(url).query());
401
402 // Go back to the error page, to make sure the history is correct.
403 GoBackAndWaitForNavigations(2);
404 ExpectDisplayingLinkDoctor(browser(), net::ERR_NAME_NOT_RESOLVED);
405 }
406
407 // Test that a DNS error occuring in an iframe does not result in showing the
408 // Link Doctor.
239 IN_PROC_BROWSER_TEST_F(ErrorPageTest, IFrameDNSError_Basic) { 409 IN_PROC_BROWSER_TEST_F(ErrorPageTest, IFrameDNSError_Basic) {
240 NavigateToURLAndWaitForTitle( 410 NavigateToURLAndWaitForTitle(
241 content::URLRequestMockHTTPJob::GetMockUrl( 411 content::URLRequestMockHTTPJob::GetMockUrl(
242 base::FilePath(FILE_PATH_LITERAL("iframe_dns_error.html"))), 412 base::FilePath(FILE_PATH_LITERAL("iframe_dns_error.html"))),
243 "Blah", 413 "Blah",
244 1); 414 1);
245 // We expect to have two history entries, since we started off with navigation 415 // We expect to have two history entries, since we started off with navigation
246 // to "about:blank" and then navigated to "iframe_dns_error.html". 416 // to "about:blank" and then navigated to "iframe_dns_error.html".
247 EXPECT_EQ(2, 417 EXPECT_EQ(2,
248 browser()->tab_strip_model()->GetActiveWebContents()-> 418 browser()->tab_strip_model()->GetActiveWebContents()->
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 519
350 // Checks that the Link Doctor is not loaded when we receive an actual 404 page. 520 // Checks that the Link Doctor is not loaded when we receive an actual 404 page.
351 IN_PROC_BROWSER_TEST_F(ErrorPageTest, Page404) { 521 IN_PROC_BROWSER_TEST_F(ErrorPageTest, Page404) {
352 NavigateToURLAndWaitForTitle( 522 NavigateToURLAndWaitForTitle(
353 content::URLRequestMockHTTPJob::GetMockUrl( 523 content::URLRequestMockHTTPJob::GetMockUrl(
354 base::FilePath(FILE_PATH_LITERAL("page404.html"))), 524 base::FilePath(FILE_PATH_LITERAL("page404.html"))),
355 "SUCCESS", 525 "SUCCESS",
356 1); 526 1);
357 } 527 }
358 528
359 // Returns Javascript code that executes plain text search for the page.
360 // Pass into content::ExecuteScriptAndExtractBool as |script| parameter.
361 std::string GetTextContentContainsStringScript(
362 const std::string& value_to_search) {
363 return base::StringPrintf(
364 "var textContent = document.body.textContent;"
365 "var hasError = textContent.indexOf('%s') >= 0;"
366 "domAutomationController.send(hasError);",
367 value_to_search.c_str());
368 }
369
370 // Protocol handler that fails all requests with net::ERR_ADDRESS_UNREACHABLE. 529 // Protocol handler that fails all requests with net::ERR_ADDRESS_UNREACHABLE.
371 class AddressUnreachableProtocolHandler 530 class AddressUnreachableProtocolHandler
372 : public net::URLRequestJobFactory::ProtocolHandler { 531 : public net::URLRequestJobFactory::ProtocolHandler {
373 public: 532 public:
374 AddressUnreachableProtocolHandler() {} 533 AddressUnreachableProtocolHandler() {}
375 virtual ~AddressUnreachableProtocolHandler() {} 534 virtual ~AddressUnreachableProtocolHandler() {}
376 535
377 // net::URLRequestJobFactory::ProtocolHandler: 536 // net::URLRequestJobFactory::ProtocolHandler:
378 virtual net::URLRequestJob* MaybeCreateJob( 537 virtual net::URLRequestJob* MaybeCreateJob(
379 net::URLRequest* request, 538 net::URLRequest* request,
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
430 }; 589 };
431 590
432 // Make sure that when the Link Doctor fails to load, the network error page is 591 // Make sure that when the Link Doctor fails to load, the network error page is
433 // successfully loaded. 592 // successfully loaded.
434 IN_PROC_BROWSER_TEST_F(ErrorPageLinkDoctorFailTest, LinkDoctorFail) { 593 IN_PROC_BROWSER_TEST_F(ErrorPageLinkDoctorFailTest, LinkDoctorFail) {
435 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( 594 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(
436 browser(), 595 browser(),
437 URLRequestFailedJob::GetMockHttpUrl(net::ERR_NAME_NOT_RESOLVED), 596 URLRequestFailedJob::GetMockHttpUrl(net::ERR_NAME_NOT_RESOLVED),
438 2); 597 2);
439 598
440 // Verify that the expected error page is being displayed. Do this by making 599 // Verify that the expected error page is being displayed.
441 // sure the original error code (ERR_NAME_NOT_RESOLVED) is displayed. 600 ExpectDisplayingLocalErrorPage(browser(), net::ERR_NAME_NOT_RESOLVED);
442 bool result = false;
443 EXPECT_TRUE(content::ExecuteScriptAndExtractBool(
444 browser()->tab_strip_model()->GetActiveWebContents(),
445 GetTextContentContainsStringScript("ERR_NAME_NOT_RESOLVED"),
446 &result));
447 EXPECT_TRUE(result);
448 } 601 }
449 602
450 // A test fixture that simulates failing requests for an IDN domain name. 603 // A test fixture that simulates failing requests for an IDN domain name.
451 class ErrorPageForIDNTest : public InProcessBrowserTest { 604 class ErrorPageForIDNTest : public InProcessBrowserTest {
452 public: 605 public:
453 // Target hostname in different forms. 606 // Target hostname in different forms.
454 static const char kHostname[]; 607 static const char kHostname[];
455 static const char kHostnameJSUnicode[]; 608 static const char kHostnameJSUnicode[];
456 609
457 // InProcessBrowserTest: 610 // InProcessBrowserTest:
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
490 643
491 // Make sure error page shows correct unicode for IDN. 644 // Make sure error page shows correct unicode for IDN.
492 IN_PROC_BROWSER_TEST_F(ErrorPageForIDNTest, IDN) { 645 IN_PROC_BROWSER_TEST_F(ErrorPageForIDNTest, IDN) {
493 // ERR_UNSAFE_PORT will not trigger the link doctor. 646 // ERR_UNSAFE_PORT will not trigger the link doctor.
494 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( 647 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(
495 browser(), 648 browser(),
496 URLRequestFailedJob::GetMockHttpUrlForHostname(net::ERR_UNSAFE_PORT, 649 URLRequestFailedJob::GetMockHttpUrlForHostname(net::ERR_UNSAFE_PORT,
497 kHostname), 650 kHostname),
498 1); 651 1);
499 652
500 bool result = false; 653 ToggleHelpBox(browser());
501 EXPECT_TRUE(content::ExecuteScriptAndExtractBool( 654 EXPECT_TRUE(IsDisplayingText(browser(), kHostnameJSUnicode));
502 browser()->tab_strip_model()->GetActiveWebContents(),
503 GetTextContentContainsStringScript(kHostnameJSUnicode),
504 &result));
505 EXPECT_TRUE(result);
506 } 655 }
507 656
508 } // namespace 657 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698