| 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/command_line.h" | 5 #include "base/command_line.h" |
| 6 #include "base/logging.h" | 6 #include "base/logging.h" |
| 7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "content/browser/frame_host/cross_site_transferring_request.h" | 8 #include "content/browser/frame_host/cross_site_transferring_request.h" |
| 9 #include "content/browser/frame_host/interstitial_page_impl.h" | 9 #include "content/browser/frame_host/interstitial_page_impl.h" |
| 10 #include "content/browser/frame_host/navigation_entry_impl.h" | 10 #include "content/browser/frame_host/navigation_entry_impl.h" |
| (...skipping 2615 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2626 // two-finger-scrolling on a touchpad. | 2626 // two-finger-scrolling on a touchpad. |
| 2627 modifiers = WebInputEvent::ControlKey; | 2627 modifiers = WebInputEvent::ControlKey; |
| 2628 event = SyntheticWebMouseWheelEventBuilder::Build(0, 5, modifiers, true); | 2628 event = SyntheticWebMouseWheelEventBuilder::Build(0, 5, modifiers, true); |
| 2629 EXPECT_FALSE(contents()->HandleWheelEvent(event)); | 2629 EXPECT_FALSE(contents()->HandleWheelEvent(event)); |
| 2630 EXPECT_EQ(0, delegate->GetAndResetContentsZoomChangedCallCount()); | 2630 EXPECT_EQ(0, delegate->GetAndResetContentsZoomChangedCallCount()); |
| 2631 | 2631 |
| 2632 // Ensure pointers to the delegate aren't kept beyond its lifetime. | 2632 // Ensure pointers to the delegate aren't kept beyond its lifetime. |
| 2633 contents()->SetDelegate(NULL); | 2633 contents()->SetDelegate(NULL); |
| 2634 } | 2634 } |
| 2635 | 2635 |
| 2636 // Tests that trackpad GesturePinchUpdate events get turned into browser zoom. | |
| 2637 TEST_F(WebContentsImplTest, HandleGestureEvent) { | |
| 2638 using blink::WebGestureEvent; | |
| 2639 using blink::WebInputEvent; | |
| 2640 | |
| 2641 scoped_ptr<ContentsZoomChangedDelegate> delegate( | |
| 2642 new ContentsZoomChangedDelegate()); | |
| 2643 contents()->SetDelegate(delegate.get()); | |
| 2644 | |
| 2645 const float kZoomStepValue = 0.6f; | |
| 2646 blink::WebGestureEvent event = SyntheticWebGestureEventBuilder::Build( | |
| 2647 WebInputEvent::GesturePinchUpdate, blink::WebGestureDeviceTouchpad); | |
| 2648 | |
| 2649 // A pinch less than the step value doesn't change the zoom level. | |
| 2650 event.data.pinchUpdate.scale = 1.0f + kZoomStepValue * 0.8f; | |
| 2651 EXPECT_TRUE(contents()->HandleGestureEvent(event)); | |
| 2652 EXPECT_EQ(0, delegate->GetAndResetContentsZoomChangedCallCount()); | |
| 2653 | |
| 2654 // But repeating the event so the combined scale is greater does. | |
| 2655 EXPECT_TRUE(contents()->HandleGestureEvent(event)); | |
| 2656 EXPECT_EQ(1, delegate->GetAndResetContentsZoomChangedCallCount()); | |
| 2657 EXPECT_TRUE(delegate->last_zoom_in()); | |
| 2658 | |
| 2659 // Pinching back out one step goes back to 100%. | |
| 2660 event.data.pinchUpdate.scale = 1.0f - kZoomStepValue; | |
| 2661 EXPECT_TRUE(contents()->HandleGestureEvent(event)); | |
| 2662 EXPECT_EQ(1, delegate->GetAndResetContentsZoomChangedCallCount()); | |
| 2663 EXPECT_FALSE(delegate->last_zoom_in()); | |
| 2664 | |
| 2665 // Pinching out again doesn't zoom (step is twice as large around 100%). | |
| 2666 EXPECT_TRUE(contents()->HandleGestureEvent(event)); | |
| 2667 EXPECT_EQ(0, delegate->GetAndResetContentsZoomChangedCallCount()); | |
| 2668 | |
| 2669 // And again now it zooms once per step. | |
| 2670 EXPECT_TRUE(contents()->HandleGestureEvent(event)); | |
| 2671 EXPECT_EQ(1, delegate->GetAndResetContentsZoomChangedCallCount()); | |
| 2672 EXPECT_FALSE(delegate->last_zoom_in()); | |
| 2673 | |
| 2674 // No other type of gesture event is handled by WebContentsImpl (for example | |
| 2675 // a touchscreen pinch gesture). | |
| 2676 event = SyntheticWebGestureEventBuilder::Build( | |
| 2677 WebInputEvent::GesturePinchUpdate, blink::WebGestureDeviceTouchscreen); | |
| 2678 event.data.pinchUpdate.scale = 1.0f + kZoomStepValue * 3; | |
| 2679 EXPECT_FALSE(contents()->HandleGestureEvent(event)); | |
| 2680 EXPECT_EQ(0, delegate->GetAndResetContentsZoomChangedCallCount()); | |
| 2681 | |
| 2682 // Ensure pointers to the delegate aren't kept beyond it's lifetime. | |
| 2683 contents()->SetDelegate(NULL); | |
| 2684 } | |
| 2685 | |
| 2686 // Tests that GetRelatedActiveContentsCount is shared between related | 2636 // Tests that GetRelatedActiveContentsCount is shared between related |
| 2687 // SiteInstances and includes WebContents that have not navigated yet. | 2637 // SiteInstances and includes WebContents that have not navigated yet. |
| 2688 TEST_F(WebContentsImplTest, ActiveContentsCountBasic) { | 2638 TEST_F(WebContentsImplTest, ActiveContentsCountBasic) { |
| 2689 scoped_refptr<SiteInstance> instance1( | 2639 scoped_refptr<SiteInstance> instance1( |
| 2690 SiteInstance::CreateForURL(browser_context(), GURL("http://a.com"))); | 2640 SiteInstance::CreateForURL(browser_context(), GURL("http://a.com"))); |
| 2691 scoped_refptr<SiteInstance> instance2( | 2641 scoped_refptr<SiteInstance> instance2( |
| 2692 instance1->GetRelatedSiteInstance(GURL("http://b.com"))); | 2642 instance1->GetRelatedSiteInstance(GURL("http://b.com"))); |
| 2693 | 2643 |
| 2694 EXPECT_EQ(0u, instance1->GetRelatedActiveContentsCount()); | 2644 EXPECT_EQ(0u, instance1->GetRelatedActiveContentsCount()); |
| 2695 EXPECT_EQ(0u, instance2->GetRelatedActiveContentsCount()); | 2645 EXPECT_EQ(0u, instance2->GetRelatedActiveContentsCount()); |
| (...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3070 frame->SendBeforeUnloadHandlersPresent(false); | 3020 frame->SendBeforeUnloadHandlersPresent(false); |
| 3071 EXPECT_FALSE(frame->SuddenTerminationAllowed()); | 3021 EXPECT_FALSE(frame->SuddenTerminationAllowed()); |
| 3072 frame->SendBeforeUnloadHandlersPresent(true); | 3022 frame->SendBeforeUnloadHandlersPresent(true); |
| 3073 frame->SendUnloadHandlersPresent(false); | 3023 frame->SendUnloadHandlersPresent(false); |
| 3074 EXPECT_FALSE(frame->SuddenTerminationAllowed()); | 3024 EXPECT_FALSE(frame->SuddenTerminationAllowed()); |
| 3075 frame->SendBeforeUnloadHandlersPresent(false); | 3025 frame->SendBeforeUnloadHandlersPresent(false); |
| 3076 EXPECT_TRUE(frame->SuddenTerminationAllowed()); | 3026 EXPECT_TRUE(frame->SuddenTerminationAllowed()); |
| 3077 } | 3027 } |
| 3078 | 3028 |
| 3079 } // namespace content | 3029 } // namespace content |
| OLD | NEW |