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 "content/public/test/render_view_test.h" | 5 #include "content/public/test/render_view_test.h" |
6 | 6 |
7 #include <cctype> | 7 #include <cctype> |
8 | 8 |
9 #include "base/location.h" | 9 #include "base/location.h" |
10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
311 | 311 |
312 void RenderViewTest::SendNativeKeyEvent( | 312 void RenderViewTest::SendNativeKeyEvent( |
313 const NativeWebKeyboardEvent& key_event) { | 313 const NativeWebKeyboardEvent& key_event) { |
314 SendWebKeyboardEvent(key_event); | 314 SendWebKeyboardEvent(key_event); |
315 } | 315 } |
316 | 316 |
317 void RenderViewTest::SendWebKeyboardEvent( | 317 void RenderViewTest::SendWebKeyboardEvent( |
318 const blink::WebKeyboardEvent& key_event) { | 318 const blink::WebKeyboardEvent& key_event) { |
319 RenderViewImpl* impl = static_cast<RenderViewImpl*>(view_); | 319 RenderViewImpl* impl = static_cast<RenderViewImpl*>(view_); |
320 impl->OnMessageReceived( | 320 impl->OnMessageReceived( |
321 InputMsg_HandleInputEvent(0, &key_event, ui::LatencyInfo(), false)); | 321 InputMsg_HandleInputEvent(0, &key_event, ui::LatencyInfo())); |
322 } | 322 } |
323 | 323 |
324 void RenderViewTest::SendWebMouseEvent( | 324 void RenderViewTest::SendWebMouseEvent( |
325 const blink::WebMouseEvent& mouse_event) { | 325 const blink::WebMouseEvent& mouse_event) { |
326 RenderViewImpl* impl = static_cast<RenderViewImpl*>(view_); | 326 RenderViewImpl* impl = static_cast<RenderViewImpl*>(view_); |
327 impl->OnMessageReceived( | 327 impl->OnMessageReceived( |
328 InputMsg_HandleInputEvent(0, &mouse_event, ui::LatencyInfo(), false)); | 328 InputMsg_HandleInputEvent(0, &mouse_event, ui::LatencyInfo())); |
329 } | 329 } |
330 | 330 |
331 const char* const kGetCoordinatesScript = | 331 const char* const kGetCoordinatesScript = |
332 "(function() {" | 332 "(function() {" |
333 " function GetCoordinates(elem) {" | 333 " function GetCoordinates(elem) {" |
334 " if (!elem)" | 334 " if (!elem)" |
335 " return [ 0, 0];" | 335 " return [ 0, 0];" |
336 " var coordinates = [ elem.offsetLeft, elem.offsetTop];" | 336 " var coordinates = [ elem.offsetLeft, elem.offsetTop];" |
337 " var parent_coordinates = GetCoordinates(elem.offsetParent);" | 337 " var parent_coordinates = GetCoordinates(elem.offsetParent);" |
338 " coordinates[0] += parent_coordinates[0];" | 338 " coordinates[0] += parent_coordinates[0];" |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
385 | 385 |
386 void RenderViewTest::SimulatePointClick(const gfx::Point& point) { | 386 void RenderViewTest::SimulatePointClick(const gfx::Point& point) { |
387 WebMouseEvent mouse_event; | 387 WebMouseEvent mouse_event; |
388 mouse_event.type = WebInputEvent::MouseDown; | 388 mouse_event.type = WebInputEvent::MouseDown; |
389 mouse_event.button = WebMouseEvent::ButtonLeft; | 389 mouse_event.button = WebMouseEvent::ButtonLeft; |
390 mouse_event.x = point.x(); | 390 mouse_event.x = point.x(); |
391 mouse_event.y = point.y(); | 391 mouse_event.y = point.y(); |
392 mouse_event.clickCount = 1; | 392 mouse_event.clickCount = 1; |
393 RenderViewImpl* impl = static_cast<RenderViewImpl*>(view_); | 393 RenderViewImpl* impl = static_cast<RenderViewImpl*>(view_); |
394 impl->OnMessageReceived( | 394 impl->OnMessageReceived( |
395 InputMsg_HandleInputEvent(0, &mouse_event, ui::LatencyInfo(), false)); | 395 InputMsg_HandleInputEvent(0, &mouse_event, ui::LatencyInfo())); |
396 mouse_event.type = WebInputEvent::MouseUp; | 396 mouse_event.type = WebInputEvent::MouseUp; |
397 impl->OnMessageReceived( | 397 impl->OnMessageReceived( |
398 InputMsg_HandleInputEvent(0, &mouse_event, ui::LatencyInfo(), false)); | 398 InputMsg_HandleInputEvent(0, &mouse_event, ui::LatencyInfo())); |
399 } | 399 } |
400 | 400 |
401 | 401 |
402 bool RenderViewTest::SimulateElementRightClick(const std::string& element_id) { | 402 bool RenderViewTest::SimulateElementRightClick(const std::string& element_id) { |
403 gfx::Rect bounds = GetElementBounds(element_id); | 403 gfx::Rect bounds = GetElementBounds(element_id); |
404 if (bounds.IsEmpty()) | 404 if (bounds.IsEmpty()) |
405 return false; | 405 return false; |
406 SimulatePointRightClick(bounds.CenterPoint()); | 406 SimulatePointRightClick(bounds.CenterPoint()); |
407 return true; | 407 return true; |
408 } | 408 } |
409 | 409 |
410 void RenderViewTest::SimulatePointRightClick(const gfx::Point& point) { | 410 void RenderViewTest::SimulatePointRightClick(const gfx::Point& point) { |
411 WebMouseEvent mouse_event; | 411 WebMouseEvent mouse_event; |
412 mouse_event.type = WebInputEvent::MouseDown; | 412 mouse_event.type = WebInputEvent::MouseDown; |
413 mouse_event.button = WebMouseEvent::ButtonRight; | 413 mouse_event.button = WebMouseEvent::ButtonRight; |
414 mouse_event.x = point.x(); | 414 mouse_event.x = point.x(); |
415 mouse_event.y = point.y(); | 415 mouse_event.y = point.y(); |
416 mouse_event.clickCount = 1; | 416 mouse_event.clickCount = 1; |
417 RenderViewImpl* impl = static_cast<RenderViewImpl*>(view_); | 417 RenderViewImpl* impl = static_cast<RenderViewImpl*>(view_); |
418 impl->OnMessageReceived( | 418 impl->OnMessageReceived( |
419 InputMsg_HandleInputEvent(0, &mouse_event, ui::LatencyInfo(), false)); | 419 InputMsg_HandleInputEvent(0, &mouse_event, ui::LatencyInfo())); |
420 mouse_event.type = WebInputEvent::MouseUp; | 420 mouse_event.type = WebInputEvent::MouseUp; |
421 impl->OnMessageReceived( | 421 impl->OnMessageReceived( |
422 InputMsg_HandleInputEvent(0, &mouse_event, ui::LatencyInfo(), false)); | 422 InputMsg_HandleInputEvent(0, &mouse_event, ui::LatencyInfo())); |
423 } | 423 } |
424 | 424 |
425 void RenderViewTest::SimulateRectTap(const gfx::Rect& rect) { | 425 void RenderViewTest::SimulateRectTap(const gfx::Rect& rect) { |
426 WebGestureEvent gesture_event; | 426 WebGestureEvent gesture_event; |
427 gesture_event.x = rect.CenterPoint().x(); | 427 gesture_event.x = rect.CenterPoint().x(); |
428 gesture_event.y = rect.CenterPoint().y(); | 428 gesture_event.y = rect.CenterPoint().y(); |
429 gesture_event.data.tap.tapCount = 1; | 429 gesture_event.data.tap.tapCount = 1; |
430 gesture_event.data.tap.width = rect.width(); | 430 gesture_event.data.tap.width = rect.width(); |
431 gesture_event.data.tap.height = rect.height(); | 431 gesture_event.data.tap.height = rect.height(); |
432 gesture_event.type = WebInputEvent::GestureTap; | 432 gesture_event.type = WebInputEvent::GestureTap; |
433 RenderViewImpl* impl = static_cast<RenderViewImpl*>(view_); | 433 RenderViewImpl* impl = static_cast<RenderViewImpl*>(view_); |
434 impl->OnMessageReceived( | 434 impl->OnMessageReceived( |
435 InputMsg_HandleInputEvent(0, &gesture_event, ui::LatencyInfo(), false)); | 435 InputMsg_HandleInputEvent(0, &gesture_event, ui::LatencyInfo())); |
436 impl->FocusChangeComplete(); | 436 impl->FocusChangeComplete(); |
437 } | 437 } |
438 | 438 |
439 void RenderViewTest::SetFocused(const blink::WebNode& node) { | 439 void RenderViewTest::SetFocused(const blink::WebNode& node) { |
440 RenderViewImpl* impl = static_cast<RenderViewImpl*>(view_); | 440 RenderViewImpl* impl = static_cast<RenderViewImpl*>(view_); |
441 impl->focusedNodeChanged(blink::WebNode(), node); | 441 impl->focusedNodeChanged(blink::WebNode(), node); |
442 } | 442 } |
443 | 443 |
444 void RenderViewTest::Reload(const GURL& url) { | 444 void RenderViewTest::Reload(const GURL& url) { |
445 CommonNavigationParams common_params( | 445 CommonNavigationParams common_params( |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
589 TestRenderFrame* frame = | 589 TestRenderFrame* frame = |
590 static_cast<TestRenderFrame*>(impl->GetMainRenderFrame()); | 590 static_cast<TestRenderFrame*>(impl->GetMainRenderFrame()); |
591 frame->Navigate(common_params, StartNavigationParams(), request_params); | 591 frame->Navigate(common_params, StartNavigationParams(), request_params); |
592 | 592 |
593 // The load actually happens asynchronously, so we pump messages to process | 593 // The load actually happens asynchronously, so we pump messages to process |
594 // the pending continuation. | 594 // the pending continuation. |
595 FrameLoadWaiter(frame).Wait(); | 595 FrameLoadWaiter(frame).Wait(); |
596 } | 596 } |
597 | 597 |
598 } // namespace content | 598 } // namespace content |
OLD | NEW |