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

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: Add comment, fix indent. Created 4 years, 5 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);
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 // Clean up so we don't leak it.
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);
clamy 2016/07/21 11:52:44 Why were those calls needed?
Alexander Semashko 2016/07/21 14:00:22 Not sure I understood your question correctly, but
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 1065 matching lines...) Expand 10 before | Expand all | Expand 10 after
2031 2054
2032 frame()->SetAccessibilityMode(AccessibilityModeOff); 2055 frame()->SetAccessibilityMode(AccessibilityModeOff);
2033 ASSERT_EQ(AccessibilityModeOff, frame()->accessibility_mode()); 2056 ASSERT_EQ(AccessibilityModeOff, frame()->accessibility_mode());
2034 ASSERT_FALSE(frame()->render_accessibility()); 2057 ASSERT_FALSE(frame()->render_accessibility());
2035 2058
2036 frame()->SetAccessibilityMode(AccessibilityModeComplete); 2059 frame()->SetAccessibilityMode(AccessibilityModeComplete);
2037 ASSERT_EQ(AccessibilityModeComplete, frame()->accessibility_mode()); 2060 ASSERT_EQ(AccessibilityModeComplete, frame()->accessibility_mode());
2038 ASSERT_TRUE(frame()->render_accessibility()); 2061 ASSERT_TRUE(frame()->render_accessibility());
2039 } 2062 }
2040 2063
2064 TEST_F(RenderViewImplTest, RendererNavigationStartTransmittedToBrowser) {
2065 base::TimeTicks lower_bound_navigation_start(base::TimeTicks::Now());
2066 frame()->GetWebFrame()->loadHTMLString(
2067 "hello world", blink::WebURL(GURL("data:text/html,")));
2068
2069 FrameHostMsg_DidStartProvisionalLoad::Param host_nav_params =
2070 ProcessAndReadIPC<FrameHostMsg_DidStartProvisionalLoad>();
2071 base::TimeTicks transmitted_start = std::get<1>(host_nav_params);
2072 EXPECT_FALSE(transmitted_start.is_null());
2073 EXPECT_LT(lower_bound_navigation_start, transmitted_start);
2074 }
2075
2076 TEST_F(RenderViewImplTest, BrowserNavigationStart) {
2077 auto common_params = MakeCommonNavigationParams(-TimeDelta::FromSeconds(1));
2078
2079 frame()->Navigate(common_params, StartNavigationParams(),
2080 RequestNavigationParams());
2081 FrameHostMsg_DidStartProvisionalLoad::Param nav_params =
2082 ProcessAndReadIPC<FrameHostMsg_DidStartProvisionalLoad>();
2083 EXPECT_EQ(common_params.navigation_start, std::get<1>(nav_params));
2084 }
2085
2041 // Sanity check for the Navigation Timing API |navigationStart| override. We 2086 // Sanity check for the Navigation Timing API |navigationStart| override. We
2042 // are asserting only most basic constraints, as TimeTicks (passed as the 2087 // are asserting only most basic constraints, as TimeTicks (passed as the
2043 // override) are not comparable with the wall time (returned by the Blink API). 2088 // override) are not comparable with the wall time (returned by the Blink API).
2044 TEST_F(RenderViewImplTest, NavigationStartOverride) { 2089 TEST_F(RenderViewImplTest, BrowserNavigationStartSanitized) {
2045 // Verify that a navigation that claims to have started in the future - 42 2090 // Verify that a navigation that claims to have started in the future - 42
2046 // days from now is *not* reported as one that starts in the future; as we 2091 // days from now is *not* reported as one that starts in the future; as we
2047 // sanitize the override allowing a maximum of ::Now(). 2092 // sanitize the override allowing a maximum of ::Now().
2048 CommonNavigationParams late_common_params; 2093 auto late_common_params = MakeCommonNavigationParams(TimeDelta::FromDays(42));
2049 late_common_params.url = GURL("data:text/html,<div>Another page</div>");
2050 late_common_params.navigation_type = FrameMsg_Navigate_Type::NORMAL;
2051 late_common_params.transition = ui::PAGE_TRANSITION_TYPED;
2052 late_common_params.navigation_start =
2053 base::TimeTicks::Now() + base::TimeDelta::FromDays(42);
2054 late_common_params.method = "POST"; 2094 late_common_params.method = "POST";
2055 2095
2056 frame()->Navigate(late_common_params, StartNavigationParams(), 2096 frame()->Navigate(late_common_params, StartNavigationParams(),
2057 RequestNavigationParams()); 2097 RequestNavigationParams());
2058 ProcessPendingMessages(); 2098 ProcessPendingMessages();
2059 base::Time after_navigation = 2099 base::Time after_navigation =
2060 base::Time::Now() + base::TimeDelta::FromDays(1); 2100 base::Time::Now() + base::TimeDelta::FromDays(1);
2061 2101
2062 base::Time late_nav_reported_start = 2102 base::Time late_nav_reported_start =
2063 base::Time::FromDoubleT(GetMainFrame()->performance().navigationStart()); 2103 base::Time::FromDoubleT(GetMainFrame()->performance().navigationStart());
2064 EXPECT_LE(late_nav_reported_start, after_navigation); 2104 EXPECT_LE(late_nav_reported_start, after_navigation);
2065 } 2105 }
2066 2106
2067 TEST_F(RenderViewImplTest, RendererNavigationStartTransmittedToBrowser) { 2107 // Checks that a browser-initiated navigation in an initial document that was
2068 base::TimeTicks lower_bound_navigation_start; 2108 // not accessed uses browser-side timestamp.
2069 frame()->GetWebFrame()->loadHTMLString( 2109 TEST_F(RenderViewImplTest,
2070 "hello world", blink::WebURL(GURL("data:text/html,"))); 2110 BrowserNavigationStartUsedIfInitialDocumentWasNotAccessed) {
2111 blink_platform_impl_.SetWebURLLoaderFactory(base::Bind(&CreateMockURLLoader));
2112 // Open a page that will be navigated later.
2113 ExecuteJavaScriptForTests("window.open('https://google.com/');");
2114 // The new page starts a provisional load (it will not commit).
2071 ProcessPendingMessages(); 2115 ProcessPendingMessages();
2072 const IPC::Message* frame_navigate_msg = 2116 render_thread_->sink().ClearMessages();
2073 render_thread_->sink().GetUniqueMessageMatching( 2117
2074 FrameHostMsg_DidStartProvisionalLoad::ID); 2118 auto* new_main_frame =
2075 FrameHostMsg_DidStartProvisionalLoad::Param host_nav_params; 2119 static_cast<TestRenderFrame*>(RenderFrame::FromRoutingID(
2076 FrameHostMsg_DidStartProvisionalLoad::Read(frame_navigate_msg, 2120 render_thread_->new_window_main_frame_routing_id()));
2077 &host_nav_params); 2121 ASSERT_TRUE(new_main_frame);
2078 base::TimeTicks transmitted_start = std::get<1>(host_nav_params); 2122
2079 EXPECT_FALSE(transmitted_start.is_null()); 2123 auto common_params = MakeCommonNavigationParams(-TimeDelta::FromSeconds(1));
2080 EXPECT_LT(lower_bound_navigation_start, transmitted_start); 2124 new_main_frame->Navigate(common_params, StartNavigationParams(),
2125 RequestNavigationParams());
2126
2127 FrameHostMsg_DidStartProvisionalLoad::Param nav_params =
2128 ProcessAndReadIPC<FrameHostMsg_DidStartProvisionalLoad>();
2129 EXPECT_EQ(common_params.navigation_start, std::get<1>(nav_params));
2130
2131 CloseRenderView(
2132 RenderViewImpl::FromRoutingID(render_thread_->new_window_routing_id()));
2133 }
2134
2135 // Checks that a browser-initiated navigation in an initial document that has
2136 // been accessed does not use browser-side timestamp (there may be arbitrary
2137 // content and/or scripts injected, including beforeunload handler that shows
2138 // a confirmation dialog).
2139 TEST_F(RenderViewImplTest,
2140 BrowserNavigationStartDiscardedIfInitialDocumentWasAccessed) {
2141 blink_platform_impl_.SetWebURLLoaderFactory(base::Bind(&CreateMockURLLoader));
2142 // Open a page that will be navigated later.
2143 ExecuteJavaScriptForTests(
2144 "var w = window.open('https://google.com/');"
2145 "w.document.body.appendChild(w.document.createElement('div'));");
2146 // The new page starts a provisional load (it will not commit).
2147 ProcessPendingMessages();
2148 render_thread_->sink().ClearMessages();
2149
2150 auto* new_main_frame =
2151 static_cast<TestRenderFrame*>(RenderFrame::FromRoutingID(
2152 render_thread_->new_window_main_frame_routing_id()));
2153 ASSERT_TRUE(new_main_frame);
2154
2155 auto common_params = MakeCommonNavigationParams(-TimeDelta::FromSeconds(1));
2156 new_main_frame->Navigate(common_params, StartNavigationParams(),
2157 RequestNavigationParams());
2158
2159 FrameHostMsg_DidStartProvisionalLoad::Param nav_params =
2160 ProcessAndReadIPC<FrameHostMsg_DidStartProvisionalLoad>();
2161 EXPECT_GT(std::get<1>(nav_params), common_params.navigation_start);
2162
2163 CloseRenderView(
2164 RenderViewImpl::FromRoutingID(render_thread_->new_window_routing_id()));
2165 }
2166
2167 TEST_F(RenderViewImplTest,
2168 FiringBeforeUnloadInSubFrameDiscardsBrowserNavigationStart) {
2169 // Add a beforeunload handler in the initial document.
2170 ExecuteJavaScriptForTests(
2171 "var frame = document.createElement('iframe');"
2172 "document.body.appendChild(frame);"
2173 "frame.contentWindow.onbeforeunload = function() { return null; };");
2174 // Need to drop the DidStartProvisionalLoad message from the child frame.
2175 ProcessPendingMessages();
2176 render_thread_->sink().ClearMessages();
2177
2178 auto common_params = MakeCommonNavigationParams(-TimeDelta::FromSeconds(1));
2179 frame()->Navigate(common_params, StartNavigationParams(),
2180 RequestNavigationParams());
2181
2182 FrameHostMsg_DidStartProvisionalLoad::Param host_nav_params =
2183 ProcessAndReadIPC<FrameHostMsg_DidStartProvisionalLoad>();
2184 EXPECT_GT(std::get<1>(host_nav_params), common_params.navigation_start);
2081 } 2185 }
2082 2186
2083 TEST_F(RenderViewImplTest, BrowserNavigationStartNotUsedForReload) { 2187 TEST_F(RenderViewImplTest, BrowserNavigationStartNotUsedForReload) {
2084 const char url_string[] = "data:text/html,<div>Page</div>"; 2188 const char url_string[] = "data:text/html,<div>Page</div>";
2085 // Navigate once, then reload. 2189 // Navigate once, then reload.
2086 LoadHTML(url_string); 2190 LoadHTML(url_string);
2087 ProcessPendingMessages(); 2191 ProcessPendingMessages();
2088 render_thread_->sink().ClearMessages(); 2192 render_thread_->sink().ClearMessages();
2089 2193
2090 CommonNavigationParams common_params; 2194 CommonNavigationParams common_params;
2091 common_params.url = GURL(url_string); 2195 common_params.url = GURL(url_string);
2092 common_params.navigation_type = 2196 common_params.navigation_type =
2093 FrameMsg_Navigate_Type::RELOAD_ORIGINAL_REQUEST_URL; 2197 FrameMsg_Navigate_Type::RELOAD_ORIGINAL_REQUEST_URL;
2094 common_params.transition = ui::PAGE_TRANSITION_RELOAD; 2198 common_params.transition = ui::PAGE_TRANSITION_RELOAD;
2095 2199
2200 // The browser navigation_start should not be used because beforeunload will
2201 // be fired during Navigate.
2096 frame()->Navigate(common_params, StartNavigationParams(), 2202 frame()->Navigate(common_params, StartNavigationParams(),
2097 RequestNavigationParams()); 2203 RequestNavigationParams());
2098 2204
2099 FrameHostMsg_DidStartProvisionalLoad::Param host_nav_params = 2205 FrameHostMsg_DidStartProvisionalLoad::Param host_nav_params =
2100 ProcessAndReadIPC<FrameHostMsg_DidStartProvisionalLoad>(); 2206 ProcessAndReadIPC<FrameHostMsg_DidStartProvisionalLoad>();
2101 // The true timestamp is later than the browser initiated one.
2102 EXPECT_PRED2(TimeTicksGT, std::get<1>(host_nav_params), 2207 EXPECT_PRED2(TimeTicksGT, std::get<1>(host_nav_params),
2103 common_params.navigation_start); 2208 common_params.navigation_start);
2104 } 2209 }
2105 2210
2106 TEST_F(RenderViewImplTest, BrowserNavigationStartNotUsedForHistoryNavigation) { 2211 TEST_F(RenderViewImplTest,
2212 BrowserNavigationStartNotUsedForSameProcessHistoryNavigation) {
2107 LoadHTML("<div id=pagename>Page A</div>"); 2213 LoadHTML("<div id=pagename>Page A</div>");
2108 LoadHTML("<div id=pagename>Page B</div>"); 2214 LoadHTML("<div id=pagename>Page B</div>");
2109 PageState back_state = GetCurrentPageState(); 2215 PageState back_state = GetCurrentPageState();
2110 LoadHTML("<div id=pagename>Page C</div>"); 2216 LoadHTML("<div id=pagename>Page C</div>");
2111 PageState forward_state = GetCurrentPageState(); 2217 PageState forward_state = GetCurrentPageState();
2112 ProcessPendingMessages(); 2218 ProcessPendingMessages();
2113 render_thread_->sink().ClearMessages(); 2219 render_thread_->sink().ClearMessages();
2114 2220
2115 // Go back. 2221 // Go back.
2222 // The browser navigation_start should not be used because beforeunload will
2223 // be fired during GoToOffsetWithParams.
2116 CommonNavigationParams common_params_back; 2224 CommonNavigationParams common_params_back;
2117 common_params_back.url = 2225 common_params_back.url =
2118 GURL("data:text/html;charset=utf-8,<div id=pagename>Page B</div>"); 2226 GURL("data:text/html;charset=utf-8,<div id=pagename>Page B</div>");
2119 common_params_back.transition = ui::PAGE_TRANSITION_FORWARD_BACK; 2227 common_params_back.transition = ui::PAGE_TRANSITION_FORWARD_BACK;
2120 GoToOffsetWithParams(-1, back_state, common_params_back, 2228 GoToOffsetWithParams(-1, back_state, common_params_back,
2121 StartNavigationParams(), RequestNavigationParams()); 2229 StartNavigationParams(), RequestNavigationParams());
2122 FrameHostMsg_DidStartProvisionalLoad::Param host_nav_params = 2230 FrameHostMsg_DidStartProvisionalLoad::Param host_nav_params =
2123 ProcessAndReadIPC<FrameHostMsg_DidStartProvisionalLoad>(); 2231 ProcessAndReadIPC<FrameHostMsg_DidStartProvisionalLoad>();
2124 EXPECT_PRED2(TimeTicksGT, std::get<1>(host_nav_params), 2232 EXPECT_PRED2(TimeTicksGT, std::get<1>(host_nav_params),
2125 common_params_back.navigation_start); 2233 common_params_back.navigation_start);
2126 render_thread_->sink().ClearMessages(); 2234 render_thread_->sink().ClearMessages();
2127 2235
2128 // Go forward. 2236 // Go forward.
2237 // The browser navigation_start should not be used because beforeunload will
2238 // be fired during GoToOffsetWithParams.
2129 CommonNavigationParams common_params_forward; 2239 CommonNavigationParams common_params_forward;
2130 common_params_forward.url = 2240 common_params_forward.url =
2131 GURL("data:text/html;charset=utf-8,<div id=pagename>Page C</div>"); 2241 GURL("data:text/html;charset=utf-8,<div id=pagename>Page C</div>");
2132 common_params_forward.transition = ui::PAGE_TRANSITION_FORWARD_BACK; 2242 common_params_forward.transition = ui::PAGE_TRANSITION_FORWARD_BACK;
2133 GoToOffsetWithParams(1, forward_state, common_params_forward, 2243 GoToOffsetWithParams(1, forward_state, common_params_forward,
2134 StartNavigationParams(), RequestNavigationParams()); 2244 StartNavigationParams(), RequestNavigationParams());
2135 FrameHostMsg_DidStartProvisionalLoad::Param host_nav_params2 = 2245 FrameHostMsg_DidStartProvisionalLoad::Param host_nav_params2 =
2136 ProcessAndReadIPC<FrameHostMsg_DidStartProvisionalLoad>(); 2246 ProcessAndReadIPC<FrameHostMsg_DidStartProvisionalLoad>();
2137 EXPECT_PRED2(TimeTicksGT, std::get<1>(host_nav_params2), 2247 EXPECT_PRED2(TimeTicksGT, std::get<1>(host_nav_params2),
2138 common_params_forward.navigation_start); 2248 common_params_forward.navigation_start);
2139 } 2249 }
2140 2250
2141 TEST_F(RenderViewImplTest, BrowserNavigationStartSuccessfullyTransmitted) { 2251 TEST_F(RenderViewImplTest,
2142 CommonNavigationParams common_params; 2252 BrowserNavigationStartUsedForCrossProcessHistoryNavigation) {
2143 common_params.url = GURL("data:text/html,<div>Page</div>"); 2253 auto common_params = MakeCommonNavigationParams(-TimeDelta::FromSeconds(1));
2144 common_params.navigation_type = FrameMsg_Navigate_Type::NORMAL; 2254 common_params.transition = ui::PAGE_TRANSITION_FORWARD_BACK;
2145 common_params.transition = ui::PAGE_TRANSITION_TYPED;
2146 2255
2147 frame()->Navigate(common_params, StartNavigationParams(), 2256 RequestNavigationParams request_params;
2148 RequestNavigationParams()); 2257 request_params.page_state =
2258 PageState::CreateForTesting(common_params.url, false, nullptr, nullptr);
2259 request_params.page_id = 1;
2260 request_params.nav_entry_id = 42;
2261 request_params.pending_history_list_offset = 1;
2262 request_params.current_history_list_offset = 0;
2263 request_params.current_history_list_length = 1;
2264 frame()->Navigate(common_params, StartNavigationParams(), request_params);
2149 2265
2150 FrameHostMsg_DidStartProvisionalLoad::Param host_nav_params = 2266 FrameHostMsg_DidStartProvisionalLoad::Param host_nav_params =
2151 ProcessAndReadIPC<FrameHostMsg_DidStartProvisionalLoad>(); 2267 ProcessAndReadIPC<FrameHostMsg_DidStartProvisionalLoad>();
2152 EXPECT_EQ(std::get<1>(host_nav_params), common_params.navigation_start); 2268 EXPECT_EQ(std::get<1>(host_nav_params), common_params.navigation_start);
2153 } 2269 }
2154 2270
2155 TEST_F(RenderViewImplTest, PreferredSizeZoomed) { 2271 TEST_F(RenderViewImplTest, PreferredSizeZoomed) {
2156 LoadHTML("<body style='margin:0;'><div style='display:inline-block; " 2272 LoadHTML("<body style='margin:0;'><div style='display:inline-block; "
2157 "width:400px; height:400px;'/></body>"); 2273 "width:400px; height:400px;'/></body>");
2158 view()->webview()->mainFrame()->setCanHaveScrollbars(false); 2274 view()->webview()->mainFrame()->setCanHaveScrollbars(false);
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after
2495 ExpectPauseAndResume(3); 2611 ExpectPauseAndResume(3);
2496 blink::WebScriptSource source2( 2612 blink::WebScriptSource source2(
2497 WebString::fromUTF8("function func2() { func1(); }; func2();")); 2613 WebString::fromUTF8("function func2() { func1(); }; func2();"));
2498 frame()->GetWebFrame()->executeScriptInIsolatedWorld(17, &source2, 1, 1); 2614 frame()->GetWebFrame()->executeScriptInIsolatedWorld(17, &source2, 1, 1);
2499 2615
2500 EXPECT_FALSE(IsPaused()); 2616 EXPECT_FALSE(IsPaused());
2501 Detach(); 2617 Detach();
2502 } 2618 }
2503 2619
2504 } // namespace content 2620 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698