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 "base/logging.h" | 5 #include "base/logging.h" |
6 #include "base/strings/utf_string_conversions.h" | 6 #include "base/strings/utf_string_conversions.h" |
7 #include "content/browser/frame_host/cross_site_transferring_request.h" | 7 #include "content/browser/frame_host/cross_site_transferring_request.h" |
8 #include "content/browser/frame_host/interstitial_page_impl.h" | 8 #include "content/browser/frame_host/interstitial_page_impl.h" |
9 #include "content/browser/frame_host/navigation_entry_impl.h" | 9 #include "content/browser/frame_host/navigation_entry_impl.h" |
10 #include "content/browser/renderer_host/render_view_host_impl.h" | 10 #include "content/browser/renderer_host/render_view_host_impl.h" |
(...skipping 2412 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2423 // Unless there is no vertical movement. | 2423 // Unless there is no vertical movement. |
2424 dy = 0; | 2424 dy = 0; |
2425 event = SyntheticWebMouseWheelEventBuilder::Build(2, dy, modifiers, false); | 2425 event = SyntheticWebMouseWheelEventBuilder::Build(2, dy, modifiers, false); |
2426 EXPECT_FALSE(contents()->HandleWheelEvent(event)); | 2426 EXPECT_FALSE(contents()->HandleWheelEvent(event)); |
2427 EXPECT_EQ(0, delegate->GetAndResetContentsZoomChangedCallCount()); | 2427 EXPECT_EQ(0, delegate->GetAndResetContentsZoomChangedCallCount()); |
2428 | 2428 |
2429 // Ensure pointers to the delegate aren't kept beyond it's lifetime. | 2429 // Ensure pointers to the delegate aren't kept beyond it's lifetime. |
2430 contents()->SetDelegate(NULL); | 2430 contents()->SetDelegate(NULL); |
2431 } | 2431 } |
2432 | 2432 |
| 2433 // Tests that trackpad GesturePinchUpdate events get turned into browser zoom. |
| 2434 TEST_F(WebContentsImplTest, HandleGestureEvent) { |
| 2435 using blink::WebGestureEvent; |
| 2436 using blink::WebInputEvent; |
| 2437 |
| 2438 scoped_ptr<ContentsZoomChangedDelegate> delegate( |
| 2439 new ContentsZoomChangedDelegate()); |
| 2440 contents()->SetDelegate(delegate.get()); |
| 2441 |
| 2442 const float kZoomStepValue = 0.6f; |
| 2443 blink::WebGestureEvent event = SyntheticWebGestureEventBuilder::Build( |
| 2444 WebInputEvent::GesturePinchUpdate, WebGestureEvent::Touchpad); |
| 2445 |
| 2446 // A pinch less than the step value doesn't change the zoom level. |
| 2447 event.data.pinchUpdate.scale = kZoomStepValue * 0.8f; |
| 2448 EXPECT_TRUE(contents()->HandleGestureEvent(event)); |
| 2449 EXPECT_EQ(0, delegate->GetAndResetContentsZoomChangedCallCount()); |
| 2450 |
| 2451 // But repeating the event so the combined scale is greater does. |
| 2452 EXPECT_TRUE(contents()->HandleGestureEvent(event)); |
| 2453 EXPECT_EQ(1, delegate->GetAndResetContentsZoomChangedCallCount()); |
| 2454 EXPECT_TRUE(delegate->last_zoom_in()); |
| 2455 |
| 2456 // Pinching back out one step goes back to 100%. |
| 2457 event.data.pinchUpdate.scale = -kZoomStepValue; |
| 2458 EXPECT_TRUE(contents()->HandleGestureEvent(event)); |
| 2459 EXPECT_EQ(1, delegate->GetAndResetContentsZoomChangedCallCount()); |
| 2460 EXPECT_FALSE(delegate->last_zoom_in()); |
| 2461 |
| 2462 // Pinching out again doesn't zoom (step is twice as large around 100%). |
| 2463 EXPECT_TRUE(contents()->HandleGestureEvent(event)); |
| 2464 EXPECT_EQ(0, delegate->GetAndResetContentsZoomChangedCallCount()); |
| 2465 |
| 2466 // And again now it zooms once per step. |
| 2467 EXPECT_TRUE(contents()->HandleGestureEvent(event)); |
| 2468 EXPECT_EQ(1, delegate->GetAndResetContentsZoomChangedCallCount()); |
| 2469 EXPECT_FALSE(delegate->last_zoom_in()); |
| 2470 |
| 2471 // No other type of gesture event is handled by WebContentsImpl (for example |
| 2472 // a touchscreen pinch gesture). |
| 2473 event = SyntheticWebGestureEventBuilder::Build( |
| 2474 WebInputEvent::GesturePinchUpdate, WebGestureEvent::Touchscreen); |
| 2475 event.data.pinchUpdate.scale = kZoomStepValue * 3; |
| 2476 EXPECT_FALSE(contents()->HandleGestureEvent(event)); |
| 2477 EXPECT_EQ(0, delegate->GetAndResetContentsZoomChangedCallCount()); |
| 2478 |
| 2479 // Ensure pointers to the delegate aren't kept beyond it's lifetime. |
| 2480 contents()->SetDelegate(NULL); |
| 2481 } |
| 2482 |
2433 } // namespace content | 2483 } // namespace content |
OLD | NEW |