OLD | NEW |
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/browsing_data/browsing_data_helper.h" | 11 #include "chrome/browser/browsing_data/browsing_data_helper.h" |
10 #include "chrome/browser/browsing_data/browsing_data_remover.h" | 12 #include "chrome/browser/browsing_data/browsing_data_remover.h" |
11 #include "chrome/browser/google/google_util.h" | 13 #include "chrome/browser/google/google_util.h" |
12 #include "chrome/browser/net/url_request_mock_util.h" | 14 #include "chrome/browser/net/url_request_mock_util.h" |
13 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
14 #include "chrome/browser/ui/browser.h" | 16 #include "chrome/browser/ui/browser.h" |
15 #include "chrome/browser/ui/browser_commands.h" | 17 #include "chrome/browser/ui/browser_commands.h" |
16 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 18 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 19 #include "chrome/common/chrome_paths.h" |
17 #include "chrome/common/pref_names.h" | 20 #include "chrome/common/pref_names.h" |
18 #include "chrome/test/base/in_process_browser_test.h" | 21 #include "chrome/test/base/in_process_browser_test.h" |
19 #include "chrome/test/base/ui_test_utils.h" | 22 #include "chrome/test/base/ui_test_utils.h" |
20 #include "content/public/browser/notification_service.h" | 23 #include "content/public/browser/notification_service.h" |
21 #include "content/public/browser/render_view_host.h" | 24 #include "content/public/browser/render_view_host.h" |
22 #include "content/public/browser/web_contents.h" | 25 #include "content/public/browser/web_contents.h" |
23 #include "content/public/browser/web_contents_observer.h" | 26 #include "content/public/browser/web_contents_observer.h" |
24 #include "content/public/test/browser_test_utils.h" | 27 #include "content/public/test/browser_test_utils.h" |
25 #include "content/public/test/test_navigation_observer.h" | 28 #include "content/public/test/test_navigation_observer.h" |
26 #include "content/test/net/url_request_failed_job.h" | 29 #include "content/test/net/url_request_failed_job.h" |
27 #include "content/test/net/url_request_mock_http_job.h" | 30 #include "content/test/net/url_request_mock_http_job.h" |
28 #include "net/base/net_errors.h" | 31 #include "net/base/net_errors.h" |
29 #include "net/base/net_util.h" | 32 #include "net/base/net_util.h" |
30 #include "net/http/failing_http_transaction_factory.h" | 33 #include "net/http/failing_http_transaction_factory.h" |
31 #include "net/http/http_cache.h" | 34 #include "net/http/http_cache.h" |
32 #include "net/test/spawned_test_server/spawned_test_server.h" | 35 #include "net/test/spawned_test_server/spawned_test_server.h" |
33 #include "net/url_request/url_request_context.h" | 36 #include "net/url_request/url_request_context.h" |
34 #include "net/url_request/url_request_context_getter.h" | 37 #include "net/url_request/url_request_context_getter.h" |
35 #include "net/url_request/url_request_filter.h" | 38 #include "net/url_request/url_request_filter.h" |
36 #include "net/url_request/url_request_job_factory.h" | 39 #include "net/url_request/url_request_job_factory.h" |
37 | 40 |
38 using content::BrowserThread; | 41 using content::BrowserThread; |
39 using content::NavigationController; | 42 using content::NavigationController; |
40 using content::URLRequestFailedJob; | 43 using content::URLRequestFailedJob; |
41 | 44 |
42 namespace { | 45 namespace { |
43 | 46 |
| 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 Link Doctor information, 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 Link Doctor suggestions. |
| 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 Link Doctor |
| 105 // is being displayed, with the specified specified error code. |
| 106 void ExpectDisplayingLinkDoctor(Browser* browser, net::Error error_code) { |
| 107 // Expand the help box so innerText will include text below the fold. |
| 108 ToggleHelpBox(browser); |
| 109 |
| 110 EXPECT_TRUE(IsDisplayingNetError(browser, error_code)); |
| 111 |
| 112 // Check that suggestions from the mock Link Doctor results are displayed. |
| 113 EXPECT_TRUE(IsDisplayingText(browser, "http://correction1/")); |
| 114 EXPECT_TRUE(IsDisplayingText(browser, "http://correction2/")); |
| 115 |
| 116 // Check that the search box is populated correctly. |
| 117 bool search_box_populated = false; |
| 118 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( |
| 119 browser->tab_strip_model()->GetActiveWebContents(), |
| 120 "var searchText = document.getElementById('search-box').value;" |
| 121 "domAutomationController.send(searchText == 'search query');", |
| 122 &search_box_populated)); |
| 123 EXPECT_TRUE(search_box_populated); |
| 124 } |
| 125 |
44 class ErrorPageTest : public InProcessBrowserTest { | 126 class ErrorPageTest : public InProcessBrowserTest { |
45 public: | 127 public: |
46 enum HistoryNavigationDirection { | 128 enum HistoryNavigationDirection { |
47 HISTORY_NAVIGATE_BACK, | 129 HISTORY_NAVIGATE_BACK, |
48 HISTORY_NAVIGATE_FORWARD, | 130 HISTORY_NAVIGATE_FORWARD, |
49 }; | 131 }; |
50 | 132 |
51 // Navigates the active tab to a mock url created for the file at |file_path|. | 133 // Navigates the active tab to a mock url created for the file at |file_path|. |
52 void NavigateToFileURL(const base::FilePath::StringType& file_path) { | 134 void NavigateToFileURL(const base::FilePath::StringType& file_path) { |
53 ui_test_utils::NavigateToURL( | 135 ui_test_utils::NavigateToURL( |
(...skipping 28 matching lines...) Expand all Loading... |
82 | 164 |
83 // Navigates forward in the history and waits for |num_navigations| to occur, | 165 // Navigates forward in the history and waits for |num_navigations| to occur, |
84 // and the title to change to |expected_title|. | 166 // and the title to change to |expected_title|. |
85 void GoForwardAndWaitForTitle(const std::string& expected_title, | 167 void GoForwardAndWaitForTitle(const std::string& expected_title, |
86 int num_navigations) { | 168 int num_navigations) { |
87 NavigateHistoryAndWaitForTitle(expected_title, | 169 NavigateHistoryAndWaitForTitle(expected_title, |
88 num_navigations, | 170 num_navigations, |
89 HISTORY_NAVIGATE_FORWARD); | 171 HISTORY_NAVIGATE_FORWARD); |
90 } | 172 } |
91 | 173 |
| 174 void GoBackAndWaitForNavigations(int num_navigations) { |
| 175 NavigateHistory(num_navigations, HISTORY_NAVIGATE_BACK); |
| 176 } |
| 177 |
| 178 void GoForwardAndWaitForNavigations(int num_navigations) { |
| 179 NavigateHistory(num_navigations, HISTORY_NAVIGATE_FORWARD); |
| 180 } |
| 181 |
92 // Confirms that the javascript variable indicating whether or not we have | 182 // Confirms that the javascript variable indicating whether or not we have |
93 // a stale copy in the cache has been set to |expected|. | 183 // a stale copy in the cache has been set to |expected|. |
94 bool ProbeStaleCopyValue(bool expected) { | 184 bool ProbeStaleCopyValue(bool expected) { |
95 const char* js_cache_probe = | 185 const char* js_cache_probe = |
96 "(function () {\n" | 186 "(function () {\n" |
97 " if ('staleCopyInCache' in templateData) {\n" | 187 " if ('staleCopyInCache' in templateData) {\n" |
98 " domAutomationController.send(\n" | 188 " domAutomationController.send(\n" |
99 " templateData.staleCopyInCache ? 'yes' : 'no');\n" | 189 " templateData.staleCopyInCache ? 'yes' : 'no');\n" |
100 " } else {\n" | 190 " } else {\n" |
101 " domAutomationController.send('absent');\n" | 191 " domAutomationController.send('absent');\n" |
102 " }\n" | 192 " }\n" |
103 "})();"; | 193 "})();"; |
104 | 194 |
105 std::string result; | 195 std::string result; |
106 bool ret = | 196 bool ret = |
107 content::ExecuteScriptAndExtractString( | 197 content::ExecuteScriptAndExtractString( |
108 browser()->tab_strip_model()->GetActiveWebContents(), | 198 browser()->tab_strip_model()->GetActiveWebContents(), |
109 js_cache_probe, | 199 js_cache_probe, |
110 &result); | 200 &result); |
111 EXPECT_TRUE(ret); | 201 EXPECT_TRUE(ret); |
112 if (!ret) | 202 if (!ret) |
113 return false; | 203 return false; |
114 EXPECT_EQ(expected ? "yes" : "no", result); | 204 EXPECT_EQ(expected ? "yes" : "no", result); |
115 return ((expected ? "yes" : "no") == result); | 205 return ((expected ? "yes" : "no") == result); |
116 } | 206 } |
117 | 207 |
118 protected: | 208 protected: |
| 209 static void EnableMocks(const GURL& search_url) { |
| 210 chrome_browser_net::SetUrlRequestMocksEnabled(true); |
| 211 |
| 212 // Add a mock for the search engine the error page will use. |
| 213 base::FilePath root_http; |
| 214 PathService::Get(chrome::DIR_TEST_DATA, &root_http); |
| 215 content::URLRequestMockHTTPJob::AddHostnameToFileHandler( |
| 216 search_url.host(), root_http.AppendASCII("title3.html")); |
| 217 } |
| 218 |
119 virtual void SetUpOnMainThread() OVERRIDE { | 219 virtual void SetUpOnMainThread() OVERRIDE { |
120 BrowserThread::PostTask( | 220 BrowserThread::PostTask( |
121 BrowserThread::IO, FROM_HERE, | 221 BrowserThread::IO, FROM_HERE, |
122 base::Bind(&chrome_browser_net::SetUrlRequestMocksEnabled, true)); | 222 base::Bind(&ErrorPageTest::EnableMocks, |
| 223 google_util::GetGoogleSearchURL(browser()->profile()))); |
123 } | 224 } |
124 | 225 |
125 // Returns a GURL that results in a DNS error. | 226 // Returns a GURL that results in a DNS error. |
126 GURL GetDnsErrorURL() const { | 227 GURL GetDnsErrorURL() const { |
127 return URLRequestFailedJob::GetMockHttpUrl(net::ERR_NAME_NOT_RESOLVED); | 228 return URLRequestFailedJob::GetMockHttpUrl(net::ERR_NAME_NOT_RESOLVED); |
128 } | 229 } |
129 | 230 |
130 private: | 231 private: |
131 // Navigates the browser the indicated direction in the history and waits for | 232 // Navigates the browser the indicated direction in the history and waits for |
132 // |num_navigations| to occur and the title to change to |expected_title|. | 233 // |num_navigations| to occur and the title to change to |expected_title|. |
133 void NavigateHistoryAndWaitForTitle(const std::string& expected_title, | 234 void NavigateHistoryAndWaitForTitle(const std::string& expected_title, |
134 int num_navigations, | 235 int num_navigations, |
135 HistoryNavigationDirection direction) { | 236 HistoryNavigationDirection direction) { |
136 content::TitleWatcher title_watcher( | 237 content::TitleWatcher title_watcher( |
137 browser()->tab_strip_model()->GetActiveWebContents(), | 238 browser()->tab_strip_model()->GetActiveWebContents(), |
138 base::ASCIIToUTF16(expected_title)); | 239 base::ASCIIToUTF16(expected_title)); |
139 | 240 |
| 241 NavigateHistory(num_navigations, direction); |
| 242 |
| 243 EXPECT_EQ(title_watcher.WaitAndGetTitle(), |
| 244 base::ASCIIToUTF16(expected_title)); |
| 245 } |
| 246 |
| 247 void NavigateHistory(int num_navigations, |
| 248 HistoryNavigationDirection direction) { |
140 content::TestNavigationObserver test_navigation_observer( | 249 content::TestNavigationObserver test_navigation_observer( |
141 browser()->tab_strip_model()->GetActiveWebContents(), | 250 browser()->tab_strip_model()->GetActiveWebContents(), |
142 num_navigations); | 251 num_navigations); |
143 if (direction == HISTORY_NAVIGATE_BACK) { | 252 if (direction == HISTORY_NAVIGATE_BACK) { |
144 chrome::GoBack(browser(), CURRENT_TAB); | 253 chrome::GoBack(browser(), CURRENT_TAB); |
145 } else if (direction == HISTORY_NAVIGATE_FORWARD) { | 254 } else if (direction == HISTORY_NAVIGATE_FORWARD) { |
146 chrome::GoForward(browser(), CURRENT_TAB); | 255 chrome::GoForward(browser(), CURRENT_TAB); |
147 } else { | 256 } else { |
148 FAIL(); | 257 FAIL(); |
149 } | 258 } |
150 test_navigation_observer.Wait(); | 259 test_navigation_observer.Wait(); |
151 | |
152 EXPECT_EQ(title_watcher.WaitAndGetTitle(), | |
153 base::ASCIIToUTF16(expected_title)); | |
154 } | 260 } |
155 }; | 261 }; |
156 | 262 |
157 class TestFailProvisionalLoadObserver : public content::WebContentsObserver { | 263 class TestFailProvisionalLoadObserver : public content::WebContentsObserver { |
158 public: | 264 public: |
159 explicit TestFailProvisionalLoadObserver(content::WebContents* contents) | 265 explicit TestFailProvisionalLoadObserver(content::WebContents* contents) |
160 : content::WebContentsObserver(contents) {} | 266 : content::WebContentsObserver(contents) {} |
161 virtual ~TestFailProvisionalLoadObserver() {} | 267 virtual ~TestFailProvisionalLoadObserver() {} |
162 | 268 |
163 // This method is invoked when the provisional load failed. | 269 // This method is invoked when the provisional load failed. |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 // See crbug.com/109669 | 302 // See crbug.com/109669 |
197 #if defined(USE_AURA) || defined(OS_WIN) | 303 #if defined(USE_AURA) || defined(OS_WIN) |
198 #define MAYBE_DNSError_Basic DISABLED_DNSError_Basic | 304 #define MAYBE_DNSError_Basic DISABLED_DNSError_Basic |
199 #else | 305 #else |
200 #define MAYBE_DNSError_Basic DNSError_Basic | 306 #define MAYBE_DNSError_Basic DNSError_Basic |
201 #endif | 307 #endif |
202 // Test that a DNS error occuring in the main frame redirects to an error page. | 308 // Test that a DNS error occuring in the main frame redirects to an error page. |
203 IN_PROC_BROWSER_TEST_F(ErrorPageTest, MAYBE_DNSError_Basic) { | 309 IN_PROC_BROWSER_TEST_F(ErrorPageTest, MAYBE_DNSError_Basic) { |
204 // The first navigation should fail, and the second one should be the error | 310 // The first navigation should fail, and the second one should be the error |
205 // page. | 311 // page. |
206 NavigateToURLAndWaitForTitle(GetDnsErrorURL(), "Mock Link Doctor", 2); | 312 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( |
| 313 browser(), GetDnsErrorURL(), 2); |
| 314 ExpectDisplayingLinkDoctor(browser(), net::ERR_NAME_NOT_RESOLVED); |
207 } | 315 } |
208 | 316 |
209 // See crbug.com/109669 | 317 // See crbug.com/109669 |
210 #if defined(USE_AURA) | 318 #if defined(USE_AURA) |
211 #define MAYBE_DNSError_GoBack1 DISABLED_DNSError_GoBack1 | 319 #define MAYBE_DNSError_GoBack1 DISABLED_DNSError_GoBack1 |
212 #else | 320 #else |
213 #define MAYBE_DNSError_GoBack1 DNSError_GoBack1 | 321 #define MAYBE_DNSError_GoBack1 DNSError_GoBack1 |
214 #endif | 322 #endif |
215 | 323 |
216 // Test that a DNS error occuring in the main frame does not result in an | 324 // Test that a DNS error occuring in the main frame does not result in an |
217 // additional session history entry. | 325 // additional session history entry. |
218 IN_PROC_BROWSER_TEST_F(ErrorPageTest, MAYBE_DNSError_GoBack1) { | 326 IN_PROC_BROWSER_TEST_F(ErrorPageTest, MAYBE_DNSError_GoBack1) { |
219 NavigateToFileURL(FILE_PATH_LITERAL("title2.html")); | 327 NavigateToFileURL(FILE_PATH_LITERAL("title2.html")); |
220 NavigateToURLAndWaitForTitle(GetDnsErrorURL(), "Mock Link Doctor", 2); | 328 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( |
| 329 browser(), GetDnsErrorURL(), 2); |
| 330 ExpectDisplayingLinkDoctor(browser(), net::ERR_NAME_NOT_RESOLVED); |
221 GoBackAndWaitForTitle("Title Of Awesomeness", 1); | 331 GoBackAndWaitForTitle("Title Of Awesomeness", 1); |
222 } | 332 } |
223 | 333 |
224 // See crbug.com/109669 | 334 // See crbug.com/109669 |
225 #if defined(USE_AURA) | 335 #if defined(USE_AURA) |
226 #define MAYBE_DNSError_GoBack2 DISABLED_DNSError_GoBack2 | 336 #define MAYBE_DNSError_GoBack2 DISABLED_DNSError_GoBack2 |
227 #else | 337 #else |
228 #define MAYBE_DNSError_GoBack2 DNSError_GoBack2 | 338 #define MAYBE_DNSError_GoBack2 DNSError_GoBack2 |
229 #endif | 339 #endif |
230 // Test that a DNS error occuring in the main frame does not result in an | 340 // Test that a DNS error occuring in the main frame does not result in an |
231 // additional session history entry. | 341 // additional session history entry. |
232 IN_PROC_BROWSER_TEST_F(ErrorPageTest, DNSError_GoBack2) { | 342 IN_PROC_BROWSER_TEST_F(ErrorPageTest, DNSError_GoBack2) { |
233 NavigateToFileURL(FILE_PATH_LITERAL("title2.html")); | 343 NavigateToFileURL(FILE_PATH_LITERAL("title2.html")); |
234 | 344 |
235 NavigateToURLAndWaitForTitle(GetDnsErrorURL(), "Mock Link Doctor", 2); | 345 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( |
| 346 browser(), GetDnsErrorURL(), 2); |
| 347 ExpectDisplayingLinkDoctor(browser(), net::ERR_NAME_NOT_RESOLVED); |
| 348 |
236 NavigateToFileURL(FILE_PATH_LITERAL("title3.html")); | 349 NavigateToFileURL(FILE_PATH_LITERAL("title3.html")); |
237 | 350 |
238 GoBackAndWaitForTitle("Mock Link Doctor", 2); | 351 GoBackAndWaitForNavigations(2); |
| 352 ExpectDisplayingLinkDoctor(browser(), net::ERR_NAME_NOT_RESOLVED); |
| 353 |
239 GoBackAndWaitForTitle("Title Of Awesomeness", 1); | 354 GoBackAndWaitForTitle("Title Of Awesomeness", 1); |
240 } | 355 } |
241 | 356 |
242 // See crbug.com/109669 | 357 // See crbug.com/109669 |
243 #if defined(USE_AURA) | 358 #if defined(USE_AURA) |
244 #define MAYBE_DNSError_GoBack2AndForward DISABLED_DNSError_GoBack2AndForward | 359 #define MAYBE_DNSError_GoBack2AndForward DISABLED_DNSError_GoBack2AndForward |
245 #else | 360 #else |
246 #define MAYBE_DNSError_GoBack2AndForward DNSError_GoBack2AndForward | 361 #define MAYBE_DNSError_GoBack2AndForward DNSError_GoBack2AndForward |
247 #endif | 362 #endif |
248 // Test that a DNS error occuring in the main frame does not result in an | 363 // Test that a DNS error occuring in the main frame does not result in an |
249 // additional session history entry. | 364 // additional session history entry. |
250 IN_PROC_BROWSER_TEST_F(ErrorPageTest, DNSError_GoBack2AndForward) { | 365 IN_PROC_BROWSER_TEST_F(ErrorPageTest, DNSError_GoBack2AndForward) { |
251 NavigateToFileURL(FILE_PATH_LITERAL("title2.html")); | 366 NavigateToFileURL(FILE_PATH_LITERAL("title2.html")); |
252 | 367 |
253 NavigateToURLAndWaitForTitle(GetDnsErrorURL(), "Mock Link Doctor", 2); | 368 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( |
| 369 browser(), GetDnsErrorURL(), 2); |
| 370 ExpectDisplayingLinkDoctor(browser(), net::ERR_NAME_NOT_RESOLVED); |
| 371 |
254 NavigateToFileURL(FILE_PATH_LITERAL("title3.html")); | 372 NavigateToFileURL(FILE_PATH_LITERAL("title3.html")); |
255 | 373 |
256 GoBackAndWaitForTitle("Mock Link Doctor", 2); | 374 GoBackAndWaitForNavigations(2); |
| 375 ExpectDisplayingLinkDoctor(browser(), net::ERR_NAME_NOT_RESOLVED); |
| 376 |
257 GoBackAndWaitForTitle("Title Of Awesomeness", 1); | 377 GoBackAndWaitForTitle("Title Of Awesomeness", 1); |
258 | 378 |
259 GoForwardAndWaitForTitle("Mock Link Doctor", 2); | 379 GoForwardAndWaitForNavigations(2); |
| 380 ExpectDisplayingLinkDoctor(browser(), net::ERR_NAME_NOT_RESOLVED); |
260 } | 381 } |
261 | 382 |
262 // See crbug.com/109669 | 383 // See crbug.com/109669 |
263 #if defined(USE_AURA) | 384 #if defined(USE_AURA) |
264 #define MAYBE_DNSError_GoBack2Forward2 DISABLED_DNSError_GoBack2Forward2 | 385 #define MAYBE_DNSError_GoBack2Forward2 DISABLED_DNSError_GoBack2Forward2 |
265 #else | 386 #else |
266 #define MAYBE_DNSError_GoBack2Forward2 DNSError_GoBack2Forward2 | 387 #define MAYBE_DNSError_GoBack2Forward2 DNSError_GoBack2Forward2 |
267 #endif | 388 #endif |
268 // Test that a DNS error occuring in the main frame does not result in an | 389 // Test that a DNS error occuring in the main frame does not result in an |
269 // additional session history entry. | 390 // additional session history entry. |
270 IN_PROC_BROWSER_TEST_F(ErrorPageTest, DNSError_GoBack2Forward2) { | 391 IN_PROC_BROWSER_TEST_F(ErrorPageTest, DNSError_GoBack2Forward2) { |
271 NavigateToFileURL(FILE_PATH_LITERAL("title3.html")); | 392 NavigateToFileURL(FILE_PATH_LITERAL("title3.html")); |
272 | 393 |
273 NavigateToURLAndWaitForTitle(GetDnsErrorURL(), "Mock Link Doctor", 2); | 394 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( |
| 395 browser(), GetDnsErrorURL(), 2); |
| 396 ExpectDisplayingLinkDoctor(browser(), net::ERR_NAME_NOT_RESOLVED); |
| 397 |
274 NavigateToFileURL(FILE_PATH_LITERAL("title2.html")); | 398 NavigateToFileURL(FILE_PATH_LITERAL("title2.html")); |
275 | 399 |
276 GoBackAndWaitForTitle("Mock Link Doctor", 2); | 400 GoBackAndWaitForNavigations(2); |
| 401 ExpectDisplayingLinkDoctor(browser(), net::ERR_NAME_NOT_RESOLVED); |
| 402 |
277 GoBackAndWaitForTitle("Title Of More Awesomeness", 1); | 403 GoBackAndWaitForTitle("Title Of More Awesomeness", 1); |
278 | 404 |
279 GoForwardAndWaitForTitle("Mock Link Doctor", 2); | 405 GoForwardAndWaitForNavigations(2); |
| 406 ExpectDisplayingLinkDoctor(browser(), net::ERR_NAME_NOT_RESOLVED); |
| 407 |
280 GoForwardAndWaitForTitle("Title Of Awesomeness", 1); | 408 GoForwardAndWaitForTitle("Title Of Awesomeness", 1); |
281 } | 409 } |
282 | 410 |
283 // Test that a DNS error occuring in an iframe. | 411 // See crbug.com/109669 |
| 412 #if defined(USE_AURA) |
| 413 #define MAYBE_DNSError_DoSearch DNSError_DoSearch |
| 414 #else |
| 415 #define MAYBE_DNSError_DoSearch DNSError_DoSearch |
| 416 #endif |
| 417 // Test that the search button on a DNS error page works. |
| 418 IN_PROC_BROWSER_TEST_F(ErrorPageTest, MAYBE_DNSError_DoSearch) { |
| 419 // The first navigation should fail, and the second one should be the error |
| 420 // page. |
| 421 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( |
| 422 browser(), GetDnsErrorURL(), 2); |
| 423 ExpectDisplayingLinkDoctor(browser(), net::ERR_NAME_NOT_RESOLVED); |
| 424 |
| 425 // Do a search and make sure the browser ends up at the right page. |
| 426 content::TestNavigationObserver nav_observer( |
| 427 browser()->tab_strip_model()->GetActiveWebContents(), |
| 428 1); |
| 429 content::TitleWatcher title_watcher( |
| 430 browser()->tab_strip_model()->GetActiveWebContents(), |
| 431 base::ASCIIToUTF16("Title Of More Awesomeness")); |
| 432 ASSERT_TRUE(content::ExecuteScript( |
| 433 browser()->tab_strip_model()->GetActiveWebContents(), |
| 434 "document.getElementById('search-button').click();")); |
| 435 nav_observer.Wait(); |
| 436 EXPECT_EQ(base::ASCIIToUTF16("Title Of More Awesomeness"), |
| 437 title_watcher.WaitAndGetTitle()); |
| 438 |
| 439 // Check the path and query string. |
| 440 std::string url; |
| 441 ASSERT_TRUE(content::ExecuteScriptAndExtractString( |
| 442 browser()->tab_strip_model()->GetActiveWebContents(), |
| 443 "domAutomationController.send(window.location.href);", |
| 444 &url)); |
| 445 EXPECT_EQ("/search", GURL(url).path()); |
| 446 EXPECT_EQ("q=search%20query", GURL(url).query()); |
| 447 |
| 448 // Go back to the error page, to make sure the history is correct. |
| 449 GoBackAndWaitForNavigations(2); |
| 450 ExpectDisplayingLinkDoctor(browser(), net::ERR_NAME_NOT_RESOLVED); |
| 451 } |
| 452 |
| 453 // Test that a DNS error occuring in an iframe does not result in showing the |
| 454 // Link Doctor. |
284 IN_PROC_BROWSER_TEST_F(ErrorPageTest, IFrameDNSError_Basic) { | 455 IN_PROC_BROWSER_TEST_F(ErrorPageTest, IFrameDNSError_Basic) { |
285 NavigateToURLAndWaitForTitle( | 456 NavigateToURLAndWaitForTitle( |
286 content::URLRequestMockHTTPJob::GetMockUrl( | 457 content::URLRequestMockHTTPJob::GetMockUrl( |
287 base::FilePath(FILE_PATH_LITERAL("iframe_dns_error.html"))), | 458 base::FilePath(FILE_PATH_LITERAL("iframe_dns_error.html"))), |
288 "Blah", | 459 "Blah", |
289 1); | 460 1); |
290 // We expect to have two history entries, since we started off with navigation | 461 // We expect to have two history entries, since we started off with navigation |
291 // to "about:blank" and then navigated to "iframe_dns_error.html". | 462 // to "about:blank" and then navigated to "iframe_dns_error.html". |
292 EXPECT_EQ(2, | 463 EXPECT_EQ(2, |
293 browser()->tab_strip_model()->GetActiveWebContents()-> | 464 browser()->tab_strip_model()->GetActiveWebContents()-> |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
435 // that there is no cached copy. | 606 // that there is no cached copy. |
436 BrowsingDataRemover* remover = | 607 BrowsingDataRemover* remover = |
437 BrowsingDataRemover::CreateForUnboundedRange(browser()->profile()); | 608 BrowsingDataRemover::CreateForUnboundedRange(browser()->profile()); |
438 remover->Remove(BrowsingDataRemover::REMOVE_CACHE, | 609 remover->Remove(BrowsingDataRemover::REMOVE_CACHE, |
439 BrowsingDataHelper::UNPROTECTED_WEB); | 610 BrowsingDataHelper::UNPROTECTED_WEB); |
440 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( | 611 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( |
441 browser(), test_url, 1); | 612 browser(), test_url, 1); |
442 EXPECT_TRUE(ProbeStaleCopyValue(false)); | 613 EXPECT_TRUE(ProbeStaleCopyValue(false)); |
443 } | 614 } |
444 | 615 |
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 | |
456 // Protocol handler that fails all requests with net::ERR_ADDRESS_UNREACHABLE. | 616 // Protocol handler that fails all requests with net::ERR_ADDRESS_UNREACHABLE. |
457 class AddressUnreachableProtocolHandler | 617 class AddressUnreachableProtocolHandler |
458 : public net::URLRequestJobFactory::ProtocolHandler { | 618 : public net::URLRequestJobFactory::ProtocolHandler { |
459 public: | 619 public: |
460 AddressUnreachableProtocolHandler() {} | 620 AddressUnreachableProtocolHandler() {} |
461 virtual ~AddressUnreachableProtocolHandler() {} | 621 virtual ~AddressUnreachableProtocolHandler() {} |
462 | 622 |
463 // net::URLRequestJobFactory::ProtocolHandler: | 623 // net::URLRequestJobFactory::ProtocolHandler: |
464 virtual net::URLRequestJob* MaybeCreateJob( | 624 virtual net::URLRequestJob* MaybeCreateJob( |
465 net::URLRequest* request, | 625 net::URLRequest* request, |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
516 }; | 676 }; |
517 | 677 |
518 // Make sure that when the Link Doctor fails to load, the network error page is | 678 // Make sure that when the Link Doctor fails to load, the network error page is |
519 // successfully loaded. | 679 // successfully loaded. |
520 IN_PROC_BROWSER_TEST_F(ErrorPageLinkDoctorFailTest, LinkDoctorFail) { | 680 IN_PROC_BROWSER_TEST_F(ErrorPageLinkDoctorFailTest, LinkDoctorFail) { |
521 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( | 681 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( |
522 browser(), | 682 browser(), |
523 URLRequestFailedJob::GetMockHttpUrl(net::ERR_NAME_NOT_RESOLVED), | 683 URLRequestFailedJob::GetMockHttpUrl(net::ERR_NAME_NOT_RESOLVED), |
524 2); | 684 2); |
525 | 685 |
526 // Verify that the expected error page is being displayed. Do this by making | 686 // Verify that the expected error page is being displayed. |
527 // sure the original error code (ERR_NAME_NOT_RESOLVED) is displayed. | 687 ExpectDisplayingLocalErrorPage(browser(), net::ERR_NAME_NOT_RESOLVED); |
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); | |
534 } | 688 } |
535 | 689 |
536 // Checks that when an error occurs and a link doctor load fails, the stale | 690 // Checks that when an error occurs and a link doctor load fails, the stale |
537 // cache status of the page is correctly transferred. Most logic copied | 691 // cache status of the page is correctly transferred. Most logic copied |
538 // from StaleCacheStatus above. | 692 // from StaleCacheStatus above. |
539 IN_PROC_BROWSER_TEST_F(ErrorPageLinkDoctorFailTest, | 693 IN_PROC_BROWSER_TEST_F(ErrorPageLinkDoctorFailTest, |
540 StaleCacheStatusFailedLinkDoctor) { | 694 StaleCacheStatusFailedLinkDoctor) { |
541 ASSERT_TRUE(test_server()->Start()); | 695 ASSERT_TRUE(test_server()->Start()); |
542 // Load cache with entry with "nocache" set, to create stale | 696 // Load cache with entry with "nocache" set, to create stale |
543 // cache. | 697 // cache. |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
611 | 765 |
612 // Make sure error page shows correct unicode for IDN. | 766 // Make sure error page shows correct unicode for IDN. |
613 IN_PROC_BROWSER_TEST_F(ErrorPageForIDNTest, IDN) { | 767 IN_PROC_BROWSER_TEST_F(ErrorPageForIDNTest, IDN) { |
614 // ERR_UNSAFE_PORT will not trigger the link doctor. | 768 // ERR_UNSAFE_PORT will not trigger the link doctor. |
615 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( | 769 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( |
616 browser(), | 770 browser(), |
617 URLRequestFailedJob::GetMockHttpUrlForHostname(net::ERR_UNSAFE_PORT, | 771 URLRequestFailedJob::GetMockHttpUrlForHostname(net::ERR_UNSAFE_PORT, |
618 kHostname), | 772 kHostname), |
619 1); | 773 1); |
620 | 774 |
621 bool result = false; | 775 ToggleHelpBox(browser()); |
622 EXPECT_TRUE(content::ExecuteScriptAndExtractBool( | 776 EXPECT_TRUE(IsDisplayingText(browser(), kHostnameJSUnicode)); |
623 browser()->tab_strip_model()->GetActiveWebContents(), | |
624 GetTextContentContainsStringScript(kHostnameJSUnicode), | |
625 &result)); | |
626 EXPECT_TRUE(result); | |
627 } | 777 } |
628 | 778 |
629 } // namespace | 779 } // namespace |
OLD | NEW |