// Copyright 2018 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 "third_party/blink/renderer/modules/accessibility/ax_range.h" #include "testing/gtest/include/gtest/gtest.h" #include "third_party/blink/renderer/modules/accessibility/ax_object.h" #include "third_party/blink/renderer/modules/accessibility/ax_position.h" #include "third_party/blink/renderer/modules/accessibility/testing/accessibility_test.h" namespace blink { namespace test { TEST_F(AccessibilityTest, CommonAncestorContainerOfRange) { SetBodyInnerHTML(R"HTML(" R"
hello
there
hello there
)HTML"); const AXObject* paragraph = GetAXObjectByElementId("paragraph"); ASSERT_NE(nullptr, paragraph); const AXObject* text = paragraph->FirstChild(); ASSERT_NE(nullptr, text); ASSERT_EQ(ax::mojom::Role::kStaticText, text->RoleValue()); const AXRange paragraph_range( AXPosition::CreateLastPositionInObject(*paragraph), AXPosition::CreateLastPositionInObject(*paragraph)); const AXRange text_range(AXPosition::CreateLastPositionInObject(*text), AXPosition::CreateLastPositionInObject(*text)); EXPECT_TRUE(paragraph_range.IsCollapsed()); EXPECT_TRUE(text_range.IsCollapsed()); EXPECT_FALSE(AXRange::RangeOfContents(*paragraph).IsCollapsed()); } TEST_F(AccessibilityTest, RangeOfContents) { SetBodyInnerHTML(R"HTML(hello there
)HTML"); const AXObject* paragraph = GetAXObjectByElementId("paragraph"); ASSERT_NE(nullptr, paragraph); const AXRange paragraph_range = AXRange::RangeOfContents(*paragraph); EXPECT_EQ(AXPosition::CreateFirstPositionInObject(*paragraph), paragraph_range.Start()); EXPECT_EQ(AXPosition::CreateLastPositionInObject(*paragraph), paragraph_range.End()); } } // namespace test } // namespace blink