OLD | NEW |
---|---|
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 Loading... | |
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 within ~15ms of each other under low resolution timers | |
nasko
2015/11/14 00:33:24
nit: No need to quote exact time difference, as th
| |
141 // could record the same value. Allow for this by relaxing constraints on | |
142 // 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 Loading... | |
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 history_list_length = view()->historyBackListCount() + | |
185 view()->historyForwardListCount() + 1; | |
186 int pending_offset = offset + view()->history_list_offset_; | |
187 | |
188 request_params.page_state = state; | |
189 request_params.page_id = view()->page_id_ + offset; | |
190 request_params.nav_entry_id = pending_offset + 1; | |
191 request_params.pending_history_list_offset = pending_offset; | |
192 request_params.current_history_list_offset = view()->history_list_offset_; | |
193 request_params.current_history_list_length = history_list_length; | |
194 frame()->Navigate(common_params, start_params, request_params); | |
195 | |
196 // The load actually happens asynchronously, so we pump messages to process | |
197 // the pending continuation. | |
198 FrameLoadWaiter(frame()).Wait(); | |
199 } | |
200 | |
201 template<class T> | |
202 typename T::Param ProcessAndReadIPC() { | |
203 ProcessPendingMessages(); | |
204 const IPC::Message* message = | |
205 render_thread_->sink().GetUniqueMessageMatching(T::ID); | |
206 typename T::Param param; | |
207 T::Read(message, ¶m); | |
208 return param; | |
209 } | |
210 | |
171 // Sends IPC messages that emulates a key-press event. | 211 // Sends IPC messages that emulates a key-press event. |
172 int SendKeyEvent(MockKeyboard::Layout layout, | 212 int SendKeyEvent(MockKeyboard::Layout layout, |
173 int key_code, | 213 int key_code, |
174 MockKeyboard::Modifiers modifiers, | 214 MockKeyboard::Modifiers modifiers, |
175 base::string16* output) { | 215 base::string16* output) { |
176 #if defined(OS_WIN) | 216 #if defined(OS_WIN) |
177 // Retrieve the Unicode character for the given tuple (keyboard-layout, | 217 // Retrieve the Unicode character for the given tuple (keyboard-layout, |
178 // key-code, and modifiers). | 218 // key-code, and modifiers). |
179 // Exit when a keyboard-layout driver cannot assign a Unicode character to | 219 // 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 | 220 // the tuple to prevent sending an invalid key code to the RenderView |
(...skipping 2096 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2277 RequestNavigationParams()); | 2317 RequestNavigationParams()); |
2278 ProcessPendingMessages(); | 2318 ProcessPendingMessages(); |
2279 base::Time after_navigation = | 2319 base::Time after_navigation = |
2280 base::Time::Now() + base::TimeDelta::FromDays(1); | 2320 base::Time::Now() + base::TimeDelta::FromDays(1); |
2281 | 2321 |
2282 base::Time late_nav_reported_start = | 2322 base::Time late_nav_reported_start = |
2283 base::Time::FromDoubleT(GetMainFrame()->performance().navigationStart()); | 2323 base::Time::FromDoubleT(GetMainFrame()->performance().navigationStart()); |
2284 EXPECT_LE(late_nav_reported_start, after_navigation); | 2324 EXPECT_LE(late_nav_reported_start, after_navigation); |
2285 } | 2325 } |
2286 | 2326 |
2327 TEST_F(RenderViewImplTest, RendererNavigationStartTransmittedToBrowser) { | |
2328 base::TimeTicks lower_bound_navigation_start; | |
2329 frame()->GetWebFrame()->loadHTMLString( | |
2330 "hello world", blink::WebURL(GURL("data:text/html,"))); | |
2331 ProcessPendingMessages(); | |
2332 const IPC::Message* frame_navigate_msg = | |
2333 render_thread_->sink().GetUniqueMessageMatching( | |
2334 FrameHostMsg_DidStartProvisionalLoadForFrame::ID); | |
2335 FrameHostMsg_DidStartProvisionalLoadForFrame::Param host_nav_params; | |
2336 FrameHostMsg_DidStartProvisionalLoadForFrame::Read(frame_navigate_msg, | |
2337 &host_nav_params); | |
2338 base::TimeTicks transmitted_start = base::get<1>(host_nav_params); | |
2339 EXPECT_FALSE(transmitted_start.is_null()); | |
2340 EXPECT_LT(lower_bound_navigation_start, transmitted_start); | |
2341 } | |
2342 | |
2343 TEST_F(RenderViewImplTest, BrowserNavigationStartNotUsedForReload) { | |
2344 const char url_string[] = "data:text/html,<div>Page</div>"; | |
2345 // Navigate once, then reload. | |
2346 LoadHTML(url_string); | |
2347 ProcessPendingMessages(); | |
2348 render_thread_->sink().ClearMessages(); | |
2349 | |
2350 CommonNavigationParams common_params; | |
2351 common_params.url = GURL(url_string); | |
2352 common_params.navigation_type = | |
2353 FrameMsg_Navigate_Type::RELOAD_ORIGINAL_REQUEST_URL; | |
2354 common_params.transition = ui::PAGE_TRANSITION_RELOAD; | |
2355 | |
2356 frame()->Navigate(common_params, StartNavigationParams(), | |
2357 RequestNavigationParams()); | |
2358 | |
2359 FrameHostMsg_DidStartProvisionalLoadForFrame::Param host_nav_params = | |
2360 ProcessAndReadIPC<FrameHostMsg_DidStartProvisionalLoadForFrame>(); | |
2361 // The true timestamp is later than the browser initiated one. | |
2362 ASSERT_PRED2(TimeTicksGT, base::get<1>(host_nav_params), | |
nasko
2015/11/14 00:33:24
EXPECT
| |
2363 common_params.navigation_start); | |
2364 } | |
2365 | |
2366 TEST_F(RenderViewImplTest, BrowserNavigationStartNotUsedForHistoryNavigation) { | |
2367 LoadHTML("<div id=pagename>Page A</div>"); | |
2368 LoadHTML("<div id=pagename>Page B</div>"); | |
2369 PageState back_state = | |
2370 HistoryEntryToPageState(view()->history_controller()->GetCurrentEntry()); | |
2371 LoadHTML("<div id=pagename>Page C</div>"); | |
2372 PageState forward_state = | |
2373 HistoryEntryToPageState(view()->history_controller()->GetCurrentEntry()); | |
2374 ProcessPendingMessages(); | |
2375 render_thread_->sink().ClearMessages(); | |
2376 | |
2377 CommonNavigationParams common_params; | |
2378 common_params.transition = ui::PAGE_TRANSITION_FORWARD_BACK; | |
2379 // Go back. | |
2380 GoToOffsetWithParams(-1, back_state, common_params, StartNavigationParams(), | |
2381 RequestNavigationParams()); | |
2382 FrameHostMsg_DidStartProvisionalLoadForFrame::Param host_nav_params = | |
2383 ProcessAndReadIPC<FrameHostMsg_DidStartProvisionalLoadForFrame>(); | |
2384 ASSERT_PRED2(TimeTicksGT, base::get<1>(host_nav_params), | |
2385 common_params.navigation_start); | |
2386 render_thread_->sink().ClearMessages(); | |
2387 | |
2388 // Go forward. | |
2389 GoToOffsetWithParams(1, forward_state, common_params, | |
2390 StartNavigationParams(), | |
2391 RequestNavigationParams()); | |
2392 FrameHostMsg_DidStartProvisionalLoadForFrame::Param host_nav_params2 = | |
2393 ProcessAndReadIPC<FrameHostMsg_DidStartProvisionalLoadForFrame>(); | |
2394 ASSERT_PRED2(TimeTicksGT, base::get<1>(host_nav_params2), | |
2395 common_params.navigation_start); | |
2396 } | |
2397 | |
2398 TEST_F(RenderViewImplTest, BrowserNavigationStartSuccessfullyTransmitted) { | |
2399 CommonNavigationParams common_params; | |
2400 common_params.url = GURL("data:text/html,<div>Page</div>"); | |
2401 common_params.navigation_type = FrameMsg_Navigate_Type::NORMAL; | |
2402 common_params.transition = ui::PAGE_TRANSITION_TYPED; | |
2403 | |
2404 frame()->Navigate(common_params, StartNavigationParams(), | |
2405 RequestNavigationParams()); | |
2406 | |
2407 FrameHostMsg_DidStartProvisionalLoadForFrame::Param host_nav_params = | |
2408 ProcessAndReadIPC<FrameHostMsg_DidStartProvisionalLoadForFrame>(); | |
2409 EXPECT_EQ(base::get<1>(host_nav_params), common_params.navigation_start); | |
2410 } | |
2411 | |
2287 TEST_F(RenderViewImplTest, PreferredSizeZoomed) { | 2412 TEST_F(RenderViewImplTest, PreferredSizeZoomed) { |
2288 LoadHTML("<body style='margin:0;'><div style='display:inline-block; " | 2413 LoadHTML("<body style='margin:0;'><div style='display:inline-block; " |
2289 "width:400px; height:400px;'/></body>"); | 2414 "width:400px; height:400px;'/></body>"); |
2290 view()->webview()->mainFrame()->setCanHaveScrollbars(false); | 2415 view()->webview()->mainFrame()->setCanHaveScrollbars(false); |
2291 EnablePreferredSizeMode(); | 2416 EnablePreferredSizeMode(); |
2292 | 2417 |
2293 gfx::Size size = GetPreferredSize(); | 2418 gfx::Size size = GetPreferredSize(); |
2294 EXPECT_EQ(gfx::Size(400, 400), size); | 2419 EXPECT_EQ(gfx::Size(400, 400), size); |
2295 | 2420 |
2296 SetZoomLevel(ZoomFactorToZoomLevel(2.0)); | 2421 SetZoomLevel(ZoomFactorToZoomLevel(2.0)); |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2354 FROM_HERE, | 2479 FROM_HERE, |
2355 base::Bind(&DevToolsAgentTest::CloseWhilePaused, base::Unretained(this))); | 2480 base::Bind(&DevToolsAgentTest::CloseWhilePaused, base::Unretained(this))); |
2356 ExecuteJavaScriptForTests("debugger;"); | 2481 ExecuteJavaScriptForTests("debugger;"); |
2357 | 2482 |
2358 // CloseWhilePaused should resume execution and continue here. | 2483 // CloseWhilePaused should resume execution and continue here. |
2359 EXPECT_FALSE(IsPaused()); | 2484 EXPECT_FALSE(IsPaused()); |
2360 Detach(); | 2485 Detach(); |
2361 } | 2486 } |
2362 | 2487 |
2363 } // namespace content | 2488 } // namespace content |
OLD | NEW |