Chromium Code Reviews| 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/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. | |
|
Deprecated (see juliatuttle)
2014/02/04 17:44:21
Technically it'd be nicer if you searched for the
mmenke
2014/02/04 19:43:56
I'm not sure...Then I'd be depending on an english
Deprecated (see juliatuttle)
2014/02/04 20:20:20
Maybe search for it by id then? I don't like that
mmenke
2014/02/04 20:31:09
Getting it by its id and simulating a click sounds
| |
| 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); | |
|
Deprecated (see juliatuttle)
2014/02/04 17:44:21
It bothers me that this relies on the fact that th
mmenke
2014/02/04 19:43:56
I agree that this is weird and ugly, but it's done
Deprecated (see juliatuttle)
2014/02/04 20:20:20
Alright.
| |
| 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 Loading... | |
| 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 // Navigates back in the history and waits for |num_navigations| to occur. | |
|
Deprecated (see juliatuttle)
2014/02/04 17:44:21
GoBack(2) to me reads as "go back twice"; I'd pref
mmenke
2014/02/04 19:43:56
I agree, done.
| |
| 167 void GoBack(int num_navigations) { | |
| 168 NavigateHistory(num_navigations, HISTORY_NAVIGATE_BACK); | |
| 169 } | |
| 170 | |
| 171 // Navigates forward in the history and waits for |num_navigations| to occur. | |
| 172 void GoForward(int num_navigations) { | |
| 173 NavigateHistory(num_navigations, HISTORY_NAVIGATE_FORWARD); | |
| 174 } | |
| 175 | |
| 85 protected: | 176 protected: |
| 177 static void EnableMocks(const GURL& search_url) { | |
| 178 chrome_browser_net::SetUrlRequestMocksEnabled(true); | |
| 179 | |
| 180 // Add a mock for the search engine the error page will use. | |
| 181 base::FilePath root_http; | |
| 182 PathService::Get(chrome::DIR_TEST_DATA, &root_http); | |
| 183 content::URLRequestMockHTTPJob::AddHostnameToFileHandler( | |
| 184 search_url.host(), root_http.AppendASCII("title3.html")); | |
| 185 } | |
| 186 | |
| 86 virtual void SetUpOnMainThread() OVERRIDE { | 187 virtual void SetUpOnMainThread() OVERRIDE { |
| 87 BrowserThread::PostTask( | 188 BrowserThread::PostTask( |
| 88 BrowserThread::IO, FROM_HERE, | 189 BrowserThread::IO, FROM_HERE, |
| 89 base::Bind(&chrome_browser_net::SetUrlRequestMocksEnabled, true)); | 190 base::Bind(&ErrorPageTest::EnableMocks, |
| 191 google_util::GetGoogleSearchURL(browser()->profile()))); | |
| 90 } | 192 } |
| 91 | 193 |
| 92 // Returns a GURL that results in a DNS error. | 194 // Returns a GURL that results in a DNS error. |
| 93 GURL GetDnsErrorURL() const { | 195 GURL GetDnsErrorURL() const { |
| 94 return URLRequestFailedJob::GetMockHttpUrl(net::ERR_NAME_NOT_RESOLVED); | 196 return URLRequestFailedJob::GetMockHttpUrl(net::ERR_NAME_NOT_RESOLVED); |
| 95 } | 197 } |
| 96 | 198 |
| 97 private: | 199 private: |
| 98 // Navigates the browser the indicated direction in the history and waits for | 200 // 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|. | 201 // |num_navigations| to occur and the title to change to |expected_title|. |
| 100 void NavigateHistoryAndWaitForTitle(const std::string& expected_title, | 202 void NavigateHistoryAndWaitForTitle(const std::string& expected_title, |
| 101 int num_navigations, | 203 int num_navigations, |
| 102 HistoryNavigationDirection direction) { | 204 HistoryNavigationDirection direction) { |
| 103 content::TitleWatcher title_watcher( | 205 content::TitleWatcher title_watcher( |
| 104 browser()->tab_strip_model()->GetActiveWebContents(), | 206 browser()->tab_strip_model()->GetActiveWebContents(), |
| 105 base::ASCIIToUTF16(expected_title)); | 207 base::ASCIIToUTF16(expected_title)); |
| 106 | 208 |
| 209 NavigateHistory(num_navigations, direction); | |
| 210 | |
| 211 EXPECT_EQ(title_watcher.WaitAndGetTitle(), | |
| 212 base::ASCIIToUTF16(expected_title)); | |
| 213 } | |
| 214 | |
| 215 void NavigateHistory(int num_navigations, | |
| 216 HistoryNavigationDirection direction) { | |
| 107 content::TestNavigationObserver test_navigation_observer( | 217 content::TestNavigationObserver test_navigation_observer( |
| 108 browser()->tab_strip_model()->GetActiveWebContents(), | 218 browser()->tab_strip_model()->GetActiveWebContents(), |
| 109 num_navigations); | 219 num_navigations); |
| 110 if (direction == HISTORY_NAVIGATE_BACK) { | 220 if (direction == HISTORY_NAVIGATE_BACK) { |
| 111 chrome::GoBack(browser(), CURRENT_TAB); | 221 chrome::GoBack(browser(), CURRENT_TAB); |
| 112 } else if (direction == HISTORY_NAVIGATE_FORWARD) { | 222 } else if (direction == HISTORY_NAVIGATE_FORWARD) { |
| 113 chrome::GoForward(browser(), CURRENT_TAB); | 223 chrome::GoForward(browser(), CURRENT_TAB); |
| 114 } else { | 224 } else { |
| 115 FAIL(); | 225 FAIL(); |
| 116 } | 226 } |
| 117 test_navigation_observer.Wait(); | 227 test_navigation_observer.Wait(); |
| 118 | |
| 119 EXPECT_EQ(title_watcher.WaitAndGetTitle(), | |
| 120 base::ASCIIToUTF16(expected_title)); | |
| 121 } | 228 } |
| 122 }; | 229 }; |
| 123 | 230 |
| 124 | 231 |
| 125 class TestFailProvisionalLoadObserver : public content::WebContentsObserver { | 232 class TestFailProvisionalLoadObserver : public content::WebContentsObserver { |
| 126 public: | 233 public: |
| 127 explicit TestFailProvisionalLoadObserver(content::WebContents* contents) | 234 explicit TestFailProvisionalLoadObserver(content::WebContents* contents) |
| 128 : content::WebContentsObserver(contents) {} | 235 : content::WebContentsObserver(contents) {} |
| 129 virtual ~TestFailProvisionalLoadObserver() {} | 236 virtual ~TestFailProvisionalLoadObserver() {} |
| 130 | 237 |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 151 // See crbug.com/109669 | 258 // See crbug.com/109669 |
| 152 #if defined(USE_AURA) || defined(OS_WIN) | 259 #if defined(USE_AURA) || defined(OS_WIN) |
| 153 #define MAYBE_DNSError_Basic DISABLED_DNSError_Basic | 260 #define MAYBE_DNSError_Basic DISABLED_DNSError_Basic |
| 154 #else | 261 #else |
| 155 #define MAYBE_DNSError_Basic DNSError_Basic | 262 #define MAYBE_DNSError_Basic DNSError_Basic |
| 156 #endif | 263 #endif |
| 157 // Test that a DNS error occuring in the main frame redirects to an error page. | 264 // 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) { | 265 IN_PROC_BROWSER_TEST_F(ErrorPageTest, MAYBE_DNSError_Basic) { |
| 159 // The first navigation should fail, and the second one should be the error | 266 // The first navigation should fail, and the second one should be the error |
| 160 // page. | 267 // page. |
| 161 NavigateToURLAndWaitForTitle(GetDnsErrorURL(), "Mock Link Doctor", 2); | 268 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( |
| 269 browser(), GetDnsErrorURL(), 2); | |
| 270 ExpectDisplayingLinkDoctor(browser(), net::ERR_NAME_NOT_RESOLVED); | |
| 162 } | 271 } |
| 163 | 272 |
| 164 // See crbug.com/109669 | 273 // See crbug.com/109669 |
| 165 #if defined(USE_AURA) | 274 #if defined(USE_AURA) |
| 166 #define MAYBE_DNSError_GoBack1 DISABLED_DNSError_GoBack1 | 275 #define MAYBE_DNSError_GoBack1 DISABLED_DNSError_GoBack1 |
| 167 #else | 276 #else |
| 168 #define MAYBE_DNSError_GoBack1 DNSError_GoBack1 | 277 #define MAYBE_DNSError_GoBack1 DNSError_GoBack1 |
| 169 #endif | 278 #endif |
| 170 | 279 |
| 171 // Test that a DNS error occuring in the main frame does not result in an | 280 // Test that a DNS error occuring in the main frame does not result in an |
| 172 // additional session history entry. | 281 // additional session history entry. |
| 173 IN_PROC_BROWSER_TEST_F(ErrorPageTest, MAYBE_DNSError_GoBack1) { | 282 IN_PROC_BROWSER_TEST_F(ErrorPageTest, MAYBE_DNSError_GoBack1) { |
| 174 NavigateToFileURL(FILE_PATH_LITERAL("title2.html")); | 283 NavigateToFileURL(FILE_PATH_LITERAL("title2.html")); |
| 175 NavigateToURLAndWaitForTitle(GetDnsErrorURL(), "Mock Link Doctor", 2); | 284 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( |
| 285 browser(), GetDnsErrorURL(), 2); | |
| 286 ExpectDisplayingLinkDoctor(browser(), net::ERR_NAME_NOT_RESOLVED); | |
| 176 GoBackAndWaitForTitle("Title Of Awesomeness", 1); | 287 GoBackAndWaitForTitle("Title Of Awesomeness", 1); |
| 177 } | 288 } |
| 178 | 289 |
| 179 // See crbug.com/109669 | 290 // See crbug.com/109669 |
| 180 #if defined(USE_AURA) | 291 #if defined(USE_AURA) |
| 181 #define MAYBE_DNSError_GoBack2 DISABLED_DNSError_GoBack2 | 292 #define MAYBE_DNSError_GoBack2 DISABLED_DNSError_GoBack2 |
| 182 #else | 293 #else |
| 183 #define MAYBE_DNSError_GoBack2 DNSError_GoBack2 | 294 #define MAYBE_DNSError_GoBack2 DNSError_GoBack2 |
| 184 #endif | 295 #endif |
| 185 // Test that a DNS error occuring in the main frame does not result in an | 296 // Test that a DNS error occuring in the main frame does not result in an |
| 186 // additional session history entry. | 297 // additional session history entry. |
| 187 IN_PROC_BROWSER_TEST_F(ErrorPageTest, DNSError_GoBack2) { | 298 IN_PROC_BROWSER_TEST_F(ErrorPageTest, DNSError_GoBack2) { |
| 188 NavigateToFileURL(FILE_PATH_LITERAL("title2.html")); | 299 NavigateToFileURL(FILE_PATH_LITERAL("title2.html")); |
| 189 | 300 |
| 190 NavigateToURLAndWaitForTitle(GetDnsErrorURL(), "Mock Link Doctor", 2); | 301 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( |
| 302 browser(), GetDnsErrorURL(), 2); | |
| 303 ExpectDisplayingLinkDoctor(browser(), net::ERR_NAME_NOT_RESOLVED); | |
| 304 | |
| 191 NavigateToFileURL(FILE_PATH_LITERAL("title3.html")); | 305 NavigateToFileURL(FILE_PATH_LITERAL("title3.html")); |
| 192 | 306 |
| 193 GoBackAndWaitForTitle("Mock Link Doctor", 2); | 307 GoBack(2); |
| 308 ExpectDisplayingLinkDoctor(browser(), net::ERR_NAME_NOT_RESOLVED); | |
| 309 | |
| 194 GoBackAndWaitForTitle("Title Of Awesomeness", 1); | 310 GoBackAndWaitForTitle("Title Of Awesomeness", 1); |
| 195 } | 311 } |
| 196 | 312 |
| 197 // See crbug.com/109669 | 313 // See crbug.com/109669 |
| 198 #if defined(USE_AURA) | 314 #if defined(USE_AURA) |
| 199 #define MAYBE_DNSError_GoBack2AndForward DISABLED_DNSError_GoBack2AndForward | 315 #define MAYBE_DNSError_GoBack2AndForward DISABLED_DNSError_GoBack2AndForward |
| 200 #else | 316 #else |
| 201 #define MAYBE_DNSError_GoBack2AndForward DNSError_GoBack2AndForward | 317 #define MAYBE_DNSError_GoBack2AndForward DNSError_GoBack2AndForward |
| 202 #endif | 318 #endif |
| 203 // Test that a DNS error occuring in the main frame does not result in an | 319 // Test that a DNS error occuring in the main frame does not result in an |
| 204 // additional session history entry. | 320 // additional session history entry. |
| 205 IN_PROC_BROWSER_TEST_F(ErrorPageTest, DNSError_GoBack2AndForward) { | 321 IN_PROC_BROWSER_TEST_F(ErrorPageTest, DNSError_GoBack2AndForward) { |
| 206 NavigateToFileURL(FILE_PATH_LITERAL("title2.html")); | 322 NavigateToFileURL(FILE_PATH_LITERAL("title2.html")); |
| 207 | 323 |
| 208 NavigateToURLAndWaitForTitle(GetDnsErrorURL(), "Mock Link Doctor", 2); | 324 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( |
| 325 browser(), GetDnsErrorURL(), 2); | |
| 326 ExpectDisplayingLinkDoctor(browser(), net::ERR_NAME_NOT_RESOLVED); | |
| 327 | |
| 209 NavigateToFileURL(FILE_PATH_LITERAL("title3.html")); | 328 NavigateToFileURL(FILE_PATH_LITERAL("title3.html")); |
| 210 | 329 |
| 211 GoBackAndWaitForTitle("Mock Link Doctor", 2); | 330 GoBack(2); |
| 331 ExpectDisplayingLinkDoctor(browser(), net::ERR_NAME_NOT_RESOLVED); | |
| 332 | |
| 212 GoBackAndWaitForTitle("Title Of Awesomeness", 1); | 333 GoBackAndWaitForTitle("Title Of Awesomeness", 1); |
| 213 | 334 |
| 214 GoForwardAndWaitForTitle("Mock Link Doctor", 2); | 335 GoForward(2); |
| 336 ExpectDisplayingLinkDoctor(browser(), net::ERR_NAME_NOT_RESOLVED); | |
| 215 } | 337 } |
| 216 | 338 |
| 217 // See crbug.com/109669 | 339 // See crbug.com/109669 |
| 218 #if defined(USE_AURA) | 340 #if defined(USE_AURA) |
| 219 #define MAYBE_DNSError_GoBack2Forward2 DISABLED_DNSError_GoBack2Forward2 | 341 #define MAYBE_DNSError_GoBack2Forward2 DISABLED_DNSError_GoBack2Forward2 |
| 220 #else | 342 #else |
| 221 #define MAYBE_DNSError_GoBack2Forward2 DNSError_GoBack2Forward2 | 343 #define MAYBE_DNSError_GoBack2Forward2 DNSError_GoBack2Forward2 |
| 222 #endif | 344 #endif |
| 223 // Test that a DNS error occuring in the main frame does not result in an | 345 // Test that a DNS error occuring in the main frame does not result in an |
| 224 // additional session history entry. | 346 // additional session history entry. |
| 225 IN_PROC_BROWSER_TEST_F(ErrorPageTest, DNSError_GoBack2Forward2) { | 347 IN_PROC_BROWSER_TEST_F(ErrorPageTest, DNSError_GoBack2Forward2) { |
| 226 NavigateToFileURL(FILE_PATH_LITERAL("title3.html")); | 348 NavigateToFileURL(FILE_PATH_LITERAL("title3.html")); |
| 227 | 349 |
| 228 NavigateToURLAndWaitForTitle(GetDnsErrorURL(), "Mock Link Doctor", 2); | 350 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( |
| 351 browser(), GetDnsErrorURL(), 2); | |
| 352 ExpectDisplayingLinkDoctor(browser(), net::ERR_NAME_NOT_RESOLVED); | |
| 353 | |
| 229 NavigateToFileURL(FILE_PATH_LITERAL("title2.html")); | 354 NavigateToFileURL(FILE_PATH_LITERAL("title2.html")); |
| 230 | 355 |
| 231 GoBackAndWaitForTitle("Mock Link Doctor", 2); | 356 GoBack(2); |
| 357 ExpectDisplayingLinkDoctor(browser(), net::ERR_NAME_NOT_RESOLVED); | |
| 358 | |
| 232 GoBackAndWaitForTitle("Title Of More Awesomeness", 1); | 359 GoBackAndWaitForTitle("Title Of More Awesomeness", 1); |
| 233 | 360 |
| 234 GoForwardAndWaitForTitle("Mock Link Doctor", 2); | 361 GoForward(2); |
| 362 ExpectDisplayingLinkDoctor(browser(), net::ERR_NAME_NOT_RESOLVED); | |
| 363 | |
| 235 GoForwardAndWaitForTitle("Title Of Awesomeness", 1); | 364 GoForwardAndWaitForTitle("Title Of Awesomeness", 1); |
| 236 } | 365 } |
| 237 | 366 |
| 238 // Test that a DNS error occuring in an iframe. | 367 // See crbug.com/109669 |
| 368 #if defined(USE_AURA) | |
| 369 #define MAYBE_DNSError_DoSearch DISABLED_DNSError_DoSearch | |
| 370 #else | |
| 371 #define MAYBE_DNSError_DoSearch DNSError_DoSearch | |
| 372 #endif | |
| 373 // Test that the search button on a DNS error page works. | |
| 374 IN_PROC_BROWSER_TEST_F(ErrorPageTest, MAYBE_DNSError_DoSearch) { | |
| 375 // The first navigation should fail, and the second one should be the error | |
| 376 // page. | |
| 377 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( | |
| 378 browser(), GetDnsErrorURL(), 2); | |
| 379 ExpectDisplayingLinkDoctor(browser(), net::ERR_NAME_NOT_RESOLVED); | |
| 380 | |
| 381 // Do a search and make sure the browser ends up at the right page. | |
| 382 content::TestNavigationObserver nav_observer( | |
| 383 browser()->tab_strip_model()->GetActiveWebContents(), | |
| 384 1); | |
| 385 content::TitleWatcher title_watcher( | |
| 386 browser()->tab_strip_model()->GetActiveWebContents(), | |
| 387 base::ASCIIToUTF16("Title Of More Awesomeness")); | |
| 388 ASSERT_TRUE(content::ExecuteScript( | |
| 389 browser()->tab_strip_model()->GetActiveWebContents(), | |
| 390 "document.getElementById('search-button').click();")); | |
| 391 nav_observer.Wait(); | |
| 392 EXPECT_EQ(base::ASCIIToUTF16("Title Of More Awesomeness"), | |
| 393 title_watcher.WaitAndGetTitle()); | |
| 394 | |
| 395 // Check the path and query string. | |
| 396 std::string url; | |
| 397 ASSERT_TRUE(content::ExecuteScriptAndExtractString( | |
| 398 browser()->tab_strip_model()->GetActiveWebContents(), | |
| 399 "domAutomationController.send(window.location.href);", | |
| 400 &url)); | |
| 401 EXPECT_EQ("/search", GURL(url).path()); | |
| 402 EXPECT_EQ("q=search+query", GURL(url).query()); | |
| 403 | |
| 404 // Go back to the error page, to make sure the history is correct. | |
| 405 GoBack(2); | |
| 406 ExpectDisplayingLinkDoctor(browser(), net::ERR_NAME_NOT_RESOLVED); | |
| 407 } | |
| 408 | |
| 409 // Test that a DNS error occuring in an iframe does not result in showing the | |
| 410 // Link Doctor. | |
| 239 IN_PROC_BROWSER_TEST_F(ErrorPageTest, IFrameDNSError_Basic) { | 411 IN_PROC_BROWSER_TEST_F(ErrorPageTest, IFrameDNSError_Basic) { |
| 240 NavigateToURLAndWaitForTitle( | 412 NavigateToURLAndWaitForTitle( |
| 241 content::URLRequestMockHTTPJob::GetMockUrl( | 413 content::URLRequestMockHTTPJob::GetMockUrl( |
| 242 base::FilePath(FILE_PATH_LITERAL("iframe_dns_error.html"))), | 414 base::FilePath(FILE_PATH_LITERAL("iframe_dns_error.html"))), |
| 243 "Blah", | 415 "Blah", |
| 244 1); | 416 1); |
| 245 // We expect to have two history entries, since we started off with navigation | 417 // 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". | 418 // to "about:blank" and then navigated to "iframe_dns_error.html". |
| 247 EXPECT_EQ(2, | 419 EXPECT_EQ(2, |
| 248 browser()->tab_strip_model()->GetActiveWebContents()-> | 420 browser()->tab_strip_model()->GetActiveWebContents()-> |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 349 | 521 |
| 350 // Checks that the Link Doctor is not loaded when we receive an actual 404 page. | 522 // Checks that the Link Doctor is not loaded when we receive an actual 404 page. |
| 351 IN_PROC_BROWSER_TEST_F(ErrorPageTest, Page404) { | 523 IN_PROC_BROWSER_TEST_F(ErrorPageTest, Page404) { |
| 352 NavigateToURLAndWaitForTitle( | 524 NavigateToURLAndWaitForTitle( |
| 353 content::URLRequestMockHTTPJob::GetMockUrl( | 525 content::URLRequestMockHTTPJob::GetMockUrl( |
| 354 base::FilePath(FILE_PATH_LITERAL("page404.html"))), | 526 base::FilePath(FILE_PATH_LITERAL("page404.html"))), |
| 355 "SUCCESS", | 527 "SUCCESS", |
| 356 1); | 528 1); |
| 357 } | 529 } |
| 358 | 530 |
| 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. | 531 // Protocol handler that fails all requests with net::ERR_ADDRESS_UNREACHABLE. |
| 371 class AddressUnreachableProtocolHandler | 532 class AddressUnreachableProtocolHandler |
| 372 : public net::URLRequestJobFactory::ProtocolHandler { | 533 : public net::URLRequestJobFactory::ProtocolHandler { |
| 373 public: | 534 public: |
| 374 AddressUnreachableProtocolHandler() {} | 535 AddressUnreachableProtocolHandler() {} |
| 375 virtual ~AddressUnreachableProtocolHandler() {} | 536 virtual ~AddressUnreachableProtocolHandler() {} |
| 376 | 537 |
| 377 // net::URLRequestJobFactory::ProtocolHandler: | 538 // net::URLRequestJobFactory::ProtocolHandler: |
| 378 virtual net::URLRequestJob* MaybeCreateJob( | 539 virtual net::URLRequestJob* MaybeCreateJob( |
| 379 net::URLRequest* request, | 540 net::URLRequest* request, |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 430 }; | 591 }; |
| 431 | 592 |
| 432 // Make sure that when the Link Doctor fails to load, the network error page is | 593 // Make sure that when the Link Doctor fails to load, the network error page is |
| 433 // successfully loaded. | 594 // successfully loaded. |
| 434 IN_PROC_BROWSER_TEST_F(ErrorPageLinkDoctorFailTest, LinkDoctorFail) { | 595 IN_PROC_BROWSER_TEST_F(ErrorPageLinkDoctorFailTest, LinkDoctorFail) { |
| 435 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( | 596 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( |
| 436 browser(), | 597 browser(), |
| 437 URLRequestFailedJob::GetMockHttpUrl(net::ERR_NAME_NOT_RESOLVED), | 598 URLRequestFailedJob::GetMockHttpUrl(net::ERR_NAME_NOT_RESOLVED), |
| 438 2); | 599 2); |
| 439 | 600 |
| 440 // Verify that the expected error page is being displayed. Do this by making | 601 // Verify that the expected error page is being displayed. |
| 441 // sure the original error code (ERR_NAME_NOT_RESOLVED) is displayed. | 602 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 } | 603 } |
| 449 | 604 |
| 450 // A test fixture that simulates failing requests for an IDN domain name. | 605 // A test fixture that simulates failing requests for an IDN domain name. |
| 451 class ErrorPageForIDNTest : public InProcessBrowserTest { | 606 class ErrorPageForIDNTest : public InProcessBrowserTest { |
| 452 public: | 607 public: |
| 453 // Target hostname in different forms. | 608 // Target hostname in different forms. |
| 454 static const char kHostname[]; | 609 static const char kHostname[]; |
| 455 static const char kHostnameJSUnicode[]; | 610 static const char kHostnameJSUnicode[]; |
| 456 | 611 |
| 457 // InProcessBrowserTest: | 612 // InProcessBrowserTest: |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 490 | 645 |
| 491 // Make sure error page shows correct unicode for IDN. | 646 // Make sure error page shows correct unicode for IDN. |
| 492 IN_PROC_BROWSER_TEST_F(ErrorPageForIDNTest, IDN) { | 647 IN_PROC_BROWSER_TEST_F(ErrorPageForIDNTest, IDN) { |
| 493 // ERR_UNSAFE_PORT will not trigger the link doctor. | 648 // ERR_UNSAFE_PORT will not trigger the link doctor. |
| 494 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( | 649 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( |
| 495 browser(), | 650 browser(), |
| 496 URLRequestFailedJob::GetMockHttpUrlForHostname(net::ERR_UNSAFE_PORT, | 651 URLRequestFailedJob::GetMockHttpUrlForHostname(net::ERR_UNSAFE_PORT, |
| 497 kHostname), | 652 kHostname), |
| 498 1); | 653 1); |
| 499 | 654 |
| 500 bool result = false; | 655 ToggleHelpBox(browser()); |
| 501 EXPECT_TRUE(content::ExecuteScriptAndExtractBool( | 656 EXPECT_TRUE(IsDisplayingText(browser(), kHostnameJSUnicode)); |
| 502 browser()->tab_strip_model()->GetActiveWebContents(), | |
| 503 GetTextContentContainsStringScript(kHostnameJSUnicode), | |
| 504 &result)); | |
| 505 EXPECT_TRUE(result); | |
| 506 } | 657 } |
| 507 | 658 |
| 508 } // namespace | 659 } // namespace |
| OLD | NEW |