| 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 2478 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2489 TEST_F(WebContentsImplTest, HandleGestureEvent) { | 2489 TEST_F(WebContentsImplTest, HandleGestureEvent) { |
| 2490 using blink::WebGestureEvent; | 2490 using blink::WebGestureEvent; |
| 2491 using blink::WebInputEvent; | 2491 using blink::WebInputEvent; |
| 2492 | 2492 |
| 2493 scoped_ptr<ContentsZoomChangedDelegate> delegate( | 2493 scoped_ptr<ContentsZoomChangedDelegate> delegate( |
| 2494 new ContentsZoomChangedDelegate()); | 2494 new ContentsZoomChangedDelegate()); |
| 2495 contents()->SetDelegate(delegate.get()); | 2495 contents()->SetDelegate(delegate.get()); |
| 2496 | 2496 |
| 2497 const float kZoomStepValue = 0.6f; | 2497 const float kZoomStepValue = 0.6f; |
| 2498 blink::WebGestureEvent event = SyntheticWebGestureEventBuilder::Build( | 2498 blink::WebGestureEvent event = SyntheticWebGestureEventBuilder::Build( |
| 2499 WebInputEvent::GesturePinchUpdate, WebGestureEvent::Touchpad); | 2499 WebInputEvent::GesturePinchUpdate, blink::WebGestureDeviceTouchpad); |
| 2500 | 2500 |
| 2501 // A pinch less than the step value doesn't change the zoom level. | 2501 // A pinch less than the step value doesn't change the zoom level. |
| 2502 event.data.pinchUpdate.scale = 1.0f + kZoomStepValue * 0.8f; | 2502 event.data.pinchUpdate.scale = 1.0f + kZoomStepValue * 0.8f; |
| 2503 EXPECT_TRUE(contents()->HandleGestureEvent(event)); | 2503 EXPECT_TRUE(contents()->HandleGestureEvent(event)); |
| 2504 EXPECT_EQ(0, delegate->GetAndResetContentsZoomChangedCallCount()); | 2504 EXPECT_EQ(0, delegate->GetAndResetContentsZoomChangedCallCount()); |
| 2505 | 2505 |
| 2506 // But repeating the event so the combined scale is greater does. | 2506 // But repeating the event so the combined scale is greater does. |
| 2507 EXPECT_TRUE(contents()->HandleGestureEvent(event)); | 2507 EXPECT_TRUE(contents()->HandleGestureEvent(event)); |
| 2508 EXPECT_EQ(1, delegate->GetAndResetContentsZoomChangedCallCount()); | 2508 EXPECT_EQ(1, delegate->GetAndResetContentsZoomChangedCallCount()); |
| 2509 EXPECT_TRUE(delegate->last_zoom_in()); | 2509 EXPECT_TRUE(delegate->last_zoom_in()); |
| 2510 | 2510 |
| 2511 // Pinching back out one step goes back to 100%. | 2511 // Pinching back out one step goes back to 100%. |
| 2512 event.data.pinchUpdate.scale = 1.0f - kZoomStepValue; | 2512 event.data.pinchUpdate.scale = 1.0f - kZoomStepValue; |
| 2513 EXPECT_TRUE(contents()->HandleGestureEvent(event)); | 2513 EXPECT_TRUE(contents()->HandleGestureEvent(event)); |
| 2514 EXPECT_EQ(1, delegate->GetAndResetContentsZoomChangedCallCount()); | 2514 EXPECT_EQ(1, delegate->GetAndResetContentsZoomChangedCallCount()); |
| 2515 EXPECT_FALSE(delegate->last_zoom_in()); | 2515 EXPECT_FALSE(delegate->last_zoom_in()); |
| 2516 | 2516 |
| 2517 // Pinching out again doesn't zoom (step is twice as large around 100%). | 2517 // Pinching out again doesn't zoom (step is twice as large around 100%). |
| 2518 EXPECT_TRUE(contents()->HandleGestureEvent(event)); | 2518 EXPECT_TRUE(contents()->HandleGestureEvent(event)); |
| 2519 EXPECT_EQ(0, delegate->GetAndResetContentsZoomChangedCallCount()); | 2519 EXPECT_EQ(0, delegate->GetAndResetContentsZoomChangedCallCount()); |
| 2520 | 2520 |
| 2521 // And again now it zooms once per step. | 2521 // And again now it zooms once per step. |
| 2522 EXPECT_TRUE(contents()->HandleGestureEvent(event)); | 2522 EXPECT_TRUE(contents()->HandleGestureEvent(event)); |
| 2523 EXPECT_EQ(1, delegate->GetAndResetContentsZoomChangedCallCount()); | 2523 EXPECT_EQ(1, delegate->GetAndResetContentsZoomChangedCallCount()); |
| 2524 EXPECT_FALSE(delegate->last_zoom_in()); | 2524 EXPECT_FALSE(delegate->last_zoom_in()); |
| 2525 | 2525 |
| 2526 // No other type of gesture event is handled by WebContentsImpl (for example | 2526 // No other type of gesture event is handled by WebContentsImpl (for example |
| 2527 // a touchscreen pinch gesture). | 2527 // a touchscreen pinch gesture). |
| 2528 event = SyntheticWebGestureEventBuilder::Build( | 2528 event = SyntheticWebGestureEventBuilder::Build( |
| 2529 WebInputEvent::GesturePinchUpdate, WebGestureEvent::Touchscreen); | 2529 WebInputEvent::GesturePinchUpdate, blink::WebGestureDeviceTouchscreen); |
| 2530 event.data.pinchUpdate.scale = 1.0f + kZoomStepValue * 3; | 2530 event.data.pinchUpdate.scale = 1.0f + kZoomStepValue * 3; |
| 2531 EXPECT_FALSE(contents()->HandleGestureEvent(event)); | 2531 EXPECT_FALSE(contents()->HandleGestureEvent(event)); |
| 2532 EXPECT_EQ(0, delegate->GetAndResetContentsZoomChangedCallCount()); | 2532 EXPECT_EQ(0, delegate->GetAndResetContentsZoomChangedCallCount()); |
| 2533 | 2533 |
| 2534 // Ensure pointers to the delegate aren't kept beyond it's lifetime. | 2534 // Ensure pointers to the delegate aren't kept beyond it's lifetime. |
| 2535 contents()->SetDelegate(NULL); | 2535 contents()->SetDelegate(NULL); |
| 2536 } | 2536 } |
| 2537 | 2537 |
| 2538 // Tests that GetRelatedActiveContentsCount is shared between related | 2538 // Tests that GetRelatedActiveContentsCount is shared between related |
| 2539 // SiteInstances and includes WebContents that have not navigated yet. | 2539 // SiteInstances and includes WebContents that have not navigated yet. |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2635 contents->CommitPendingNavigation(); | 2635 contents->CommitPendingNavigation(); |
| 2636 EXPECT_EQ(0u, instance->GetRelatedActiveContentsCount()); | 2636 EXPECT_EQ(0u, instance->GetRelatedActiveContentsCount()); |
| 2637 EXPECT_EQ(1u, instance_webui->GetRelatedActiveContentsCount()); | 2637 EXPECT_EQ(1u, instance_webui->GetRelatedActiveContentsCount()); |
| 2638 | 2638 |
| 2639 contents.reset(); | 2639 contents.reset(); |
| 2640 EXPECT_EQ(0u, instance->GetRelatedActiveContentsCount()); | 2640 EXPECT_EQ(0u, instance->GetRelatedActiveContentsCount()); |
| 2641 EXPECT_EQ(0u, instance_webui->GetRelatedActiveContentsCount()); | 2641 EXPECT_EQ(0u, instance_webui->GetRelatedActiveContentsCount()); |
| 2642 } | 2642 } |
| 2643 | 2643 |
| 2644 } // namespace content | 2644 } // namespace content |
| OLD | NEW |