Chromium Code Reviews| Index: chrome/browser/renderer_host/chrome_render_widget_host_view_mac_history_swiper_unit_test.mm |
| diff --git a/chrome/browser/renderer_host/chrome_render_widget_host_view_mac_history_swiper_unit_test.mm b/chrome/browser/renderer_host/chrome_render_widget_host_view_mac_history_swiper_unit_test.mm |
| index dcd37e628b5d7a48bae705081bb1678bb65015f0..e37d7c0628ba1631cb79e4e72cd2bfb6b1793ab9 100644 |
| --- a/chrome/browser/renderer_host/chrome_render_widget_host_view_mac_history_swiper_unit_test.mm |
| +++ b/chrome/browser/renderer_host/chrome_render_widget_host_view_mac_history_swiper_unit_test.mm |
| @@ -90,6 +90,7 @@ class MacHistorySwiperTest : public CocoaTest { |
| CocoaTest::TearDown(); |
| } |
| + // These methods send all 3 types of events: gesture, scroll, and touch. |
| void startGestureInMiddle(); |
| void moveGestureInMiddle(); |
| void moveGestureAtPoint(NSPoint point); |
| @@ -97,6 +98,10 @@ class MacHistorySwiperTest : public CocoaTest { |
| void endGestureAtPoint(NSPoint point); |
| void rendererACKForBeganEvent(); |
| + // These methods send a single type of event. |
| + void sendBeginGestureEventInMiddle(); |
| + void sendEndGestureEventAtPoint(NSPoint point); |
| + |
| HistorySwiper* historySwiper_; |
| NSView* view_; |
| int begin_count_; |
| @@ -189,6 +194,8 @@ void MacHistorySwiperTest::endGestureAtPoint(NSPoint point) { |
| NSEvent* scrollEvent = scrollWheelEventWithPhase(NSEventPhaseEnded); |
| [historySwiper_ handleEvent:scrollEvent]; |
| + |
| + sendEndGestureEventAtPoint(point); |
| } |
| void MacHistorySwiperTest::rendererACKForBeganEvent() { |
| @@ -197,6 +204,16 @@ void MacHistorySwiperTest::rendererACKForBeganEvent() { |
| [historySwiper_ rendererHandledWheelEvent:event consumed:NO]; |
| } |
| +void MacHistorySwiperTest::sendBeginGestureEventInMiddle() { |
| + NSEvent* event = mockEventWithPoint(makePoint(0.5, 0.5), NSEventTypeGesture); |
| + [historySwiper_ beginGestureWithEvent:event]; |
| +} |
| + |
| +void MacHistorySwiperTest::sendEndGestureEventAtPoint(NSPoint point) { |
| + NSEvent* event = mockEventWithPoint(point, NSEventTypeGesture); |
| + [historySwiper_ endGestureWithEvent:event]; |
| +} |
| + |
| // Test that a simple left-swipe causes navigation. |
| TEST_F(MacHistorySwiperTest, SwipeLeft) { |
| // These tests require 10.7+ APIs. |
| @@ -472,3 +489,59 @@ TEST_F(MacHistorySwiperTest, SubstantialVerticalThenHorizontal) { |
| EXPECT_FALSE(navigated_right_); |
| EXPECT_FALSE(navigated_left_); |
| } |
| + |
| +// Magic Mouse gestures don't send -touches*WithEvent: callbacks. The history |
| +// swiper should still handle this gracefully. It should not turn vertical |
| +// motion into history swipes. |
| +TEST_F(MacHistorySwiperTest, MagicMouseStateResetsCorrectly) { |
| + // These tests require 10.7+ APIs. |
|
Lei Zhang
2015/01/15 20:18:10
Don't the official bots use the 10.6 SDK or someth
erikchen
2015/01/15 20:44:44
The binary is built with the 10.6 SDK, but this is
|
| + if (![NSEvent |
| + respondsToSelector:@selector(isSwipeTrackingFromScrollEventsEnabled)]) |
| + return; |
| + |
| + // Magic mouse events don't generate '-touches*WithEvent:' callbacks. |
| + // Send the following events: |
| + // - beginGesture |
| + // - scrollWheel: (phase=Began) |
| + // - scrollWheel: (phase=Changed), significant horizontal motion. |
| + // - scrollWheel: (phase=Ended) |
| + // - endGesture |
| + sendBeginGestureEventInMiddle(); |
| + [historySwiper_ handleEvent:scrollWheelEventWithPhase(NSEventPhaseBegan)]; |
| + |
| + // Callback from Blink to set the relevant state for history swiping. |
| + rendererACKForBeganEvent(); |
| + |
| + NSEvent* scrollEvent = scrollWheelEventWithPhase(NSEventPhaseChanged, |
| + NSEventPhaseNone, 200.0, 0); |
| + [historySwiper_ handleEvent:scrollEvent]; |
| + [historySwiper_ handleEvent:scrollWheelEventWithPhase(NSEventPhaseEnded)]; |
| + sendEndGestureEventAtPoint(makePoint(0.7, 0.5)); |
| + |
| + // Expect this sequence of events to trigger a magic mouse history swipe. |
| + EXPECT_TRUE(magic_mouse_history_swipe_); |
| + |
| + // Reset state. |
| + magic_mouse_history_swipe_ = false; |
| + |
| + // Send the following events: |
| + // - beginGesture |
| + // - scrollWheel: (phase=Began) |
| + // - scrollWheel: (phase=Changed), significant vertical motion. |
| + // - scrollWheel: (phase=Ended) |
| + // - endGesture |
| + sendBeginGestureEventInMiddle(); |
| + [historySwiper_ handleEvent:scrollWheelEventWithPhase(NSEventPhaseBegan)]; |
| + |
| + // Callback from Blink to set the relevant state for history swiping. |
| + rendererACKForBeganEvent(); |
| + |
| + scrollEvent = |
| + scrollWheelEventWithPhase(NSEventPhaseChanged, NSEventPhaseNone, 0, 20); |
| + [historySwiper_ handleEvent:scrollEvent]; |
| + [historySwiper_ handleEvent:scrollWheelEventWithPhase(NSEventPhaseEnded)]; |
| + sendEndGestureEventAtPoint(makePoint(0.5, 0.7)); |
| + |
| + // Vertical motion should never trigger a history swipe! |
| + EXPECT_FALSE(magic_mouse_history_swipe_); |
| +} |