OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 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 "core/editing/EphemeralRange.h" | 5 #include "core/editing/EphemeralRange.h" |
6 | 6 |
7 #include "core/dom/Range.h" | 7 #include "core/dom/Range.h" |
8 #include "core/editing/EditingTestBase.h" | 8 #include "core/editing/EditingTestBase.h" |
9 #include <sstream> | 9 #include <sstream> |
10 | 10 |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 | 92 |
93 // Limit a range and check that it will be traversed correctly. | 93 // Limit a range and check that it will be traversed correctly. |
94 TEST_F(EphemeralRangeTest, rangeTraversalLimited) { | 94 TEST_F(EphemeralRangeTest, rangeTraversalLimited) { |
95 const char* bodyContent = | 95 const char* bodyContent = |
96 "<p id='host'><b id='one'></b><input type='text' value='some'><span " | 96 "<p id='host'><b id='one'></b><input type='text' value='some'><span " |
97 "id='two'></p>"; | 97 "id='two'></p>"; |
98 setBodyContent(bodyContent); | 98 setBodyContent(bodyContent); |
99 | 99 |
100 // Get a limited range from <body> to <b> nodes. | 100 // Get a limited range from <body> to <b> nodes. |
101 Range* untilB = getBodyRange(); | 101 Range* untilB = getBodyRange(); |
102 untilB->setEnd(document().getElementById("one"), 0, IGNORE_EXCEPTION); | 102 untilB->setEnd(document().getElementById("one"), 0, |
| 103 IGNORE_EXCEPTION_FOR_TESTING); |
103 EXPECT_EQ("[BODY][P id=\"host\"][B id=\"one\"]", traverseRange<>(untilB)); | 104 EXPECT_EQ("[BODY][P id=\"host\"][B id=\"one\"]", traverseRange<>(untilB)); |
104 | 105 |
105 EXPECT_EQ(traverseRange<>(untilB), traverseRange(EphemeralRange(untilB))); | 106 EXPECT_EQ(traverseRange<>(untilB), traverseRange(EphemeralRange(untilB))); |
106 | 107 |
107 EXPECT_EQ("[BODY][P id=\"host\"][B id=\"one\"]", | 108 EXPECT_EQ("[BODY][P id=\"host\"][B id=\"one\"]", |
108 traverseRange<FlatTreeTraversal>(untilB)); | 109 traverseRange<FlatTreeTraversal>(untilB)); |
109 EXPECT_EQ(traverseRange<FlatTreeTraversal>(untilB), | 110 EXPECT_EQ(traverseRange<FlatTreeTraversal>(untilB), |
110 traverseRange(EphemeralRangeInFlatTree(untilB))); | 111 traverseRange(EphemeralRangeInFlatTree(untilB))); |
111 | 112 |
112 // Get a limited range from <b> to <span> nodes. | 113 // Get a limited range from <b> to <span> nodes. |
113 Range* fromBToSpan = getBodyRange(); | 114 Range* fromBToSpan = getBodyRange(); |
114 fromBToSpan->setStart(document().getElementById("one"), 0, IGNORE_EXCEPTION); | 115 fromBToSpan->setStart(document().getElementById("one"), 0, |
115 fromBToSpan->setEnd(document().getElementById("two"), 0, IGNORE_EXCEPTION); | 116 IGNORE_EXCEPTION_FOR_TESTING); |
| 117 fromBToSpan->setEnd(document().getElementById("two"), 0, |
| 118 IGNORE_EXCEPTION_FOR_TESTING); |
116 | 119 |
117 EXPECT_EQ("[B id=\"one\"][INPUT][SPAN id=\"two\"]", | 120 EXPECT_EQ("[B id=\"one\"][INPUT][SPAN id=\"two\"]", |
118 traverseRange<>(fromBToSpan)); | 121 traverseRange<>(fromBToSpan)); |
119 EXPECT_EQ(traverseRange<>(fromBToSpan), | 122 EXPECT_EQ(traverseRange<>(fromBToSpan), |
120 traverseRange(EphemeralRange(fromBToSpan))); | 123 traverseRange(EphemeralRange(fromBToSpan))); |
121 | 124 |
122 EXPECT_EQ( | 125 EXPECT_EQ( |
123 "[B id=\"one\"][INPUT][DIV id=\"inner-editor\" (editable)][#text " | 126 "[B id=\"one\"][INPUT][DIV id=\"inner-editor\" (editable)][#text " |
124 "\"some\"][SPAN id=\"two\"]", | 127 "\"some\"][SPAN id=\"two\"]", |
125 traverseRange<FlatTreeTraversal>(fromBToSpan)); | 128 traverseRange<FlatTreeTraversal>(fromBToSpan)); |
(...skipping 13 matching lines...) Expand all Loading... |
139 EXPECT_FALSE(iterable.begin() != iterable.end()); | 142 EXPECT_FALSE(iterable.begin() != iterable.end()); |
140 | 143 |
141 const EphemeralRange singlePositionRange(getBodyRange()->startPosition()); | 144 const EphemeralRange singlePositionRange(getBodyRange()->startPosition()); |
142 EXPECT_FALSE(singlePositionRange.isNull()); | 145 EXPECT_FALSE(singlePositionRange.isNull()); |
143 EXPECT_EQ(std::string(), traverseRange(singlePositionRange)); | 146 EXPECT_EQ(std::string(), traverseRange(singlePositionRange)); |
144 EXPECT_EQ(singlePositionRange.startPosition().nodeAsRangeFirstNode(), | 147 EXPECT_EQ(singlePositionRange.startPosition().nodeAsRangeFirstNode(), |
145 singlePositionRange.endPosition().nodeAsRangePastLastNode()); | 148 singlePositionRange.endPosition().nodeAsRangePastLastNode()); |
146 } | 149 } |
147 | 150 |
148 } // namespace blink | 151 } // namespace blink |
OLD | NEW |