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 <utility> | 5 #include <utility> |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
10 #include "base/files/scoped_temp_dir.h" | 10 #include "base/files/scoped_temp_dir.h" |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 EXPECT_TRUE(content::ExecuteScriptAndExtractBool( | 119 EXPECT_TRUE(content::ExecuteScriptAndExtractBool( |
120 browser->tab_strip_model()->GetActiveWebContents(), command, &result)); | 120 browser->tab_strip_model()->GetActiveWebContents(), command, &result)); |
121 return result; | 121 return result; |
122 } | 122 } |
123 | 123 |
124 // Checks that the local error page is being displayed, without remotely | 124 // Checks that the local error page is being displayed, without remotely |
125 // retrieved navigation corrections, and with the specified error code. | 125 // retrieved navigation corrections, and with the specified error code. |
126 void ExpectDisplayingLocalErrorPage(Browser* browser, net::Error error_code) { | 126 void ExpectDisplayingLocalErrorPage(Browser* browser, net::Error error_code) { |
127 EXPECT_TRUE(IsDisplayingNetError(browser, error_code)); | 127 EXPECT_TRUE(IsDisplayingNetError(browser, error_code)); |
128 | 128 |
129 // Expand the help box so innerText will include text below the fold. | 129 // Locally generated error pages should not have navigation corrections. |
130 ToggleHelpBox(browser); | 130 EXPECT_FALSE(IsDisplayingText(browser, "http://mock.http/title2.html")); |
131 | 131 |
132 // Locally generated error pages should not have navigation corrections. | 132 // Locally generated error pages should not have a link with search terms. |
133 EXPECT_FALSE(IsDisplayingText(browser, "http://correction1/")); | 133 EXPECT_FALSE(IsDisplayingText(browser, "search query")); |
134 EXPECT_FALSE(IsDisplayingText(browser, "http://correction2/")); | |
135 | |
136 // Locally generated error pages should not have a populated search box. | |
137 bool search_box_populated = false; | |
138 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( | |
139 browser->tab_strip_model()->GetActiveWebContents(), | |
140 "var searchText = document.getElementById('search-box').value;" | |
141 "domAutomationController.send(searchText == 'search query');", | |
142 &search_box_populated)); | |
143 EXPECT_FALSE(search_box_populated); | |
144 } | 134 } |
145 | 135 |
146 // Checks that an error page with information retrieved from the navigation | 136 // Checks that an error page with information retrieved from the navigation |
147 // correction service is being displayed, with the specified specified error | 137 // correction service is being displayed, with the specified specified error |
148 // code. | 138 // code. |
149 void ExpectDisplayingNavigationCorrections(Browser* browser, | 139 void ExpectDisplayingNavigationCorrections(Browser* browser, |
150 net::Error error_code) { | 140 net::Error error_code) { |
151 EXPECT_TRUE(IsDisplayingNetError(browser, error_code)); | 141 EXPECT_TRUE(IsDisplayingNetError(browser, error_code)); |
152 | 142 |
153 // Expand the help box so innerText will include text below the fold. | 143 // Check that the mock navigation corrections are displayed. |
154 ToggleHelpBox(browser); | 144 EXPECT_TRUE(IsDisplayingText(browser, "http://mock.http/title2.html")); |
155 | 145 |
156 // Check that the mock navigation corrections are displayed. | 146 // Check that the search terms are displayed as a link. |
157 EXPECT_TRUE(IsDisplayingText(browser, "http://correction1/")); | 147 EXPECT_TRUE(IsDisplayingText(browser, "search query")); |
158 EXPECT_TRUE(IsDisplayingText(browser, "http://correction2/")); | |
159 | |
160 // Check that the search box is populated correctly. | |
161 bool search_box_populated = false; | |
162 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( | |
163 browser->tab_strip_model()->GetActiveWebContents(), | |
164 "var searchText = document.getElementById('search-box').value;" | |
165 "domAutomationController.send(searchText == 'search query');", | |
166 &search_box_populated)); | |
167 EXPECT_TRUE(search_box_populated); | |
168 | 148 |
169 // The diagnostics button isn't displayed when corrections were | 149 // The diagnostics button isn't displayed when corrections were |
170 // retrieved from a remote server. | 150 // retrieved from a remote server. |
171 EXPECT_FALSE(IsDisplayingDiagnosticsButton(browser)); | 151 EXPECT_FALSE(IsDisplayingDiagnosticsButton(browser)); |
172 | |
173 // Close help box again, to return page to original state. | |
174 ToggleHelpBox(browser); | |
175 } | 152 } |
176 | 153 |
177 std::string GetShowSavedButtonLabel() { | 154 std::string GetShowSavedButtonLabel() { |
178 return l10n_util::GetStringUTF8(IDS_ERRORPAGES_BUTTON_SHOW_SAVED_COPY); | 155 return l10n_util::GetStringUTF8(IDS_ERRORPAGES_BUTTON_SHOW_SAVED_COPY); |
179 } | 156 } |
180 | 157 |
181 void AddInterceptorForURL( | 158 void AddInterceptorForURL( |
182 const GURL& url, | 159 const GURL& url, |
183 scoped_ptr<net::URLRequestInterceptor> handler) { | 160 scoped_ptr<net::URLRequestInterceptor> handler) { |
184 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 161 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
(...skipping 480 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
665 GoBackAndWaitForTitle("Title Of More Awesomeness", 1); | 642 GoBackAndWaitForTitle("Title Of More Awesomeness", 1); |
666 | 643 |
667 GoForwardAndWaitForNavigations(2); | 644 GoForwardAndWaitForNavigations(2); |
668 ExpectDisplayingNavigationCorrections(browser(), net::ERR_NAME_NOT_RESOLVED); | 645 ExpectDisplayingNavigationCorrections(browser(), net::ERR_NAME_NOT_RESOLVED); |
669 EXPECT_EQ(3, link_doctor_interceptor()->num_requests()); | 646 EXPECT_EQ(3, link_doctor_interceptor()->num_requests()); |
670 | 647 |
671 GoForwardAndWaitForTitle("Title Of Awesomeness", 1); | 648 GoForwardAndWaitForTitle("Title Of Awesomeness", 1); |
672 EXPECT_EQ(3, link_doctor_interceptor()->num_requests()); | 649 EXPECT_EQ(3, link_doctor_interceptor()->num_requests()); |
673 } | 650 } |
674 | 651 |
675 // Test that the search button on a DNS error page works. | 652 // Test that the search link on a DNS error page works. |
676 IN_PROC_BROWSER_TEST_F(ErrorPageTest, DNSError_DoSearch) { | 653 IN_PROC_BROWSER_TEST_F(ErrorPageTest, DNSError_DoSearch) { |
677 // The first navigation should fail, and the second one should be the error | 654 // The first navigation should fail, and the second one should be the error |
678 // page. | 655 // page. |
679 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( | 656 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( |
680 browser(), GetDnsErrorURL(), 2); | 657 browser(), GetDnsErrorURL(), 2); |
681 ExpectDisplayingNavigationCorrections(browser(), net::ERR_NAME_NOT_RESOLVED); | 658 ExpectDisplayingNavigationCorrections(browser(), net::ERR_NAME_NOT_RESOLVED); |
682 EXPECT_EQ(1, link_doctor_interceptor()->num_requests()); | 659 EXPECT_EQ(1, link_doctor_interceptor()->num_requests()); |
683 | 660 |
684 content::WebContents* web_contents = | 661 content::WebContents* web_contents = |
685 browser()->tab_strip_model()->GetActiveWebContents(); | 662 browser()->tab_strip_model()->GetActiveWebContents(); |
686 | 663 |
687 // Do a search and make sure the browser ends up at the right page. | 664 // Do a search and make sure the browser ends up at the right page. |
688 content::TestNavigationObserver nav_observer(web_contents, 1); | 665 content::TestNavigationObserver nav_observer(web_contents, 1); |
689 content::TitleWatcher title_watcher( | 666 content::TitleWatcher title_watcher( |
690 web_contents, | 667 web_contents, |
691 base::ASCIIToUTF16("Title Of More Awesomeness")); | 668 base::ASCIIToUTF16("Title Of More Awesomeness")); |
692 // Can't use content::ExecuteScript because it waits for scripts to send | 669 // Can't use content::ExecuteScript because it waits for scripts to send |
693 // notification that they've run, and scripts that trigger a navigation may | 670 // notification that they've run, and scripts that trigger a navigation may |
694 // not send that notification. | 671 // not send that notification. |
695 web_contents->GetMainFrame()->ExecuteJavaScriptForTests( | 672 web_contents->GetMainFrame()->ExecuteJavaScriptForTests( |
696 base::ASCIIToUTF16("document.getElementById('search-button').click();")); | 673 base::ASCIIToUTF16("document.getElementById('search-link').click();")); |
697 nav_observer.Wait(); | 674 nav_observer.Wait(); |
698 EXPECT_EQ(base::ASCIIToUTF16("Title Of More Awesomeness"), | 675 EXPECT_EQ(base::ASCIIToUTF16("Title Of More Awesomeness"), |
699 title_watcher.WaitAndGetTitle()); | 676 title_watcher.WaitAndGetTitle()); |
700 | 677 |
701 // There should have been another Link Doctor request, for tracking purposes. | 678 // There should have been another Link Doctor request, for tracking purposes. |
702 // Have to wait for it, since the search page does not depend on having | 679 // Have to wait for it, since the search page does not depend on having |
703 // sent the tracking request. | 680 // sent the tracking request. |
704 link_doctor_interceptor()->WaitForRequests(2); | 681 link_doctor_interceptor()->WaitForRequests(2); |
705 EXPECT_EQ(2, link_doctor_interceptor()->num_requests()); | 682 EXPECT_EQ(2, link_doctor_interceptor()->num_requests()); |
706 | 683 |
(...skipping 772 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1479 IN_PROC_BROWSER_TEST_F(ErrorPageForIDNTest, IDN) { | 1456 IN_PROC_BROWSER_TEST_F(ErrorPageForIDNTest, IDN) { |
1480 // ERR_UNSAFE_PORT will not trigger navigation corrections. | 1457 // ERR_UNSAFE_PORT will not trigger navigation corrections. |
1481 ui_test_utils::NavigateToURL( | 1458 ui_test_utils::NavigateToURL( |
1482 browser(), | 1459 browser(), |
1483 URLRequestFailedJob::GetMockHttpUrlForHostname(net::ERR_UNSAFE_PORT, | 1460 URLRequestFailedJob::GetMockHttpUrlForHostname(net::ERR_UNSAFE_PORT, |
1484 kHostname)); | 1461 kHostname)); |
1485 EXPECT_TRUE(IsDisplayingText(browser(), kHostnameJSUnicode)); | 1462 EXPECT_TRUE(IsDisplayingText(browser(), kHostnameJSUnicode)); |
1486 } | 1463 } |
1487 | 1464 |
1488 } // namespace | 1465 } // namespace |
OLD | NEW |