diff options
author | clamy <clamy@chromium.org> | 2015-04-09 04:32:24 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-04-09 11:32:48 +0000 |
commit | 5c7ede5ffccfba15c2d0752d03bc6979f1d81bae (patch) | |
tree | 2cd0859c38d0b5699ed2fc02b0262b04796a4029 | |
parent | 16a569a8340a53623aa0d76d4c2fcdc5e6831594 (diff) | |
download | chromium_src-5c7ede5ffccfba15c2d0752d03bc6979f1d81bae.zip chromium_src-5c7ede5ffccfba15c2d0752d03bc6979f1d81bae.tar.gz chromium_src-5c7ede5ffccfba15c2d0752d03bc6979f1d81bae.tar.bz2 |
PlzNavigate: make RenderViewtest helper functions work
This CL makes it so that the helper functions used in RenderViewImpltest work
with browser-side navigation enabled. This makes 20 browser tests pass.
BUG=475027
Review URL: https://codereview.chromium.org/1064413003
Cr-Commit-Position: refs/heads/master@{#324414}
-rw-r--r-- | content/child/web_url_loader_impl.cc | 16 | ||||
-rw-r--r-- | content/public/test/render_view_test.cc | 4 | ||||
-rw-r--r-- | content/renderer/render_frame_impl.cc | 2 | ||||
-rw-r--r-- | content/renderer/render_frame_impl.h | 1 | ||||
-rw-r--r-- | content/renderer/render_view_browsertest.cc | 74 |
5 files changed, 55 insertions, 42 deletions
diff --git a/content/child/web_url_loader_impl.cc b/content/child/web_url_loader_impl.cc index e2cec70d..585d7f9 100644 --- a/content/child/web_url_loader_impl.cc +++ b/content/child/web_url_loader_impl.cc @@ -449,13 +449,6 @@ void WebURLLoaderImpl::Context::Start(const WebURLRequest& request, url = stream_override_->stream_url; } - // PlzNavigate: the only navigation requests going through the WebURLLoader - // are the ones created by CommitNavigation. - DCHECK(!base::CommandLine::ForCurrentProcess()->HasSwitch( - switches::kEnableBrowserSideNavigation) || - stream_override_.get() || - request.frameType() == WebURLRequest::FrameTypeNone); - if (CanHandleDataURLRequestLocally()) { if (sync_load_response) { // This is a sync load. Do the work now. @@ -470,6 +463,15 @@ void WebURLLoaderImpl::Context::Start(const WebURLRequest& request, return; } + // PlzNavigate: outside of tests, the only navigation requests going through + // the WebURLLoader are the ones created by CommitNavigation. Several browser + // tests load HTML directly through a data url which will be handled by the + // block above. + DCHECK_IMPLIES(base::CommandLine::ForCurrentProcess()->HasSwitch( + switches::kEnableBrowserSideNavigation), + stream_override_.get() || + request.frameType() == WebURLRequest::FrameTypeNone); + GURL referrer_url( request.httpHeaderField(WebString::fromUTF8("Referer")).latin1()); const std::string& method = request.httpMethod().latin1(); diff --git a/content/public/test/render_view_test.cc b/content/public/test/render_view_test.cc index c8e488d..935b219 100644 --- a/content/public/test/render_view_test.cc +++ b/content/public/test/render_view_test.cc @@ -125,7 +125,9 @@ void RenderViewTest::LoadHTML(const char* html) { std::string url_str = "data:text/html;charset=utf-8,"; url_str.append(html); GURL url(url_str); - GetMainFrame()->loadRequest(WebURLRequest(url)); + WebURLRequest request(url); + request.setCheckForBrowserSideNavigation(false); + GetMainFrame()->loadRequest(request); // The load actually happens asynchronously, so we pump messages to process // the pending continuation. FrameLoadWaiter(view_->GetMainRenderFrame()).Wait(); diff --git a/content/renderer/render_frame_impl.cc b/content/renderer/render_frame_impl.cc index d4015ed..38e058a 100644 --- a/content/renderer/render_frame_impl.cc +++ b/content/renderer/render_frame_impl.cc @@ -1070,6 +1070,8 @@ void RenderFrameImpl::OnNavigate( const CommonNavigationParams& common_params, const StartNavigationParams& start_params, const RequestNavigationParams& request_params) { + DCHECK(!base::CommandLine::ForCurrentProcess()->HasSwitch( + switches::kEnableBrowserSideNavigation)); TRACE_EVENT2("navigation", "RenderFrameImpl::OnNavigate", "id", routing_id_, "url", common_params.url.possibly_invalid_spec()); diff --git a/content/renderer/render_frame_impl.h b/content/renderer/render_frame_impl.h index 59d6ec0..b08a73c 100644 --- a/content/renderer/render_frame_impl.h +++ b/content/renderer/render_frame_impl.h @@ -565,6 +565,7 @@ class CONTENT_EXPORT RenderFrameImpl private: friend class RenderFrameImplTest; friend class RenderFrameObserver; + friend class RenderViewImplTest; friend class RendererAccessibilityTest; FRIEND_TEST_ALL_PREFIXES(ExternalPopupMenuDisplayNoneTest, SelectItem); FRIEND_TEST_ALL_PREFIXES(ExternalPopupMenuRemoveTest, RemoveOnChange); diff --git a/content/renderer/render_view_browsertest.cc b/content/renderer/render_view_browsertest.cc index 164feec..839265c 100644 --- a/content/renderer/render_view_browsertest.cc +++ b/content/renderer/render_view_browsertest.cc @@ -285,6 +285,19 @@ class RenderViewImplTest : public RenderViewTest { view()->OnSetZoomLevelForView(false, level); } + void NavigateFrame(const CommonNavigationParams& common_params, + const StartNavigationParams& start_params, + const RequestNavigationParams& request_params) { + // PlzNavigate + if (base::CommandLine::ForCurrentProcess()->HasSwitch( + switches::kEnableBrowserSideNavigation)) { + frame()->OnCommitNavigation(ResourceResponseHead(), common_params.url, + common_params, request_params); + return; + } + frame()->OnNavigate(common_params, start_params, request_params); + } + private: scoped_ptr<MockKeyboard> mock_keyboard_; }; @@ -432,7 +445,7 @@ TEST_F(RenderViewImplTest, OnNavigationHttpPost) { start_params.is_post = true; start_params.browser_initiated_post_data = post_data; - frame()->OnNavigate(common_params, start_params, request_params); + NavigateFrame(common_params, start_params, request_params); ProcessPendingMessages(); const IPC::Message* frame_navigate_msg = @@ -633,7 +646,7 @@ TEST_F(RenderViewImplTest, SendSwapOutACK) { request_params.current_history_list_offset = 0; request_params.pending_history_list_offset = 1; request_params.page_id = -1; - frame()->OnNavigate(common_params, StartNavigationParams(), request_params); + NavigateFrame(common_params, StartNavigationParams(), request_params); ProcessPendingMessages(); const IPC::Message* msg3 = render_thread_->sink().GetUniqueMessageMatching( ViewHostMsg_UpdateState::ID); @@ -671,8 +684,7 @@ TEST_F(RenderViewImplTest, ReloadWhileSwappedOut) { request_params_A.pending_history_list_offset = 0; request_params_A.page_id = 1; request_params_A.page_state = state_A; - frame()->OnNavigate(common_params_A, StartNavigationParams(), - request_params_A); + NavigateFrame(common_params_A, StartNavigationParams(), request_params_A); EXPECT_EQ(1, view()->historyBackListCount()); EXPECT_EQ(2, view()->historyBackListCount() + view()->historyForwardListCount() + 1); @@ -702,7 +714,7 @@ TEST_F(RenderViewImplTest, ReloadWhileSwappedOut) { request_params.pending_history_list_offset = 0; request_params.page_id = 1; request_params.page_state = state_A; - frame()->OnNavigate(common_params, StartNavigationParams(), request_params); + NavigateFrame(common_params, StartNavigationParams(), request_params); ProcessPendingMessages(); // Verify page A committed, not swappedout://. @@ -820,8 +832,7 @@ TEST_F(RenderViewImplTest, DISABLED_LastCommittedUpdateState) { request_params_C.pending_history_list_offset = 2; request_params_C.page_id = 3; request_params_C.page_state = state_C; - frame()->OnNavigate(common_params_C, StartNavigationParams(), - request_params_C); + NavigateFrame(common_params_C, StartNavigationParams(), request_params_C); ProcessPendingMessages(); render_thread_->sink().ClearMessages(); @@ -839,8 +850,7 @@ TEST_F(RenderViewImplTest, DISABLED_LastCommittedUpdateState) { request_params_B.pending_history_list_offset = 1; request_params_B.page_id = 2; request_params_B.page_state = state_B; - frame()->OnNavigate(common_params_B, StartNavigationParams(), - request_params_B); + NavigateFrame(common_params_B, StartNavigationParams(), request_params_B); // Back to page A (page_id 1) and commit. CommonNavigationParams common_params; @@ -852,7 +862,7 @@ TEST_F(RenderViewImplTest, DISABLED_LastCommittedUpdateState) { request_params.pending_history_list_offset = 0; request_params.page_id = 1; request_params.page_state = state_A; - frame()->OnNavigate(common_params, StartNavigationParams(), request_params); + NavigateFrame(common_params, StartNavigationParams(), request_params); ProcessPendingMessages(); // Now ensure that the UpdateState message we receive is consistent @@ -904,8 +914,7 @@ TEST_F(RenderViewImplTest, StaleNavigationsIgnored) { request_params_A.pending_history_list_offset = 0; request_params_A.page_id = 1; request_params_A.page_state = state_A; - frame()->OnNavigate(common_params_A, StartNavigationParams(), - request_params_A); + NavigateFrame(common_params_A, StartNavigationParams(), request_params_A); ProcessPendingMessages(); // A new navigation commits, clearing the forward history. @@ -925,8 +934,7 @@ TEST_F(RenderViewImplTest, StaleNavigationsIgnored) { request_params_B.page_id = 2; request_params_B.page_state = state_A; // Doesn't matter, just has to be present. - frame()->OnNavigate(common_params_B, StartNavigationParams(), - request_params_B); + NavigateFrame(common_params_B, StartNavigationParams(), request_params_B); // State should be unchanged. EXPECT_EQ(2, view()->history_list_length_); @@ -1641,8 +1649,8 @@ TEST_F(RenderViewImplTest, DISABLED_DidFailProvisionalLoadWithErrorForError) { CommonNavigationParams common_params; common_params.navigation_type = FrameMsg_Navigate_Type::NORMAL; common_params.url = GURL("data:text/html,test data"); - frame()->OnNavigate(common_params, StartNavigationParams(), - RequestNavigationParams()); + NavigateFrame(common_params, StartNavigationParams(), + RequestNavigationParams()); // An error occurred. view()->GetMainRenderFrame()->didFailProvisionalLoad( @@ -1664,8 +1672,8 @@ TEST_F(RenderViewImplTest, DidFailProvisionalLoadWithErrorForCancellation) { CommonNavigationParams common_params; common_params.navigation_type = FrameMsg_Navigate_Type::NORMAL; common_params.url = GURL("data:text/html,test data"); - frame()->OnNavigate(common_params, StartNavigationParams(), - RequestNavigationParams()); + NavigateFrame(common_params, StartNavigationParams(), + RequestNavigationParams()); // A cancellation occurred. view()->GetMainRenderFrame()->didFailProvisionalLoad( @@ -1862,8 +1870,8 @@ TEST_F(RenderViewImplTest, ZoomLimit) { CommonNavigationParams common_params; common_params.url = GURL("data:text/html,min_zoomlimit_test"); view()->OnSetZoomLevelForLoadingURL(common_params.url, kMinZoomLevel); - frame()->OnNavigate(common_params, StartNavigationParams(), - RequestNavigationParams()); + NavigateFrame(common_params, StartNavigationParams(), + RequestNavigationParams()); ProcessPendingMessages(); EXPECT_DOUBLE_EQ(kMinZoomLevel, view()->GetWebView()->zoomLevel()); @@ -1872,8 +1880,8 @@ TEST_F(RenderViewImplTest, ZoomLimit) { ZoomFactorToZoomLevel(1.0)); common_params.url = GURL("data:text/html,max_zoomlimit_test"); view()->OnSetZoomLevelForLoadingURL(common_params.url, kMaxZoomLevel); - frame()->OnNavigate(common_params, StartNavigationParams(), - RequestNavigationParams()); + NavigateFrame(common_params, StartNavigationParams(), + RequestNavigationParams()); ProcessPendingMessages(); EXPECT_DOUBLE_EQ(kMaxZoomLevel, view()->GetWebView()->zoomLevel()); } @@ -1945,7 +1953,7 @@ TEST_F(RenderViewImplTest, NavigateFrame) { request_params.frame_to_navigate = "frame"; request_params.browser_navigation_start = base::TimeTicks::FromInternalValue(1); - frame()->OnNavigate(common_params, StartNavigationParams(), request_params); + NavigateFrame(common_params, StartNavigationParams(), request_params); FrameLoadWaiter( RenderFrame::FromWebFrame(frame()->GetWebFrame()->firstChild())).Wait(); @@ -2009,7 +2017,7 @@ TEST_F(RenderViewImplTest, MessageOrderInDidChangeSelection) { EXPECT_LT(last_input_type, last_selection); } -class SuppressErrorPageTest : public RenderViewTest { +class SuppressErrorPageTest : public RenderViewImplTest { public: ContentRendererClient* CreateContentRendererClient() override { return new TestContentRendererClient; @@ -2062,8 +2070,8 @@ TEST_F(SuppressErrorPageTest, MAYBE_Suppresses) { CommonNavigationParams common_params; common_params.navigation_type = FrameMsg_Navigate_Type::NORMAL; common_params.url = GURL("data:text/html,test data"); - frame()->OnNavigate(common_params, StartNavigationParams(), - RequestNavigationParams()); + NavigateFrame(common_params, StartNavigationParams(), + RequestNavigationParams()); // An error occurred. view()->GetMainRenderFrame()->didFailProvisionalLoad( @@ -2092,8 +2100,8 @@ TEST_F(SuppressErrorPageTest, MAYBE_DoesNotSuppress) { CommonNavigationParams common_params; common_params.navigation_type = FrameMsg_Navigate_Type::NORMAL; common_params.url = GURL("data:text/html,test data"); - frame()->OnNavigate(common_params, StartNavigationParams(), - RequestNavigationParams()); + NavigateFrame(common_params, StartNavigationParams(), + RequestNavigationParams()); // An error occurred. view()->GetMainRenderFrame()->didFailProvisionalLoad( @@ -2303,8 +2311,7 @@ TEST_F(RenderViewImplTest, NavigationStartOverride) { early_request_params.browser_navigation_start = base::TimeTicks::FromInternalValue(1); - frame()->OnNavigate(early_common_params, early_start_params, - early_request_params); + NavigateFrame(early_common_params, early_start_params, early_request_params); ProcessPendingMessages(); base::Time early_nav_reported_start = @@ -2324,8 +2331,7 @@ TEST_F(RenderViewImplTest, NavigationStartOverride) { late_request_params.browser_navigation_start = base::TimeTicks::Now() + base::TimeDelta::FromDays(42); - frame()->OnNavigate(late_common_params, late_start_params, - late_request_params); + NavigateFrame(late_common_params, late_start_params, late_request_params); ProcessPendingMessages(); base::Time after_navigation = base::Time::Now() + base::TimeDelta::FromDays(1); @@ -2362,8 +2368,8 @@ TEST_F(RenderViewImplTest, HistoryIsProperlyUpdatedOnNavigation) { request_params.current_history_list_offset = 1; request_params.pending_history_list_offset = 2; request_params.page_id = -1; - frame()->OnNavigate(CommonNavigationParams(), StartNavigationParams(), - request_params); + NavigateFrame(CommonNavigationParams(), StartNavigationParams(), + request_params); // The history list in RenderView should have been updated. EXPECT_EQ(1, view()->historyBackListCount()); |