| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2016 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/editing/SelectionTemplate.h" |
| 6 |
| 7 #include "core/editing/EditingTestBase.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 |
| 10 namespace blink { |
| 11 |
| 12 class SelectionTest : public EditingTestBase {}; |
| 13 |
| 14 TEST_F(SelectionTest, defaultConstructor) { |
| 15 SelectionInDOMTree selection; |
| 16 |
| 17 EXPECT_EQ(TextAffinity::Downstream, selection.affinity()); |
| 18 EXPECT_EQ(CharacterGranularity, selection.granularity()); |
| 19 EXPECT_FALSE(selection.hasTrailingWhitespace()); |
| 20 EXPECT_FALSE(selection.isDirectional()); |
| 21 EXPECT_TRUE(selection.isNone()); |
| 22 EXPECT_EQ(Position(), selection.base()); |
| 23 EXPECT_EQ(Position(), selection.extent()); |
| 24 } |
| 25 |
| 26 TEST_F(SelectionTest, caret) { |
| 27 setBodyContent("<div id='sample'>abcdef</div>"); |
| 28 |
| 29 Element* sample = document().getElementById("sample"); |
| 30 Position position(Position(sample->firstChild(), 2)); |
| 31 SelectionInDOMTree::Builder builder; |
| 32 builder.collapse(position); |
| 33 const SelectionInDOMTree& selection = builder.build(); |
| 34 |
| 35 EXPECT_EQ(TextAffinity::Downstream, selection.affinity()); |
| 36 EXPECT_EQ(CharacterGranularity, selection.granularity()); |
| 37 EXPECT_FALSE(selection.hasTrailingWhitespace()); |
| 38 EXPECT_FALSE(selection.isDirectional()); |
| 39 EXPECT_FALSE(selection.isNone()); |
| 40 EXPECT_EQ(position, selection.base()); |
| 41 EXPECT_EQ(position, selection.extent()); |
| 42 } |
| 43 |
| 44 TEST_F(SelectionTest, range) { |
| 45 setBodyContent("<div id='sample'>abcdef</div>"); |
| 46 |
| 47 Element* sample = document().getElementById("sample"); |
| 48 Position base(Position(sample->firstChild(), 2)); |
| 49 Position extent(Position(sample->firstChild(), 4)); |
| 50 SelectionInDOMTree::Builder builder; |
| 51 builder.collapse(base); |
| 52 builder.extend(extent); |
| 53 const SelectionInDOMTree& selection = builder.build(); |
| 54 |
| 55 EXPECT_EQ(TextAffinity::Downstream, selection.affinity()); |
| 56 EXPECT_EQ(CharacterGranularity, selection.granularity()); |
| 57 EXPECT_FALSE(selection.hasTrailingWhitespace()); |
| 58 EXPECT_FALSE(selection.isDirectional()); |
| 59 EXPECT_FALSE(selection.isNone()); |
| 60 EXPECT_EQ(base, selection.base()); |
| 61 EXPECT_EQ(extent, selection.extent()); |
| 62 } |
| 63 |
| 64 } // namespace blink |
| OLD | NEW |