| 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/test_navigation_observer.h" | 16 #include "content/public/test/test_navigation_observer.h" |
| 16 #include "content/test/net/url_request_failed_job.h" | 17 #include "content/test/net/url_request_failed_job.h" |
| 17 #include "content/test/net/url_request_mock_http_job.h" | 18 #include "content/test/net/url_request_mock_http_job.h" |
| 18 #include "net/base/net_errors.h" | 19 #include "net/base/net_errors.h" |
| 19 | 20 |
| 20 using content::BrowserThread; | 21 using content::BrowserThread; |
| 21 using content::NavigationController; | 22 using content::NavigationController; |
| 22 | 23 |
| 23 class ErrorPageTest : public InProcessBrowserTest { | 24 class ErrorPageTest : public InProcessBrowserTest { |
| 24 public: | 25 public: |
| 25 enum HistoryNavigationDirection { | 26 enum HistoryNavigationDirection { |
| 26 HISTORY_NAVIGATE_BACK, | 27 HISTORY_NAVIGATE_BACK, |
| 27 HISTORY_NAVIGATE_FORWARD, | 28 HISTORY_NAVIGATE_FORWARD, |
| 28 }; | 29 }; |
| 29 | 30 |
| 30 // Navigates the active tab to a mock url created for the file at |file_path|. | 31 // Navigates the active tab to a mock url created for the file at |file_path|. |
| 31 void NavigateToFileURL(const FilePath::StringType& file_path) { | 32 void NavigateToFileURL(const FilePath::StringType& file_path) { |
| 32 ui_test_utils::NavigateToURL( | 33 ui_test_utils::NavigateToURL( |
| 33 browser(), | 34 browser(), |
| 34 URLRequestMockHTTPJob::GetMockUrl(FilePath(file_path))); | 35 URLRequestMockHTTPJob::GetMockUrl(FilePath(file_path))); |
| 35 } | 36 } |
| 36 | 37 |
| 37 // Navigates to the given URL and waits for |num_navigations| to occur, and | 38 // Navigates to the given URL and waits for |num_navigations| to occur, and |
| 38 // the title to change to |expected_title|. | 39 // the title to change to |expected_title|. |
| 39 void NavigateToURLAndWaitForTitle(const GURL& url, | 40 void NavigateToURLAndWaitForTitle(const GURL& url, |
| 40 const std::string& expected_title, | 41 const std::string& expected_title, |
| 41 int num_navigations) { | 42 int num_navigations) { |
| 42 ui_test_utils::TitleWatcher title_watcher( | 43 content::TitleWatcher title_watcher( |
| 43 chrome::GetActiveWebContents(browser()), | 44 chrome::GetActiveWebContents(browser()), |
| 44 ASCIIToUTF16(expected_title)); | 45 ASCIIToUTF16(expected_title)); |
| 45 | 46 |
| 46 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( | 47 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( |
| 47 browser(), url, num_navigations); | 48 browser(), url, num_navigations); |
| 48 | 49 |
| 49 EXPECT_EQ(title_watcher.WaitAndGetTitle(), ASCIIToUTF16(expected_title)); | 50 EXPECT_EQ(title_watcher.WaitAndGetTitle(), ASCIIToUTF16(expected_title)); |
| 50 } | 51 } |
| 51 | 52 |
| 52 // Navigates back in the history and waits for |num_navigations| to occur, and | 53 // Navigates back in the history and waits for |num_navigations| to occur, and |
| (...skipping 25 matching lines...) Expand all Loading... |
| 78 GURL GetDnsErrorURL() const { | 79 GURL GetDnsErrorURL() const { |
| 79 return URLRequestFailedJob::GetMockHttpUrl(net::ERR_NAME_NOT_RESOLVED); | 80 return URLRequestFailedJob::GetMockHttpUrl(net::ERR_NAME_NOT_RESOLVED); |
| 80 } | 81 } |
| 81 | 82 |
| 82 private: | 83 private: |
| 83 // Navigates the browser the indicated direction in the history and waits for | 84 // Navigates the browser the indicated direction in the history and waits for |
| 84 // |num_navigations| to occur and the title to change to |expected_title|. | 85 // |num_navigations| to occur and the title to change to |expected_title|. |
| 85 void NavigateHistoryAndWaitForTitle(const std::string& expected_title, | 86 void NavigateHistoryAndWaitForTitle(const std::string& expected_title, |
| 86 int num_navigations, | 87 int num_navigations, |
| 87 HistoryNavigationDirection direction) { | 88 HistoryNavigationDirection direction) { |
| 88 ui_test_utils::TitleWatcher title_watcher( | 89 content::TitleWatcher title_watcher( |
| 89 chrome::GetActiveWebContents(browser()), | 90 chrome::GetActiveWebContents(browser()), |
| 90 ASCIIToUTF16(expected_title)); | 91 ASCIIToUTF16(expected_title)); |
| 91 | 92 |
| 92 content::TestNavigationObserver test_navigation_observer( | 93 content::TestNavigationObserver test_navigation_observer( |
| 93 content::Source<NavigationController>( | 94 content::Source<NavigationController>( |
| 94 &chrome::GetActiveWebContents(browser())->GetController()), | 95 &chrome::GetActiveWebContents(browser())->GetController()), |
| 95 NULL, | 96 NULL, |
| 96 num_navigations); | 97 num_navigations); |
| 97 if (direction == HISTORY_NAVIGATE_BACK) { | 98 if (direction == HISTORY_NAVIGATE_BACK) { |
| 98 chrome::GoBack(browser(), CURRENT_TAB); | 99 chrome::GoBack(browser(), CURRENT_TAB); |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 } | 233 } |
| 233 | 234 |
| 234 // Checks that the Link Doctor is not loaded when we receive an actual 404 page. | 235 // Checks that the Link Doctor is not loaded when we receive an actual 404 page. |
| 235 IN_PROC_BROWSER_TEST_F(ErrorPageTest, Page404) { | 236 IN_PROC_BROWSER_TEST_F(ErrorPageTest, Page404) { |
| 236 NavigateToURLAndWaitForTitle( | 237 NavigateToURLAndWaitForTitle( |
| 237 URLRequestMockHTTPJob::GetMockUrl( | 238 URLRequestMockHTTPJob::GetMockUrl( |
| 238 FilePath(FILE_PATH_LITERAL("page404.html"))), | 239 FilePath(FILE_PATH_LITERAL("page404.html"))), |
| 239 "SUCCESS", | 240 "SUCCESS", |
| 240 1); | 241 1); |
| 241 } | 242 } |
| OLD | NEW |