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

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

Issue 1427633004: Send navigation_start to the browser in DidStartProvisionalLoad IPC (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@navigation_start_renderer
Patch Set: Comments Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/basictypes.h" 5 #include "base/basictypes.h"
6 #include "base/bind.h" 6 #include "base/bind.h"
7 #include "base/callback.h" 7 #include "base/callback.h"
8 #include "base/location.h" 8 #include "base/location.h"
9 #include "base/single_thread_task_runner.h" 9 #include "base/single_thread_task_runner.h"
10 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 } 161 }
162 162
163 int view_page_id() { 163 int view_page_id() {
164 return view()->page_id_; 164 return view()->page_id_;
165 } 165 }
166 166
167 TestRenderFrame* frame() { 167 TestRenderFrame* frame() {
168 return static_cast<TestRenderFrame*>(view()->GetMainRenderFrame()); 168 return static_cast<TestRenderFrame*>(view()->GetMainRenderFrame());
169 } 169 }
170 170
171 void GoToOffsetWithParams(int offset,
172 const PageState& state,
173 const CommonNavigationParams common_params,
174 const StartNavigationParams start_params,
175 RequestNavigationParams request_params) {
176 EXPECT_TRUE(common_params.transition & ui::PAGE_TRANSITION_FORWARD_BACK);
177 int history_list_length = view()->historyBackListCount() +
178 view()->historyForwardListCount() + 1;
179 int pending_offset = offset + view()->history_list_offset_;
nasko 2015/11/13 21:52:54 Hmmm, not sure if asking the view() is the right t
Charlie Harrison 2015/11/14 00:25:00 For context, most of this logic is copied from ren
180
181 request_params.page_state = state;
182 request_params.page_id = view()->page_id_ + offset;
183 request_params.nav_entry_id = pending_offset + 1;
184 request_params.pending_history_list_offset = pending_offset;
185 request_params.current_history_list_offset = view()->history_list_offset_;
186 request_params.current_history_list_length = history_list_length;
187 frame()->Navigate(common_params, start_params, request_params);
188
189 // The load actually happens asynchronously, so we pump messages to process
190 // the pending continuation.
191 FrameLoadWaiter(frame()).Wait();
192 }
193
171 // Sends IPC messages that emulates a key-press event. 194 // Sends IPC messages that emulates a key-press event.
172 int SendKeyEvent(MockKeyboard::Layout layout, 195 int SendKeyEvent(MockKeyboard::Layout layout,
173 int key_code, 196 int key_code,
174 MockKeyboard::Modifiers modifiers, 197 MockKeyboard::Modifiers modifiers,
175 base::string16* output) { 198 base::string16* output) {
176 #if defined(OS_WIN) 199 #if defined(OS_WIN)
177 // Retrieve the Unicode character for the given tuple (keyboard-layout, 200 // Retrieve the Unicode character for the given tuple (keyboard-layout,
178 // key-code, and modifiers). 201 // key-code, and modifiers).
179 // Exit when a keyboard-layout driver cannot assign a Unicode character to 202 // Exit when a keyboard-layout driver cannot assign a Unicode character to
180 // the tuple to prevent sending an invalid key code to the RenderView 203 // the tuple to prevent sending an invalid key code to the RenderView
(...skipping 2116 matching lines...) Expand 10 before | Expand all | Expand 10 after
2297 RequestNavigationParams()); 2320 RequestNavigationParams());
2298 ProcessPendingMessages(); 2321 ProcessPendingMessages();
2299 base::Time after_navigation = 2322 base::Time after_navigation =
2300 base::Time::Now() + base::TimeDelta::FromDays(1); 2323 base::Time::Now() + base::TimeDelta::FromDays(1);
2301 2324
2302 base::Time late_nav_reported_start = 2325 base::Time late_nav_reported_start =
2303 base::Time::FromDoubleT(GetMainFrame()->performance().navigationStart()); 2326 base::Time::FromDoubleT(GetMainFrame()->performance().navigationStart());
2304 EXPECT_LE(late_nav_reported_start, after_navigation); 2327 EXPECT_LE(late_nav_reported_start, after_navigation);
2305 } 2328 }
2306 2329
2330 TEST_F(RenderViewImplTest, RendererNavigationStartTransmittedToBrowser) {
2331 base::TimeTicks lower_bound_navigation_start;
2332 frame()->GetWebFrame()->loadHTMLString(
2333 "hello world", blink::WebURL(GURL("data:text/html,")));
2334 ProcessPendingMessages();
2335 const IPC::Message* frame_navigate_msg =
2336 render_thread_->sink().GetUniqueMessageMatching(
2337 FrameHostMsg_DidStartProvisionalLoadForFrame::ID);
2338 FrameHostMsg_DidStartProvisionalLoadForFrame::Param host_nav_params;
2339 FrameHostMsg_DidStartProvisionalLoadForFrame::Read(frame_navigate_msg,
2340 &host_nav_params);
2341 base::TimeTicks transmitted_start = base::get<1>(host_nav_params);
2342 EXPECT_FALSE(transmitted_start.is_null());
2343 EXPECT_LT(lower_bound_navigation_start, transmitted_start);
2344 }
2345
2346 TEST_F(RenderViewImplTest, BrowserNavigationStartNotUsedForReload) {
2347 const char url_string[] = "data:text/html,<div>Page</div>";
2348 // Navigate once, then reload.
2349 LoadHTML(url_string);
2350 ProcessPendingMessages();
2351 render_thread_->sink().ClearMessages();
2352
2353 CommonNavigationParams common_params;
2354 common_params.url = GURL(url_string);
2355 common_params.navigation_type =
2356 FrameMsg_Navigate_Type::RELOAD_ORIGINAL_REQUEST_URL;
2357 common_params.transition = ui::PAGE_TRANSITION_LINK;
nasko 2015/11/13 21:52:54 Why not PAGE_TRANSITION_RELOAD?
Charlie Harrison 2015/11/14 00:25:00 No good reason. Fixed.
2358
2359 frame()->Navigate(common_params, StartNavigationParams(),
2360 RequestNavigationParams());
2361 ProcessPendingMessages();
2362
2363 const IPC::Message* frame_navigate_msg =
2364 render_thread_->sink().GetUniqueMessageMatching(
2365 FrameHostMsg_DidStartProvisionalLoadForFrame::ID);
2366 FrameHostMsg_DidStartProvisionalLoadForFrame::Param host_nav_params;
2367 FrameHostMsg_DidStartProvisionalLoadForFrame::Read(frame_navigate_msg,
2368 &host_nav_params);
2369 // The true timestamp is later than the browser initiated one.
2370 EXPECT_GT(base::get<1>(host_nav_params), common_params.navigation_start);
nasko 2015/11/13 21:52:54 Do we have enough granularity to ensure we are not
Charlie Harrison 2015/11/14 00:25:00 Good idea. It should be monotonic either way, so I
2371 }
2372
2373 TEST_F(RenderViewImplTest, BrowserNavigationStartNotUsedForHistoryNavigation) {
2374 LoadHTML("<div id=pagename>Page A</div>");
2375 LoadHTML("<div id=pagename>Page B</div>");
2376 PageState back_state =
2377 HistoryEntryToPageState(view()->history_controller()->GetCurrentEntry());
2378 LoadHTML("<div id=pagename>Page C</div>");
2379 PageState forward_state =
2380 HistoryEntryToPageState(view()->history_controller()->GetCurrentEntry());
2381 ProcessPendingMessages();
2382 render_thread_->sink().ClearMessages();
2383
2384 CommonNavigationParams common_params;
2385 common_params.transition = ui::PAGE_TRANSITION_FORWARD_BACK;
2386 // Go back.
2387 GoToOffsetWithParams(-1, back_state, common_params, StartNavigationParams(),
2388 RequestNavigationParams());
2389 ProcessPendingMessages();
2390 const IPC::Message* frame_navigate_msg =
2391 render_thread_->sink().GetUniqueMessageMatching(
2392 FrameHostMsg_DidStartProvisionalLoadForFrame::ID);
2393 FrameHostMsg_DidStartProvisionalLoadForFrame::Param host_nav_params;
2394 FrameHostMsg_DidStartProvisionalLoadForFrame::Read(frame_navigate_msg,
2395 &host_nav_params);
nasko 2015/11/13 21:52:54 This code for reading the IPC is done enough times
Charlie Harrison 2015/11/14 00:25:00 Sounds good to me. This might not end up being a w
nasko 2015/11/14 00:33:24 This looks good.
2396 EXPECT_GT(base::get<1>(host_nav_params), common_params.navigation_start);
2397 render_thread_->sink().ClearMessages();
2398
2399 // Go forward.
2400 GoToOffsetWithParams(1, forward_state, common_params,
2401 StartNavigationParams(),
2402 RequestNavigationParams());
2403 ProcessPendingMessages();
2404 const IPC::Message* frame_navigate_msg2 =
2405 render_thread_->sink().GetUniqueMessageMatching(
2406 FrameHostMsg_DidStartProvisionalLoadForFrame::ID);
2407 FrameHostMsg_DidStartProvisionalLoadForFrame::Param host_nav_params2;
2408 FrameHostMsg_DidStartProvisionalLoadForFrame::Read(frame_navigate_msg2,
2409 &host_nav_params2);
2410 EXPECT_GT(base::get<1>(host_nav_params2), common_params.navigation_start);
2411 }
2412
2413 TEST_F(RenderViewImplTest, BrowserNavigationStartSuccessfullyTransmitted) {
2414 CommonNavigationParams common_params;
2415 common_params.url = GURL("data:text/html,<div>Page</div>");
2416 common_params.navigation_type = FrameMsg_Navigate_Type::NORMAL;
2417 common_params.transition = ui::PAGE_TRANSITION_TYPED;
2418
2419 frame()->Navigate(common_params, StartNavigationParams(),
2420 RequestNavigationParams());
2421 ProcessPendingMessages();
2422
2423 const IPC::Message* frame_navigate_msg =
2424 render_thread_->sink().GetUniqueMessageMatching(
2425 FrameHostMsg_DidStartProvisionalLoadForFrame::ID);
2426 FrameHostMsg_DidStartProvisionalLoadForFrame::Param host_nav_params;
2427 FrameHostMsg_DidStartProvisionalLoadForFrame::Read(frame_navigate_msg,
2428 &host_nav_params);
2429 EXPECT_EQ(base::get<1>(host_nav_params), common_params.navigation_start);
2430 }
2431
2307 TEST_F(RenderViewImplTest, PreferredSizeZoomed) { 2432 TEST_F(RenderViewImplTest, PreferredSizeZoomed) {
2308 LoadHTML("<body style='margin:0;'><div style='display:inline-block; " 2433 LoadHTML("<body style='margin:0;'><div style='display:inline-block; "
2309 "width:400px; height:400px;'/></body>"); 2434 "width:400px; height:400px;'/></body>");
2310 view()->webview()->mainFrame()->setCanHaveScrollbars(false); 2435 view()->webview()->mainFrame()->setCanHaveScrollbars(false);
2311 EnablePreferredSizeMode(); 2436 EnablePreferredSizeMode();
2312 2437
2313 gfx::Size size = GetPreferredSize(); 2438 gfx::Size size = GetPreferredSize();
2314 EXPECT_EQ(gfx::Size(400, 400), size); 2439 EXPECT_EQ(gfx::Size(400, 400), size);
2315 2440
2316 SetZoomLevel(ZoomFactorToZoomLevel(2.0)); 2441 SetZoomLevel(ZoomFactorToZoomLevel(2.0));
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
2374 FROM_HERE, 2499 FROM_HERE,
2375 base::Bind(&DevToolsAgentTest::CloseWhilePaused, base::Unretained(this))); 2500 base::Bind(&DevToolsAgentTest::CloseWhilePaused, base::Unretained(this)));
2376 ExecuteJavaScriptForTests("debugger;"); 2501 ExecuteJavaScriptForTests("debugger;");
2377 2502
2378 // CloseWhilePaused should resume execution and continue here. 2503 // CloseWhilePaused should resume execution and continue here.
2379 EXPECT_FALSE(IsPaused()); 2504 EXPECT_FALSE(IsPaused());
2380 Detach(); 2505 Detach();
2381 } 2506 }
2382 2507
2383 } // namespace content 2508 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698