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/utf_string_conversions.h" | 6 #include "base/utf_string_conversions.h" |
7 #include "chrome/browser/net/url_request_mock_util.h" | 7 #include "chrome/browser/net/url_request_mock_util.h" |
8 #include "chrome/browser/ui/browser.h" | 8 #include "chrome/browser/ui/browser.h" |
9 #include "chrome/browser/ui/browser_commands.h" | 9 #include "chrome/browser/ui/browser_commands.h" |
10 #include "chrome/browser/ui/browser_tabstrip.h" | 10 #include "chrome/browser/ui/browser_tabstrip.h" |
11 #include "chrome/browser/ui/tab_contents/tab_contents.h" | 11 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
12 #include "chrome/test/base/in_process_browser_test.h" | 12 #include "chrome/test/base/in_process_browser_test.h" |
13 #include "chrome/test/base/ui_test_utils.h" | 13 #include "chrome/test/base/ui_test_utils.h" |
14 #include "content/public/browser/web_contents.h" | 14 #include "content/public/browser/web_contents.h" |
15 #include "content/public/test/browser_test_utils.h" | 15 #include "content/public/test/browser_test_utils.h" |
16 #include "content/public/test/test_navigation_observer.h" | 16 #include "content/public/test/test_navigation_observer.h" |
17 #include "content/test/net/url_request_failed_job.h" | 17 #include "content/test/net/url_request_failed_job.h" |
18 #include "content/test/net/url_request_mock_http_job.h" | 18 #include "content/test/net/url_request_mock_http_job.h" |
19 #include "net/base/net_errors.h" | 19 #include "net/base/net_errors.h" |
20 | 20 |
21 using content::BrowserThread; | 21 using content::BrowserThread; |
22 using content::NavigationController; | 22 using content::NavigationController; |
| 23 using content::URLRequestFailedJob; |
23 | 24 |
24 class ErrorPageTest : public InProcessBrowserTest { | 25 class ErrorPageTest : public InProcessBrowserTest { |
25 public: | 26 public: |
26 enum HistoryNavigationDirection { | 27 enum HistoryNavigationDirection { |
27 HISTORY_NAVIGATE_BACK, | 28 HISTORY_NAVIGATE_BACK, |
28 HISTORY_NAVIGATE_FORWARD, | 29 HISTORY_NAVIGATE_FORWARD, |
29 }; | 30 }; |
30 | 31 |
31 // Navigates the active tab to a mock url created for the file at |file_path|. | 32 // Navigates the active tab to a mock url created for the file at |file_path|. |
32 void NavigateToFileURL(const FilePath::StringType& file_path) { | 33 void NavigateToFileURL(const FilePath::StringType& file_path) { |
33 ui_test_utils::NavigateToURL( | 34 ui_test_utils::NavigateToURL( |
34 browser(), | 35 browser(), |
35 URLRequestMockHTTPJob::GetMockUrl(FilePath(file_path))); | 36 content::URLRequestMockHTTPJob::GetMockUrl(FilePath(file_path))); |
36 } | 37 } |
37 | 38 |
38 // Navigates to the given URL and waits for |num_navigations| to occur, and | 39 // Navigates to the given URL and waits for |num_navigations| to occur, and |
39 // the title to change to |expected_title|. | 40 // the title to change to |expected_title|. |
40 void NavigateToURLAndWaitForTitle(const GURL& url, | 41 void NavigateToURLAndWaitForTitle(const GURL& url, |
41 const std::string& expected_title, | 42 const std::string& expected_title, |
42 int num_navigations) { | 43 int num_navigations) { |
43 content::TitleWatcher title_watcher( | 44 content::TitleWatcher title_watcher( |
44 chrome::GetActiveWebContents(browser()), | 45 chrome::GetActiveWebContents(browser()), |
45 ASCIIToUTF16(expected_title)); | 46 ASCIIToUTF16(expected_title)); |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 GoBackAndWaitForTitle("Mock Link Doctor", 2); | 188 GoBackAndWaitForTitle("Mock Link Doctor", 2); |
188 GoBackAndWaitForTitle("Title Of More Awesomeness", 1); | 189 GoBackAndWaitForTitle("Title Of More Awesomeness", 1); |
189 | 190 |
190 GoForwardAndWaitForTitle("Mock Link Doctor", 2); | 191 GoForwardAndWaitForTitle("Mock Link Doctor", 2); |
191 GoForwardAndWaitForTitle("Title Of Awesomeness", 1); | 192 GoForwardAndWaitForTitle("Title Of Awesomeness", 1); |
192 } | 193 } |
193 | 194 |
194 // Test that a DNS error occuring in an iframe. | 195 // Test that a DNS error occuring in an iframe. |
195 IN_PROC_BROWSER_TEST_F(ErrorPageTest, IFrameDNSError_Basic) { | 196 IN_PROC_BROWSER_TEST_F(ErrorPageTest, IFrameDNSError_Basic) { |
196 NavigateToURLAndWaitForTitle( | 197 NavigateToURLAndWaitForTitle( |
197 URLRequestMockHTTPJob::GetMockUrl( | 198 content::URLRequestMockHTTPJob::GetMockUrl( |
198 FilePath(FILE_PATH_LITERAL("iframe_dns_error.html"))), | 199 FilePath(FILE_PATH_LITERAL("iframe_dns_error.html"))), |
199 "Blah", | 200 "Blah", |
200 1); | 201 1); |
201 } | 202 } |
202 | 203 |
203 // This test fails regularly on win_rel trybots. See crbug.com/121540 | 204 // This test fails regularly on win_rel trybots. See crbug.com/121540 |
204 #if defined(OS_WIN) | 205 #if defined(OS_WIN) |
205 #define MAYBE_IFrameDNSError_GoBack DISABLED_IFrameDNSError_GoBack | 206 #define MAYBE_IFrameDNSError_GoBack DISABLED_IFrameDNSError_GoBack |
206 #else | 207 #else |
207 #define MAYBE_IFrameDNSError_GoBack IFrameDNSError_GoBack | 208 #define MAYBE_IFrameDNSError_GoBack IFrameDNSError_GoBack |
(...skipping 17 matching lines...) Expand all Loading... |
225 IN_PROC_BROWSER_TEST_F(ErrorPageTest, MAYBE_IFrameDNSError_GoBackAndForward) { | 226 IN_PROC_BROWSER_TEST_F(ErrorPageTest, MAYBE_IFrameDNSError_GoBackAndForward) { |
226 NavigateToFileURL(FILE_PATH_LITERAL("title2.html")); | 227 NavigateToFileURL(FILE_PATH_LITERAL("title2.html")); |
227 NavigateToFileURL(FILE_PATH_LITERAL("iframe_dns_error.html")); | 228 NavigateToFileURL(FILE_PATH_LITERAL("iframe_dns_error.html")); |
228 GoBackAndWaitForTitle("Title Of Awesomeness", 1); | 229 GoBackAndWaitForTitle("Title Of Awesomeness", 1); |
229 GoForwardAndWaitForTitle("Blah", 1); | 230 GoForwardAndWaitForTitle("Blah", 1); |
230 } | 231 } |
231 | 232 |
232 // Checks that the Link Doctor is not loaded when we receive an actual 404 page. | 233 // Checks that the Link Doctor is not loaded when we receive an actual 404 page. |
233 IN_PROC_BROWSER_TEST_F(ErrorPageTest, Page404) { | 234 IN_PROC_BROWSER_TEST_F(ErrorPageTest, Page404) { |
234 NavigateToURLAndWaitForTitle( | 235 NavigateToURLAndWaitForTitle( |
235 URLRequestMockHTTPJob::GetMockUrl( | 236 content::URLRequestMockHTTPJob::GetMockUrl( |
236 FilePath(FILE_PATH_LITERAL("page404.html"))), | 237 FilePath(FILE_PATH_LITERAL("page404.html"))), |
237 "SUCCESS", | 238 "SUCCESS", |
238 1); | 239 1); |
239 } | 240 } |
OLD | NEW |