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

Side by Side Diff: chrome/browser/prerender/prerender_browsertest.cc

Issue 562603002: Move PageTransition from //content/public/common to //ui/base (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 6 years, 3 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 <deque> 5 #include <deque>
6 #include <vector> 6 #include <vector>
7 7
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
(...skipping 1127 matching lines...) Expand 10 before | Expand all | Expand 10 after
1138 void NavigateToDestURL() const { 1138 void NavigateToDestURL() const {
1139 NavigateToDestURLWithDisposition(CURRENT_TAB, true); 1139 NavigateToDestURLWithDisposition(CURRENT_TAB, true);
1140 } 1140 }
1141 1141
1142 // Opens the url in a new tab, with no opener. 1142 // Opens the url in a new tab, with no opener.
1143 void NavigateToDestURLWithDisposition( 1143 void NavigateToDestURLWithDisposition(
1144 WindowOpenDisposition disposition, 1144 WindowOpenDisposition disposition,
1145 bool expect_swap_to_succeed) const { 1145 bool expect_swap_to_succeed) const {
1146 NavigateToURLWithParams( 1146 NavigateToURLWithParams(
1147 content::OpenURLParams(dest_url_, Referrer(), disposition, 1147 content::OpenURLParams(dest_url_, Referrer(), disposition,
1148 content::PAGE_TRANSITION_TYPED, false), 1148 ui::PAGE_TRANSITION_TYPED, false),
1149 expect_swap_to_succeed); 1149 expect_swap_to_succeed);
1150 } 1150 }
1151 1151
1152 void NavigateToURL(const std::string& dest_html_file) const { 1152 void NavigateToURL(const std::string& dest_html_file) const {
1153 NavigateToURLWithDisposition(dest_html_file, CURRENT_TAB, true); 1153 NavigateToURLWithDisposition(dest_html_file, CURRENT_TAB, true);
1154 } 1154 }
1155 1155
1156 void NavigateToURLWithDisposition(const std::string& dest_html_file, 1156 void NavigateToURLWithDisposition(const std::string& dest_html_file,
1157 WindowOpenDisposition disposition, 1157 WindowOpenDisposition disposition,
1158 bool expect_swap_to_succeed) const { 1158 bool expect_swap_to_succeed) const {
1159 GURL dest_url = test_server()->GetURL(dest_html_file); 1159 GURL dest_url = test_server()->GetURL(dest_html_file);
1160 NavigateToURLWithDisposition(dest_url, disposition, expect_swap_to_succeed); 1160 NavigateToURLWithDisposition(dest_url, disposition, expect_swap_to_succeed);
1161 } 1161 }
1162 1162
1163 void NavigateToURLWithDisposition(const GURL& dest_url, 1163 void NavigateToURLWithDisposition(const GURL& dest_url,
1164 WindowOpenDisposition disposition, 1164 WindowOpenDisposition disposition,
1165 bool expect_swap_to_succeed) const { 1165 bool expect_swap_to_succeed) const {
1166 NavigateToURLWithParams( 1166 NavigateToURLWithParams(
1167 content::OpenURLParams(dest_url, Referrer(), disposition, 1167 content::OpenURLParams(dest_url, Referrer(), disposition,
1168 content::PAGE_TRANSITION_TYPED, false), 1168 ui::PAGE_TRANSITION_TYPED, false),
1169 expect_swap_to_succeed); 1169 expect_swap_to_succeed);
1170 } 1170 }
1171 1171
1172 void NavigateToURLWithParams(const content::OpenURLParams& params, 1172 void NavigateToURLWithParams(const content::OpenURLParams& params,
1173 bool expect_swap_to_succeed) const { 1173 bool expect_swap_to_succeed) const {
1174 NavigateToURLImpl(params, expect_swap_to_succeed); 1174 NavigateToURLImpl(params, expect_swap_to_succeed);
1175 } 1175 }
1176 1176
1177 void OpenDestURLViaClick() const { 1177 void OpenDestURLViaClick() const {
1178 OpenURLViaClick(dest_url_); 1178 OpenURLViaClick(dest_url_);
(...skipping 953 matching lines...) Expand 10 before | Expand all | Expand 10 after
2132 "files/prerender/prerender_location_replace.html?" + 2132 "files/prerender/prerender_location_replace.html?" +
2133 net::EscapeQueryParamValue(dest_url.spec(), false) + 2133 net::EscapeQueryParamValue(dest_url.spec(), false) +
2134 "#navigate"); 2134 "#navigate");
2135 navigate_url = navigate_url.ReplaceComponents(replacements); 2135 navigate_url = navigate_url.ReplaceComponents(replacements);
2136 2136
2137 NavigationOrSwapObserver swap_observer( 2137 NavigationOrSwapObserver swap_observer(
2138 current_browser()->tab_strip_model(), 2138 current_browser()->tab_strip_model(),
2139 GetActiveWebContents(), 2); 2139 GetActiveWebContents(), 2);
2140 current_browser()->OpenURL(OpenURLParams( 2140 current_browser()->OpenURL(OpenURLParams(
2141 navigate_url, Referrer(), CURRENT_TAB, 2141 navigate_url, Referrer(), CURRENT_TAB,
2142 content::PAGE_TRANSITION_TYPED, false)); 2142 ui::PAGE_TRANSITION_TYPED, false));
2143 swap_observer.Wait(); 2143 swap_observer.Wait();
2144 2144
2145 EXPECT_TRUE(DidDisplayPass(GetActiveWebContents())); 2145 EXPECT_TRUE(DidDisplayPass(GetActiveWebContents()));
2146 2146
2147 histogram_tester().ExpectTotalCount("Prerender.gws_PrerenderNotSwappedInPLT", 2147 histogram_tester().ExpectTotalCount("Prerender.gws_PrerenderNotSwappedInPLT",
2148 0); 2148 0);
2149 histogram_tester().ExpectTotalCount("Prerender.gws_PerceivedPLT", 1); 2149 histogram_tester().ExpectTotalCount("Prerender.gws_PerceivedPLT", 1);
2150 histogram_tester().ExpectTotalCount("Prerender.gws_PerceivedPLTMatched", 1); 2150 histogram_tester().ExpectTotalCount("Prerender.gws_PerceivedPLTMatched", 1);
2151 histogram_tester().ExpectTotalCount( 2151 histogram_tester().ExpectTotalCount(
2152 "Prerender.gws_PerceivedPLTMatchedComplete", 1); 2152 "Prerender.gws_PerceivedPLTMatchedComplete", 1);
(...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after
2625 FINAL_STATUS_RENDERER_CRASHED, 2625 FINAL_STATUS_RENDERER_CRASHED,
2626 1); 2626 1);
2627 2627
2628 // Navigate to about:crash and then wait for the renderer to crash. 2628 // Navigate to about:crash and then wait for the renderer to crash.
2629 ASSERT_TRUE(prerender->contents()); 2629 ASSERT_TRUE(prerender->contents());
2630 ASSERT_TRUE(prerender->contents()->prerender_contents()); 2630 ASSERT_TRUE(prerender->contents()->prerender_contents());
2631 prerender->contents()->prerender_contents()->GetController(). 2631 prerender->contents()->prerender_contents()->GetController().
2632 LoadURL( 2632 LoadURL(
2633 GURL(content::kChromeUICrashURL), 2633 GURL(content::kChromeUICrashURL),
2634 content::Referrer(), 2634 content::Referrer(),
2635 content::PAGE_TRANSITION_TYPED, 2635 ui::PAGE_TRANSITION_TYPED,
2636 std::string()); 2636 std::string());
2637 prerender->WaitForStop(); 2637 prerender->WaitForStop();
2638 } 2638 }
2639 #endif 2639 #endif
2640 2640
2641 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, 2641 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest,
2642 PrerenderPageWithFragment) { 2642 PrerenderPageWithFragment) {
2643 PrerenderTestURL("files/prerender/prerender_page.html#fragment", 2643 PrerenderTestURL("files/prerender/prerender_page.html#fragment",
2644 FINAL_STATUS_USED, 2644 FINAL_STATUS_USED,
2645 1); 2645 1);
(...skipping 1278 matching lines...) Expand 10 before | Expand all | Expand 10 after
3924 FINAL_STATUS_BAD_DEFERRED_REDIRECT, 0); 3924 FINAL_STATUS_BAD_DEFERRED_REDIRECT, 0);
3925 NavigateToDestURL(); 3925 NavigateToDestURL();
3926 } 3926 }
3927 3927
3928 // Checks that prerenders are not swapped for navigations with extra headers. 3928 // Checks that prerenders are not swapped for navigations with extra headers.
3929 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderExtraHeadersNoSwap) { 3929 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderExtraHeadersNoSwap) {
3930 PrerenderTestURL("files/prerender/prerender_page.html", 3930 PrerenderTestURL("files/prerender/prerender_page.html",
3931 FINAL_STATUS_APP_TERMINATING, 1); 3931 FINAL_STATUS_APP_TERMINATING, 1);
3932 3932
3933 content::OpenURLParams params(dest_url(), Referrer(), CURRENT_TAB, 3933 content::OpenURLParams params(dest_url(), Referrer(), CURRENT_TAB,
3934 content::PAGE_TRANSITION_TYPED, false); 3934 ui::PAGE_TRANSITION_TYPED, false);
3935 params.extra_headers = "X-Custom-Header: 42\r\n"; 3935 params.extra_headers = "X-Custom-Header: 42\r\n";
3936 NavigateToURLWithParams(params, false); 3936 NavigateToURLWithParams(params, false);
3937 } 3937 }
3938 3938
3939 // Checks that prerenders are not swapped for navigations with browser-initiated 3939 // Checks that prerenders are not swapped for navigations with browser-initiated
3940 // POST data. 3940 // POST data.
3941 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, 3941 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest,
3942 PrerenderBrowserInitiatedPostNoSwap) { 3942 PrerenderBrowserInitiatedPostNoSwap) {
3943 PrerenderTestURL("files/prerender/prerender_page.html", 3943 PrerenderTestURL("files/prerender/prerender_page.html",
3944 FINAL_STATUS_APP_TERMINATING, 1); 3944 FINAL_STATUS_APP_TERMINATING, 1);
3945 3945
3946 std::string post_data = "DATA"; 3946 std::string post_data = "DATA";
3947 content::OpenURLParams params(dest_url(), Referrer(), CURRENT_TAB, 3947 content::OpenURLParams params(dest_url(), Referrer(), CURRENT_TAB,
3948 content::PAGE_TRANSITION_TYPED, false); 3948 ui::PAGE_TRANSITION_TYPED, false);
3949 params.uses_post = true; 3949 params.uses_post = true;
3950 params.browser_initiated_post_data = 3950 params.browser_initiated_post_data =
3951 base::RefCountedString::TakeString(&post_data); 3951 base::RefCountedString::TakeString(&post_data);
3952 NavigateToURLWithParams(params, false); 3952 NavigateToURLWithParams(params, false);
3953 } 3953 }
3954 3954
3955 // Checks that the prerendering of a page is canceled correctly when the 3955 // Checks that the prerendering of a page is canceled correctly when the
3956 // prerendered page tries to make a second navigation entry. 3956 // prerendered page tries to make a second navigation entry.
3957 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderNewNavigationEntry) { 3957 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderNewNavigationEntry) {
3958 PrerenderTestURL("files/prerender/prerender_new_entry.html", 3958 PrerenderTestURL("files/prerender/prerender_new_entry.html",
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
4075 4075
4076 // Verify DidDisplayPass in the new tab. 4076 // Verify DidDisplayPass in the new tab.
4077 EXPECT_TRUE(DidDisplayPass(GetActiveWebContents())); 4077 EXPECT_TRUE(DidDisplayPass(GetActiveWebContents()));
4078 } 4078 }
4079 4079
4080 // Checks that prerenders honor |should_replace_current_entry|. 4080 // Checks that prerenders honor |should_replace_current_entry|.
4081 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderReplaceCurrentEntry) { 4081 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderReplaceCurrentEntry) {
4082 PrerenderTestURL("files/prerender/prerender_page.html", FINAL_STATUS_USED, 1); 4082 PrerenderTestURL("files/prerender/prerender_page.html", FINAL_STATUS_USED, 1);
4083 4083
4084 content::OpenURLParams params(dest_url(), Referrer(), CURRENT_TAB, 4084 content::OpenURLParams params(dest_url(), Referrer(), CURRENT_TAB,
4085 content::PAGE_TRANSITION_TYPED, false); 4085 ui::PAGE_TRANSITION_TYPED, false);
4086 params.should_replace_current_entry = true; 4086 params.should_replace_current_entry = true;
4087 NavigateToURLWithParams(params, false); 4087 NavigateToURLWithParams(params, false);
4088 4088
4089 const NavigationController& controller = 4089 const NavigationController& controller =
4090 GetActiveWebContents()->GetController(); 4090 GetActiveWebContents()->GetController();
4091 // First entry is about:blank, second is prerender_page.html. 4091 // First entry is about:blank, second is prerender_page.html.
4092 EXPECT_TRUE(controller.GetPendingEntry() == NULL); 4092 EXPECT_TRUE(controller.GetPendingEntry() == NULL);
4093 EXPECT_EQ(2, controller.GetEntryCount()); 4093 EXPECT_EQ(2, controller.GetEntryCount());
4094 EXPECT_EQ(GURL(url::kAboutBlankURL), controller.GetEntryAtIndex(0)->GetURL()); 4094 EXPECT_EQ(GURL(url::kAboutBlankURL), controller.GetEntryAtIndex(0)->GetURL());
4095 EXPECT_EQ(dest_url(), controller.GetEntryAtIndex(1)->GetURL()); 4095 EXPECT_EQ(dest_url(), controller.GetEntryAtIndex(1)->GetURL());
(...skipping 28 matching lines...) Expand all
4124 current_browser(), 4124 current_browser(),
4125 GURL(url::kAboutBlankURL), 4125 GURL(url::kAboutBlankURL),
4126 NEW_FOREGROUND_TAB, 4126 NEW_FOREGROUND_TAB,
4127 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); 4127 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
4128 4128
4129 // Fire off two navigations, without running the event loop between them. 4129 // Fire off two navigations, without running the event loop between them.
4130 NavigationOrSwapObserver swap_observer( 4130 NavigationOrSwapObserver swap_observer(
4131 current_browser()->tab_strip_model(), 4131 current_browser()->tab_strip_model(),
4132 GetActiveWebContents(), 2); 4132 GetActiveWebContents(), 2);
4133 current_browser()->OpenURL(OpenURLParams( 4133 current_browser()->OpenURL(OpenURLParams(
4134 url1, Referrer(), CURRENT_TAB, content::PAGE_TRANSITION_TYPED, false)); 4134 url1, Referrer(), CURRENT_TAB, ui::PAGE_TRANSITION_TYPED, false));
4135 current_browser()->OpenURL(OpenURLParams( 4135 current_browser()->OpenURL(OpenURLParams(
4136 url2, Referrer(), CURRENT_TAB, content::PAGE_TRANSITION_TYPED, false)); 4136 url2, Referrer(), CURRENT_TAB, ui::PAGE_TRANSITION_TYPED, false));
4137 swap_observer.Wait(); 4137 swap_observer.Wait();
4138 4138
4139 // The WebContents should be on url2. There may be 2 or 3 entries, depending 4139 // The WebContents should be on url2. There may be 2 or 3 entries, depending
4140 // on whether the first one managed to complete. 4140 // on whether the first one managed to complete.
4141 // 4141 //
4142 // TODO(davidben): When http://crbug.com/335835 is fixed, the 3 entry case 4142 // TODO(davidben): When http://crbug.com/335835 is fixed, the 3 entry case
4143 // shouldn't be possible because it's throttled by the pending swap that 4143 // shouldn't be possible because it's throttled by the pending swap that
4144 // cannot complete. 4144 // cannot complete.
4145 const NavigationController& controller = 4145 const NavigationController& controller =
4146 GetActiveWebContents()->GetController(); 4146 GetActiveWebContents()->GetController();
(...skipping 21 matching lines...) Expand all
4168 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); 4168 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
4169 4169
4170 // Navigate to the URL. Wait for DidStartLoading, just so it's definitely 4170 // Navigate to the URL. Wait for DidStartLoading, just so it's definitely
4171 // progressed somewhere. 4171 // progressed somewhere.
4172 content::WindowedNotificationObserver page_load_observer( 4172 content::WindowedNotificationObserver page_load_observer(
4173 content::NOTIFICATION_LOAD_START, 4173 content::NOTIFICATION_LOAD_START,
4174 content::Source<NavigationController>( 4174 content::Source<NavigationController>(
4175 &GetActiveWebContents()->GetController())); 4175 &GetActiveWebContents()->GetController()));
4176 current_browser()->OpenURL(OpenURLParams( 4176 current_browser()->OpenURL(OpenURLParams(
4177 dest_url(), Referrer(), CURRENT_TAB, 4177 dest_url(), Referrer(), CURRENT_TAB,
4178 content::PAGE_TRANSITION_TYPED, false)); 4178 ui::PAGE_TRANSITION_TYPED, false));
4179 page_load_observer.Wait(); 4179 page_load_observer.Wait();
4180 4180
4181 // Navigate somewhere else. This should succeed and abort the pending swap. 4181 // Navigate somewhere else. This should succeed and abort the pending swap.
4182 TestNavigationObserver nav_observer(GetActiveWebContents()); 4182 TestNavigationObserver nav_observer(GetActiveWebContents());
4183 current_browser()->OpenURL(OpenURLParams(GURL(url::kAboutBlankURL), 4183 current_browser()->OpenURL(OpenURLParams(GURL(url::kAboutBlankURL),
4184 Referrer(), 4184 Referrer(),
4185 CURRENT_TAB, 4185 CURRENT_TAB,
4186 content::PAGE_TRANSITION_TYPED, 4186 ui::PAGE_TRANSITION_TYPED,
4187 false)); 4187 false));
4188 nav_observer.Wait(); 4188 nav_observer.Wait();
4189 } 4189 }
4190 4190
4191 // Checks that <a ping> requests are not dropped in prerender. 4191 // Checks that <a ping> requests are not dropped in prerender.
4192 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderPing) { 4192 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderPing) {
4193 // Count hits to a certain URL. 4193 // Count hits to a certain URL.
4194 const GURL kPingURL("http://prerender.test/ping"); 4194 const GURL kPingURL("http://prerender.test/ping");
4195 base::FilePath empty_file = ui_test_utils::GetTestFilePath( 4195 base::FilePath empty_file = ui_test_utils::GetTestFilePath(
4196 base::FilePath(), base::FilePath(FILE_PATH_LITERAL("empty.html"))); 4196 base::FilePath(), base::FilePath(FILE_PATH_LITERAL("empty.html")));
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
4447 4447
4448 // Navigate to the URL entered. 4448 // Navigate to the URL entered.
4449 omnibox_view->model()->AcceptInput(CURRENT_TAB, false); 4449 omnibox_view->model()->AcceptInput(CURRENT_TAB, false);
4450 4450
4451 // Prerender should be running, but abandoned. 4451 // Prerender should be running, but abandoned.
4452 EXPECT_TRUE( 4452 EXPECT_TRUE(
4453 GetAutocompleteActionPredictor()->IsPrerenderAbandonedForTesting()); 4453 GetAutocompleteActionPredictor()->IsPrerenderAbandonedForTesting());
4454 } 4454 }
4455 4455
4456 } // namespace prerender 4456 } // namespace prerender
OLDNEW
« no previous file with comments | « chrome/browser/policy/policy_browsertest.cc ('k') | chrome/browser/prerender/prerender_contents.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698