| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <cctype> | 9 #include <cctype> |
| 10 | 10 |
| (...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 368 | 368 |
| 369 void RenderViewTest::SendNativeKeyEvent( | 369 void RenderViewTest::SendNativeKeyEvent( |
| 370 const NativeWebKeyboardEvent& key_event) { | 370 const NativeWebKeyboardEvent& key_event) { |
| 371 SendWebKeyboardEvent(key_event); | 371 SendWebKeyboardEvent(key_event); |
| 372 } | 372 } |
| 373 | 373 |
| 374 void RenderViewTest::SendWebKeyboardEvent( | 374 void RenderViewTest::SendWebKeyboardEvent( |
| 375 const blink::WebKeyboardEvent& key_event) { | 375 const blink::WebKeyboardEvent& key_event) { |
| 376 RenderViewImpl* impl = static_cast<RenderViewImpl*>(view_); | 376 RenderViewImpl* impl = static_cast<RenderViewImpl*>(view_); |
| 377 impl->OnMessageReceived(InputMsg_HandleInputEvent( | 377 impl->OnMessageReceived(InputMsg_HandleInputEvent( |
| 378 0, &key_event, ui::LatencyInfo(), | 378 0, &key_event, std::vector<IPC::WebInputEventPointer>(), |
| 379 InputEventDispatchType::DISPATCH_TYPE_BLOCKING)); | 379 ui::LatencyInfo(), InputEventDispatchType::DISPATCH_TYPE_BLOCKING)); |
| 380 } | 380 } |
| 381 | 381 |
| 382 void RenderViewTest::SendWebMouseEvent( | 382 void RenderViewTest::SendWebMouseEvent( |
| 383 const blink::WebMouseEvent& mouse_event) { | 383 const blink::WebMouseEvent& mouse_event) { |
| 384 RenderViewImpl* impl = static_cast<RenderViewImpl*>(view_); | 384 RenderViewImpl* impl = static_cast<RenderViewImpl*>(view_); |
| 385 impl->OnMessageReceived(InputMsg_HandleInputEvent( | 385 impl->OnMessageReceived(InputMsg_HandleInputEvent( |
| 386 0, &mouse_event, ui::LatencyInfo(), | 386 0, &mouse_event, std::vector<IPC::WebInputEventPointer>(), |
| 387 InputEventDispatchType::DISPATCH_TYPE_BLOCKING)); | 387 ui::LatencyInfo(), InputEventDispatchType::DISPATCH_TYPE_BLOCKING)); |
| 388 } | 388 } |
| 389 | 389 |
| 390 const char* const kGetCoordinatesScript = | 390 const char* const kGetCoordinatesScript = |
| 391 "(function() {" | 391 "(function() {" |
| 392 " function GetCoordinates(elem) {" | 392 " function GetCoordinates(elem) {" |
| 393 " if (!elem)" | 393 " if (!elem)" |
| 394 " return [ 0, 0];" | 394 " return [ 0, 0];" |
| 395 " var coordinates = [ elem.offsetLeft, elem.offsetTop];" | 395 " var coordinates = [ elem.offsetLeft, elem.offsetTop];" |
| 396 " var parent_coordinates = GetCoordinates(elem.offsetParent);" | 396 " var parent_coordinates = GetCoordinates(elem.offsetParent);" |
| 397 " coordinates[0] += parent_coordinates[0];" | 397 " coordinates[0] += parent_coordinates[0];" |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 444 | 444 |
| 445 void RenderViewTest::SimulatePointClick(const gfx::Point& point) { | 445 void RenderViewTest::SimulatePointClick(const gfx::Point& point) { |
| 446 WebMouseEvent mouse_event; | 446 WebMouseEvent mouse_event; |
| 447 mouse_event.type = WebInputEvent::MouseDown; | 447 mouse_event.type = WebInputEvent::MouseDown; |
| 448 mouse_event.button = WebMouseEvent::Button::Left; | 448 mouse_event.button = WebMouseEvent::Button::Left; |
| 449 mouse_event.x = point.x(); | 449 mouse_event.x = point.x(); |
| 450 mouse_event.y = point.y(); | 450 mouse_event.y = point.y(); |
| 451 mouse_event.clickCount = 1; | 451 mouse_event.clickCount = 1; |
| 452 RenderViewImpl* impl = static_cast<RenderViewImpl*>(view_); | 452 RenderViewImpl* impl = static_cast<RenderViewImpl*>(view_); |
| 453 impl->OnMessageReceived(InputMsg_HandleInputEvent( | 453 impl->OnMessageReceived(InputMsg_HandleInputEvent( |
| 454 0, &mouse_event, ui::LatencyInfo(), | 454 0, &mouse_event, std::vector<IPC::WebInputEventPointer>(), |
| 455 InputEventDispatchType::DISPATCH_TYPE_BLOCKING)); | 455 ui::LatencyInfo(), InputEventDispatchType::DISPATCH_TYPE_BLOCKING)); |
| 456 mouse_event.type = WebInputEvent::MouseUp; | 456 mouse_event.type = WebInputEvent::MouseUp; |
| 457 impl->OnMessageReceived(InputMsg_HandleInputEvent( | 457 impl->OnMessageReceived(InputMsg_HandleInputEvent( |
| 458 0, &mouse_event, ui::LatencyInfo(), | 458 0, &mouse_event, std::vector<IPC::WebInputEventPointer>(), |
| 459 InputEventDispatchType::DISPATCH_TYPE_BLOCKING)); | 459 ui::LatencyInfo(), InputEventDispatchType::DISPATCH_TYPE_BLOCKING)); |
| 460 } | 460 } |
| 461 | 461 |
| 462 | 462 |
| 463 bool RenderViewTest::SimulateElementRightClick(const std::string& element_id) { | 463 bool RenderViewTest::SimulateElementRightClick(const std::string& element_id) { |
| 464 gfx::Rect bounds = GetElementBounds(element_id); | 464 gfx::Rect bounds = GetElementBounds(element_id); |
| 465 if (bounds.IsEmpty()) | 465 if (bounds.IsEmpty()) |
| 466 return false; | 466 return false; |
| 467 SimulatePointRightClick(bounds.CenterPoint()); | 467 SimulatePointRightClick(bounds.CenterPoint()); |
| 468 return true; | 468 return true; |
| 469 } | 469 } |
| 470 | 470 |
| 471 void RenderViewTest::SimulatePointRightClick(const gfx::Point& point) { | 471 void RenderViewTest::SimulatePointRightClick(const gfx::Point& point) { |
| 472 WebMouseEvent mouse_event; | 472 WebMouseEvent mouse_event; |
| 473 mouse_event.type = WebInputEvent::MouseDown; | 473 mouse_event.type = WebInputEvent::MouseDown; |
| 474 mouse_event.button = WebMouseEvent::Button::Right; | 474 mouse_event.button = WebMouseEvent::Button::Right; |
| 475 mouse_event.x = point.x(); | 475 mouse_event.x = point.x(); |
| 476 mouse_event.y = point.y(); | 476 mouse_event.y = point.y(); |
| 477 mouse_event.clickCount = 1; | 477 mouse_event.clickCount = 1; |
| 478 RenderViewImpl* impl = static_cast<RenderViewImpl*>(view_); | 478 RenderViewImpl* impl = static_cast<RenderViewImpl*>(view_); |
| 479 impl->OnMessageReceived(InputMsg_HandleInputEvent( | 479 impl->OnMessageReceived(InputMsg_HandleInputEvent( |
| 480 0, &mouse_event, ui::LatencyInfo(), | 480 0, &mouse_event, std::vector<IPC::WebInputEventPointer>(), |
| 481 InputEventDispatchType::DISPATCH_TYPE_BLOCKING)); | 481 ui::LatencyInfo(), InputEventDispatchType::DISPATCH_TYPE_BLOCKING)); |
| 482 mouse_event.type = WebInputEvent::MouseUp; | 482 mouse_event.type = WebInputEvent::MouseUp; |
| 483 impl->OnMessageReceived(InputMsg_HandleInputEvent( | 483 impl->OnMessageReceived(InputMsg_HandleInputEvent( |
| 484 0, &mouse_event, ui::LatencyInfo(), | 484 0, &mouse_event, std::vector<IPC::WebInputEventPointer>(), |
| 485 InputEventDispatchType::DISPATCH_TYPE_BLOCKING)); | 485 ui::LatencyInfo(), InputEventDispatchType::DISPATCH_TYPE_BLOCKING)); |
| 486 } | 486 } |
| 487 | 487 |
| 488 void RenderViewTest::SimulateRectTap(const gfx::Rect& rect) { | 488 void RenderViewTest::SimulateRectTap(const gfx::Rect& rect) { |
| 489 WebGestureEvent gesture_event; | 489 WebGestureEvent gesture_event; |
| 490 gesture_event.x = rect.CenterPoint().x(); | 490 gesture_event.x = rect.CenterPoint().x(); |
| 491 gesture_event.y = rect.CenterPoint().y(); | 491 gesture_event.y = rect.CenterPoint().y(); |
| 492 gesture_event.data.tap.tapCount = 1; | 492 gesture_event.data.tap.tapCount = 1; |
| 493 gesture_event.data.tap.width = rect.width(); | 493 gesture_event.data.tap.width = rect.width(); |
| 494 gesture_event.data.tap.height = rect.height(); | 494 gesture_event.data.tap.height = rect.height(); |
| 495 gesture_event.type = WebInputEvent::GestureTap; | 495 gesture_event.type = WebInputEvent::GestureTap; |
| 496 gesture_event.sourceDevice = blink::WebGestureDeviceTouchpad; | 496 gesture_event.sourceDevice = blink::WebGestureDeviceTouchpad; |
| 497 RenderViewImpl* impl = static_cast<RenderViewImpl*>(view_); | 497 RenderViewImpl* impl = static_cast<RenderViewImpl*>(view_); |
| 498 impl->OnMessageReceived(InputMsg_HandleInputEvent( | 498 impl->OnMessageReceived(InputMsg_HandleInputEvent( |
| 499 0, &gesture_event, ui::LatencyInfo(), | 499 0, &gesture_event, std::vector<IPC::WebInputEventPointer>(), |
| 500 InputEventDispatchType::DISPATCH_TYPE_BLOCKING)); | 500 ui::LatencyInfo(), InputEventDispatchType::DISPATCH_TYPE_BLOCKING)); |
| 501 impl->FocusChangeComplete(); | 501 impl->FocusChangeComplete(); |
| 502 } | 502 } |
| 503 | 503 |
| 504 void RenderViewTest::SetFocused(const blink::WebNode& node) { | 504 void RenderViewTest::SetFocused(const blink::WebNode& node) { |
| 505 RenderViewImpl* impl = static_cast<RenderViewImpl*>(view_); | 505 RenderViewImpl* impl = static_cast<RenderViewImpl*>(view_); |
| 506 impl->focusedNodeChanged(blink::WebNode(), node); | 506 impl->focusedNodeChanged(blink::WebNode(), node); |
| 507 } | 507 } |
| 508 | 508 |
| 509 void RenderViewTest::Reload(const GURL& url) { | 509 void RenderViewTest::Reload(const GURL& url) { |
| 510 CommonNavigationParams common_params( | 510 CommonNavigationParams common_params( |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 658 static_cast<TestRenderFrame*>(impl->GetMainRenderFrame()); | 658 static_cast<TestRenderFrame*>(impl->GetMainRenderFrame()); |
| 659 frame->Navigate(common_params, StartNavigationParams(), request_params); | 659 frame->Navigate(common_params, StartNavigationParams(), request_params); |
| 660 | 660 |
| 661 // The load actually happens asynchronously, so we pump messages to process | 661 // The load actually happens asynchronously, so we pump messages to process |
| 662 // the pending continuation. | 662 // the pending continuation. |
| 663 FrameLoadWaiter(frame).Wait(); | 663 FrameLoadWaiter(frame).Wait(); |
| 664 view_->GetWebView()->updateAllLifecyclePhases(); | 664 view_->GetWebView()->updateAllLifecyclePhases(); |
| 665 } | 665 } |
| 666 | 666 |
| 667 } // namespace content | 667 } // namespace content |
| OLD | NEW |