| 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/command_line.h" | 6 #include "base/command_line.h" |
| 7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
| (...skipping 603 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 614 browser()->tab_strip_model()->GetActiveWebContents(); | 614 browser()->tab_strip_model()->GetActiveWebContents(); |
| 615 | 615 |
| 616 // Do a search and make sure the browser ends up at the right page. | 616 // Do a search and make sure the browser ends up at the right page. |
| 617 content::TestNavigationObserver nav_observer(web_contents, 1); | 617 content::TestNavigationObserver nav_observer(web_contents, 1); |
| 618 content::TitleWatcher title_watcher( | 618 content::TitleWatcher title_watcher( |
| 619 web_contents, | 619 web_contents, |
| 620 base::ASCIIToUTF16("Title Of More Awesomeness")); | 620 base::ASCIIToUTF16("Title Of More Awesomeness")); |
| 621 // Can't use content::ExecuteScript because it waits for scripts to send | 621 // Can't use content::ExecuteScript because it waits for scripts to send |
| 622 // notification that they've run, and scripts that trigger a navigation may | 622 // notification that they've run, and scripts that trigger a navigation may |
| 623 // not send that notification. | 623 // not send that notification. |
| 624 web_contents->GetMainFrame()->ExecuteJavaScriptForTests( | 624 web_contents->GetMainFrame()->ExecuteJavaScript( |
| 625 base::ASCIIToUTF16("document.getElementById('search-button').click();")); | 625 base::ASCIIToUTF16("document.getElementById('search-button').click();")); |
| 626 nav_observer.Wait(); | 626 nav_observer.Wait(); |
| 627 EXPECT_EQ(base::ASCIIToUTF16("Title Of More Awesomeness"), | 627 EXPECT_EQ(base::ASCIIToUTF16("Title Of More Awesomeness"), |
| 628 title_watcher.WaitAndGetTitle()); | 628 title_watcher.WaitAndGetTitle()); |
| 629 | 629 |
| 630 // There should have been another Link Doctor request, for tracking purposes. | 630 // There should have been another Link Doctor request, for tracking purposes. |
| 631 // Have to wait for it, since the search page does not depend on having | 631 // Have to wait for it, since the search page does not depend on having |
| 632 // sent the tracking request. | 632 // sent the tracking request. |
| 633 link_doctor_interceptor()->WaitForRequests(2); | 633 link_doctor_interceptor()->WaitForRequests(2); |
| 634 EXPECT_EQ(2, link_doctor_interceptor()->num_requests()); | 634 EXPECT_EQ(2, link_doctor_interceptor()->num_requests()); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 659 | 659 |
| 660 content::WebContents* web_contents = | 660 content::WebContents* web_contents = |
| 661 browser()->tab_strip_model()->GetActiveWebContents(); | 661 browser()->tab_strip_model()->GetActiveWebContents(); |
| 662 | 662 |
| 663 // Clicking the reload button should load the error page again, and there | 663 // Clicking the reload button should load the error page again, and there |
| 664 // should be two commits, as before. | 664 // should be two commits, as before. |
| 665 content::TestNavigationObserver nav_observer(web_contents, 2); | 665 content::TestNavigationObserver nav_observer(web_contents, 2); |
| 666 // Can't use content::ExecuteScript because it waits for scripts to send | 666 // Can't use content::ExecuteScript because it waits for scripts to send |
| 667 // notification that they've run, and scripts that trigger a navigation may | 667 // notification that they've run, and scripts that trigger a navigation may |
| 668 // not send that notification. | 668 // not send that notification. |
| 669 web_contents->GetMainFrame()->ExecuteJavaScriptForTests( | 669 web_contents->GetMainFrame()->ExecuteJavaScript( |
| 670 base::ASCIIToUTF16("document.getElementById('reload-button').click();")); | 670 base::ASCIIToUTF16("document.getElementById('reload-button').click();")); |
| 671 nav_observer.Wait(); | 671 nav_observer.Wait(); |
| 672 ExpectDisplayingNavigationCorrections(browser(), net::ERR_NAME_NOT_RESOLVED); | 672 ExpectDisplayingNavigationCorrections(browser(), net::ERR_NAME_NOT_RESOLVED); |
| 673 | 673 |
| 674 // There should have two more requests to the correction service: One for the | 674 // There should have two more requests to the correction service: One for the |
| 675 // new error page, and one for tracking purposes. Have to make sure to wait | 675 // new error page, and one for tracking purposes. Have to make sure to wait |
| 676 // for the tracking request, since the new error page does not depend on it. | 676 // for the tracking request, since the new error page does not depend on it. |
| 677 link_doctor_interceptor()->WaitForRequests(3); | 677 link_doctor_interceptor()->WaitForRequests(3); |
| 678 EXPECT_EQ(3, link_doctor_interceptor()->num_requests()); | 678 EXPECT_EQ(3, link_doctor_interceptor()->num_requests()); |
| 679 } | 679 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 692 | 692 |
| 693 // Simulate a click on a link. | 693 // Simulate a click on a link. |
| 694 | 694 |
| 695 content::TitleWatcher title_watcher( | 695 content::TitleWatcher title_watcher( |
| 696 web_contents, | 696 web_contents, |
| 697 base::ASCIIToUTF16("Title Of Awesomeness")); | 697 base::ASCIIToUTF16("Title Of Awesomeness")); |
| 698 std::string link_selector = | 698 std::string link_selector = |
| 699 "document.querySelector('a[href=\"http://mock.http/title2.html\"]')"; | 699 "document.querySelector('a[href=\"http://mock.http/title2.html\"]')"; |
| 700 // The tracking request is triggered by onmousedown, so it catches middle | 700 // The tracking request is triggered by onmousedown, so it catches middle |
| 701 // mouse button clicks, as well as left clicks. | 701 // mouse button clicks, as well as left clicks. |
| 702 web_contents->GetMainFrame()->ExecuteJavaScriptForTests( | 702 web_contents->GetMainFrame()->ExecuteJavaScript( |
| 703 base::ASCIIToUTF16(link_selector + ".onmousedown();")); | 703 base::ASCIIToUTF16(link_selector + ".onmousedown();")); |
| 704 // Can't use content::ExecuteScript because it waits for scripts to send | 704 // Can't use content::ExecuteScript because it waits for scripts to send |
| 705 // notification that they've run, and scripts that trigger a navigation may | 705 // notification that they've run, and scripts that trigger a navigation may |
| 706 // not send that notification. | 706 // not send that notification. |
| 707 web_contents->GetMainFrame()->ExecuteJavaScriptForTests( | 707 web_contents->GetMainFrame()->ExecuteJavaScript( |
| 708 base::ASCIIToUTF16(link_selector + ".click();")); | 708 base::ASCIIToUTF16(link_selector + ".click();")); |
| 709 EXPECT_EQ(base::ASCIIToUTF16("Title Of Awesomeness"), | 709 EXPECT_EQ(base::ASCIIToUTF16("Title Of Awesomeness"), |
| 710 title_watcher.WaitAndGetTitle()); | 710 title_watcher.WaitAndGetTitle()); |
| 711 | 711 |
| 712 // There should have been a tracking request to the correction service. Have | 712 // There should have been a tracking request to the correction service. Have |
| 713 // to make sure to wait the tracking request, since the new page does not | 713 // to make sure to wait the tracking request, since the new page does not |
| 714 // depend on it. | 714 // depend on it. |
| 715 link_doctor_interceptor()->WaitForRequests(2); | 715 link_doctor_interceptor()->WaitForRequests(2); |
| 716 EXPECT_EQ(2, link_doctor_interceptor()->num_requests()); | 716 EXPECT_EQ(2, link_doctor_interceptor()->num_requests()); |
| 717 } | 717 } |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 783 EXPECT_EQ(2, wc->GetController().GetEntryCount()); | 783 EXPECT_EQ(2, wc->GetController().GetEntryCount()); |
| 784 | 784 |
| 785 std::string script = "var frame = document.createElement('iframe');" | 785 std::string script = "var frame = document.createElement('iframe');" |
| 786 "frame.src = '" + fail_url.spec() + "';" | 786 "frame.src = '" + fail_url.spec() + "';" |
| 787 "document.body.appendChild(frame);"; | 787 "document.body.appendChild(frame);"; |
| 788 { | 788 { |
| 789 TestFailProvisionalLoadObserver fail_observer(wc); | 789 TestFailProvisionalLoadObserver fail_observer(wc); |
| 790 content::WindowedNotificationObserver load_observer( | 790 content::WindowedNotificationObserver load_observer( |
| 791 content::NOTIFICATION_LOAD_STOP, | 791 content::NOTIFICATION_LOAD_STOP, |
| 792 content::Source<NavigationController>(&wc->GetController())); | 792 content::Source<NavigationController>(&wc->GetController())); |
| 793 wc->GetMainFrame()->ExecuteJavaScriptForTests(base::ASCIIToUTF16(script)); | 793 wc->GetMainFrame()->ExecuteJavaScript(base::ASCIIToUTF16(script)); |
| 794 load_observer.Wait(); | 794 load_observer.Wait(); |
| 795 | 795 |
| 796 // Ensure we saw the expected failure. | 796 // Ensure we saw the expected failure. |
| 797 EXPECT_EQ(fail_url, fail_observer.fail_url()); | 797 EXPECT_EQ(fail_url, fail_observer.fail_url()); |
| 798 | 798 |
| 799 // Failed initial navigation of an iframe shouldn't be adding any history | 799 // Failed initial navigation of an iframe shouldn't be adding any history |
| 800 // entries. | 800 // entries. |
| 801 EXPECT_EQ(2, wc->GetController().GetEntryCount()); | 801 EXPECT_EQ(2, wc->GetController().GetEntryCount()); |
| 802 } | 802 } |
| 803 | 803 |
| 804 // Do the same test, but with an iframe that doesn't have initial URL | 804 // Do the same test, but with an iframe that doesn't have initial URL |
| 805 // assigned. | 805 // assigned. |
| 806 script = "var frame = document.createElement('iframe');" | 806 script = "var frame = document.createElement('iframe');" |
| 807 "frame.id = 'target_frame';" | 807 "frame.id = 'target_frame';" |
| 808 "document.body.appendChild(frame);"; | 808 "document.body.appendChild(frame);"; |
| 809 { | 809 { |
| 810 content::WindowedNotificationObserver load_observer( | 810 content::WindowedNotificationObserver load_observer( |
| 811 content::NOTIFICATION_LOAD_STOP, | 811 content::NOTIFICATION_LOAD_STOP, |
| 812 content::Source<NavigationController>(&wc->GetController())); | 812 content::Source<NavigationController>(&wc->GetController())); |
| 813 wc->GetMainFrame()->ExecuteJavaScriptForTests(base::ASCIIToUTF16(script)); | 813 wc->GetMainFrame()->ExecuteJavaScript(base::ASCIIToUTF16(script)); |
| 814 load_observer.Wait(); | 814 load_observer.Wait(); |
| 815 } | 815 } |
| 816 | 816 |
| 817 script = "var f = document.getElementById('target_frame');" | 817 script = "var f = document.getElementById('target_frame');" |
| 818 "f.src = '" + fail_url.spec() + "';"; | 818 "f.src = '" + fail_url.spec() + "';"; |
| 819 { | 819 { |
| 820 TestFailProvisionalLoadObserver fail_observer(wc); | 820 TestFailProvisionalLoadObserver fail_observer(wc); |
| 821 content::WindowedNotificationObserver load_observer( | 821 content::WindowedNotificationObserver load_observer( |
| 822 content::NOTIFICATION_LOAD_STOP, | 822 content::NOTIFICATION_LOAD_STOP, |
| 823 content::Source<NavigationController>(&wc->GetController())); | 823 content::Source<NavigationController>(&wc->GetController())); |
| 824 wc->GetMainFrame()->ExecuteJavaScriptForTests(base::ASCIIToUTF16(script)); | 824 wc->GetMainFrame()->ExecuteJavaScript(base::ASCIIToUTF16(script)); |
| 825 load_observer.Wait(); | 825 load_observer.Wait(); |
| 826 | 826 |
| 827 EXPECT_EQ(fail_url, fail_observer.fail_url()); | 827 EXPECT_EQ(fail_url, fail_observer.fail_url()); |
| 828 EXPECT_EQ(2, wc->GetController().GetEntryCount()); | 828 EXPECT_EQ(2, wc->GetController().GetEntryCount()); |
| 829 } | 829 } |
| 830 EXPECT_EQ(0, link_doctor_interceptor()->num_requests()); | 830 EXPECT_EQ(0, link_doctor_interceptor()->num_requests()); |
| 831 } | 831 } |
| 832 | 832 |
| 833 // Checks that navigation corrections are not loaded when we receive an actual | 833 // Checks that navigation corrections are not loaded when we receive an actual |
| 834 // 404 page. | 834 // 404 page. |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 993 | 993 |
| 994 EXPECT_EQ(2, interceptor()->failures()); | 994 EXPECT_EQ(2, interceptor()->failures()); |
| 995 EXPECT_EQ(2, interceptor()->requests()); | 995 EXPECT_EQ(2, interceptor()->requests()); |
| 996 | 996 |
| 997 ToggleHelpBox(browser()); | 997 ToggleHelpBox(browser()); |
| 998 EXPECT_TRUE(IsDisplayingText(browser(), "error.page.auto.reload")); | 998 EXPECT_TRUE(IsDisplayingText(browser(), "error.page.auto.reload")); |
| 999 | 999 |
| 1000 content::WebContents* web_contents = | 1000 content::WebContents* web_contents = |
| 1001 browser()->tab_strip_model()->GetActiveWebContents(); | 1001 browser()->tab_strip_model()->GetActiveWebContents(); |
| 1002 content::TestNavigationObserver nav_observer(web_contents, 1); | 1002 content::TestNavigationObserver nav_observer(web_contents, 1); |
| 1003 web_contents->GetMainFrame()->ExecuteJavaScriptForTests( | 1003 web_contents->GetMainFrame()->ExecuteJavaScript( |
| 1004 base::ASCIIToUTF16("document.getElementById('reload-button').click();")); | 1004 base::ASCIIToUTF16("document.getElementById('reload-button').click();")); |
| 1005 nav_observer.Wait(); | 1005 nav_observer.Wait(); |
| 1006 EXPECT_FALSE(IsDisplayingText(browser(), "error.page.auto.reload")); | 1006 EXPECT_FALSE(IsDisplayingText(browser(), "error.page.auto.reload")); |
| 1007 } | 1007 } |
| 1008 | 1008 |
| 1009 // Interceptor that fails all requests with net::ERR_ADDRESS_UNREACHABLE. | 1009 // Interceptor that fails all requests with net::ERR_ADDRESS_UNREACHABLE. |
| 1010 class AddressUnreachableInterceptor : public net::URLRequestInterceptor { | 1010 class AddressUnreachableInterceptor : public net::URLRequestInterceptor { |
| 1011 public: | 1011 public: |
| 1012 AddressUnreachableInterceptor() {} | 1012 AddressUnreachableInterceptor() {} |
| 1013 ~AddressUnreachableInterceptor() override {} | 1013 ~AddressUnreachableInterceptor() override {} |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1221 ui_test_utils::NavigateToURL( | 1221 ui_test_utils::NavigateToURL( |
| 1222 browser(), | 1222 browser(), |
| 1223 URLRequestFailedJob::GetMockHttpUrlForHostname(net::ERR_UNSAFE_PORT, | 1223 URLRequestFailedJob::GetMockHttpUrlForHostname(net::ERR_UNSAFE_PORT, |
| 1224 kHostname)); | 1224 kHostname)); |
| 1225 | 1225 |
| 1226 ToggleHelpBox(browser()); | 1226 ToggleHelpBox(browser()); |
| 1227 EXPECT_TRUE(IsDisplayingText(browser(), kHostnameJSUnicode)); | 1227 EXPECT_TRUE(IsDisplayingText(browser(), kHostnameJSUnicode)); |
| 1228 } | 1228 } |
| 1229 | 1229 |
| 1230 } // namespace | 1230 } // namespace |
| OLD | NEW |