Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "content/renderer/render_widget.h" | |
| 6 | |
| 7 #include <vector> | |
| 8 | |
| 9 #include "content/common/input/synthetic_web_input_event_builders.h" | |
| 10 #include "content/common/input_messages.h" | |
| 11 #include "content/public/test/mock_render_thread.h" | |
| 12 #include "content/test/mock_render_process.h" | |
| 13 #include "ipc/ipc_test_sink.h" | |
| 14 #include "testing/gtest/include/gtest/gtest.h" | |
| 15 #include "third_party/WebKit/public/web/WebInputEvent.h" | |
| 16 #include "ui/gfx/rect.h" | |
| 17 | |
| 18 namespace content { | |
| 19 | |
| 20 class RenderWidgetUnittest : public testing::Test { | |
| 21 public: | |
| 22 RenderWidgetUnittest() {} | |
| 23 virtual ~RenderWidgetUnittest() {} | |
| 24 | |
| 25 virtual void SetUp() OVERRIDE { | |
| 26 render_process_.reset(new MockRenderProcess()); | |
|
jamesr
2013/12/03 00:44:38
nit: if these will be unconditionally default allo
sadrul
2013/12/03 03:20:00
Good point. Done.
| |
| 27 render_thread_.reset(new MockRenderThread()); | |
| 28 } | |
| 29 | |
| 30 private: | |
| 31 scoped_ptr<MockRenderProcess> render_process_; | |
| 32 scoped_ptr<MockRenderThread> render_thread_; | |
| 33 | |
| 34 DISALLOW_COPY_AND_ASSIGN(RenderWidgetUnittest); | |
| 35 }; | |
| 36 | |
| 37 class TouchableRenderWidget : public RenderWidget { | |
| 38 public: | |
| 39 TouchableRenderWidget() : RenderWidget(blink::WebPopupTypeNone, | |
| 40 blink::WebScreenInfo(), | |
| 41 false, | |
| 42 false) {} | |
| 43 | |
| 44 void SetTouchRegion(const std::vector<gfx::Rect>& rects) { | |
| 45 rects_ = rects; | |
| 46 } | |
| 47 | |
| 48 void SendInputEvent(const blink::WebInputEvent& event) { | |
| 49 OnHandleInputEvent(&event, ui::LatencyInfo(), false); | |
| 50 } | |
| 51 | |
| 52 IPC::TestSink* sink() { return &sink_; } | |
| 53 | |
| 54 protected: | |
| 55 virtual ~TouchableRenderWidget() {} | |
| 56 | |
| 57 // Overridden from RenderWidget: | |
| 58 virtual bool HasTouchEventHandlersAt(const gfx::Point& point) const OVERRIDE { | |
| 59 for (std::vector<gfx::Rect>::const_iterator iter = rects_.begin(); | |
| 60 iter != rects_.end(); ++iter) { | |
| 61 if ((*iter).Contains(point)) | |
| 62 return true; | |
| 63 } | |
| 64 return false; | |
| 65 } | |
| 66 | |
| 67 virtual bool Send(IPC::Message* msg) OVERRIDE { | |
| 68 sink_.OnMessageReceived(*msg); | |
| 69 delete msg; | |
| 70 return true; | |
| 71 } | |
| 72 | |
| 73 private: | |
| 74 std::vector<gfx::Rect> rects_; | |
| 75 IPC::TestSink sink_; | |
| 76 | |
| 77 DISALLOW_COPY_AND_ASSIGN(TouchableRenderWidget); | |
| 78 }; | |
| 79 | |
| 80 TEST_F(RenderWidgetUnittest, TouchHitTestSinglePoint) { | |
| 81 scoped_refptr<TouchableRenderWidget> widget = new TouchableRenderWidget(); | |
| 82 | |
| 83 blink::WebInputEvent::Type type; | |
| 84 InputEventAckState ack_state; | |
| 85 ui::LatencyInfo latency; | |
| 86 | |
| 87 SyntheticWebTouchEvent touch; | |
| 88 touch.PressPoint(10, 10); | |
| 89 | |
| 90 widget->SendInputEvent(touch); | |
| 91 ASSERT_EQ(1u, widget->sink()->message_count()); | |
| 92 | |
| 93 // Since there's currently no touch-event handling region, the response should | |
| 94 // be 'no consumer exists'. | |
| 95 const IPC::Message* message = widget->sink()->GetMessageAt(0); | |
| 96 EXPECT_EQ(InputHostMsg_HandleInputEvent_ACK::ID, message->type()); | |
| 97 InputHostMsg_HandleInputEvent_ACK::Read(message, &type, &ack_state, &latency); | |
| 98 EXPECT_EQ(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS, ack_state); | |
| 99 widget->sink()->ClearMessages(); | |
| 100 | |
| 101 std::vector<gfx::Rect> rects; | |
| 102 rects.push_back(gfx::Rect(0, 0, 20, 20)); | |
| 103 rects.push_back(gfx::Rect(25, 0, 10, 10)); | |
| 104 widget->SetTouchRegion(rects); | |
| 105 | |
| 106 widget->SendInputEvent(touch); | |
| 107 ASSERT_EQ(1u, widget->sink()->message_count()); | |
| 108 message = widget->sink()->GetMessageAt(0); | |
| 109 EXPECT_EQ(InputHostMsg_HandleInputEvent_ACK::ID, message->type()); | |
| 110 InputHostMsg_HandleInputEvent_ACK::Read(message, &type, &ack_state, &latency); | |
| 111 EXPECT_EQ(INPUT_EVENT_ACK_STATE_NOT_CONSUMED, ack_state); | |
| 112 widget->sink()->ClearMessages(); | |
| 113 } | |
| 114 | |
| 115 TEST_F(RenderWidgetUnittest, TouchHitTestMultiplePoints) { | |
| 116 scoped_refptr<TouchableRenderWidget> widget = new TouchableRenderWidget(); | |
| 117 std::vector<gfx::Rect> rects; | |
| 118 rects.push_back(gfx::Rect(0, 0, 20, 20)); | |
| 119 rects.push_back(gfx::Rect(25, 0, 10, 10)); | |
| 120 widget->SetTouchRegion(rects); | |
| 121 | |
| 122 blink::WebInputEvent::Type type; | |
| 123 InputEventAckState ack_state; | |
| 124 ui::LatencyInfo latency; | |
| 125 | |
| 126 SyntheticWebTouchEvent touch; | |
| 127 touch.PressPoint(25, 25); | |
| 128 | |
| 129 widget->SendInputEvent(touch); | |
| 130 ASSERT_EQ(1u, widget->sink()->message_count()); | |
| 131 | |
| 132 // Since there's currently no touch-event handling region, the response should | |
| 133 // be 'no consumer exists'. | |
| 134 const IPC::Message* message = widget->sink()->GetMessageAt(0); | |
| 135 EXPECT_EQ(InputHostMsg_HandleInputEvent_ACK::ID, message->type()); | |
| 136 InputHostMsg_HandleInputEvent_ACK::Read(message, &type, &ack_state, &latency); | |
| 137 EXPECT_EQ(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS, ack_state); | |
| 138 widget->sink()->ClearMessages(); | |
| 139 | |
| 140 // Press a second touch point. This time, on a touch-handling region. | |
| 141 touch.PressPoint(10, 10); | |
| 142 widget->SendInputEvent(touch); | |
| 143 ASSERT_EQ(1u, widget->sink()->message_count()); | |
| 144 message = widget->sink()->GetMessageAt(0); | |
| 145 EXPECT_EQ(InputHostMsg_HandleInputEvent_ACK::ID, message->type()); | |
| 146 InputHostMsg_HandleInputEvent_ACK::Read(message, &type, &ack_state, &latency); | |
| 147 EXPECT_EQ(INPUT_EVENT_ACK_STATE_NOT_CONSUMED, ack_state); | |
| 148 widget->sink()->ClearMessages(); | |
| 149 } | |
| 150 | |
| 151 } // namespace content | |
| OLD | NEW |