blob: f2ed5f9c2df0df9ef414d10b6ad9e288cfc4baf4 [file] [log] [blame]
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/renderer/core/dom/node_computed_style.h"
#include "third_party/blink/renderer/core/testing/core_unit_test_helper.h"
#include "third_party/blink/renderer/platform/testing/runtime_enabled_features_test_helpers.h"
namespace blink {
class StyleAdjusterTest : public RenderingTest {
public:
StyleAdjusterTest()
: RenderingTest(MakeGarbageCollected<SingleChildLocalFrameClient>()) {}
};
TEST_F(StyleAdjusterTest, TouchActionPropagatedAcrossIframes) {
GetDocument().SetBaseURLOverride(KURL("http://test.com"));
SetBodyInnerHTML(R"HTML(
<style>body { margin: 0; } iframe { display: block; } </style>
<iframe id='owner' src='http://test.com' width='500' height='500'
style='touch-action: none'>
</iframe>
)HTML");
SetChildFrameHTML(R"HTML(
<style>body { margin: 0; } #target { width: 200px; height: 200px; }
</style>
<div id='target' style='touch-action: pinch-zoom'></div>
)HTML");
UpdateAllLifecyclePhasesForTest();
Element* target = ChildDocument().getElementById("target");
EXPECT_EQ(TouchAction::kTouchActionNone,
target->GetComputedStyle()->GetEffectiveTouchAction());
Element* owner = GetDocument().getElementById("owner");
owner->setAttribute(html_names::kStyleAttr, "touch-action: auto");
UpdateAllLifecyclePhasesForTest();
EXPECT_EQ(TouchAction::kTouchActionPinchZoom,
target->GetComputedStyle()->GetEffectiveTouchAction());
}
TEST_F(StyleAdjusterTest, TouchActionPanningReEnabledByScrollers) {
GetDocument().SetBaseURLOverride(KURL("http://test.com"));
SetBodyInnerHTML(R"HTML(
<style>#ancestor { margin: 0; touch-action: pinch-zoom; }
#scroller { overflow: scroll; width: 100px; height: 100px; }
#target { width: 200px; height: 200px; } </style>
<div id='ancestor'><div id='scroller'><div id='target'>
</div></div></div>
)HTML");
UpdateAllLifecyclePhasesForTest();
Element* target = GetDocument().getElementById("target");
EXPECT_EQ(TouchAction::kTouchActionManipulation,
target->GetComputedStyle()->GetEffectiveTouchAction());
}
TEST_F(StyleAdjusterTest, TouchActionPropagatedWhenAncestorStyleChanges) {
GetDocument().SetBaseURLOverride(KURL("http://test.com"));
SetBodyInnerHTML(R"HTML(
<style>#ancestor { margin: 0; touch-action: pan-x; }
#potential-scroller { width: 100px; height: 100px; overflow: hidden; }
#target { width: 200px; height: 200px; }</style>
<div id='ancestor'><div id='potential-scroller'><div id='target'>
</div></div></div>
)HTML");
UpdateAllLifecyclePhasesForTest();
Element* target = GetDocument().getElementById("target");
EXPECT_EQ(TouchAction::kTouchActionPanX,
target->GetComputedStyle()->GetEffectiveTouchAction());
Element* ancestor = GetDocument().getElementById("ancestor");
ancestor->setAttribute(html_names::kStyleAttr, "touch-action: pan-y");
UpdateAllLifecyclePhasesForTest();
EXPECT_EQ(TouchAction::kTouchActionPanY,
target->GetComputedStyle()->GetEffectiveTouchAction());
Element* potential_scroller =
GetDocument().getElementById("potential-scroller");
potential_scroller->setAttribute(html_names::kStyleAttr, "overflow: scroll");
UpdateAllLifecyclePhasesForTest();
EXPECT_EQ(TouchAction::kTouchActionPan,
target->GetComputedStyle()->GetEffectiveTouchAction());
}
TEST_F(StyleAdjusterTest, TouchActionRestrictedByLowerAncestor) {
GetDocument().SetBaseURLOverride(KURL("http://test.com"));
SetBodyInnerHTML(R"HTML(
<div id='ancestor' style='touch-action: pan'>
<div id='parent' style='touch-action: pan-right pan-y'>
<div id='target' style='touch-action: pan-x'>
</div></div></div>
)HTML");
UpdateAllLifecyclePhasesForTest();
Element* target = GetDocument().getElementById("target");
EXPECT_EQ(TouchAction::kTouchActionPanRight,
target->GetComputedStyle()->GetEffectiveTouchAction());
Element* parent = GetDocument().getElementById("parent");
parent->setAttribute(html_names::kStyleAttr, "touch-action: auto");
UpdateAllLifecyclePhasesForTest();
EXPECT_EQ(TouchAction::kTouchActionPanX,
target->GetComputedStyle()->GetEffectiveTouchAction());
}
} // namespace blink