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

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

Issue 185003002: Revert 254207 "Switch to using the new Link Doctor API." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 6 years, 9 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"
8 #include "base/prefs/pref_service.h" 6 #include "base/prefs/pref_service.h"
9 #include "base/strings/stringprintf.h" 7 #include "base/strings/stringprintf.h"
10 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
11 #include "chrome/browser/browsing_data/browsing_data_helper.h" 9 #include "chrome/browser/browsing_data/browsing_data_helper.h"
12 #include "chrome/browser/browsing_data/browsing_data_remover.h" 10 #include "chrome/browser/browsing_data/browsing_data_remover.h"
13 #include "chrome/browser/google/google_util.h" 11 #include "chrome/browser/google/google_util.h"
14 #include "chrome/browser/net/url_request_mock_util.h" 12 #include "chrome/browser/net/url_request_mock_util.h"
15 #include "chrome/browser/profiles/profile.h" 13 #include "chrome/browser/profiles/profile.h"
16 #include "chrome/browser/ui/browser.h" 14 #include "chrome/browser/ui/browser.h"
17 #include "chrome/browser/ui/browser_commands.h" 15 #include "chrome/browser/ui/browser_commands.h"
18 #include "chrome/browser/ui/tabs/tab_strip_model.h" 16 #include "chrome/browser/ui/tabs/tab_strip_model.h"
19 #include "chrome/common/chrome_paths.h"
20 #include "chrome/common/pref_names.h" 17 #include "chrome/common/pref_names.h"
21 #include "chrome/test/base/in_process_browser_test.h" 18 #include "chrome/test/base/in_process_browser_test.h"
22 #include "chrome/test/base/ui_test_utils.h" 19 #include "chrome/test/base/ui_test_utils.h"
23 #include "content/public/browser/notification_service.h" 20 #include "content/public/browser/notification_service.h"
24 #include "content/public/browser/render_view_host.h" 21 #include "content/public/browser/render_view_host.h"
25 #include "content/public/browser/web_contents.h" 22 #include "content/public/browser/web_contents.h"
26 #include "content/public/browser/web_contents_observer.h" 23 #include "content/public/browser/web_contents_observer.h"
27 #include "content/public/test/browser_test_utils.h" 24 #include "content/public/test/browser_test_utils.h"
28 #include "content/public/test/test_navigation_observer.h" 25 #include "content/public/test/test_navigation_observer.h"
29 #include "content/test/net/url_request_failed_job.h" 26 #include "content/test/net/url_request_failed_job.h"
30 #include "content/test/net/url_request_mock_http_job.h" 27 #include "content/test/net/url_request_mock_http_job.h"
31 #include "net/base/net_errors.h" 28 #include "net/base/net_errors.h"
32 #include "net/base/net_util.h" 29 #include "net/base/net_util.h"
33 #include "net/http/failing_http_transaction_factory.h" 30 #include "net/http/failing_http_transaction_factory.h"
34 #include "net/http/http_cache.h" 31 #include "net/http/http_cache.h"
35 #include "net/test/spawned_test_server/spawned_test_server.h" 32 #include "net/test/spawned_test_server/spawned_test_server.h"
36 #include "net/url_request/url_request_context.h" 33 #include "net/url_request/url_request_context.h"
37 #include "net/url_request/url_request_context_getter.h" 34 #include "net/url_request/url_request_context_getter.h"
38 #include "net/url_request/url_request_filter.h" 35 #include "net/url_request/url_request_filter.h"
39 #include "net/url_request/url_request_job_factory.h" 36 #include "net/url_request/url_request_job_factory.h"
40 37
41 using content::BrowserThread; 38 using content::BrowserThread;
42 using content::NavigationController; 39 using content::NavigationController;
43 using content::URLRequestFailedJob; 40 using content::URLRequestFailedJob;
44 41
45 namespace { 42 namespace {
46 43
47 // Returns true if |text| is displayed on the page |browser| is currently
48 // displaying. Uses "innerText", so will miss hidden text, and whitespace
49 // space handling may be weird.
50 bool WARN_UNUSED_RESULT IsDisplayingText(Browser* browser,
51 const std::string& text) {
52 std::string command = base::StringPrintf(
53 "var textContent = document.body.innerText;"
54 "var hasText = textContent.indexOf('%s') >= 0;"
55 "domAutomationController.send(hasText);",
56 text.c_str());
57 bool result = false;
58 EXPECT_TRUE(content::ExecuteScriptAndExtractBool(
59 browser->tab_strip_model()->GetActiveWebContents(), command, &result));
60 return result;
61 }
62
63 // Expands the more box on the currently displayed error page.
64 void ToggleHelpBox(Browser* browser) {
65 EXPECT_TRUE(content::ExecuteScript(
66 browser->tab_strip_model()->GetActiveWebContents(),
67 "document.getElementById('more-less-button').click();"));
68 }
69
70 // Returns true if |browser| is displaying the text representation of
71 // |error_code| on the current page.
72 bool WARN_UNUSED_RESULT IsDisplayingNetError(Browser* browser,
73 net::Error error_code) {
74 // Get the error as a string, and remove the leading "net::", which is not
75 // included on error pages.
76 std::string error_string = net::ErrorToString(error_code);
77 base::RemoveChars(error_string, "net:", &error_string);
78
79 return IsDisplayingText(browser, error_string);
80 }
81
82 // Checks that the local error page is being displayed, without remotely
83 // retrieved navigation corrections, and with the specified error code.
84 void ExpectDisplayingLocalErrorPage(Browser* browser, net::Error error_code) {
85 // Expand the help box so innerText will include text below the fold.
86 ToggleHelpBox(browser);
87
88 EXPECT_TRUE(IsDisplayingNetError(browser, error_code));
89
90 // Locally generated error pages should not have navigation corrections.
91 EXPECT_FALSE(IsDisplayingText(browser, "http://correction1/"));
92 EXPECT_FALSE(IsDisplayingText(browser, "http://correction2/"));
93
94 // Locally generated error pages should not have a populated search box.
95 bool search_box_populated = false;
96 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
97 browser->tab_strip_model()->GetActiveWebContents(),
98 "var searchText = document.getElementById('search-box').value;"
99 "domAutomationController.send(searchText == 'search query');",
100 &search_box_populated));
101 EXPECT_FALSE(search_box_populated);
102 }
103
104 // Checks that an error page with information retrieved from the navigation
105 // correction service is being displayed, with the specified specified error
106 // code.
107 void ExpectDisplayingNavigationCorrections(Browser* browser,
108 net::Error error_code) {
109 // Expand the help box so innerText will include text below the fold.
110 ToggleHelpBox(browser);
111
112 EXPECT_TRUE(IsDisplayingNetError(browser, error_code));
113
114 // Check that the mock navigation corrections are displayed.
115 EXPECT_TRUE(IsDisplayingText(browser, "http://correction1/"));
116 EXPECT_TRUE(IsDisplayingText(browser, "http://correction2/"));
117
118 // Check that the search box is populated correctly.
119 bool search_box_populated = false;
120 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
121 browser->tab_strip_model()->GetActiveWebContents(),
122 "var searchText = document.getElementById('search-box').value;"
123 "domAutomationController.send(searchText == 'search query');",
124 &search_box_populated));
125 EXPECT_TRUE(search_box_populated);
126 }
127
128 class ErrorPageTest : public InProcessBrowserTest { 44 class ErrorPageTest : public InProcessBrowserTest {
129 public: 45 public:
130 enum HistoryNavigationDirection { 46 enum HistoryNavigationDirection {
131 HISTORY_NAVIGATE_BACK, 47 HISTORY_NAVIGATE_BACK,
132 HISTORY_NAVIGATE_FORWARD, 48 HISTORY_NAVIGATE_FORWARD,
133 }; 49 };
134 50
135 // Navigates the active tab to a mock url created for the file at |file_path|. 51 // Navigates the active tab to a mock url created for the file at |file_path|.
136 void NavigateToFileURL(const base::FilePath::StringType& file_path) { 52 void NavigateToFileURL(const base::FilePath::StringType& file_path) {
137 ui_test_utils::NavigateToURL( 53 ui_test_utils::NavigateToURL(
(...skipping 28 matching lines...) Expand all
166 82
167 // Navigates forward in the history and waits for |num_navigations| to occur, 83 // Navigates forward in the history and waits for |num_navigations| to occur,
168 // and the title to change to |expected_title|. 84 // and the title to change to |expected_title|.
169 void GoForwardAndWaitForTitle(const std::string& expected_title, 85 void GoForwardAndWaitForTitle(const std::string& expected_title,
170 int num_navigations) { 86 int num_navigations) {
171 NavigateHistoryAndWaitForTitle(expected_title, 87 NavigateHistoryAndWaitForTitle(expected_title,
172 num_navigations, 88 num_navigations,
173 HISTORY_NAVIGATE_FORWARD); 89 HISTORY_NAVIGATE_FORWARD);
174 } 90 }
175 91
176 void GoBackAndWaitForNavigations(int num_navigations) {
177 NavigateHistory(num_navigations, HISTORY_NAVIGATE_BACK);
178 }
179
180 void GoForwardAndWaitForNavigations(int num_navigations) {
181 NavigateHistory(num_navigations, HISTORY_NAVIGATE_FORWARD);
182 }
183
184 // Confirms that the javascript variable indicating whether or not we have 92 // Confirms that the javascript variable indicating whether or not we have
185 // a stale copy in the cache has been set to |expected|. 93 // a stale copy in the cache has been set to |expected|.
186 bool ProbeStaleCopyValue(bool expected) { 94 bool ProbeStaleCopyValue(bool expected) {
187 const char* js_cache_probe = 95 const char* js_cache_probe =
188 "(function () {\n" 96 "(function () {\n"
189 " if ('staleCopyInCache' in templateData) {\n" 97 " if ('staleCopyInCache' in templateData) {\n"
190 " domAutomationController.send(\n" 98 " domAutomationController.send(\n"
191 " templateData.staleCopyInCache ? 'yes' : 'no');\n" 99 " templateData.staleCopyInCache ? 'yes' : 'no');\n"
192 " } else {\n" 100 " } else {\n"
193 " domAutomationController.send('absent');\n" 101 " domAutomationController.send('absent');\n"
194 " }\n" 102 " }\n"
195 "})();"; 103 "})();";
196 104
197 std::string result; 105 std::string result;
198 bool ret = 106 bool ret =
199 content::ExecuteScriptAndExtractString( 107 content::ExecuteScriptAndExtractString(
200 browser()->tab_strip_model()->GetActiveWebContents(), 108 browser()->tab_strip_model()->GetActiveWebContents(),
201 js_cache_probe, 109 js_cache_probe,
202 &result); 110 &result);
203 EXPECT_TRUE(ret); 111 EXPECT_TRUE(ret);
204 if (!ret) 112 if (!ret)
205 return false; 113 return false;
206 EXPECT_EQ(expected ? "yes" : "no", result); 114 EXPECT_EQ(expected ? "yes" : "no", result);
207 return ((expected ? "yes" : "no") == result); 115 return ((expected ? "yes" : "no") == result);
208 } 116 }
209 117
210 protected: 118 protected:
211 static void EnableMocks(const GURL& search_url) {
212 chrome_browser_net::SetUrlRequestMocksEnabled(true);
213
214 // Add a mock for the search engine the error page will use.
215 base::FilePath root_http;
216 PathService::Get(chrome::DIR_TEST_DATA, &root_http);
217 content::URLRequestMockHTTPJob::AddHostnameToFileHandler(
218 search_url.host(), root_http.AppendASCII("title3.html"));
219 }
220
221 virtual void SetUpOnMainThread() OVERRIDE { 119 virtual void SetUpOnMainThread() OVERRIDE {
222 BrowserThread::PostTask( 120 BrowserThread::PostTask(
223 BrowserThread::IO, FROM_HERE, 121 BrowserThread::IO, FROM_HERE,
224 base::Bind(&ErrorPageTest::EnableMocks, 122 base::Bind(&chrome_browser_net::SetUrlRequestMocksEnabled, true));
225 google_util::GetGoogleSearchURL(browser()->profile())));
226 } 123 }
227 124
228 // Returns a GURL that results in a DNS error. 125 // Returns a GURL that results in a DNS error.
229 GURL GetDnsErrorURL() const { 126 GURL GetDnsErrorURL() const {
230 return URLRequestFailedJob::GetMockHttpUrl(net::ERR_NAME_NOT_RESOLVED); 127 return URLRequestFailedJob::GetMockHttpUrl(net::ERR_NAME_NOT_RESOLVED);
231 } 128 }
232 129
233 private: 130 private:
234 // Navigates the browser the indicated direction in the history and waits for 131 // Navigates the browser the indicated direction in the history and waits for
235 // |num_navigations| to occur and the title to change to |expected_title|. 132 // |num_navigations| to occur and the title to change to |expected_title|.
236 void NavigateHistoryAndWaitForTitle(const std::string& expected_title, 133 void NavigateHistoryAndWaitForTitle(const std::string& expected_title,
237 int num_navigations, 134 int num_navigations,
238 HistoryNavigationDirection direction) { 135 HistoryNavigationDirection direction) {
239 content::TitleWatcher title_watcher( 136 content::TitleWatcher title_watcher(
240 browser()->tab_strip_model()->GetActiveWebContents(), 137 browser()->tab_strip_model()->GetActiveWebContents(),
241 base::ASCIIToUTF16(expected_title)); 138 base::ASCIIToUTF16(expected_title));
242 139
243 NavigateHistory(num_navigations, direction);
244
245 EXPECT_EQ(title_watcher.WaitAndGetTitle(),
246 base::ASCIIToUTF16(expected_title));
247 }
248
249 void NavigateHistory(int num_navigations,
250 HistoryNavigationDirection direction) {
251 content::TestNavigationObserver test_navigation_observer( 140 content::TestNavigationObserver test_navigation_observer(
252 browser()->tab_strip_model()->GetActiveWebContents(), 141 browser()->tab_strip_model()->GetActiveWebContents(),
253 num_navigations); 142 num_navigations);
254 if (direction == HISTORY_NAVIGATE_BACK) { 143 if (direction == HISTORY_NAVIGATE_BACK) {
255 chrome::GoBack(browser(), CURRENT_TAB); 144 chrome::GoBack(browser(), CURRENT_TAB);
256 } else if (direction == HISTORY_NAVIGATE_FORWARD) { 145 } else if (direction == HISTORY_NAVIGATE_FORWARD) {
257 chrome::GoForward(browser(), CURRENT_TAB); 146 chrome::GoForward(browser(), CURRENT_TAB);
258 } else { 147 } else {
259 FAIL(); 148 FAIL();
260 } 149 }
261 test_navigation_observer.Wait(); 150 test_navigation_observer.Wait();
151
152 EXPECT_EQ(title_watcher.WaitAndGetTitle(),
153 base::ASCIIToUTF16(expected_title));
262 } 154 }
263 }; 155 };
264 156
265 class TestFailProvisionalLoadObserver : public content::WebContentsObserver { 157 class TestFailProvisionalLoadObserver : public content::WebContentsObserver {
266 public: 158 public:
267 explicit TestFailProvisionalLoadObserver(content::WebContents* contents) 159 explicit TestFailProvisionalLoadObserver(content::WebContents* contents)
268 : content::WebContentsObserver(contents) {} 160 : content::WebContentsObserver(contents) {}
269 virtual ~TestFailProvisionalLoadObserver() {} 161 virtual ~TestFailProvisionalLoadObserver() {}
270 162
271 // This method is invoked when the provisional load failed. 163 // This method is invoked when the provisional load failed.
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 // See crbug.com/109669 196 // See crbug.com/109669
305 #if defined(USE_AURA) || defined(OS_WIN) 197 #if defined(USE_AURA) || defined(OS_WIN)
306 #define MAYBE_DNSError_Basic DISABLED_DNSError_Basic 198 #define MAYBE_DNSError_Basic DISABLED_DNSError_Basic
307 #else 199 #else
308 #define MAYBE_DNSError_Basic DNSError_Basic 200 #define MAYBE_DNSError_Basic DNSError_Basic
309 #endif 201 #endif
310 // Test that a DNS error occuring in the main frame redirects to an error page. 202 // Test that a DNS error occuring in the main frame redirects to an error page.
311 IN_PROC_BROWSER_TEST_F(ErrorPageTest, MAYBE_DNSError_Basic) { 203 IN_PROC_BROWSER_TEST_F(ErrorPageTest, MAYBE_DNSError_Basic) {
312 // The first navigation should fail, and the second one should be the error 204 // The first navigation should fail, and the second one should be the error
313 // page. 205 // page.
314 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( 206 NavigateToURLAndWaitForTitle(GetDnsErrorURL(), "Mock Link Doctor", 2);
315 browser(), GetDnsErrorURL(), 2);
316 ExpectDisplayingNavigationCorrections(browser(), net::ERR_NAME_NOT_RESOLVED);
317 } 207 }
318 208
319 // See crbug.com/109669 209 // See crbug.com/109669
320 #if defined(USE_AURA) 210 #if defined(USE_AURA)
321 #define MAYBE_DNSError_GoBack1 DISABLED_DNSError_GoBack1 211 #define MAYBE_DNSError_GoBack1 DISABLED_DNSError_GoBack1
322 #else 212 #else
323 #define MAYBE_DNSError_GoBack1 DNSError_GoBack1 213 #define MAYBE_DNSError_GoBack1 DNSError_GoBack1
324 #endif 214 #endif
325 215
326 // Test that a DNS error occuring in the main frame does not result in an 216 // Test that a DNS error occuring in the main frame does not result in an
327 // additional session history entry. 217 // additional session history entry.
328 IN_PROC_BROWSER_TEST_F(ErrorPageTest, MAYBE_DNSError_GoBack1) { 218 IN_PROC_BROWSER_TEST_F(ErrorPageTest, MAYBE_DNSError_GoBack1) {
329 NavigateToFileURL(FILE_PATH_LITERAL("title2.html")); 219 NavigateToFileURL(FILE_PATH_LITERAL("title2.html"));
330 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( 220 NavigateToURLAndWaitForTitle(GetDnsErrorURL(), "Mock Link Doctor", 2);
331 browser(), GetDnsErrorURL(), 2);
332 ExpectDisplayingNavigationCorrections(browser(), net::ERR_NAME_NOT_RESOLVED);
333 GoBackAndWaitForTitle("Title Of Awesomeness", 1); 221 GoBackAndWaitForTitle("Title Of Awesomeness", 1);
334 } 222 }
335 223
336 // See crbug.com/109669 224 // See crbug.com/109669
337 #if defined(USE_AURA) 225 #if defined(USE_AURA)
338 #define MAYBE_DNSError_GoBack2 DISABLED_DNSError_GoBack2 226 #define MAYBE_DNSError_GoBack2 DISABLED_DNSError_GoBack2
339 #else 227 #else
340 #define MAYBE_DNSError_GoBack2 DNSError_GoBack2 228 #define MAYBE_DNSError_GoBack2 DNSError_GoBack2
341 #endif 229 #endif
342 // Test that a DNS error occuring in the main frame does not result in an 230 // Test that a DNS error occuring in the main frame does not result in an
343 // additional session history entry. 231 // additional session history entry.
344 IN_PROC_BROWSER_TEST_F(ErrorPageTest, DNSError_GoBack2) { 232 IN_PROC_BROWSER_TEST_F(ErrorPageTest, DNSError_GoBack2) {
345 NavigateToFileURL(FILE_PATH_LITERAL("title2.html")); 233 NavigateToFileURL(FILE_PATH_LITERAL("title2.html"));
346 234
347 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( 235 NavigateToURLAndWaitForTitle(GetDnsErrorURL(), "Mock Link Doctor", 2);
348 browser(), GetDnsErrorURL(), 2);
349 ExpectDisplayingNavigationCorrections(browser(), net::ERR_NAME_NOT_RESOLVED);
350
351 NavigateToFileURL(FILE_PATH_LITERAL("title3.html")); 236 NavigateToFileURL(FILE_PATH_LITERAL("title3.html"));
352 237
353 GoBackAndWaitForNavigations(2); 238 GoBackAndWaitForTitle("Mock Link Doctor", 2);
354 ExpectDisplayingNavigationCorrections(browser(), net::ERR_NAME_NOT_RESOLVED);
355
356 GoBackAndWaitForTitle("Title Of Awesomeness", 1); 239 GoBackAndWaitForTitle("Title Of Awesomeness", 1);
357 } 240 }
358 241
359 // See crbug.com/109669 242 // See crbug.com/109669
360 #if defined(USE_AURA) 243 #if defined(USE_AURA)
361 #define MAYBE_DNSError_GoBack2AndForward DISABLED_DNSError_GoBack2AndForward 244 #define MAYBE_DNSError_GoBack2AndForward DISABLED_DNSError_GoBack2AndForward
362 #else 245 #else
363 #define MAYBE_DNSError_GoBack2AndForward DNSError_GoBack2AndForward 246 #define MAYBE_DNSError_GoBack2AndForward DNSError_GoBack2AndForward
364 #endif 247 #endif
365 // Test that a DNS error occuring in the main frame does not result in an 248 // Test that a DNS error occuring in the main frame does not result in an
366 // additional session history entry. 249 // additional session history entry.
367 IN_PROC_BROWSER_TEST_F(ErrorPageTest, DNSError_GoBack2AndForward) { 250 IN_PROC_BROWSER_TEST_F(ErrorPageTest, DNSError_GoBack2AndForward) {
368 NavigateToFileURL(FILE_PATH_LITERAL("title2.html")); 251 NavigateToFileURL(FILE_PATH_LITERAL("title2.html"));
369 252
370 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( 253 NavigateToURLAndWaitForTitle(GetDnsErrorURL(), "Mock Link Doctor", 2);
371 browser(), GetDnsErrorURL(), 2);
372 ExpectDisplayingNavigationCorrections(browser(), net::ERR_NAME_NOT_RESOLVED);
373
374 NavigateToFileURL(FILE_PATH_LITERAL("title3.html")); 254 NavigateToFileURL(FILE_PATH_LITERAL("title3.html"));
375 255
376 GoBackAndWaitForNavigations(2); 256 GoBackAndWaitForTitle("Mock Link Doctor", 2);
377 ExpectDisplayingNavigationCorrections(browser(), net::ERR_NAME_NOT_RESOLVED);
378
379 GoBackAndWaitForTitle("Title Of Awesomeness", 1); 257 GoBackAndWaitForTitle("Title Of Awesomeness", 1);
380 258
381 GoForwardAndWaitForNavigations(2); 259 GoForwardAndWaitForTitle("Mock Link Doctor", 2);
382 ExpectDisplayingNavigationCorrections(browser(), net::ERR_NAME_NOT_RESOLVED);
383 } 260 }
384 261
385 // See crbug.com/109669 262 // See crbug.com/109669
386 #if defined(USE_AURA) 263 #if defined(USE_AURA)
387 #define MAYBE_DNSError_GoBack2Forward2 DISABLED_DNSError_GoBack2Forward2 264 #define MAYBE_DNSError_GoBack2Forward2 DISABLED_DNSError_GoBack2Forward2
388 #else 265 #else
389 #define MAYBE_DNSError_GoBack2Forward2 DNSError_GoBack2Forward2 266 #define MAYBE_DNSError_GoBack2Forward2 DNSError_GoBack2Forward2
390 #endif 267 #endif
391 // Test that a DNS error occuring in the main frame does not result in an 268 // Test that a DNS error occuring in the main frame does not result in an
392 // additional session history entry. 269 // additional session history entry.
393 IN_PROC_BROWSER_TEST_F(ErrorPageTest, DNSError_GoBack2Forward2) { 270 IN_PROC_BROWSER_TEST_F(ErrorPageTest, DNSError_GoBack2Forward2) {
394 NavigateToFileURL(FILE_PATH_LITERAL("title3.html")); 271 NavigateToFileURL(FILE_PATH_LITERAL("title3.html"));
395 272
396 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( 273 NavigateToURLAndWaitForTitle(GetDnsErrorURL(), "Mock Link Doctor", 2);
397 browser(), GetDnsErrorURL(), 2);
398 ExpectDisplayingNavigationCorrections(browser(), net::ERR_NAME_NOT_RESOLVED);
399
400 NavigateToFileURL(FILE_PATH_LITERAL("title2.html")); 274 NavigateToFileURL(FILE_PATH_LITERAL("title2.html"));
401 275
402 GoBackAndWaitForNavigations(2); 276 GoBackAndWaitForTitle("Mock Link Doctor", 2);
403 ExpectDisplayingNavigationCorrections(browser(), net::ERR_NAME_NOT_RESOLVED);
404
405 GoBackAndWaitForTitle("Title Of More Awesomeness", 1); 277 GoBackAndWaitForTitle("Title Of More Awesomeness", 1);
406 278
407 GoForwardAndWaitForNavigations(2); 279 GoForwardAndWaitForTitle("Mock Link Doctor", 2);
408 ExpectDisplayingNavigationCorrections(browser(), net::ERR_NAME_NOT_RESOLVED);
409
410 GoForwardAndWaitForTitle("Title Of Awesomeness", 1); 280 GoForwardAndWaitForTitle("Title Of Awesomeness", 1);
411 } 281 }
412 282
413 // See crbug.com/109669 283 // Test that a DNS error occuring in an iframe.
414 #if defined(USE_AURA)
415 #define MAYBE_DNSError_DoSearch DNSError_DoSearch
416 #else
417 #define MAYBE_DNSError_DoSearch DNSError_DoSearch
418 #endif
419 // Test that the search button on a DNS error page works.
420 IN_PROC_BROWSER_TEST_F(ErrorPageTest, MAYBE_DNSError_DoSearch) {
421 // The first navigation should fail, and the second one should be the error
422 // page.
423 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(
424 browser(), GetDnsErrorURL(), 2);
425 ExpectDisplayingNavigationCorrections(browser(), net::ERR_NAME_NOT_RESOLVED);
426
427 // Do a search and make sure the browser ends up at the right page.
428 content::TestNavigationObserver nav_observer(
429 browser()->tab_strip_model()->GetActiveWebContents(),
430 1);
431 content::TitleWatcher title_watcher(
432 browser()->tab_strip_model()->GetActiveWebContents(),
433 base::ASCIIToUTF16("Title Of More Awesomeness"));
434 ASSERT_TRUE(content::ExecuteScript(
435 browser()->tab_strip_model()->GetActiveWebContents(),
436 "document.getElementById('search-button').click();"));
437 nav_observer.Wait();
438 EXPECT_EQ(base::ASCIIToUTF16("Title Of More Awesomeness"),
439 title_watcher.WaitAndGetTitle());
440
441 // Check the path and query string.
442 std::string url;
443 ASSERT_TRUE(content::ExecuteScriptAndExtractString(
444 browser()->tab_strip_model()->GetActiveWebContents(),
445 "domAutomationController.send(window.location.href);",
446 &url));
447 EXPECT_EQ("/search", GURL(url).path());
448 EXPECT_EQ("q=search%20query", GURL(url).query());
449
450 // Go back to the error page, to make sure the history is correct.
451 GoBackAndWaitForNavigations(2);
452 ExpectDisplayingNavigationCorrections(browser(), net::ERR_NAME_NOT_RESOLVED);
453 }
454
455 // Test that a DNS error occuring in an iframe does not result in showing
456 // navigation corrections.
457 IN_PROC_BROWSER_TEST_F(ErrorPageTest, IFrameDNSError_Basic) { 284 IN_PROC_BROWSER_TEST_F(ErrorPageTest, IFrameDNSError_Basic) {
458 NavigateToURLAndWaitForTitle( 285 NavigateToURLAndWaitForTitle(
459 content::URLRequestMockHTTPJob::GetMockUrl( 286 content::URLRequestMockHTTPJob::GetMockUrl(
460 base::FilePath(FILE_PATH_LITERAL("iframe_dns_error.html"))), 287 base::FilePath(FILE_PATH_LITERAL("iframe_dns_error.html"))),
461 "Blah", 288 "Blah",
462 1); 289 1);
463 // We expect to have two history entries, since we started off with navigation 290 // We expect to have two history entries, since we started off with navigation
464 // to "about:blank" and then navigated to "iframe_dns_error.html". 291 // to "about:blank" and then navigated to "iframe_dns_error.html".
465 EXPECT_EQ(2, 292 EXPECT_EQ(2,
466 browser()->tab_strip_model()->GetActiveWebContents()-> 293 browser()->tab_strip_model()->GetActiveWebContents()->
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
558 content::Source<NavigationController>(&wc->GetController())); 385 content::Source<NavigationController>(&wc->GetController()));
559 wc->GetRenderViewHost()->ExecuteJavascriptInWebFrame( 386 wc->GetRenderViewHost()->ExecuteJavascriptInWebFrame(
560 base::string16(), base::ASCIIToUTF16(script)); 387 base::string16(), base::ASCIIToUTF16(script));
561 load_observer.Wait(); 388 load_observer.Wait();
562 389
563 EXPECT_EQ(fail_url, fail_observer.fail_url()); 390 EXPECT_EQ(fail_url, fail_observer.fail_url());
564 EXPECT_EQ(2, wc->GetController().GetEntryCount()); 391 EXPECT_EQ(2, wc->GetController().GetEntryCount());
565 } 392 }
566 } 393 }
567 394
568 // Checks that navigation corrections are not loaded when we receive an actual 395 // Checks that the Link Doctor is not loaded when we receive an actual 404 page.
569 // 404 page.
570 IN_PROC_BROWSER_TEST_F(ErrorPageTest, Page404) { 396 IN_PROC_BROWSER_TEST_F(ErrorPageTest, Page404) {
571 NavigateToURLAndWaitForTitle( 397 NavigateToURLAndWaitForTitle(
572 content::URLRequestMockHTTPJob::GetMockUrl( 398 content::URLRequestMockHTTPJob::GetMockUrl(
573 base::FilePath(FILE_PATH_LITERAL("page404.html"))), 399 base::FilePath(FILE_PATH_LITERAL("page404.html"))),
574 "SUCCESS", 400 "SUCCESS",
575 1); 401 1);
576 } 402 }
577 403
578 // Checks that when an error occurs, the stale cache status of the page 404 // Checks that when an error occurs, the stale cache status of the page
579 // is correctly transferred. 405 // is correctly transferred.
580 IN_PROC_BROWSER_TEST_F(ErrorPageTest, StaleCacheStatus) { 406 IN_PROC_BROWSER_TEST_F(ErrorPageTest, StaleCacheStatus) {
581 ASSERT_TRUE(test_server()->Start()); 407 ASSERT_TRUE(test_server()->Start());
582 // Load cache with entry with "nocache" set, to create stale 408 // Load cache with entry with "nocache" set, to create stale
583 // cache. 409 // cache.
584 GURL test_url(test_server()->GetURL("files/nocache.html")); 410 GURL test_url(test_server()->GetURL("files/nocache.html"));
585 NavigateToURLAndWaitForTitle(test_url, "Nocache Test Page", 1); 411 NavigateToURLAndWaitForTitle(test_url, "Nocache Test Page", 1);
586 412
587 // Reload same URL after forcing an error from the the network layer; 413 // Reload same URL after forcing an error from the the network layer;
588 // confirm that the error page is told the cached copy exists. 414 // confirm that the error page is told the cached copy exists.
589 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter = 415 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter =
590 browser()->profile()->GetRequestContext(); 416 browser()->profile()->GetRequestContext();
591 BrowserThread::PostTask( 417 BrowserThread::PostTask(
592 BrowserThread::IO, FROM_HERE, 418 BrowserThread::IO, FROM_HERE,
593 base::Bind(&InterceptNetworkTransactions, url_request_context_getter, 419 base::Bind(&InterceptNetworkTransactions, url_request_context_getter,
420 // Note that we can't use an error that'll invoke the link
421 // doctor. In normal network error conditions that would
422 // work (because the link doctor fetch would also fail,
423 // putting us back in the main offline path), but
424 // SetUrlRequestMocksEnabled() has also specfied a link
425 // doctor mock, which will be accessible because it
426 // won't go through the network cache.
594 net::ERR_FAILED)); 427 net::ERR_FAILED));
595 428
596 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( 429 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(
597 // With no navigation corrections to load, there's only one navigation. 430 // With no link doctor load, there's only one navigation.
598 browser(), test_url, 1); 431 browser(), test_url, 1);
599 EXPECT_TRUE(ProbeStaleCopyValue(true)); 432 EXPECT_TRUE(ProbeStaleCopyValue(true));
600 433
601 // Clear the cache and reload the same URL; confirm the error page is told 434 // Clear the cache and reload the same URL; confirm the error page is told
602 // that there is no cached copy. 435 // that there is no cached copy.
603 BrowsingDataRemover* remover = 436 BrowsingDataRemover* remover =
604 BrowsingDataRemover::CreateForUnboundedRange(browser()->profile()); 437 BrowsingDataRemover::CreateForUnboundedRange(browser()->profile());
605 remover->Remove(BrowsingDataRemover::REMOVE_CACHE, 438 remover->Remove(BrowsingDataRemover::REMOVE_CACHE,
606 BrowsingDataHelper::UNPROTECTED_WEB); 439 BrowsingDataHelper::UNPROTECTED_WEB);
607 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( 440 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(
608 browser(), test_url, 1); 441 browser(), test_url, 1);
609 EXPECT_TRUE(ProbeStaleCopyValue(false)); 442 EXPECT_TRUE(ProbeStaleCopyValue(false));
610 } 443 }
611 444
445 // Returns Javascript code that executes plain text search for the page.
446 // Pass into content::ExecuteScriptAndExtractBool as |script| parameter.
447 std::string GetTextContentContainsStringScript(
448 const std::string& value_to_search) {
449 return base::StringPrintf(
450 "var textContent = document.body.textContent;"
451 "var hasError = textContent.indexOf('%s') >= 0;"
452 "domAutomationController.send(hasError);",
453 value_to_search.c_str());
454 }
455
612 // Protocol handler that fails all requests with net::ERR_ADDRESS_UNREACHABLE. 456 // Protocol handler that fails all requests with net::ERR_ADDRESS_UNREACHABLE.
613 class AddressUnreachableProtocolHandler 457 class AddressUnreachableProtocolHandler
614 : public net::URLRequestJobFactory::ProtocolHandler { 458 : public net::URLRequestJobFactory::ProtocolHandler {
615 public: 459 public:
616 AddressUnreachableProtocolHandler() {} 460 AddressUnreachableProtocolHandler() {}
617 virtual ~AddressUnreachableProtocolHandler() {} 461 virtual ~AddressUnreachableProtocolHandler() {}
618 462
619 // net::URLRequestJobFactory::ProtocolHandler: 463 // net::URLRequestJobFactory::ProtocolHandler:
620 virtual net::URLRequestJob* MaybeCreateJob( 464 virtual net::URLRequestJob* MaybeCreateJob(
621 net::URLRequest* request, 465 net::URLRequest* request,
622 net::NetworkDelegate* network_delegate) const OVERRIDE { 466 net::NetworkDelegate* network_delegate) const OVERRIDE {
623 return new URLRequestFailedJob(request, 467 return new URLRequestFailedJob(request,
624 network_delegate, 468 network_delegate,
625 net::ERR_ADDRESS_UNREACHABLE); 469 net::ERR_ADDRESS_UNREACHABLE);
626 } 470 }
627 471
628 private: 472 private:
629 DISALLOW_COPY_AND_ASSIGN(AddressUnreachableProtocolHandler); 473 DISALLOW_COPY_AND_ASSIGN(AddressUnreachableProtocolHandler);
630 }; 474 };
631 475
632 // A test fixture that returns ERR_ADDRESS_UNREACHABLE for all navigation 476 // A test fixture that returns ERR_ADDRESS_UNREACHABLE for all Link Doctor
633 // correction requests. ERR_NAME_NOT_RESOLVED is more typical, but need to use 477 // requests. ERR_NAME_NOT_RESOLVED is more typical, but need to use a different
634 // a different error for the correction service and the original page to 478 // error for the Link Doctor and the original page to validate the right page
635 // validate the right page is being displayed. 479 // is being displayed.
636 class ErrorPageNavigationCorrectionsFailTest : public ErrorPageTest { 480 class ErrorPageLinkDoctorFailTest : public ErrorPageTest {
637 public: 481 public:
638 // InProcessBrowserTest: 482 // InProcessBrowserTest:
639 virtual void SetUpOnMainThread() OVERRIDE { 483 virtual void SetUpOnMainThread() OVERRIDE {
640 BrowserThread::PostTask( 484 BrowserThread::PostTask(
641 BrowserThread::IO, FROM_HERE, 485 BrowserThread::IO, FROM_HERE,
642 base::Bind(&ErrorPageNavigationCorrectionsFailTest::AddFilters)); 486 base::Bind(&ErrorPageLinkDoctorFailTest::AddFilters));
643 } 487 }
644 488
645 virtual void CleanUpOnMainThread() OVERRIDE { 489 virtual void CleanUpOnMainThread() OVERRIDE {
646 BrowserThread::PostTask( 490 BrowserThread::PostTask(
647 BrowserThread::IO, FROM_HERE, 491 BrowserThread::IO, FROM_HERE,
648 base::Bind(&ErrorPageNavigationCorrectionsFailTest::RemoveFilters)); 492 base::Bind(&ErrorPageLinkDoctorFailTest::RemoveFilters));
649 } 493 }
650 494
651 private: 495 private:
652 // Adds a filter that causes all correction service requests to fail with 496 // Adds a filter that causes all requests for the Link Doctor's scheme and
653 // ERR_ADDRESS_UNREACHABLE. 497 // host to fail with ERR_ADDRESS_UNREACHABLE. Since the Link Doctor adds
498 // query strings, it's not enough to just fail exact matches.
654 // 499 //
655 // Also adds the content::URLRequestFailedJob filter. 500 // Also adds the content::URLRequestFailedJob filter.
656 static void AddFilters() { 501 static void AddFilters() {
657 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 502 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
658 content::URLRequestFailedJob::AddUrlHandler(); 503 content::URLRequestFailedJob::AddUrlHandler();
659 504
660 net::URLRequestFilter::GetInstance()->AddUrlProtocolHandler( 505 net::URLRequestFilter::GetInstance()->AddHostnameProtocolHandler(
661 google_util::LinkDoctorBaseURL(), 506 google_util::LinkDoctorBaseURL().scheme(),
507 google_util::LinkDoctorBaseURL().host(),
662 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler>( 508 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler>(
663 new AddressUnreachableProtocolHandler())); 509 new AddressUnreachableProtocolHandler()));
664 } 510 }
665 511
666 static void RemoveFilters() { 512 static void RemoveFilters() {
667 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 513 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
668 net::URLRequestFilter::GetInstance()->ClearHandlers(); 514 net::URLRequestFilter::GetInstance()->ClearHandlers();
669 } 515 }
670 }; 516 };
671 517
672 // Make sure that when corrections fail to load, the network error page is 518 // Make sure that when the Link Doctor fails to load, the network error page is
673 // successfully loaded. 519 // successfully loaded.
674 IN_PROC_BROWSER_TEST_F(ErrorPageNavigationCorrectionsFailTest, 520 IN_PROC_BROWSER_TEST_F(ErrorPageLinkDoctorFailTest, LinkDoctorFail) {
675 FetchCorrectionsFails) {
676 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( 521 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(
677 browser(), 522 browser(),
678 URLRequestFailedJob::GetMockHttpUrl(net::ERR_NAME_NOT_RESOLVED), 523 URLRequestFailedJob::GetMockHttpUrl(net::ERR_NAME_NOT_RESOLVED),
679 2); 524 2);
680 525
681 // Verify that the expected error page is being displayed. 526 // Verify that the expected error page is being displayed. Do this by making
682 ExpectDisplayingLocalErrorPage(browser(), net::ERR_NAME_NOT_RESOLVED); 527 // sure the original error code (ERR_NAME_NOT_RESOLVED) is displayed.
528 bool result = false;
529 EXPECT_TRUE(content::ExecuteScriptAndExtractBool(
530 browser()->tab_strip_model()->GetActiveWebContents(),
531 GetTextContentContainsStringScript("ERR_NAME_NOT_RESOLVED"),
532 &result));
533 EXPECT_TRUE(result);
683 } 534 }
684 535
685 // Checks that when an error occurs and a corrections fail to load, the stale 536 // Checks that when an error occurs and a link doctor load fails, the stale
686 // cache status of the page is correctly transferred. Most logic copied 537 // cache status of the page is correctly transferred. Most logic copied
687 // from StaleCacheStatus above. 538 // from StaleCacheStatus above.
688 IN_PROC_BROWSER_TEST_F(ErrorPageNavigationCorrectionsFailTest, 539 IN_PROC_BROWSER_TEST_F(ErrorPageLinkDoctorFailTest,
689 StaleCacheStatusFailedCorrections) { 540 StaleCacheStatusFailedLinkDoctor) {
690 ASSERT_TRUE(test_server()->Start()); 541 ASSERT_TRUE(test_server()->Start());
691 // Load cache with entry with "nocache" set, to create stale 542 // Load cache with entry with "nocache" set, to create stale
692 // cache. 543 // cache.
693 GURL test_url(test_server()->GetURL("files/nocache.html")); 544 GURL test_url(test_server()->GetURL("files/nocache.html"));
694 NavigateToURLAndWaitForTitle(test_url, "Nocache Test Page", 1); 545 NavigateToURLAndWaitForTitle(test_url, "Nocache Test Page", 1);
695 546
696 // Reload same URL after forcing an error from the the network layer; 547 // Reload same URL after forcing an error from the the network layer;
697 // confirm that the error page is told the cached copy exists. 548 // confirm that the error page is told the cached copy exists.
698 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter = 549 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter =
699 browser()->profile()->GetRequestContext(); 550 browser()->profile()->GetRequestContext();
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
753 }; 604 };
754 605
755 const char ErrorPageForIDNTest::kHostname[] = 606 const char ErrorPageForIDNTest::kHostname[] =
756 "xn--d1abbgf6aiiy.xn--p1ai"; 607 "xn--d1abbgf6aiiy.xn--p1ai";
757 const char ErrorPageForIDNTest::kHostnameJSUnicode[] = 608 const char ErrorPageForIDNTest::kHostnameJSUnicode[] =
758 "\\u043f\\u0440\\u0435\\u0437\\u0438\\u0434\\u0435\\u043d\\u0442." 609 "\\u043f\\u0440\\u0435\\u0437\\u0438\\u0434\\u0435\\u043d\\u0442."
759 "\\u0440\\u0444"; 610 "\\u0440\\u0444";
760 611
761 // Make sure error page shows correct unicode for IDN. 612 // Make sure error page shows correct unicode for IDN.
762 IN_PROC_BROWSER_TEST_F(ErrorPageForIDNTest, IDN) { 613 IN_PROC_BROWSER_TEST_F(ErrorPageForIDNTest, IDN) {
763 // ERR_UNSAFE_PORT will not trigger navigation corrections. 614 // ERR_UNSAFE_PORT will not trigger the link doctor.
764 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( 615 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(
765 browser(), 616 browser(),
766 URLRequestFailedJob::GetMockHttpUrlForHostname(net::ERR_UNSAFE_PORT, 617 URLRequestFailedJob::GetMockHttpUrlForHostname(net::ERR_UNSAFE_PORT,
767 kHostname), 618 kHostname),
768 1); 619 1);
769 620
770 ToggleHelpBox(browser()); 621 bool result = false;
771 EXPECT_TRUE(IsDisplayingText(browser(), kHostnameJSUnicode)); 622 EXPECT_TRUE(content::ExecuteScriptAndExtractBool(
623 browser()->tab_strip_model()->GetActiveWebContents(),
624 GetTextContentContainsStringScript(kHostnameJSUnicode),
625 &result));
626 EXPECT_TRUE(result);
772 } 627 }
773 628
774 } // namespace 629 } // 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