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/tabs/tab_strip_model.h" |
11 #include "chrome/test/base/in_process_browser_test.h" | 11 #include "chrome/test/base/in_process_browser_test.h" |
12 #include "chrome/test/base/ui_test_utils.h" | 12 #include "chrome/test/base/ui_test_utils.h" |
13 #include "content/public/browser/web_contents.h" | 13 #include "content/public/browser/web_contents.h" |
14 #include "content/public/test/browser_test_utils.h" | 14 #include "content/public/test/browser_test_utils.h" |
15 #include "content/public/test/test_navigation_observer.h" | 15 #include "content/public/test/test_navigation_observer.h" |
16 #include "content/test/net/url_request_failed_job.h" | 16 #include "content/test/net/url_request_failed_job.h" |
17 #include "content/test/net/url_request_mock_http_job.h" | 17 #include "content/test/net/url_request_mock_http_job.h" |
18 #include "net/base/net_errors.h" | 18 #include "net/base/net_errors.h" |
19 | 19 |
20 using content::BrowserThread; | 20 using content::BrowserThread; |
(...skipping 13 matching lines...) Expand all Loading... |
34 browser(), | 34 browser(), |
35 content::URLRequestMockHTTPJob::GetMockUrl(FilePath(file_path))); | 35 content::URLRequestMockHTTPJob::GetMockUrl(FilePath(file_path))); |
36 } | 36 } |
37 | 37 |
38 // 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 |
39 // the title to change to |expected_title|. | 39 // the title to change to |expected_title|. |
40 void NavigateToURLAndWaitForTitle(const GURL& url, | 40 void NavigateToURLAndWaitForTitle(const GURL& url, |
41 const std::string& expected_title, | 41 const std::string& expected_title, |
42 int num_navigations) { | 42 int num_navigations) { |
43 content::TitleWatcher title_watcher( | 43 content::TitleWatcher title_watcher( |
44 chrome::GetActiveWebContents(browser()), | 44 browser()->tab_strip_model()->GetActiveWebContents(), |
45 ASCIIToUTF16(expected_title)); | 45 ASCIIToUTF16(expected_title)); |
46 | 46 |
47 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( | 47 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( |
48 browser(), url, num_navigations); | 48 browser(), url, num_navigations); |
49 | 49 |
50 EXPECT_EQ(title_watcher.WaitAndGetTitle(), ASCIIToUTF16(expected_title)); | 50 EXPECT_EQ(title_watcher.WaitAndGetTitle(), ASCIIToUTF16(expected_title)); |
51 } | 51 } |
52 | 52 |
53 // 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 |
54 // the title to change to |expected_title|. | 54 // the title to change to |expected_title|. |
(...skipping 25 matching lines...) Expand all Loading... |
80 return URLRequestFailedJob::GetMockHttpUrl(net::ERR_NAME_NOT_RESOLVED); | 80 return URLRequestFailedJob::GetMockHttpUrl(net::ERR_NAME_NOT_RESOLVED); |
81 } | 81 } |
82 | 82 |
83 private: | 83 private: |
84 // 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 |
85 // |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|. |
86 void NavigateHistoryAndWaitForTitle(const std::string& expected_title, | 86 void NavigateHistoryAndWaitForTitle(const std::string& expected_title, |
87 int num_navigations, | 87 int num_navigations, |
88 HistoryNavigationDirection direction) { | 88 HistoryNavigationDirection direction) { |
89 content::TitleWatcher title_watcher( | 89 content::TitleWatcher title_watcher( |
90 chrome::GetActiveWebContents(browser()), | 90 browser()->tab_strip_model()->GetActiveWebContents(), |
91 ASCIIToUTF16(expected_title)); | 91 ASCIIToUTF16(expected_title)); |
92 | 92 |
93 content::TestNavigationObserver test_navigation_observer( | 93 content::TestNavigationObserver test_navigation_observer( |
94 content::Source<NavigationController>( | 94 content::Source<NavigationController>( |
95 &chrome::GetActiveWebContents(browser())->GetController()), | 95 &browser()->tab_strip_model()->GetActiveWebContents()-> |
| 96 GetController()), |
96 NULL, | 97 NULL, |
97 num_navigations); | 98 num_navigations); |
98 if (direction == HISTORY_NAVIGATE_BACK) { | 99 if (direction == HISTORY_NAVIGATE_BACK) { |
99 chrome::GoBack(browser(), CURRENT_TAB); | 100 chrome::GoBack(browser(), CURRENT_TAB); |
100 } else if (direction == HISTORY_NAVIGATE_FORWARD) { | 101 } else if (direction == HISTORY_NAVIGATE_FORWARD) { |
101 chrome::GoForward(browser(), CURRENT_TAB); | 102 chrome::GoForward(browser(), CURRENT_TAB); |
102 } else { | 103 } else { |
103 FAIL(); | 104 FAIL(); |
104 } | 105 } |
105 test_navigation_observer.WaitForObservation( | 106 test_navigation_observer.WaitForObservation( |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
237 } | 238 } |
238 | 239 |
239 // Checks that the Link Doctor is not loaded when we receive an actual 404 page. | 240 // Checks that the Link Doctor is not loaded when we receive an actual 404 page. |
240 IN_PROC_BROWSER_TEST_F(ErrorPageTest, Page404) { | 241 IN_PROC_BROWSER_TEST_F(ErrorPageTest, Page404) { |
241 NavigateToURLAndWaitForTitle( | 242 NavigateToURLAndWaitForTitle( |
242 content::URLRequestMockHTTPJob::GetMockUrl( | 243 content::URLRequestMockHTTPJob::GetMockUrl( |
243 FilePath(FILE_PATH_LITERAL("page404.html"))), | 244 FilePath(FILE_PATH_LITERAL("page404.html"))), |
244 "SUCCESS", | 245 "SUCCESS", |
245 1); | 246 1); |
246 } | 247 } |
OLD | NEW |