Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(569)

Side by Side Diff: chrome/browser/errorpage_browsertest.cc

Issue 1391423002: net: Remove FilePath version of URLRequestMockHTTPJob::GetMockUrl(). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: mmenke review Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/files/scoped_temp_dir.h" 8 #include "base/files/scoped_temp_dir.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 ErrorPageTest() : link_doctor_interceptor_(NULL) {} 323 ErrorPageTest() : link_doctor_interceptor_(NULL) {}
324 ~ErrorPageTest() override {} 324 ~ErrorPageTest() override {}
325 325
326 // Navigates the active tab to a mock url created for the file at |file_path|. 326 // Navigates the active tab to a mock url created for the file at |file_path|.
327 // Needed for StaleCacheStatus and StaleCacheStatusFailedCorrections tests. 327 // Needed for StaleCacheStatus and StaleCacheStatusFailedCorrections tests.
328 void SetUpCommandLine(base::CommandLine* command_line) override { 328 void SetUpCommandLine(base::CommandLine* command_line) override {
329 command_line->AppendSwitchASCII(switches::kShowSavedCopy, 329 command_line->AppendSwitchASCII(switches::kShowSavedCopy,
330 switches::kEnableShowSavedCopyPrimary); 330 switches::kEnableShowSavedCopyPrimary);
331 } 331 }
332 332
333 // Navigates the active tab to a mock url created for the file at |file_path|. 333 // Navigates the active tab to a mock url created for the file at |path|.
334 void NavigateToFileURL(const base::FilePath::StringType& file_path) { 334 void NavigateToFileURL(const std::string& path) {
335 ui_test_utils::NavigateToURL( 335 ui_test_utils::NavigateToURL(browser(),
336 browser(), 336 net::URLRequestMockHTTPJob::GetMockUrl(path));
337 net::URLRequestMockHTTPJob::GetMockUrl(base::FilePath(file_path)));
338 } 337 }
339 338
340 // Navigates to the given URL and waits for |num_navigations| to occur, and 339 // Navigates to the given URL and waits for |num_navigations| to occur, and
341 // the title to change to |expected_title|. 340 // the title to change to |expected_title|.
342 void NavigateToURLAndWaitForTitle(const GURL& url, 341 void NavigateToURLAndWaitForTitle(const GURL& url,
343 const std::string& expected_title, 342 const std::string& expected_title,
344 int num_navigations) { 343 int num_navigations) {
345 content::TitleWatcher title_watcher( 344 content::TitleWatcher title_watcher(
346 browser()->tab_strip_model()->GetActiveWebContents(), 345 browser()->tab_strip_model()->GetActiveWebContents(),
347 base::ASCIIToUTF16(expected_title)); 346 base::ASCIIToUTF16(expected_title));
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
577 // the Link Doctor response. The second navigation is the Link Doctor. 576 // the Link Doctor response. The second navigation is the Link Doctor.
578 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( 577 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(
579 browser(), GetDnsErrorURL(), 2); 578 browser(), GetDnsErrorURL(), 2);
580 ExpectDisplayingNavigationCorrections(browser(), net::ERR_NAME_NOT_RESOLVED); 579 ExpectDisplayingNavigationCorrections(browser(), net::ERR_NAME_NOT_RESOLVED);
581 EXPECT_EQ(1, link_doctor_interceptor()->num_requests()); 580 EXPECT_EQ(1, link_doctor_interceptor()->num_requests());
582 } 581 }
583 582
584 // Test that a DNS error occuring in the main frame does not result in an 583 // Test that a DNS error occuring in the main frame does not result in an
585 // additional session history entry. 584 // additional session history entry.
586 IN_PROC_BROWSER_TEST_F(ErrorPageTest, DNSError_GoBack1) { 585 IN_PROC_BROWSER_TEST_F(ErrorPageTest, DNSError_GoBack1) {
587 NavigateToFileURL(FILE_PATH_LITERAL("title2.html")); 586 NavigateToFileURL("title2.html");
588 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( 587 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(
589 browser(), GetDnsErrorURL(), 2); 588 browser(), GetDnsErrorURL(), 2);
590 ExpectDisplayingNavigationCorrections(browser(), net::ERR_NAME_NOT_RESOLVED); 589 ExpectDisplayingNavigationCorrections(browser(), net::ERR_NAME_NOT_RESOLVED);
591 GoBackAndWaitForTitle("Title Of Awesomeness", 1); 590 GoBackAndWaitForTitle("Title Of Awesomeness", 1);
592 EXPECT_EQ(1, link_doctor_interceptor()->num_requests()); 591 EXPECT_EQ(1, link_doctor_interceptor()->num_requests());
593 } 592 }
594 593
595 // Test that a DNS error occuring in the main frame does not result in an 594 // Test that a DNS error occuring in the main frame does not result in an
596 // additional session history entry. 595 // additional session history entry.
597 IN_PROC_BROWSER_TEST_F(ErrorPageTest, DNSError_GoBack2) { 596 IN_PROC_BROWSER_TEST_F(ErrorPageTest, DNSError_GoBack2) {
598 NavigateToFileURL(FILE_PATH_LITERAL("title2.html")); 597 NavigateToFileURL("title2.html");
599 598
600 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( 599 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(
601 browser(), GetDnsErrorURL(), 2); 600 browser(), GetDnsErrorURL(), 2);
602 ExpectDisplayingNavigationCorrections(browser(), net::ERR_NAME_NOT_RESOLVED); 601 ExpectDisplayingNavigationCorrections(browser(), net::ERR_NAME_NOT_RESOLVED);
603 EXPECT_EQ(1, link_doctor_interceptor()->num_requests()); 602 EXPECT_EQ(1, link_doctor_interceptor()->num_requests());
604 603
605 NavigateToFileURL(FILE_PATH_LITERAL("title3.html")); 604 NavigateToFileURL("title3.html");
606 605
607 GoBackAndWaitForNavigations(2); 606 GoBackAndWaitForNavigations(2);
608 ExpectDisplayingNavigationCorrections(browser(), net::ERR_NAME_NOT_RESOLVED); 607 ExpectDisplayingNavigationCorrections(browser(), net::ERR_NAME_NOT_RESOLVED);
609 EXPECT_EQ(2, link_doctor_interceptor()->num_requests()); 608 EXPECT_EQ(2, link_doctor_interceptor()->num_requests());
610 609
611 GoBackAndWaitForTitle("Title Of Awesomeness", 1); 610 GoBackAndWaitForTitle("Title Of Awesomeness", 1);
612 EXPECT_EQ(2, link_doctor_interceptor()->num_requests()); 611 EXPECT_EQ(2, link_doctor_interceptor()->num_requests());
613 } 612 }
614 613
615 // Test that a DNS error occuring in the main frame does not result in an 614 // Test that a DNS error occuring in the main frame does not result in an
616 // additional session history entry. 615 // additional session history entry.
617 IN_PROC_BROWSER_TEST_F(ErrorPageTest, DNSError_GoBack2AndForward) { 616 IN_PROC_BROWSER_TEST_F(ErrorPageTest, DNSError_GoBack2AndForward) {
618 NavigateToFileURL(FILE_PATH_LITERAL("title2.html")); 617 NavigateToFileURL("title2.html");
619 618
620 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( 619 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(
621 browser(), GetDnsErrorURL(), 2); 620 browser(), GetDnsErrorURL(), 2);
622 ExpectDisplayingNavigationCorrections(browser(), net::ERR_NAME_NOT_RESOLVED); 621 ExpectDisplayingNavigationCorrections(browser(), net::ERR_NAME_NOT_RESOLVED);
623 EXPECT_EQ(1, link_doctor_interceptor()->num_requests()); 622 EXPECT_EQ(1, link_doctor_interceptor()->num_requests());
624 623
625 NavigateToFileURL(FILE_PATH_LITERAL("title3.html")); 624 NavigateToFileURL("title3.html");
626 625
627 GoBackAndWaitForNavigations(2); 626 GoBackAndWaitForNavigations(2);
628 ExpectDisplayingNavigationCorrections(browser(), net::ERR_NAME_NOT_RESOLVED); 627 ExpectDisplayingNavigationCorrections(browser(), net::ERR_NAME_NOT_RESOLVED);
629 EXPECT_EQ(2, link_doctor_interceptor()->num_requests()); 628 EXPECT_EQ(2, link_doctor_interceptor()->num_requests());
630 629
631 GoBackAndWaitForTitle("Title Of Awesomeness", 1); 630 GoBackAndWaitForTitle("Title Of Awesomeness", 1);
632 631
633 GoForwardAndWaitForNavigations(2); 632 GoForwardAndWaitForNavigations(2);
634 ExpectDisplayingNavigationCorrections(browser(), net::ERR_NAME_NOT_RESOLVED); 633 ExpectDisplayingNavigationCorrections(browser(), net::ERR_NAME_NOT_RESOLVED);
635 EXPECT_EQ(3, link_doctor_interceptor()->num_requests()); 634 EXPECT_EQ(3, link_doctor_interceptor()->num_requests());
636 } 635 }
637 636
638 // Test that a DNS error occuring in the main frame does not result in an 637 // Test that a DNS error occuring in the main frame does not result in an
639 // additional session history entry. 638 // additional session history entry.
640 IN_PROC_BROWSER_TEST_F(ErrorPageTest, DNSError_GoBack2Forward2) { 639 IN_PROC_BROWSER_TEST_F(ErrorPageTest, DNSError_GoBack2Forward2) {
641 NavigateToFileURL(FILE_PATH_LITERAL("title3.html")); 640 NavigateToFileURL("title3.html");
642 641
643 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( 642 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(
644 browser(), GetDnsErrorURL(), 2); 643 browser(), GetDnsErrorURL(), 2);
645 ExpectDisplayingNavigationCorrections(browser(), net::ERR_NAME_NOT_RESOLVED); 644 ExpectDisplayingNavigationCorrections(browser(), net::ERR_NAME_NOT_RESOLVED);
646 EXPECT_EQ(1, link_doctor_interceptor()->num_requests()); 645 EXPECT_EQ(1, link_doctor_interceptor()->num_requests());
647 646
648 NavigateToFileURL(FILE_PATH_LITERAL("title2.html")); 647 NavigateToFileURL("title2.html");
649 648
650 GoBackAndWaitForNavigations(2); 649 GoBackAndWaitForNavigations(2);
651 ExpectDisplayingNavigationCorrections(browser(), net::ERR_NAME_NOT_RESOLVED); 650 ExpectDisplayingNavigationCorrections(browser(), net::ERR_NAME_NOT_RESOLVED);
652 EXPECT_EQ(2, link_doctor_interceptor()->num_requests()); 651 EXPECT_EQ(2, link_doctor_interceptor()->num_requests());
653 652
654 GoBackAndWaitForTitle("Title Of More Awesomeness", 1); 653 GoBackAndWaitForTitle("Title Of More Awesomeness", 1);
655 654
656 GoForwardAndWaitForNavigations(2); 655 GoForwardAndWaitForNavigations(2);
657 ExpectDisplayingNavigationCorrections(browser(), net::ERR_NAME_NOT_RESOLVED); 656 ExpectDisplayingNavigationCorrections(browser(), net::ERR_NAME_NOT_RESOLVED);
658 EXPECT_EQ(3, link_doctor_interceptor()->num_requests()); 657 EXPECT_EQ(3, link_doctor_interceptor()->num_requests());
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
773 // to make sure to wait the tracking request, since the new page does not 772 // to make sure to wait the tracking request, since the new page does not
774 // depend on it. 773 // depend on it.
775 link_doctor_interceptor()->WaitForRequests(2); 774 link_doctor_interceptor()->WaitForRequests(2);
776 EXPECT_EQ(2, link_doctor_interceptor()->num_requests()); 775 EXPECT_EQ(2, link_doctor_interceptor()->num_requests());
777 } 776 }
778 777
779 // Test that a DNS error occuring in an iframe does not result in showing 778 // Test that a DNS error occuring in an iframe does not result in showing
780 // navigation corrections. 779 // navigation corrections.
781 IN_PROC_BROWSER_TEST_F(ErrorPageTest, IFrameDNSError_Basic) { 780 IN_PROC_BROWSER_TEST_F(ErrorPageTest, IFrameDNSError_Basic) {
782 NavigateToURLAndWaitForTitle( 781 NavigateToURLAndWaitForTitle(
783 net::URLRequestMockHTTPJob::GetMockUrl( 782 net::URLRequestMockHTTPJob::GetMockUrl("iframe_dns_error.html"), "Blah",
784 base::FilePath(FILE_PATH_LITERAL("iframe_dns_error.html"))),
785 "Blah",
786 1); 783 1);
787 // We expect to have two history entries, since we started off with navigation 784 // We expect to have two history entries, since we started off with navigation
788 // to "about:blank" and then navigated to "iframe_dns_error.html". 785 // to "about:blank" and then navigated to "iframe_dns_error.html".
789 EXPECT_EQ(2, 786 EXPECT_EQ(2,
790 browser()->tab_strip_model()->GetActiveWebContents()-> 787 browser()->tab_strip_model()->GetActiveWebContents()->
791 GetController().GetEntryCount()); 788 GetController().GetEntryCount());
792 EXPECT_EQ(0, link_doctor_interceptor()->num_requests()); 789 EXPECT_EQ(0, link_doctor_interceptor()->num_requests());
793 } 790 }
794 791
795 // This test fails regularly on win_rel trybots. See crbug.com/121540 792 // This test fails regularly on win_rel trybots. See crbug.com/121540
796 #if defined(OS_WIN) 793 #if defined(OS_WIN)
797 #define MAYBE_IFrameDNSError_GoBack DISABLED_IFrameDNSError_GoBack 794 #define MAYBE_IFrameDNSError_GoBack DISABLED_IFrameDNSError_GoBack
798 #else 795 #else
799 #define MAYBE_IFrameDNSError_GoBack IFrameDNSError_GoBack 796 #define MAYBE_IFrameDNSError_GoBack IFrameDNSError_GoBack
800 #endif 797 #endif
801 // Test that a DNS error occuring in an iframe does not result in an 798 // Test that a DNS error occuring in an iframe does not result in an
802 // additional session history entry. 799 // additional session history entry.
803 IN_PROC_BROWSER_TEST_F(ErrorPageTest, MAYBE_IFrameDNSError_GoBack) { 800 IN_PROC_BROWSER_TEST_F(ErrorPageTest, MAYBE_IFrameDNSError_GoBack) {
804 NavigateToFileURL(FILE_PATH_LITERAL("title2.html")); 801 NavigateToFileURL("title2.html");
805 NavigateToFileURL(FILE_PATH_LITERAL("iframe_dns_error.html")); 802 NavigateToFileURL("iframe_dns_error.html");
806 GoBackAndWaitForTitle("Title Of Awesomeness", 1); 803 GoBackAndWaitForTitle("Title Of Awesomeness", 1);
807 EXPECT_EQ(0, link_doctor_interceptor()->num_requests()); 804 EXPECT_EQ(0, link_doctor_interceptor()->num_requests());
808 } 805 }
809 806
810 // This test fails regularly on win_rel trybots. See crbug.com/121540 807 // This test fails regularly on win_rel trybots. See crbug.com/121540
811 // 808 //
812 // This fails on linux_aura bringup: http://crbug.com/163931 809 // This fails on linux_aura bringup: http://crbug.com/163931
813 #if defined(OS_WIN) || (defined(OS_LINUX) && !defined(OS_CHROMEOS) && defined(US E_AURA)) 810 #if defined(OS_WIN) || (defined(OS_LINUX) && !defined(OS_CHROMEOS) && defined(US E_AURA))
814 #define MAYBE_IFrameDNSError_GoBackAndForward DISABLED_IFrameDNSError_GoBackAndF orward 811 #define MAYBE_IFrameDNSError_GoBackAndForward DISABLED_IFrameDNSError_GoBackAndF orward
815 #else 812 #else
816 #define MAYBE_IFrameDNSError_GoBackAndForward IFrameDNSError_GoBackAndForward 813 #define MAYBE_IFrameDNSError_GoBackAndForward IFrameDNSError_GoBackAndForward
817 #endif 814 #endif
818 // Test that a DNS error occuring in an iframe does not result in an 815 // Test that a DNS error occuring in an iframe does not result in an
819 // additional session history entry. 816 // additional session history entry.
820 IN_PROC_BROWSER_TEST_F(ErrorPageTest, MAYBE_IFrameDNSError_GoBackAndForward) { 817 IN_PROC_BROWSER_TEST_F(ErrorPageTest, MAYBE_IFrameDNSError_GoBackAndForward) {
821 NavigateToFileURL(FILE_PATH_LITERAL("title2.html")); 818 NavigateToFileURL("title2.html");
822 NavigateToFileURL(FILE_PATH_LITERAL("iframe_dns_error.html")); 819 NavigateToFileURL("iframe_dns_error.html");
823 GoBackAndWaitForTitle("Title Of Awesomeness", 1); 820 GoBackAndWaitForTitle("Title Of Awesomeness", 1);
824 GoForwardAndWaitForTitle("Blah", 1); 821 GoForwardAndWaitForTitle("Blah", 1);
825 EXPECT_EQ(0, link_doctor_interceptor()->num_requests()); 822 EXPECT_EQ(0, link_doctor_interceptor()->num_requests());
826 } 823 }
827 824
828 // Test that a DNS error occuring in an iframe, once the main document is 825 // Test that a DNS error occuring in an iframe, once the main document is
829 // completed loading, does not result in an additional session history entry. 826 // completed loading, does not result in an additional session history entry.
830 // To ensure that the main document has completed loading, JavaScript is used to 827 // To ensure that the main document has completed loading, JavaScript is used to
831 // inject an iframe after loading is done. 828 // inject an iframe after loading is done.
832 IN_PROC_BROWSER_TEST_F(ErrorPageTest, IFrameDNSError_JavaScript) { 829 IN_PROC_BROWSER_TEST_F(ErrorPageTest, IFrameDNSError_JavaScript) {
833 content::WebContents* wc = 830 content::WebContents* wc =
834 browser()->tab_strip_model()->GetActiveWebContents(); 831 browser()->tab_strip_model()->GetActiveWebContents();
835 GURL fail_url = 832 GURL fail_url =
836 URLRequestFailedJob::GetMockHttpUrl(net::ERR_NAME_NOT_RESOLVED); 833 URLRequestFailedJob::GetMockHttpUrl(net::ERR_NAME_NOT_RESOLVED);
837 834
838 // Load a regular web page, in which we will inject an iframe. 835 // Load a regular web page, in which we will inject an iframe.
839 NavigateToFileURL(FILE_PATH_LITERAL("title2.html")); 836 NavigateToFileURL("title2.html");
840 837
841 // We expect to have two history entries, since we started off with navigation 838 // We expect to have two history entries, since we started off with navigation
842 // to "about:blank" and then navigated to "title2.html". 839 // to "about:blank" and then navigated to "title2.html".
843 EXPECT_EQ(2, wc->GetController().GetEntryCount()); 840 EXPECT_EQ(2, wc->GetController().GetEntryCount());
844 841
845 std::string script = "var frame = document.createElement('iframe');" 842 std::string script = "var frame = document.createElement('iframe');"
846 "frame.src = '" + fail_url.spec() + "';" 843 "frame.src = '" + fail_url.spec() + "';"
847 "document.body.appendChild(frame);"; 844 "document.body.appendChild(frame);";
848 { 845 {
849 TestFailProvisionalLoadObserver fail_observer(wc); 846 TestFailProvisionalLoadObserver fail_observer(wc);
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
887 EXPECT_EQ(fail_url, fail_observer.fail_url()); 884 EXPECT_EQ(fail_url, fail_observer.fail_url());
888 EXPECT_EQ(2, wc->GetController().GetEntryCount()); 885 EXPECT_EQ(2, wc->GetController().GetEntryCount());
889 } 886 }
890 EXPECT_EQ(0, link_doctor_interceptor()->num_requests()); 887 EXPECT_EQ(0, link_doctor_interceptor()->num_requests());
891 } 888 }
892 889
893 // Checks that navigation corrections are not loaded when we receive an actual 890 // Checks that navigation corrections are not loaded when we receive an actual
894 // 404 page. 891 // 404 page.
895 IN_PROC_BROWSER_TEST_F(ErrorPageTest, Page404) { 892 IN_PROC_BROWSER_TEST_F(ErrorPageTest, Page404) {
896 NavigateToURLAndWaitForTitle( 893 NavigateToURLAndWaitForTitle(
897 net::URLRequestMockHTTPJob::GetMockUrl( 894 net::URLRequestMockHTTPJob::GetMockUrl("page404.html"), "SUCCESS", 1);
898 base::FilePath(FILE_PATH_LITERAL("page404.html"))),
899 "SUCCESS",
900 1);
901 EXPECT_EQ(0, link_doctor_interceptor()->num_requests()); 895 EXPECT_EQ(0, link_doctor_interceptor()->num_requests());
902 } 896 }
903 897
904 // Checks that when an error occurs, the stale cache status of the page 898 // Checks that when an error occurs, the stale cache status of the page
905 // is correctly transferred, and that stale cached copied can be loaded 899 // is correctly transferred, and that stale cached copied can be loaded
906 // from the javascript. 900 // from the javascript.
907 IN_PROC_BROWSER_TEST_F(ErrorPageTest, StaleCacheStatus) { 901 IN_PROC_BROWSER_TEST_F(ErrorPageTest, StaleCacheStatus) {
908 ASSERT_TRUE(test_server()->Start()); 902 ASSERT_TRUE(test_server()->Start());
909 // Load cache with entry with "nocache" set, to create stale 903 // Load cache with entry with "nocache" set, to create stale
910 // cache. 904 // cache.
(...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after
1285 ui_test_utils::NavigateToURL( 1279 ui_test_utils::NavigateToURL(
1286 browser(), 1280 browser(),
1287 URLRequestFailedJob::GetMockHttpUrlForHostname(net::ERR_UNSAFE_PORT, 1281 URLRequestFailedJob::GetMockHttpUrlForHostname(net::ERR_UNSAFE_PORT,
1288 kHostname)); 1282 kHostname));
1289 1283
1290 ToggleHelpBox(browser()); 1284 ToggleHelpBox(browser());
1291 EXPECT_TRUE(IsDisplayingText(browser(), kHostnameJSUnicode)); 1285 EXPECT_TRUE(IsDisplayingText(browser(), kHostnameJSUnicode));
1292 } 1286 }
1293 1287
1294 } // namespace 1288 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698