| 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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 #include "third_party/WebKit/public/platform/WebURLRequest.h" | 44 #include "third_party/WebKit/public/platform/WebURLRequest.h" |
| 45 #include "third_party/WebKit/public/platform/scheduler/renderer/renderer_schedul
er.h" | 45 #include "third_party/WebKit/public/platform/scheduler/renderer/renderer_schedul
er.h" |
| 46 #include "third_party/WebKit/public/web/WebDocument.h" | 46 #include "third_party/WebKit/public/web/WebDocument.h" |
| 47 #include "third_party/WebKit/public/web/WebHistoryItem.h" | 47 #include "third_party/WebKit/public/web/WebHistoryItem.h" |
| 48 #include "third_party/WebKit/public/web/WebInputElement.h" | 48 #include "third_party/WebKit/public/web/WebInputElement.h" |
| 49 #include "third_party/WebKit/public/web/WebKit.h" | 49 #include "third_party/WebKit/public/web/WebKit.h" |
| 50 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 50 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
| 51 #include "third_party/WebKit/public/web/WebScriptSource.h" | 51 #include "third_party/WebKit/public/web/WebScriptSource.h" |
| 52 #include "third_party/WebKit/public/web/WebView.h" | 52 #include "third_party/WebKit/public/web/WebView.h" |
| 53 #include "ui/base/resource/resource_bundle.h" | 53 #include "ui/base/resource/resource_bundle.h" |
| 54 #include "ui/events/base_event_utils.h" |
| 54 #include "ui/events/keycodes/keyboard_codes.h" | 55 #include "ui/events/keycodes/keyboard_codes.h" |
| 55 #include "v8/include/v8.h" | 56 #include "v8/include/v8.h" |
| 56 | 57 |
| 57 #if defined(OS_MACOSX) | 58 #if defined(OS_MACOSX) |
| 58 #include "base/mac/scoped_nsautorelease_pool.h" | 59 #include "base/mac/scoped_nsautorelease_pool.h" |
| 59 #endif | 60 #endif |
| 60 | 61 |
| 61 #if defined(OS_WIN) | 62 #if defined(OS_WIN) |
| 62 #include "content/child/dwrite_font_proxy/dwrite_font_proxy_init_win.h" | 63 #include "content/child/dwrite_font_proxy/dwrite_font_proxy_init_win.h" |
| 63 #include "content/test/dwrite_font_fake_sender_win.h" | 64 #include "content/test/dwrite_font_fake_sender_win.h" |
| (...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 442 | 443 |
| 443 bool RenderViewTest::SimulateElementClick(const std::string& element_id) { | 444 bool RenderViewTest::SimulateElementClick(const std::string& element_id) { |
| 444 gfx::Rect bounds = GetElementBounds(element_id); | 445 gfx::Rect bounds = GetElementBounds(element_id); |
| 445 if (bounds.IsEmpty()) | 446 if (bounds.IsEmpty()) |
| 446 return false; | 447 return false; |
| 447 SimulatePointClick(bounds.CenterPoint()); | 448 SimulatePointClick(bounds.CenterPoint()); |
| 448 return true; | 449 return true; |
| 449 } | 450 } |
| 450 | 451 |
| 451 void RenderViewTest::SimulatePointClick(const gfx::Point& point) { | 452 void RenderViewTest::SimulatePointClick(const gfx::Point& point) { |
| 452 WebMouseEvent mouse_event; | 453 WebMouseEvent mouse_event(WebInputEvent::MouseDown, |
| 453 mouse_event.type = WebInputEvent::MouseDown; | 454 WebInputEvent::NoModifiers, |
| 455 ui::EventTimeStampToSeconds(ui::EventTimeForNow())); |
| 454 mouse_event.button = WebMouseEvent::Button::Left; | 456 mouse_event.button = WebMouseEvent::Button::Left; |
| 455 mouse_event.x = point.x(); | 457 mouse_event.x = point.x(); |
| 456 mouse_event.y = point.y(); | 458 mouse_event.y = point.y(); |
| 457 mouse_event.clickCount = 1; | 459 mouse_event.clickCount = 1; |
| 458 RenderViewImpl* impl = static_cast<RenderViewImpl*>(view_); | 460 RenderViewImpl* impl = static_cast<RenderViewImpl*>(view_); |
| 459 impl->OnMessageReceived(InputMsg_HandleInputEvent( | 461 impl->OnMessageReceived(InputMsg_HandleInputEvent( |
| 460 0, &mouse_event, ui::LatencyInfo(), | 462 0, &mouse_event, ui::LatencyInfo(), |
| 461 InputEventDispatchType::DISPATCH_TYPE_BLOCKING)); | 463 InputEventDispatchType::DISPATCH_TYPE_BLOCKING)); |
| 462 mouse_event.type = WebInputEvent::MouseUp; | 464 mouse_event.setType(WebInputEvent::MouseUp); |
| 463 impl->OnMessageReceived(InputMsg_HandleInputEvent( | 465 impl->OnMessageReceived(InputMsg_HandleInputEvent( |
| 464 0, &mouse_event, ui::LatencyInfo(), | 466 0, &mouse_event, ui::LatencyInfo(), |
| 465 InputEventDispatchType::DISPATCH_TYPE_BLOCKING)); | 467 InputEventDispatchType::DISPATCH_TYPE_BLOCKING)); |
| 466 } | 468 } |
| 467 | 469 |
| 468 | 470 |
| 469 bool RenderViewTest::SimulateElementRightClick(const std::string& element_id) { | 471 bool RenderViewTest::SimulateElementRightClick(const std::string& element_id) { |
| 470 gfx::Rect bounds = GetElementBounds(element_id); | 472 gfx::Rect bounds = GetElementBounds(element_id); |
| 471 if (bounds.IsEmpty()) | 473 if (bounds.IsEmpty()) |
| 472 return false; | 474 return false; |
| 473 SimulatePointRightClick(bounds.CenterPoint()); | 475 SimulatePointRightClick(bounds.CenterPoint()); |
| 474 return true; | 476 return true; |
| 475 } | 477 } |
| 476 | 478 |
| 477 void RenderViewTest::SimulatePointRightClick(const gfx::Point& point) { | 479 void RenderViewTest::SimulatePointRightClick(const gfx::Point& point) { |
| 478 WebMouseEvent mouse_event; | 480 WebMouseEvent mouse_event(WebInputEvent::MouseDown, |
| 479 mouse_event.type = WebInputEvent::MouseDown; | 481 WebInputEvent::NoModifiers, |
| 482 ui::EventTimeStampToSeconds(ui::EventTimeForNow())); |
| 480 mouse_event.button = WebMouseEvent::Button::Right; | 483 mouse_event.button = WebMouseEvent::Button::Right; |
| 481 mouse_event.x = point.x(); | 484 mouse_event.x = point.x(); |
| 482 mouse_event.y = point.y(); | 485 mouse_event.y = point.y(); |
| 483 mouse_event.clickCount = 1; | 486 mouse_event.clickCount = 1; |
| 484 RenderViewImpl* impl = static_cast<RenderViewImpl*>(view_); | 487 RenderViewImpl* impl = static_cast<RenderViewImpl*>(view_); |
| 485 impl->OnMessageReceived(InputMsg_HandleInputEvent( | 488 impl->OnMessageReceived(InputMsg_HandleInputEvent( |
| 486 0, &mouse_event, ui::LatencyInfo(), | 489 0, &mouse_event, ui::LatencyInfo(), |
| 487 InputEventDispatchType::DISPATCH_TYPE_BLOCKING)); | 490 InputEventDispatchType::DISPATCH_TYPE_BLOCKING)); |
| 488 mouse_event.type = WebInputEvent::MouseUp; | 491 mouse_event.setType(WebInputEvent::MouseUp); |
| 489 impl->OnMessageReceived(InputMsg_HandleInputEvent( | 492 impl->OnMessageReceived(InputMsg_HandleInputEvent( |
| 490 0, &mouse_event, ui::LatencyInfo(), | 493 0, &mouse_event, ui::LatencyInfo(), |
| 491 InputEventDispatchType::DISPATCH_TYPE_BLOCKING)); | 494 InputEventDispatchType::DISPATCH_TYPE_BLOCKING)); |
| 492 } | 495 } |
| 493 | 496 |
| 494 void RenderViewTest::SimulateRectTap(const gfx::Rect& rect) { | 497 void RenderViewTest::SimulateRectTap(const gfx::Rect& rect) { |
| 495 WebGestureEvent gesture_event; | 498 WebGestureEvent gesture_event( |
| 499 WebInputEvent::GestureTap, WebInputEvent::NoModifiers, |
| 500 ui::EventTimeStampToSeconds(ui::EventTimeForNow())); |
| 496 gesture_event.x = rect.CenterPoint().x(); | 501 gesture_event.x = rect.CenterPoint().x(); |
| 497 gesture_event.y = rect.CenterPoint().y(); | 502 gesture_event.y = rect.CenterPoint().y(); |
| 498 gesture_event.data.tap.tapCount = 1; | 503 gesture_event.data.tap.tapCount = 1; |
| 499 gesture_event.data.tap.width = rect.width(); | 504 gesture_event.data.tap.width = rect.width(); |
| 500 gesture_event.data.tap.height = rect.height(); | 505 gesture_event.data.tap.height = rect.height(); |
| 501 gesture_event.type = WebInputEvent::GestureTap; | |
| 502 gesture_event.sourceDevice = blink::WebGestureDeviceTouchpad; | 506 gesture_event.sourceDevice = blink::WebGestureDeviceTouchpad; |
| 503 RenderViewImpl* impl = static_cast<RenderViewImpl*>(view_); | 507 RenderViewImpl* impl = static_cast<RenderViewImpl*>(view_); |
| 504 impl->OnMessageReceived(InputMsg_HandleInputEvent( | 508 impl->OnMessageReceived(InputMsg_HandleInputEvent( |
| 505 0, &gesture_event, ui::LatencyInfo(), | 509 0, &gesture_event, ui::LatencyInfo(), |
| 506 InputEventDispatchType::DISPATCH_TYPE_BLOCKING)); | 510 InputEventDispatchType::DISPATCH_TYPE_BLOCKING)); |
| 507 impl->FocusChangeComplete(); | 511 impl->FocusChangeComplete(); |
| 508 } | 512 } |
| 509 | 513 |
| 510 void RenderViewTest::SetFocused(const blink::WebNode& node) { | 514 void RenderViewTest::SetFocused(const blink::WebNode& node) { |
| 511 RenderViewImpl* impl = static_cast<RenderViewImpl*>(view_); | 515 RenderViewImpl* impl = static_cast<RenderViewImpl*>(view_); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 540 params.top_controls_height = 0.f; | 544 params.top_controls_height = 0.f; |
| 541 params.browser_controls_shrink_blink_size = false; | 545 params.browser_controls_shrink_blink_size = false; |
| 542 params.is_fullscreen_granted = is_fullscreen_granted; | 546 params.is_fullscreen_granted = is_fullscreen_granted; |
| 543 params.display_mode = blink::WebDisplayModeBrowser; | 547 params.display_mode = blink::WebDisplayModeBrowser; |
| 544 std::unique_ptr<IPC::Message> resize_message(new ViewMsg_Resize(0, params)); | 548 std::unique_ptr<IPC::Message> resize_message(new ViewMsg_Resize(0, params)); |
| 545 OnMessageReceived(*resize_message); | 549 OnMessageReceived(*resize_message); |
| 546 } | 550 } |
| 547 | 551 |
| 548 void RenderViewTest::SimulateUserTypingASCIICharacter(char ascii_character, | 552 void RenderViewTest::SimulateUserTypingASCIICharacter(char ascii_character, |
| 549 bool flush_message_loop) { | 553 bool flush_message_loop) { |
| 550 blink::WebKeyboardEvent event; | 554 int modifiers = blink::WebInputEvent::NoModifiers; |
| 555 if (isupper(ascii_character) || ascii_character == '@' || |
| 556 ascii_character == '_') { |
| 557 modifiers = blink::WebKeyboardEvent::ShiftKey; |
| 558 } |
| 559 |
| 560 blink::WebKeyboardEvent event( |
| 561 blink::WebKeyboardEvent::RawKeyDown, modifiers, |
| 562 ui::EventTimeStampToSeconds(ui::EventTimeForNow())); |
| 551 event.text[0] = ascii_character; | 563 event.text[0] = ascii_character; |
| 552 ASSERT_TRUE(GetWindowsKeyCode(ascii_character, &event.windowsKeyCode)); | 564 ASSERT_TRUE(GetWindowsKeyCode(ascii_character, &event.windowsKeyCode)); |
| 553 if (isupper(ascii_character) || ascii_character == '@' || | |
| 554 ascii_character == '_') { | |
| 555 event.modifiers = blink::WebKeyboardEvent::ShiftKey; | |
| 556 } | |
| 557 | |
| 558 event.type = blink::WebKeyboardEvent::RawKeyDown; | |
| 559 SendWebKeyboardEvent(event); | 565 SendWebKeyboardEvent(event); |
| 560 | 566 |
| 561 event.type = blink::WebKeyboardEvent::Char; | 567 event.setType(blink::WebKeyboardEvent::Char); |
| 562 SendWebKeyboardEvent(event); | 568 SendWebKeyboardEvent(event); |
| 563 | 569 |
| 564 event.type = blink::WebKeyboardEvent::KeyUp; | 570 event.setType(blink::WebKeyboardEvent::KeyUp); |
| 565 SendWebKeyboardEvent(event); | 571 SendWebKeyboardEvent(event); |
| 566 | 572 |
| 567 if (flush_message_loop) { | 573 if (flush_message_loop) { |
| 568 // Processing is delayed because of a Blink bug: | 574 // Processing is delayed because of a Blink bug: |
| 569 // https://bugs.webkit.org/show_bug.cgi?id=16976 See | 575 // https://bugs.webkit.org/show_bug.cgi?id=16976 See |
| 570 // PasswordAutofillAgent::TextDidChangeInTextField() for details. | 576 // PasswordAutofillAgent::TextDidChangeInTextField() for details. |
| 571 base::RunLoop().RunUntilIdle(); | 577 base::RunLoop().RunUntilIdle(); |
| 572 } | 578 } |
| 573 } | 579 } |
| 574 | 580 |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 664 static_cast<TestRenderFrame*>(impl->GetMainRenderFrame()); | 670 static_cast<TestRenderFrame*>(impl->GetMainRenderFrame()); |
| 665 frame->Navigate(common_params, StartNavigationParams(), request_params); | 671 frame->Navigate(common_params, StartNavigationParams(), request_params); |
| 666 | 672 |
| 667 // The load actually happens asynchronously, so we pump messages to process | 673 // The load actually happens asynchronously, so we pump messages to process |
| 668 // the pending continuation. | 674 // the pending continuation. |
| 669 FrameLoadWaiter(frame).Wait(); | 675 FrameLoadWaiter(frame).Wait(); |
| 670 view_->GetWebView()->updateAllLifecyclePhases(); | 676 view_->GetWebView()->updateAllLifecyclePhases(); |
| 671 } | 677 } |
| 672 | 678 |
| 673 } // namespace content | 679 } // namespace content |
| OLD | NEW |