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

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: Conflict Resolution: FrameHostMsg_DidStartProvisionalLoad 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
« no previous file with comments | « content/renderer/render_frame_impl.cc ('k') | content/test/test_render_frame_host.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 bool UseWebUIForURL(BrowserContext* browser_context, 130 bool UseWebUIForURL(BrowserContext* browser_context,
131 const GURL& url) const override { 131 const GURL& url) const override {
132 return HasWebUIScheme(url); 132 return HasWebUIScheme(url);
133 } 133 }
134 bool UseWebUIBindingsForURL(BrowserContext* browser_context, 134 bool UseWebUIBindingsForURL(BrowserContext* browser_context,
135 const GURL& url) const override { 135 const GURL& url) const override {
136 return HasWebUIScheme(url); 136 return HasWebUIScheme(url);
137 } 137 }
138 }; 138 };
139 139
140 // Timestamps logged close to each other under low resolution timers
141 // are more likely to record the same value. Allow for this by relaxing
142 // constraints on systems with these timers.
143 bool TimeTicksGT(const base::TimeTicks& x, const base::TimeTicks& y) {
144 return base::TimeTicks::IsHighResolution() ? x > y : x >= y;
145 }
146
140 } // namespace 147 } // namespace
141 148
142 class RenderViewImplTest : public RenderViewTest { 149 class RenderViewImplTest : public RenderViewTest {
143 public: 150 public:
144 RenderViewImplTest() { 151 RenderViewImplTest() {
145 // Attach a pseudo keyboard device to this object. 152 // Attach a pseudo keyboard device to this object.
146 mock_keyboard_.reset(new MockKeyboard()); 153 mock_keyboard_.reset(new MockKeyboard());
147 } 154 }
148 155
149 ~RenderViewImplTest() override {} 156 ~RenderViewImplTest() override {}
(...skipping 11 matching lines...) Expand all
161 } 168 }
162 169
163 int view_page_id() { 170 int view_page_id() {
164 return view()->page_id_; 171 return view()->page_id_;
165 } 172 }
166 173
167 TestRenderFrame* frame() { 174 TestRenderFrame* frame() {
168 return static_cast<TestRenderFrame*>(view()->GetMainRenderFrame()); 175 return static_cast<TestRenderFrame*>(view()->GetMainRenderFrame());
169 } 176 }
170 177
178 void GoToOffsetWithParams(int offset,
179 const PageState& state,
180 const CommonNavigationParams common_params,
181 const StartNavigationParams start_params,
182 RequestNavigationParams request_params) {
183 EXPECT_TRUE(common_params.transition & ui::PAGE_TRANSITION_FORWARD_BACK);
184 int pending_offset = offset + view()->history_list_offset_;
185
186 request_params.page_state = state;
187 request_params.page_id = view()->page_id_ + offset;
188 request_params.nav_entry_id = pending_offset + 1;
189 request_params.pending_history_list_offset = pending_offset;
190 request_params.current_history_list_offset = view()->history_list_offset_;
191 request_params.current_history_list_length = view()->history_list_length_;
192 frame()->Navigate(common_params, start_params, request_params);
193
194 // The load actually happens asynchronously, so we pump messages to process
195 // the pending continuation.
196 FrameLoadWaiter(frame()).Wait();
197 }
198
199 template<class T>
200 typename T::Param ProcessAndReadIPC() {
201 ProcessPendingMessages();
202 const IPC::Message* message =
203 render_thread_->sink().GetUniqueMessageMatching(T::ID);
204 typename T::Param param;
205 T::Read(message, &param);
206 return param;
207 }
208
171 // Sends IPC messages that emulates a key-press event. 209 // Sends IPC messages that emulates a key-press event.
172 int SendKeyEvent(MockKeyboard::Layout layout, 210 int SendKeyEvent(MockKeyboard::Layout layout,
173 int key_code, 211 int key_code,
174 MockKeyboard::Modifiers modifiers, 212 MockKeyboard::Modifiers modifiers,
175 base::string16* output) { 213 base::string16* output) {
176 #if defined(OS_WIN) 214 #if defined(OS_WIN)
177 // Retrieve the Unicode character for the given tuple (keyboard-layout, 215 // Retrieve the Unicode character for the given tuple (keyboard-layout,
178 // key-code, and modifiers). 216 // key-code, and modifiers).
179 // Exit when a keyboard-layout driver cannot assign a Unicode character to 217 // 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 218 // the tuple to prevent sending an invalid key code to the RenderView
(...skipping 2096 matching lines...) Expand 10 before | Expand all | Expand 10 after
2277 RequestNavigationParams()); 2315 RequestNavigationParams());
2278 ProcessPendingMessages(); 2316 ProcessPendingMessages();
2279 base::Time after_navigation = 2317 base::Time after_navigation =
2280 base::Time::Now() + base::TimeDelta::FromDays(1); 2318 base::Time::Now() + base::TimeDelta::FromDays(1);
2281 2319
2282 base::Time late_nav_reported_start = 2320 base::Time late_nav_reported_start =
2283 base::Time::FromDoubleT(GetMainFrame()->performance().navigationStart()); 2321 base::Time::FromDoubleT(GetMainFrame()->performance().navigationStart());
2284 EXPECT_LE(late_nav_reported_start, after_navigation); 2322 EXPECT_LE(late_nav_reported_start, after_navigation);
2285 } 2323 }
2286 2324
2325 TEST_F(RenderViewImplTest, RendererNavigationStartTransmittedToBrowser) {
2326 base::TimeTicks lower_bound_navigation_start;
2327 frame()->GetWebFrame()->loadHTMLString(
2328 "hello world", blink::WebURL(GURL("data:text/html,")));
2329 ProcessPendingMessages();
2330 const IPC::Message* frame_navigate_msg =
2331 render_thread_->sink().GetUniqueMessageMatching(
2332 FrameHostMsg_DidStartProvisionalLoad::ID);
2333 FrameHostMsg_DidStartProvisionalLoad::Param host_nav_params;
2334 FrameHostMsg_DidStartProvisionalLoad::Read(frame_navigate_msg,
2335 &host_nav_params);
2336 base::TimeTicks transmitted_start = base::get<1>(host_nav_params);
2337 EXPECT_FALSE(transmitted_start.is_null());
2338 EXPECT_LT(lower_bound_navigation_start, transmitted_start);
2339 }
2340
2341 TEST_F(RenderViewImplTest, BrowserNavigationStartNotUsedForReload) {
2342 const char url_string[] = "data:text/html,<div>Page</div>";
2343 // Navigate once, then reload.
2344 LoadHTML(url_string);
2345 ProcessPendingMessages();
2346 render_thread_->sink().ClearMessages();
2347
2348 CommonNavigationParams common_params;
2349 common_params.url = GURL(url_string);
2350 common_params.navigation_type =
2351 FrameMsg_Navigate_Type::RELOAD_ORIGINAL_REQUEST_URL;
2352 common_params.transition = ui::PAGE_TRANSITION_RELOAD;
2353
2354 frame()->Navigate(common_params, StartNavigationParams(),
2355 RequestNavigationParams());
2356
2357 FrameHostMsg_DidStartProvisionalLoad::Param host_nav_params =
2358 ProcessAndReadIPC<FrameHostMsg_DidStartProvisionalLoad>();
2359 // The true timestamp is later than the browser initiated one.
2360 EXPECT_PRED2(TimeTicksGT, base::get<1>(host_nav_params),
2361 common_params.navigation_start);
2362 }
2363
2364 TEST_F(RenderViewImplTest, BrowserNavigationStartNotUsedForHistoryNavigation) {
2365 LoadHTML("<div id=pagename>Page A</div>");
2366 LoadHTML("<div id=pagename>Page B</div>");
2367 PageState back_state =
2368 HistoryEntryToPageState(view()->history_controller()->GetCurrentEntry());
2369 LoadHTML("<div id=pagename>Page C</div>");
2370 PageState forward_state =
2371 HistoryEntryToPageState(view()->history_controller()->GetCurrentEntry());
2372 ProcessPendingMessages();
2373 render_thread_->sink().ClearMessages();
2374
2375 CommonNavigationParams common_params;
2376 common_params.transition = ui::PAGE_TRANSITION_FORWARD_BACK;
2377 // Go back.
2378 GoToOffsetWithParams(-1, back_state, common_params, StartNavigationParams(),
2379 RequestNavigationParams());
2380 FrameHostMsg_DidStartProvisionalLoad::Param host_nav_params =
2381 ProcessAndReadIPC<FrameHostMsg_DidStartProvisionalLoad>();
2382 EXPECT_PRED2(TimeTicksGT, base::get<1>(host_nav_params),
2383 common_params.navigation_start);
2384 render_thread_->sink().ClearMessages();
2385
2386 // Go forward.
2387 GoToOffsetWithParams(1, forward_state, common_params,
2388 StartNavigationParams(),
2389 RequestNavigationParams());
2390 FrameHostMsg_DidStartProvisionalLoad::Param host_nav_params2 =
2391 ProcessAndReadIPC<FrameHostMsg_DidStartProvisionalLoad>();
2392 EXPECT_PRED2(TimeTicksGT, base::get<1>(host_nav_params2),
2393 common_params.navigation_start);
2394 }
2395
2396 TEST_F(RenderViewImplTest, BrowserNavigationStartSuccessfullyTransmitted) {
2397 CommonNavigationParams common_params;
2398 common_params.url = GURL("data:text/html,<div>Page</div>");
2399 common_params.navigation_type = FrameMsg_Navigate_Type::NORMAL;
2400 common_params.transition = ui::PAGE_TRANSITION_TYPED;
2401
2402 frame()->Navigate(common_params, StartNavigationParams(),
2403 RequestNavigationParams());
2404
2405 FrameHostMsg_DidStartProvisionalLoad::Param host_nav_params =
2406 ProcessAndReadIPC<FrameHostMsg_DidStartProvisionalLoad>();
2407 EXPECT_EQ(base::get<1>(host_nav_params), common_params.navigation_start);
2408 }
2409
2287 TEST_F(RenderViewImplTest, PreferredSizeZoomed) { 2410 TEST_F(RenderViewImplTest, PreferredSizeZoomed) {
2288 LoadHTML("<body style='margin:0;'><div style='display:inline-block; " 2411 LoadHTML("<body style='margin:0;'><div style='display:inline-block; "
2289 "width:400px; height:400px;'/></body>"); 2412 "width:400px; height:400px;'/></body>");
2290 view()->webview()->mainFrame()->setCanHaveScrollbars(false); 2413 view()->webview()->mainFrame()->setCanHaveScrollbars(false);
2291 EnablePreferredSizeMode(); 2414 EnablePreferredSizeMode();
2292 2415
2293 gfx::Size size = GetPreferredSize(); 2416 gfx::Size size = GetPreferredSize();
2294 EXPECT_EQ(gfx::Size(400, 400), size); 2417 EXPECT_EQ(gfx::Size(400, 400), size);
2295 2418
2296 SetZoomLevel(ZoomFactorToZoomLevel(2.0)); 2419 SetZoomLevel(ZoomFactorToZoomLevel(2.0));
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
2354 FROM_HERE, 2477 FROM_HERE,
2355 base::Bind(&DevToolsAgentTest::CloseWhilePaused, base::Unretained(this))); 2478 base::Bind(&DevToolsAgentTest::CloseWhilePaused, base::Unretained(this)));
2356 ExecuteJavaScriptForTests("debugger;"); 2479 ExecuteJavaScriptForTests("debugger;");
2357 2480
2358 // CloseWhilePaused should resume execution and continue here. 2481 // CloseWhilePaused should resume execution and continue here.
2359 EXPECT_FALSE(IsPaused()); 2482 EXPECT_FALSE(IsPaused());
2360 Detach(); 2483 Detach();
2361 } 2484 }
2362 2485
2363 } // namespace content 2486 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/render_frame_impl.cc ('k') | content/test/test_render_frame_host.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698