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

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: Don't expose too much in public test infra 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_;
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 2121 matching lines...) Expand 10 before | Expand all | Expand 10 after
2302 RequestNavigationParams()); 2325 RequestNavigationParams());
2303 ProcessPendingMessages(); 2326 ProcessPendingMessages();
2304 base::Time after_navigation = 2327 base::Time after_navigation =
2305 base::Time::Now() + base::TimeDelta::FromDays(1); 2328 base::Time::Now() + base::TimeDelta::FromDays(1);
2306 2329
2307 base::Time late_nav_reported_start = 2330 base::Time late_nav_reported_start =
2308 base::Time::FromDoubleT(GetMainFrame()->performance().navigationStart()); 2331 base::Time::FromDoubleT(GetMainFrame()->performance().navigationStart());
2309 EXPECT_LE(late_nav_reported_start, after_navigation); 2332 EXPECT_LE(late_nav_reported_start, after_navigation);
2310 } 2333 }
2311 2334
2335 TEST_F(RenderViewImplTest, RendererNavigationStartTransmittedToBrowser) {
2336 base::TimeTicks lower_bound_navigation_start;
2337 frame()->GetWebFrame()->loadHTMLString(
2338 "hello world", blink::WebURL(GURL("data:text/html,")));
2339 ProcessPendingMessages();
2340 const IPC::Message* frame_navigate_msg =
2341 render_thread_->sink().GetUniqueMessageMatching(
2342 FrameHostMsg_DidStartProvisionalLoadForFrame::ID);
2343 FrameHostMsg_DidStartProvisionalLoadForFrame::Param host_nav_params;
2344 FrameHostMsg_DidStartProvisionalLoadForFrame::Read(frame_navigate_msg,
2345 &host_nav_params);
2346 base::TimeTicks transmitted_start = base::get<1>(host_nav_params);
2347 EXPECT_FALSE(transmitted_start.is_null());
2348 EXPECT_LT(lower_bound_navigation_start, transmitted_start);
2349 }
2350
2351 TEST_F(RenderViewImplTest, BrowserNavigationStartNotUsedForReload) {
clamy 2015/11/06 14:28:39 Following the answer from igrigorik@ it seems we s
2352 const char url_string[] = "data:text/html,<div>Page</div>";
2353 // Navigate once, then reload.
2354 LoadHTML(url_string);
2355 ProcessPendingMessages();
2356 render_thread_->sink().ClearMessages();
2357
2358 CommonNavigationParams common_params;
2359 common_params.url = GURL(url_string);
2360 common_params.navigation_type =
2361 FrameMsg_Navigate_Type::RELOAD_ORIGINAL_REQUEST_URL;
2362 common_params.transition = ui::PAGE_TRANSITION_LINK;
2363
2364 frame()->Navigate(common_params, StartNavigationParams(),
2365 RequestNavigationParams());
2366 ProcessPendingMessages();
2367
2368 const IPC::Message* frame_navigate_msg =
2369 render_thread_->sink().GetUniqueMessageMatching(
2370 FrameHostMsg_DidStartProvisionalLoadForFrame::ID);
2371 FrameHostMsg_DidStartProvisionalLoadForFrame::Param host_nav_params;
2372 FrameHostMsg_DidStartProvisionalLoadForFrame::Read(frame_navigate_msg,
2373 &host_nav_params);
2374 // The true timestamp is later than the browser initiated one.
2375 EXPECT_GT(base::get<1>(host_nav_params), common_params.navigation_start);
2376 }
2377
2378 TEST_F(RenderViewImplTest, BrowserNavigationStartNotUsedForHistoryNavigation) {
2379 LoadHTML("<div id=pagename>Page A</div>");
2380 LoadHTML("<div id=pagename>Page B</div>");
2381 PageState back_state =
2382 HistoryEntryToPageState(view()->history_controller()->GetCurrentEntry());
2383 LoadHTML("<div id=pagename>Page C</div>");
2384 PageState forward_state =
2385 HistoryEntryToPageState(view()->history_controller()->GetCurrentEntry());
2386 ProcessPendingMessages();
2387 render_thread_->sink().ClearMessages();
2388
2389 CommonNavigationParams common_params;
2390 common_params.transition = ui::PAGE_TRANSITION_FORWARD_BACK;
2391 // Go back.
2392 GoToOffsetWithParams(-1, back_state, common_params, StartNavigationParams(),
2393 RequestNavigationParams());
2394 ProcessPendingMessages();
2395 const IPC::Message* frame_navigate_msg =
2396 render_thread_->sink().GetUniqueMessageMatching(
2397 FrameHostMsg_DidStartProvisionalLoadForFrame::ID);
2398 FrameHostMsg_DidStartProvisionalLoadForFrame::Param host_nav_params;
2399 FrameHostMsg_DidStartProvisionalLoadForFrame::Read(frame_navigate_msg,
2400 &host_nav_params);
2401 EXPECT_GT(base::get<1>(host_nav_params), common_params.navigation_start);
2402 render_thread_->sink().ClearMessages();
2403
2404 // Go forward.
2405 GoToOffsetWithParams(1, forward_state, common_params,
2406 StartNavigationParams(),
2407 RequestNavigationParams());
2408 ProcessPendingMessages();
2409 const IPC::Message* frame_navigate_msg2 =
2410 render_thread_->sink().GetUniqueMessageMatching(
2411 FrameHostMsg_DidStartProvisionalLoadForFrame::ID);
2412 FrameHostMsg_DidStartProvisionalLoadForFrame::Param host_nav_params2;
2413 FrameHostMsg_DidStartProvisionalLoadForFrame::Read(frame_navigate_msg2,
2414 &host_nav_params2);
2415 EXPECT_GT(base::get<1>(host_nav_params2), common_params.navigation_start);
2416 }
2417
2418 TEST_F(RenderViewImplTest, BrowserNavigationStartSuccessfullyTransmitted) {
2419 CommonNavigationParams common_params;
2420 common_params.url = GURL("data:text/html,<div>Page</div>");
2421 common_params.navigation_type = FrameMsg_Navigate_Type::NORMAL;
2422 common_params.transition = ui::PAGE_TRANSITION_TYPED;
2423
2424 frame()->Navigate(common_params, StartNavigationParams(),
2425 RequestNavigationParams());
2426 ProcessPendingMessages();
2427
2428 const IPC::Message* frame_navigate_msg =
2429 render_thread_->sink().GetUniqueMessageMatching(
2430 FrameHostMsg_DidStartProvisionalLoadForFrame::ID);
2431 FrameHostMsg_DidStartProvisionalLoadForFrame::Param host_nav_params;
2432 FrameHostMsg_DidStartProvisionalLoadForFrame::Read(frame_navigate_msg,
2433 &host_nav_params);
2434 EXPECT_EQ(base::get<1>(host_nav_params), common_params.navigation_start);
2435 }
2436
2312 TEST_F(RenderViewImplTest, PreferredSizeZoomed) { 2437 TEST_F(RenderViewImplTest, PreferredSizeZoomed) {
2313 LoadHTML("<body style='margin:0;'><div style='display:inline-block; " 2438 LoadHTML("<body style='margin:0;'><div style='display:inline-block; "
2314 "width:400px; height:400px;'/></body>"); 2439 "width:400px; height:400px;'/></body>");
2315 view()->webview()->mainFrame()->setCanHaveScrollbars(false); 2440 view()->webview()->mainFrame()->setCanHaveScrollbars(false);
2316 EnablePreferredSizeMode(); 2441 EnablePreferredSizeMode();
2317 2442
2318 gfx::Size size = GetPreferredSize(); 2443 gfx::Size size = GetPreferredSize();
2319 EXPECT_EQ(gfx::Size(400, 400), size); 2444 EXPECT_EQ(gfx::Size(400, 400), size);
2320 2445
2321 SetZoomLevel(ZoomFactorToZoomLevel(2.0)); 2446 SetZoomLevel(ZoomFactorToZoomLevel(2.0));
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
2379 FROM_HERE, 2504 FROM_HERE,
2380 base::Bind(&DevToolsAgentTest::CloseWhilePaused, base::Unretained(this))); 2505 base::Bind(&DevToolsAgentTest::CloseWhilePaused, base::Unretained(this)));
2381 ExecuteJavaScriptForTests("debugger;"); 2506 ExecuteJavaScriptForTests("debugger;");
2382 2507
2383 // CloseWhilePaused should resume execution and continue here. 2508 // CloseWhilePaused should resume execution and continue here.
2384 EXPECT_FALSE(IsPaused()); 2509 EXPECT_FALSE(IsPaused());
2385 Detach(); 2510 Detach();
2386 } 2511 }
2387 2512
2388 } // namespace content 2513 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698