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

Side by Side Diff: content/renderer/render_view_browsertest.cc

Issue 2103733004: Set navigationStart correctly for all load types. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comments. Created 4 years, 4 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 <stddef.h> 5 #include <stddef.h>
6 #include <stdint.h> 6 #include <stdint.h>
7 #include <tuple> 7 #include <tuple>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/callback.h" 10 #include "base/callback.h"
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 #include "content/renderer/gpu/render_widget_compositor.h" 51 #include "content/renderer/gpu/render_widget_compositor.h"
52 #include "content/renderer/history_controller.h" 52 #include "content/renderer/history_controller.h"
53 #include "content/renderer/history_serialization.h" 53 #include "content/renderer/history_serialization.h"
54 #include "content/renderer/navigation_state_impl.h" 54 #include "content/renderer/navigation_state_impl.h"
55 #include "content/renderer/render_frame_proxy.h" 55 #include "content/renderer/render_frame_proxy.h"
56 #include "content/renderer/render_process.h" 56 #include "content/renderer/render_process.h"
57 #include "content/renderer/render_view_impl.h" 57 #include "content/renderer/render_view_impl.h"
58 #include "content/shell/browser/shell.h" 58 #include "content/shell/browser/shell.h"
59 #include "content/shell/browser/shell_browser_context.h" 59 #include "content/shell/browser/shell_browser_context.h"
60 #include "content/test/mock_keyboard.h" 60 #include "content/test/mock_keyboard.h"
61 #include "content/test/mock_weburlloader.h"
61 #include "content/test/test_render_frame.h" 62 #include "content/test/test_render_frame.h"
62 #include "net/base/net_errors.h" 63 #include "net/base/net_errors.h"
63 #include "net/cert/cert_status_flags.h" 64 #include "net/cert/cert_status_flags.h"
64 #include "testing/gtest/include/gtest/gtest.h" 65 #include "testing/gtest/include/gtest/gtest.h"
65 #include "third_party/WebKit/public/platform/WebData.h" 66 #include "third_party/WebKit/public/platform/WebData.h"
66 #include "third_party/WebKit/public/platform/WebHTTPBody.h" 67 #include "third_party/WebKit/public/platform/WebHTTPBody.h"
67 #include "third_party/WebKit/public/platform/WebString.h" 68 #include "third_party/WebKit/public/platform/WebString.h"
68 #include "third_party/WebKit/public/platform/WebURLResponse.h" 69 #include "third_party/WebKit/public/platform/WebURLResponse.h"
69 #include "third_party/WebKit/public/web/WebDataSource.h" 70 #include "third_party/WebKit/public/web/WebDataSource.h"
70 #include "third_party/WebKit/public/web/WebDeviceEmulationParams.h" 71 #include "third_party/WebKit/public/web/WebDeviceEmulationParams.h"
(...skipping 19 matching lines...) Expand all
90 #include "ui/events/test/events_test_utils.h" 91 #include "ui/events/test/events_test_utils.h"
91 #include "ui/events/test/events_test_utils_x11.h" 92 #include "ui/events/test/events_test_utils_x11.h"
92 #endif 93 #endif
93 94
94 #if defined(USE_OZONE) 95 #if defined(USE_OZONE)
95 #include "ui/events/keycodes/keyboard_code_conversion.h" 96 #include "ui/events/keycodes/keyboard_code_conversion.h"
96 #endif 97 #endif
97 98
98 #include "url/url_constants.h" 99 #include "url/url_constants.h"
99 100
101 using base::TimeDelta;
100 using blink::WebFrame; 102 using blink::WebFrame;
101 using blink::WebFrameContentDumper; 103 using blink::WebFrameContentDumper;
102 using blink::WebInputEvent; 104 using blink::WebInputEvent;
103 using blink::WebLocalFrame; 105 using blink::WebLocalFrame;
104 using blink::WebMouseEvent; 106 using blink::WebMouseEvent;
105 using blink::WebRuntimeFeatures; 107 using blink::WebRuntimeFeatures;
106 using blink::WebString; 108 using blink::WebString;
107 using blink::WebTextDirection; 109 using blink::WebTextDirection;
108 using blink::WebURLError; 110 using blink::WebURLError;
109 111
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 result.unique_name = 184 result.unique_name =
183 base::UTF16ToUTF8(base::StringPiece16(frame->uniqueName())); 185 base::UTF16ToUTF8(base::StringPiece16(frame->uniqueName()));
184 result.sandbox_flags = frame->effectiveSandboxFlags(); 186 result.sandbox_flags = frame->effectiveSandboxFlags();
185 // result.should_enforce_strict_mixed_content_checking is calculated in the 187 // result.should_enforce_strict_mixed_content_checking is calculated in the
186 // browser... 188 // browser...
187 result.origin = frame->getSecurityOrigin(); 189 result.origin = frame->getSecurityOrigin();
188 190
189 return result; 191 return result;
190 } 192 }
191 193
194 // Returns CommonNavigationParams for a normal navigation to a data: url, with
195 // navigation_start set to Now() plus the given offset.
196 CommonNavigationParams MakeCommonNavigationParams(
197 TimeDelta navigation_start_offset) {
198 CommonNavigationParams params;
199 params.url = GURL("data:text/html,<div>Page</div>");
200 params.navigation_start = base::TimeTicks::Now() + navigation_start_offset;
201 params.navigation_type = FrameMsg_Navigate_Type::NORMAL;
202 params.transition = ui::PAGE_TRANSITION_TYPED;
203 return params;
204 }
205
206 blink::WebURLLoader* CreateMockURLLoader() {
207 return new testing::NiceMock<MockWebURLLoader>();
208 }
209
192 } // namespace 210 } // namespace
193 211
194 class RenderViewImplTest : public RenderViewTest { 212 class RenderViewImplTest : public RenderViewTest {
195 public: 213 public:
196 RenderViewImplTest() { 214 RenderViewImplTest() {
197 // Attach a pseudo keyboard device to this object. 215 // Attach a pseudo keyboard device to this object.
198 mock_keyboard_.reset(new MockKeyboard()); 216 mock_keyboard_.reset(new MockKeyboard());
199 } 217 }
200 218
201 ~RenderViewImplTest() override {} 219 ~RenderViewImplTest() override {}
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 // the pending continuation. 258 // the pending continuation.
241 FrameLoadWaiter(frame()).Wait(); 259 FrameLoadWaiter(frame()).Wait();
242 } 260 }
243 261
244 template<class T> 262 template<class T>
245 typename T::Param ProcessAndReadIPC() { 263 typename T::Param ProcessAndReadIPC() {
246 ProcessPendingMessages(); 264 ProcessPendingMessages();
247 const IPC::Message* message = 265 const IPC::Message* message =
248 render_thread_->sink().GetUniqueMessageMatching(T::ID); 266 render_thread_->sink().GetUniqueMessageMatching(T::ID);
249 typename T::Param param; 267 typename T::Param param;
250 T::Read(message, &param); 268 EXPECT_TRUE(message);
clamy 2016/08/24 23:23:09 Why is this needed?
Alexander Semashko 2016/08/25 10:44:33 Simplifies debugging tests. Earlier, if the messag
269 if (message)
270 T::Read(message, &param);
251 return param; 271 return param;
252 } 272 }
253 273
254 // Sends IPC messages that emulates a key-press event. 274 // Sends IPC messages that emulates a key-press event.
255 int SendKeyEvent(MockKeyboard::Layout layout, 275 int SendKeyEvent(MockKeyboard::Layout layout,
256 int key_code, 276 int key_code,
257 MockKeyboard::Modifiers modifiers, 277 MockKeyboard::Modifiers modifiers,
258 base::string16* output) { 278 base::string16* output) {
259 #if defined(OS_WIN) 279 #if defined(OS_WIN)
260 // Retrieve the Unicode character for the given tuple (keyboard-layout, 280 // Retrieve the Unicode character for the given tuple (keyboard-layout,
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
369 const gfx::Size& GetPreferredSize() { 389 const gfx::Size& GetPreferredSize() {
370 view()->CheckPreferredSize(); 390 view()->CheckPreferredSize();
371 return view()->preferred_size_; 391 return view()->preferred_size_;
372 } 392 }
373 393
374 void SetZoomLevel(double level) { 394 void SetZoomLevel(double level) {
375 view()->OnSetZoomLevel( 395 view()->OnSetZoomLevel(
376 PageMsg_SetZoomLevel_Command::USE_CURRENT_TEMPORARY_MODE, level); 396 PageMsg_SetZoomLevel_Command::USE_CURRENT_TEMPORARY_MODE, level);
377 } 397 }
378 398
399 // Closes a view created during the test, i.e. not the |view()|. Checks that
400 // the main frame is detached and deleted, and makes sure the view does not
401 // leak.
402 void CloseRenderView(RenderViewImpl* new_view) {
403 new_view->Close();
404 EXPECT_FALSE(new_view->GetMainRenderFrame());
405
406 new_view->Release();
407 }
408
379 private: 409 private:
380 std::unique_ptr<MockKeyboard> mock_keyboard_; 410 std::unique_ptr<MockKeyboard> mock_keyboard_;
381 }; 411 };
382 412
383 class DevToolsAgentTest : public RenderViewImplTest { 413 class DevToolsAgentTest : public RenderViewImplTest {
384 public: 414 public:
385 void Attach() { 415 void Attach() {
386 notifications_ = std::vector<std::string>(); 416 notifications_ = std::vector<std::string>();
387 expecting_pause_ = false; 417 expecting_pause_ = false;
388 std::string host_id = "host_id"; 418 std::string host_id = "host_id";
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
532 // after closing it. 562 // after closing it.
533 TEST_F(RenderViewImplTest, RenderFrameClearedAfterClose) { 563 TEST_F(RenderViewImplTest, RenderFrameClearedAfterClose) {
534 // Create a new main frame RenderFrame so that we don't interfere with the 564 // Create a new main frame RenderFrame so that we don't interfere with the
535 // shutdown of frame() in RenderViewTest.TearDown. 565 // shutdown of frame() in RenderViewTest.TearDown.
536 blink::WebURLRequest popup_request(GURL("http://foo.com")); 566 blink::WebURLRequest popup_request(GURL("http://foo.com"));
537 blink::WebView* new_web_view = view()->createView( 567 blink::WebView* new_web_view = view()->createView(
538 GetMainFrame(), popup_request, blink::WebWindowFeatures(), "foo", 568 GetMainFrame(), popup_request, blink::WebWindowFeatures(), "foo",
539 blink::WebNavigationPolicyNewForegroundTab, false); 569 blink::WebNavigationPolicyNewForegroundTab, false);
540 RenderViewImpl* new_view = RenderViewImpl::FromWebView(new_web_view); 570 RenderViewImpl* new_view = RenderViewImpl::FromWebView(new_web_view);
541 571
542 // Close the view, causing the main RenderFrame to be detached and deleted. 572 // Checks that the frame is deleted properly and cleans up the view.
543 new_view->Close(); 573 CloseRenderView(new_view);
544 EXPECT_FALSE(new_view->GetMainRenderFrame());
545
546 // Clean up after the new view so we don't leak it.
547 new_view->Release();
548 } 574 }
549 575
550 // Test that we get form state change notifications when input fields change. 576 // Test that we get form state change notifications when input fields change.
551 TEST_F(RenderViewImplTest, OnNavStateChanged) { 577 TEST_F(RenderViewImplTest, OnNavStateChanged) {
552 view()->set_send_content_state_immediately(true); 578 view()->set_send_content_state_immediately(true);
553 LoadHTML("<input type=\"text\" id=\"elt_text\"></input>"); 579 LoadHTML("<input type=\"text\" id=\"elt_text\"></input>");
554 580
555 // We should NOT have gotten a form state change notification yet. 581 // We should NOT have gotten a form state change notification yet.
556 EXPECT_FALSE(render_thread_->sink().GetFirstMessageMatching( 582 EXPECT_FALSE(render_thread_->sink().GetFirstMessageMatching(
557 FrameHostMsg_UpdateState::ID)); 583 FrameHostMsg_UpdateState::ID));
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
814 GetMainFrame(), popup_request, blink::WebWindowFeatures(), "foo", 840 GetMainFrame(), popup_request, blink::WebWindowFeatures(), "foo",
815 blink::WebNavigationPolicyNewForegroundTab, false); 841 blink::WebNavigationPolicyNewForegroundTab, false);
816 RenderViewImpl* new_view = RenderViewImpl::FromWebView(new_web_view); 842 RenderViewImpl* new_view = RenderViewImpl::FromWebView(new_web_view);
817 blink::WebFrameClient::NavigationPolicyInfo popup_policy_info(popup_request); 843 blink::WebFrameClient::NavigationPolicyInfo popup_policy_info(popup_request);
818 popup_policy_info.navigationType = blink::WebNavigationTypeLinkClicked; 844 popup_policy_info.navigationType = blink::WebNavigationTypeLinkClicked;
819 popup_policy_info.defaultPolicy = blink::WebNavigationPolicyNewForegroundTab; 845 popup_policy_info.defaultPolicy = blink::WebNavigationPolicyNewForegroundTab;
820 policy = static_cast<RenderFrameImpl*>(new_view->GetMainRenderFrame())-> 846 policy = static_cast<RenderFrameImpl*>(new_view->GetMainRenderFrame())->
821 decidePolicyForNavigation(popup_policy_info); 847 decidePolicyForNavigation(popup_policy_info);
822 EXPECT_EQ(blink::WebNavigationPolicyIgnore, policy); 848 EXPECT_EQ(blink::WebNavigationPolicyIgnore, policy);
823 849
824 // Clean up after the new view so we don't leak it. 850 CloseRenderView(new_view);
825 new_view->Close();
826 new_view->Release();
827 } 851 }
828 852
829 // Verify that security origins are replicated properly to RenderFrameProxies 853 // Verify that security origins are replicated properly to RenderFrameProxies
830 // when swapping out. 854 // when swapping out.
831 TEST_F(RenderViewImplTest, OriginReplicationForSwapOut) { 855 TEST_F(RenderViewImplTest, OriginReplicationForSwapOut) {
832 // This test should only run with --site-per-process, since origin 856 // This test should only run with --site-per-process, since origin
833 // replication only happens in that mode. 857 // replication only happens in that mode.
834 if (!AreAllSitesIsolatedForTesting()) 858 if (!AreAllSitesIsolatedForTesting())
835 return; 859 return;
836 860
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
944 // Respond to a swap out request. 968 // Respond to a swap out request.
945 TestRenderFrame* new_main_frame = 969 TestRenderFrame* new_main_frame =
946 static_cast<TestRenderFrame*>(new_view->GetMainRenderFrame()); 970 static_cast<TestRenderFrame*>(new_view->GetMainRenderFrame());
947 new_main_frame->SwapOut( 971 new_main_frame->SwapOut(
948 kProxyRoutingId, true, 972 kProxyRoutingId, true,
949 ReconstructReplicationStateForTesting(new_main_frame)); 973 ReconstructReplicationStateForTesting(new_main_frame));
950 974
951 // Simulate getting painted after swapping out. 975 // Simulate getting painted after swapping out.
952 new_view->DidFlushPaint(); 976 new_view->DidFlushPaint();
953 977
954 new_view->Close(); 978 CloseRenderView(new_view);
955 new_view->Release();
956 } 979 }
957 980
958 // Verify that the renderer process doesn't crash when device scale factor 981 // Verify that the renderer process doesn't crash when device scale factor
959 // changes after a cross-process navigation has commited. 982 // changes after a cross-process navigation has commited.
960 // See https://crbug.com/571603. 983 // See https://crbug.com/571603.
961 TEST_F(RenderViewImplTest, SetZoomLevelAfterCrossProcessNavigation) { 984 TEST_F(RenderViewImplTest, SetZoomLevelAfterCrossProcessNavigation) {
962 // This test should only run with out-of-process iframes enabled. 985 // This test should only run with out-of-process iframes enabled.
963 if (!SiteIsolationPolicy::AreCrossProcessFramesPossible()) 986 if (!SiteIsolationPolicy::AreCrossProcessFramesPossible())
964 return; 987 return;
965 988
(...skipping 1050 matching lines...) Expand 10 before | Expand all | Expand 10 after
2016 2039
2017 frame()->SetAccessibilityMode(AccessibilityModeOff); 2040 frame()->SetAccessibilityMode(AccessibilityModeOff);
2018 ASSERT_EQ(AccessibilityModeOff, frame()->accessibility_mode()); 2041 ASSERT_EQ(AccessibilityModeOff, frame()->accessibility_mode());
2019 ASSERT_FALSE(frame()->render_accessibility()); 2042 ASSERT_FALSE(frame()->render_accessibility());
2020 2043
2021 frame()->SetAccessibilityMode(AccessibilityModeComplete); 2044 frame()->SetAccessibilityMode(AccessibilityModeComplete);
2022 ASSERT_EQ(AccessibilityModeComplete, frame()->accessibility_mode()); 2045 ASSERT_EQ(AccessibilityModeComplete, frame()->accessibility_mode());
2023 ASSERT_TRUE(frame()->render_accessibility()); 2046 ASSERT_TRUE(frame()->render_accessibility());
2024 } 2047 }
2025 2048
2049 // Checks that when a navigation starts in the renderer, |navigation_start| is
2050 // recorded at an appropriate time and is passed in the corresponding message.
2051 TEST_F(RenderViewImplTest, RendererNavigationStartTransmittedToBrowser) {
2052 base::TimeTicks lower_bound_navigation_start(base::TimeTicks::Now());
2053 frame()->GetWebFrame()->loadHTMLString(
2054 "hello world", blink::WebURL(GURL("data:text/html,")));
2055
2056 FrameHostMsg_DidStartProvisionalLoad::Param host_nav_params =
2057 ProcessAndReadIPC<FrameHostMsg_DidStartProvisionalLoad>();
2058 base::TimeTicks transmitted_start = std::get<1>(host_nav_params);
2059 EXPECT_FALSE(transmitted_start.is_null());
2060 EXPECT_LT(lower_bound_navigation_start, transmitted_start);
2061 }
2062
2063 // Checks that a browser-initiated navigation in an initial document that was
2064 // not accessed uses browser-side timestamp.
2065 // This test assumes that |frame()| contains an unaccessed initial document at
2066 // start.
2067 TEST_F(RenderViewImplTest, BrowserNavigationStart) {
2068 auto common_params = MakeCommonNavigationParams(-TimeDelta::FromSeconds(1));
2069
2070 frame()->Navigate(common_params, StartNavigationParams(),
2071 RequestNavigationParams());
2072 FrameHostMsg_DidStartProvisionalLoad::Param nav_params =
2073 ProcessAndReadIPC<FrameHostMsg_DidStartProvisionalLoad>();
2074 EXPECT_EQ(common_params.navigation_start, std::get<1>(nav_params));
2075 }
2076
2026 // Sanity check for the Navigation Timing API |navigationStart| override. We 2077 // Sanity check for the Navigation Timing API |navigationStart| override. We
2027 // are asserting only most basic constraints, as TimeTicks (passed as the 2078 // are asserting only most basic constraints, as TimeTicks (passed as the
2028 // override) are not comparable with the wall time (returned by the Blink API). 2079 // override) are not comparable with the wall time (returned by the Blink API).
2029 TEST_F(RenderViewImplTest, NavigationStartOverride) { 2080 TEST_F(RenderViewImplTest, BrowserNavigationStartSanitized) {
2030 // Verify that a navigation that claims to have started in the future - 42 2081 // Verify that a navigation that claims to have started in the future - 42
2031 // days from now is *not* reported as one that starts in the future; as we 2082 // days from now is *not* reported as one that starts in the future; as we
2032 // sanitize the override allowing a maximum of ::Now(). 2083 // sanitize the override allowing a maximum of ::Now().
2033 CommonNavigationParams late_common_params; 2084 auto late_common_params = MakeCommonNavigationParams(TimeDelta::FromDays(42));
2034 late_common_params.url = GURL("data:text/html,<div>Another page</div>");
2035 late_common_params.navigation_type = FrameMsg_Navigate_Type::NORMAL;
2036 late_common_params.transition = ui::PAGE_TRANSITION_TYPED;
2037 late_common_params.navigation_start =
2038 base::TimeTicks::Now() + base::TimeDelta::FromDays(42);
2039 late_common_params.method = "POST"; 2085 late_common_params.method = "POST";
2040 2086
2041 frame()->Navigate(late_common_params, StartNavigationParams(), 2087 frame()->Navigate(late_common_params, StartNavigationParams(),
2042 RequestNavigationParams()); 2088 RequestNavigationParams());
2043 ProcessPendingMessages(); 2089 ProcessPendingMessages();
2044 base::Time after_navigation = 2090 base::Time after_navigation =
2045 base::Time::Now() + base::TimeDelta::FromDays(1); 2091 base::Time::Now() + base::TimeDelta::FromDays(1);
2046 2092
2047 base::Time late_nav_reported_start = 2093 base::Time late_nav_reported_start =
2048 base::Time::FromDoubleT(GetMainFrame()->performance().navigationStart()); 2094 base::Time::FromDoubleT(GetMainFrame()->performance().navigationStart());
2049 EXPECT_LE(late_nav_reported_start, after_navigation); 2095 EXPECT_LE(late_nav_reported_start, after_navigation);
2050 } 2096 }
2051 2097
2052 TEST_F(RenderViewImplTest, RendererNavigationStartTransmittedToBrowser) { 2098 // Checks that a browser-initiated navigation in an initial document that has
2053 base::TimeTicks lower_bound_navigation_start; 2099 // been accessed does not use browser-side timestamp (there may be arbitrary
2054 frame()->GetWebFrame()->loadHTMLString( 2100 // content and/or scripts injected, including beforeunload handler that shows
2055 "hello world", blink::WebURL(GURL("data:text/html,"))); 2101 // a confirmation dialog).
2102 TEST_F(RenderViewImplTest, NavigationStartWhenInitialDocumentWasAccessed) {
2103 blink_platform_impl_.SetWebURLLoaderFactory(base::Bind(&CreateMockURLLoader));
2104 // Open a page that will be navigated later.
2105 ExecuteJavaScriptForTests(
2106 "var w = window.open('https://google.com/');"
2107 "w.document.body.appendChild(w.document.createElement('div'));");
2108 // The new page starts a provisional load (it will not commit).
2056 ProcessPendingMessages(); 2109 ProcessPendingMessages();
2057 const IPC::Message* frame_navigate_msg = 2110 render_thread_->sink().ClearMessages();
2058 render_thread_->sink().GetUniqueMessageMatching( 2111
2059 FrameHostMsg_DidStartProvisionalLoad::ID); 2112 auto* new_main_frame =
2060 FrameHostMsg_DidStartProvisionalLoad::Param host_nav_params; 2113 static_cast<TestRenderFrame*>(RenderFrame::FromRoutingID(
2061 FrameHostMsg_DidStartProvisionalLoad::Read(frame_navigate_msg, 2114 render_thread_->new_window_main_frame_routing_id()));
2062 &host_nav_params); 2115 ASSERT_TRUE(new_main_frame);
2063 base::TimeTicks transmitted_start = std::get<1>(host_nav_params); 2116
2064 EXPECT_FALSE(transmitted_start.is_null()); 2117 auto common_params = MakeCommonNavigationParams(-TimeDelta::FromSeconds(1));
2065 EXPECT_LT(lower_bound_navigation_start, transmitted_start); 2118 new_main_frame->Navigate(common_params, StartNavigationParams(),
2119 RequestNavigationParams());
2120
2121 FrameHostMsg_DidStartProvisionalLoad::Param nav_params =
2122 ProcessAndReadIPC<FrameHostMsg_DidStartProvisionalLoad>();
2123 EXPECT_GT(std::get<1>(nav_params), common_params.navigation_start);
2124
2125 CloseRenderView(
2126 RenderViewImpl::FromRoutingID(render_thread_->new_window_routing_id()));
2066 } 2127 }
2067 2128
2068 TEST_F(RenderViewImplTest, BrowserNavigationStartNotUsedForReload) { 2129 TEST_F(RenderViewImplTest, NavigationStartForReload) {
2069 const char url_string[] = "data:text/html,<div>Page</div>"; 2130 const char url_string[] = "data:text/html,<div>Page</div>";
2070 // Navigate once, then reload. 2131 // Navigate once, then reload.
2071 LoadHTML(url_string); 2132 LoadHTML(url_string);
2072 ProcessPendingMessages(); 2133 ProcessPendingMessages();
2073 render_thread_->sink().ClearMessages(); 2134 render_thread_->sink().ClearMessages();
2074 2135
2075 CommonNavigationParams common_params; 2136 CommonNavigationParams common_params;
2076 common_params.url = GURL(url_string); 2137 common_params.url = GURL(url_string);
2077 common_params.navigation_type = 2138 common_params.navigation_type =
2078 FrameMsg_Navigate_Type::RELOAD_ORIGINAL_REQUEST_URL; 2139 FrameMsg_Navigate_Type::RELOAD_ORIGINAL_REQUEST_URL;
2079 common_params.transition = ui::PAGE_TRANSITION_RELOAD; 2140 common_params.transition = ui::PAGE_TRANSITION_RELOAD;
2080 2141
2142 // The browser navigation_start should not be used because beforeunload will
2143 // be fired during Navigate.
2081 frame()->Navigate(common_params, StartNavigationParams(), 2144 frame()->Navigate(common_params, StartNavigationParams(),
2082 RequestNavigationParams()); 2145 RequestNavigationParams());
2083 2146
2084 FrameHostMsg_DidStartProvisionalLoad::Param host_nav_params = 2147 FrameHostMsg_DidStartProvisionalLoad::Param host_nav_params =
2085 ProcessAndReadIPC<FrameHostMsg_DidStartProvisionalLoad>(); 2148 ProcessAndReadIPC<FrameHostMsg_DidStartProvisionalLoad>();
2086 // The true timestamp is later than the browser initiated one. 2149
2087 EXPECT_PRED2(TimeTicksGT, std::get<1>(host_nav_params), 2150 if (!IsBrowserSideNavigationEnabled()) {
2088 common_params.navigation_start); 2151 // The browser navigation_start should not be used because beforeunload was
2152 // fired during Navigate.
2153 EXPECT_PRED2(TimeTicksGT, std::get<1>(host_nav_params),
2154 common_params.navigation_start);
2155 } else {
2156 // PlzNavigate: the browser navigation_start is always used.
2157 EXPECT_EQ(common_params.navigation_start, std::get<1>(host_nav_params));
2158 }
2089 } 2159 }
2090 2160
2091 TEST_F(RenderViewImplTest, BrowserNavigationStartNotUsedForHistoryNavigation) { 2161 TEST_F(RenderViewImplTest, NavigationStartForSameProcessHistoryNavigation) {
2092 LoadHTML("<div id=pagename>Page A</div>"); 2162 LoadHTML("<div id=pagename>Page A</div>");
2093 LoadHTML("<div id=pagename>Page B</div>"); 2163 LoadHTML("<div id=pagename>Page B</div>");
2094 PageState back_state = GetCurrentPageState(); 2164 PageState back_state = GetCurrentPageState();
2095 LoadHTML("<div id=pagename>Page C</div>"); 2165 LoadHTML("<div id=pagename>Page C</div>");
2096 PageState forward_state = GetCurrentPageState(); 2166 PageState forward_state = GetCurrentPageState();
2097 ProcessPendingMessages(); 2167 ProcessPendingMessages();
2098 render_thread_->sink().ClearMessages(); 2168 render_thread_->sink().ClearMessages();
2099 2169
2100 // Go back. 2170 // Go back.
2101 CommonNavigationParams common_params_back; 2171 CommonNavigationParams common_params_back;
2102 common_params_back.url = 2172 common_params_back.url =
2103 GURL("data:text/html;charset=utf-8,<div id=pagename>Page B</div>"); 2173 GURL("data:text/html;charset=utf-8,<div id=pagename>Page B</div>");
2104 common_params_back.transition = ui::PAGE_TRANSITION_FORWARD_BACK; 2174 common_params_back.transition = ui::PAGE_TRANSITION_FORWARD_BACK;
2105 GoToOffsetWithParams(-1, back_state, common_params_back, 2175 GoToOffsetWithParams(-1, back_state, common_params_back,
2106 StartNavigationParams(), RequestNavigationParams()); 2176 StartNavigationParams(), RequestNavigationParams());
2107 FrameHostMsg_DidStartProvisionalLoad::Param host_nav_params = 2177 FrameHostMsg_DidStartProvisionalLoad::Param host_nav_params =
2108 ProcessAndReadIPC<FrameHostMsg_DidStartProvisionalLoad>(); 2178 ProcessAndReadIPC<FrameHostMsg_DidStartProvisionalLoad>();
2109 EXPECT_PRED2(TimeTicksGT, std::get<1>(host_nav_params), 2179 if (!IsBrowserSideNavigationEnabled()) {
2110 common_params_back.navigation_start); 2180 // The browser navigation_start should not be used because beforeunload was
2181 // fired during GoToOffsetWithParams.
2182 EXPECT_PRED2(TimeTicksGT, std::get<1>(host_nav_params),
2183 common_params_back.navigation_start);
2184 } else {
2185 // PlzNavigate: the browser navigation_start is always used.
2186 EXPECT_EQ(common_params_back.navigation_start,
2187 std::get<1>(host_nav_params));
2188 }
2111 render_thread_->sink().ClearMessages(); 2189 render_thread_->sink().ClearMessages();
2112 2190
2113 // Go forward. 2191 // Go forward.
2114 CommonNavigationParams common_params_forward; 2192 CommonNavigationParams common_params_forward;
2115 common_params_forward.url = 2193 common_params_forward.url =
2116 GURL("data:text/html;charset=utf-8,<div id=pagename>Page C</div>"); 2194 GURL("data:text/html;charset=utf-8,<div id=pagename>Page C</div>");
2117 common_params_forward.transition = ui::PAGE_TRANSITION_FORWARD_BACK; 2195 common_params_forward.transition = ui::PAGE_TRANSITION_FORWARD_BACK;
2118 GoToOffsetWithParams(1, forward_state, common_params_forward, 2196 GoToOffsetWithParams(1, forward_state, common_params_forward,
2119 StartNavigationParams(), RequestNavigationParams()); 2197 StartNavigationParams(), RequestNavigationParams());
2120 FrameHostMsg_DidStartProvisionalLoad::Param host_nav_params2 = 2198 FrameHostMsg_DidStartProvisionalLoad::Param host_nav_params2 =
2121 ProcessAndReadIPC<FrameHostMsg_DidStartProvisionalLoad>(); 2199 ProcessAndReadIPC<FrameHostMsg_DidStartProvisionalLoad>();
2122 EXPECT_PRED2(TimeTicksGT, std::get<1>(host_nav_params2), 2200 if (!IsBrowserSideNavigationEnabled()) {
2123 common_params_forward.navigation_start); 2201 EXPECT_PRED2(TimeTicksGT, std::get<1>(host_nav_params2),
2202 common_params_forward.navigation_start);
2203 } else {
2204 EXPECT_EQ(common_params_forward.navigation_start,
2205 std::get<1>(host_nav_params2));
2206 }
2124 } 2207 }
2125 2208
2126 TEST_F(RenderViewImplTest, BrowserNavigationStartSuccessfullyTransmitted) { 2209 TEST_F(RenderViewImplTest, NavigationStartForCrossProcessHistoryNavigation) {
2127 CommonNavigationParams common_params; 2210 auto common_params = MakeCommonNavigationParams(-TimeDelta::FromSeconds(1));
2128 common_params.url = GURL("data:text/html,<div>Page</div>"); 2211 common_params.transition = ui::PAGE_TRANSITION_FORWARD_BACK;
2129 common_params.navigation_type = FrameMsg_Navigate_Type::NORMAL;
2130 common_params.transition = ui::PAGE_TRANSITION_TYPED;
2131 2212
2132 frame()->Navigate(common_params, StartNavigationParams(), 2213 RequestNavigationParams request_params;
2133 RequestNavigationParams()); 2214 request_params.page_state =
2215 PageState::CreateForTesting(common_params.url, false, nullptr, nullptr);
2216 request_params.page_id = 1;
2217 request_params.nav_entry_id = 42;
2218 request_params.pending_history_list_offset = 1;
2219 request_params.current_history_list_offset = 0;
2220 request_params.current_history_list_length = 1;
2221 frame()->Navigate(common_params, StartNavigationParams(), request_params);
2134 2222
2135 FrameHostMsg_DidStartProvisionalLoad::Param host_nav_params = 2223 FrameHostMsg_DidStartProvisionalLoad::Param host_nav_params =
2136 ProcessAndReadIPC<FrameHostMsg_DidStartProvisionalLoad>(); 2224 ProcessAndReadIPC<FrameHostMsg_DidStartProvisionalLoad>();
2137 EXPECT_EQ(std::get<1>(host_nav_params), common_params.navigation_start); 2225 EXPECT_EQ(std::get<1>(host_nav_params), common_params.navigation_start);
2138 } 2226 }
2139 2227
2140 TEST_F(RenderViewImplTest, PreferredSizeZoomed) { 2228 TEST_F(RenderViewImplTest, PreferredSizeZoomed) {
2141 LoadHTML("<body style='margin:0;'><div style='display:inline-block; " 2229 LoadHTML("<body style='margin:0;'><div style='display:inline-block; "
2142 "width:400px; height:400px;'/></body>"); 2230 "width:400px; height:400px;'/></body>");
2143 view()->webview()->mainFrame()->setCanHaveScrollbars(false); 2231 view()->webview()->mainFrame()->setCanHaveScrollbars(false);
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after
2480 ExpectPauseAndResume(3); 2568 ExpectPauseAndResume(3);
2481 blink::WebScriptSource source2( 2569 blink::WebScriptSource source2(
2482 WebString::fromUTF8("function func2() { func1(); }; func2();")); 2570 WebString::fromUTF8("function func2() { func1(); }; func2();"));
2483 frame()->GetWebFrame()->executeScriptInIsolatedWorld(17, &source2, 1, 1); 2571 frame()->GetWebFrame()->executeScriptInIsolatedWorld(17, &source2, 1, 1);
2484 2572
2485 EXPECT_FALSE(IsPaused()); 2573 EXPECT_FALSE(IsPaused());
2486 Detach(); 2574 Detach();
2487 } 2575 }
2488 2576
2489 } // namespace content 2577 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/render_frame_impl.cc ('k') | third_party/WebKit/Source/core/loader/FrameLoader.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698