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