| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "core/dom/NodeComputedStyle.h" |
| 6 #include "core/layout/LayoutTestHelper.h" |
| 7 #include "platform/testing/RuntimeEnabledFeaturesTestHelpers.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 |
| 10 namespace blink { |
| 11 |
| 12 class StyleAdjusterTest : public RenderingTest { |
| 13 public: |
| 14 StyleAdjusterTest() : RenderingTest(SingleChildLocalFrameClient::Create()) {} |
| 15 }; |
| 16 |
| 17 TEST_F(StyleAdjusterTest, TouchActionPropagatedAcrossIframes) { |
| 18 GetDocument().SetBaseURLOverride(KURL(kParsedURLString, "http://test.com")); |
| 19 SetBodyInnerHTML( |
| 20 "<style>body { margin: 0; } iframe { display: block; } </style>" |
| 21 "<iframe id='owner' src='http://test.com' width='500' height='500' " |
| 22 "style='touch-action: none'>" |
| 23 "</iframe>"); |
| 24 SetChildFrameHTML( |
| 25 "<style>body { margin: 0; } #target { width: 200px; height: 200px; } " |
| 26 "</style>" |
| 27 "<div id='target' style='touch-action: pinch-zoom'></div>"); |
| 28 GetDocument().View()->UpdateAllLifecyclePhases(); |
| 29 |
| 30 Element* target = ChildDocument().getElementById("target"); |
| 31 EXPECT_EQ(TouchAction::kTouchActionNone, |
| 32 target->GetComputedStyle()->GetEffectiveTouchAction()); |
| 33 |
| 34 Element* owner = GetDocument().getElementById("owner"); |
| 35 owner->setAttribute(HTMLNames::styleAttr, "touch-action: auto"); |
| 36 GetDocument().View()->UpdateAllLifecyclePhases(); |
| 37 EXPECT_EQ(TouchAction::kTouchActionPinchZoom, |
| 38 target->GetComputedStyle()->GetEffectiveTouchAction()); |
| 39 } |
| 40 |
| 41 TEST_F(StyleAdjusterTest, TouchActionPanningReEnabledByScrollers) { |
| 42 GetDocument().SetBaseURLOverride(KURL(kParsedURLString, "http://test.com")); |
| 43 SetBodyInnerHTML( |
| 44 "<style>#ancestor { margin: 0; touch-action: pinch-zoom; } " |
| 45 "#scroller { overflow: scroll; width: 100px; height: 100px; } " |
| 46 "#target { width: 200px; height: 200px; } </style>" |
| 47 "<div id='ancestor'><div id='scroller'><div id='target'>" |
| 48 "</div></div></div>"); |
| 49 GetDocument().View()->UpdateAllLifecyclePhases(); |
| 50 |
| 51 Element* target = GetDocument().getElementById("target"); |
| 52 EXPECT_EQ(TouchAction::kTouchActionManipulation, |
| 53 target->GetComputedStyle()->GetEffectiveTouchAction()); |
| 54 } |
| 55 |
| 56 TEST_F(StyleAdjusterTest, TouchActionPropagatedWhenAncestorStyleChanges) { |
| 57 GetDocument().SetBaseURLOverride(KURL(kParsedURLString, "http://test.com")); |
| 58 SetBodyInnerHTML( |
| 59 "<style>#ancestor { margin: 0; touch-action: pan-x; } " |
| 60 "#potential-scroller { width: 100px; height: 100px; overflow: hidden; } " |
| 61 "#target { width: 200px; height: 200px; }</style>" |
| 62 "<div id='ancestor'><div id='potential-scroller'><div id='target'>" |
| 63 "</div></div></div>"); |
| 64 GetDocument().View()->UpdateAllLifecyclePhases(); |
| 65 |
| 66 Element* target = GetDocument().getElementById("target"); |
| 67 EXPECT_EQ(TouchAction::kTouchActionPanX, |
| 68 target->GetComputedStyle()->GetEffectiveTouchAction()); |
| 69 |
| 70 Element* ancestor = GetDocument().getElementById("ancestor"); |
| 71 ancestor->setAttribute(HTMLNames::styleAttr, "touch-action: pan-y"); |
| 72 GetDocument().View()->UpdateAllLifecyclePhases(); |
| 73 EXPECT_EQ(TouchAction::kTouchActionPanY, |
| 74 target->GetComputedStyle()->GetEffectiveTouchAction()); |
| 75 |
| 76 Element* potential_scroller = |
| 77 GetDocument().getElementById("potential-scroller"); |
| 78 potential_scroller->setAttribute(HTMLNames::styleAttr, "overflow: scroll"); |
| 79 GetDocument().View()->UpdateAllLifecyclePhases(); |
| 80 EXPECT_EQ(TouchAction::kTouchActionPan, |
| 81 target->GetComputedStyle()->GetEffectiveTouchAction()); |
| 82 } |
| 83 |
| 84 TEST_F(StyleAdjusterTest, TouchActionRestrictedByLowerAncestor) { |
| 85 GetDocument().SetBaseURLOverride(KURL(kParsedURLString, "http://test.com")); |
| 86 SetBodyInnerHTML( |
| 87 "<div id='ancestor' style='touch-action: pan'>" |
| 88 "<div id='parent' style='touch-action: pan-right pan-y'>" |
| 89 "<div id='target' style='touch-action: pan-x'>" |
| 90 "</div></div></div>"); |
| 91 GetDocument().View()->UpdateAllLifecyclePhases(); |
| 92 |
| 93 Element* target = GetDocument().getElementById("target"); |
| 94 EXPECT_EQ(TouchAction::kTouchActionPanRight, |
| 95 target->GetComputedStyle()->GetEffectiveTouchAction()); |
| 96 |
| 97 Element* parent = GetDocument().getElementById("parent"); |
| 98 parent->setAttribute(HTMLNames::styleAttr, "touch-action: auto"); |
| 99 GetDocument().View()->UpdateAllLifecyclePhases(); |
| 100 EXPECT_EQ(TouchAction::kTouchActionPanX, |
| 101 target->GetComputedStyle()->GetEffectiveTouchAction()); |
| 102 } |
| 103 } // namespace blink |
| OLD | NEW |