| Index: content/browser/renderer_host/render_widget_host_view_mac_unittest.mm
|
| diff --git a/content/browser/renderer_host/render_widget_host_view_mac_unittest.mm b/content/browser/renderer_host/render_widget_host_view_mac_unittest.mm
|
| index 6fb79d187f3ea963ab6917fb8740e47f8690179c..c46298a1651781e21fe791f2f545e9a3ca09f9da 100644
|
| --- a/content/browser/renderer_host/render_widget_host_view_mac_unittest.mm
|
| +++ b/content/browser/renderer_host/render_widget_host_view_mac_unittest.mm
|
| @@ -866,7 +866,38 @@ TEST_F(RenderWidgetHostViewMacTest, Background) {
|
| host->Shutdown();
|
| }
|
|
|
| -TEST_F(RenderWidgetHostViewMacTest, PinchThresholding) {
|
| +class RenderWidgetHostViewMacPinchTest : public RenderWidgetHostViewMacTest {
|
| + public:
|
| + RenderWidgetHostViewMacPinchTest() : process_host_(NULL) {}
|
| +
|
| + bool ZoomDisabledForPinchUpdateMessage() {
|
| + const IPC::Message* message = NULL;
|
| + // The first message may be a PinchBegin. Go for the second message if
|
| + // there are two.
|
| + switch (process_host_->sink().message_count()) {
|
| + case 1:
|
| + message = process_host_->sink().GetMessageAt(0);
|
| + break;
|
| + case 2:
|
| + message = process_host_->sink().GetMessageAt(1);
|
| + break;
|
| + default:
|
| + NOTREACHED();
|
| + break;
|
| + }
|
| + DCHECK(message);
|
| + Tuple<IPC::WebInputEventPointer, ui::LatencyInfo, bool> data;
|
| + InputMsg_HandleInputEvent::Read(message, &data);
|
| + IPC::WebInputEventPointer ipc_event = get<0>(data);
|
| + const blink::WebGestureEvent* gesture_event =
|
| + static_cast<const blink::WebGestureEvent*>(ipc_event);
|
| + return gesture_event->data.pinchUpdate.zoomDisabled;
|
| + }
|
| +
|
| + MockRenderProcessHost* process_host_;
|
| +};
|
| +
|
| +TEST_F(RenderWidgetHostViewMacPinchTest, PinchThresholding) {
|
| // This tests Lion+ functionality, so don't run the test pre-Lion.
|
| if (!base::mac::IsOSLionOrLater())
|
| return;
|
| @@ -875,11 +906,10 @@ TEST_F(RenderWidgetHostViewMacTest, PinchThresholding) {
|
| // the MockRenderProcessHost that is set up by the test harness which mocks
|
| // out |OnMessageReceived()|.
|
| TestBrowserContext browser_context;
|
| - MockRenderProcessHost* process_host =
|
| - new MockRenderProcessHost(&browser_context);
|
| + process_host_ = new MockRenderProcessHost(&browser_context);
|
| MockRenderWidgetHostDelegate delegate;
|
| MockRenderWidgetHostImpl* host = new MockRenderWidgetHostImpl(
|
| - &delegate, process_host, MSG_ROUTING_NONE);
|
| + &delegate, process_host_, MSG_ROUTING_NONE);
|
| RenderWidgetHostViewMac* view = new RenderWidgetHostViewMac(host, false);
|
|
|
| // We'll use this IPC message to ack events.
|
| @@ -901,27 +931,34 @@ TEST_F(RenderWidgetHostViewMacTest, PinchThresholding) {
|
| NSEvent* pinchEndEvent =
|
| MockGestureEvent(NSEventTypeEndGesture, 100.5, 0);
|
|
|
| - // No messages are sent for the pinch begin and the first update event.
|
| [view->cocoa_view() beginGestureWithEvent:pinchBeginEvent];
|
| + EXPECT_EQ(0U, process_host_->sink().message_count());
|
| +
|
| + // No zoom is sent for the first update event.
|
| [view->cocoa_view() magnifyWithEvent:pinchUpdateEvents[0]];
|
| - ASSERT_EQ(0U, process_host->sink().message_count());
|
| + host->OnMessageReceived(*response);
|
| + EXPECT_EQ(2U, process_host_->sink().message_count());
|
| + EXPECT_TRUE(ZoomDisabledForPinchUpdateMessage());
|
| + process_host_->sink().ClearMessages();
|
|
|
| - // The second update event crosses the threshold of 0.4, and so a begin
|
| - // and update are sent.
|
| + // The second update event crosses the threshold of 0.4, and so zoom is no
|
| + // longer disabled.
|
| [view->cocoa_view() magnifyWithEvent:pinchUpdateEvents[1]];
|
| - ASSERT_EQ(2U, process_host->sink().message_count());
|
| + EXPECT_FALSE(ZoomDisabledForPinchUpdateMessage());
|
| host->OnMessageReceived(*response);
|
| + EXPECT_EQ(1U, process_host_->sink().message_count());
|
| + process_host_->sink().ClearMessages();
|
|
|
| - // The third update only causes one event to be sent.
|
| + // The third update still has zoom enabled.
|
| [view->cocoa_view() magnifyWithEvent:pinchUpdateEvents[2]];
|
| - ASSERT_EQ(3U, process_host->sink().message_count());
|
| + EXPECT_FALSE(ZoomDisabledForPinchUpdateMessage());
|
| host->OnMessageReceived(*response);
|
| + EXPECT_EQ(1U, process_host_->sink().message_count());
|
| + process_host_->sink().ClearMessages();
|
|
|
| - // As does the end.
|
| [view->cocoa_view() endGestureWithEvent:pinchEndEvent];
|
| - ASSERT_EQ(4U, process_host->sink().message_count());
|
| -
|
| - process_host->sink().ClearMessages();
|
| + EXPECT_EQ(1U, process_host_->sink().message_count());
|
| + process_host_->sink().ClearMessages();
|
| }
|
|
|
| // Do a gesture that doesn't cross the threshold, but happens within 1 second,
|
| @@ -934,20 +971,19 @@ TEST_F(RenderWidgetHostViewMacTest, PinchThresholding) {
|
| NSEvent* pinchEndEvent =
|
| MockGestureEvent(NSEventTypeEndGesture, 101.2, 0);
|
|
|
| - // No message comes for the begin event.
|
| [view->cocoa_view() beginGestureWithEvent:pinchBeginEvent];
|
| - ASSERT_EQ(0U, process_host->sink().message_count());
|
| + EXPECT_EQ(0U, process_host_->sink().message_count());
|
|
|
| - // Two messages come for the first update event.
|
| + // Expect that a zoom happen because the time threshold has not passed.
|
| [view->cocoa_view() magnifyWithEvent:pinchUpdateEvent];
|
| - ASSERT_EQ(2U, process_host->sink().message_count());
|
| + EXPECT_FALSE(ZoomDisabledForPinchUpdateMessage());
|
| host->OnMessageReceived(*response);
|
| + EXPECT_EQ(2U, process_host_->sink().message_count());
|
| + process_host_->sink().ClearMessages();
|
|
|
| - // The end event sends one message.
|
| [view->cocoa_view() endGestureWithEvent:pinchEndEvent];
|
| - ASSERT_EQ(3U, process_host->sink().message_count());
|
| -
|
| - process_host->sink().ClearMessages();
|
| + EXPECT_EQ(1U, process_host_->sink().message_count());
|
| + process_host_->sink().ClearMessages();
|
| }
|
|
|
| // Do a gesture that doesn't cross the threshold and happens more than one
|
| @@ -960,19 +996,19 @@ TEST_F(RenderWidgetHostViewMacTest, PinchThresholding) {
|
| NSEvent* pinchEndEvent =
|
| MockGestureEvent(NSEventTypeEndGesture, 103.2, 0);
|
|
|
| - // No message comes for the begin event.
|
| [view->cocoa_view() beginGestureWithEvent:pinchBeginEvent];
|
| - ASSERT_EQ(0U, process_host->sink().message_count());
|
| + EXPECT_EQ(0U, process_host_->sink().message_count());
|
|
|
| - // Two messages come for the first update event.
|
| + // Expect that zoom be disabled because the time threshold has passed.
|
| [view->cocoa_view() magnifyWithEvent:pinchUpdateEvent];
|
| - ASSERT_EQ(0U, process_host->sink().message_count());
|
| + EXPECT_EQ(2U, process_host_->sink().message_count());
|
| + EXPECT_TRUE(ZoomDisabledForPinchUpdateMessage());
|
| + host->OnMessageReceived(*response);
|
| + process_host_->sink().ClearMessages();
|
|
|
| - // As does the end.
|
| [view->cocoa_view() endGestureWithEvent:pinchEndEvent];
|
| - ASSERT_EQ(0U, process_host->sink().message_count());
|
| -
|
| - process_host->sink().ClearMessages();
|
| + EXPECT_EQ(1U, process_host_->sink().message_count());
|
| + process_host_->sink().ClearMessages();
|
| }
|
|
|
| // Clean up.
|
|
|