| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "config.h" | 5 #include "config.h" |
| 6 #include "core/editing/VisibleSelection.h" | 6 #include "core/editing/VisibleSelection.h" |
| 7 | 7 |
| 8 #include "core/dom/Range.h" | 8 #include "core/dom/Range.h" |
| 9 #include "core/editing/EditingTestBase.h" | 9 #include "core/editing/EditingTestBase.h" |
| 10 | 10 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 TEST_F(VisibleSelectionTest, Initialisation) | 54 TEST_F(VisibleSelectionTest, Initialisation) |
| 55 { | 55 { |
| 56 setBodyContent(LOREM_IPSUM); | 56 setBodyContent(LOREM_IPSUM); |
| 57 | 57 |
| 58 VisibleSelection selection; | 58 VisibleSelection selection; |
| 59 setSelection(selection, 0); | 59 setSelection(selection, 0); |
| 60 | 60 |
| 61 EXPECT_FALSE(selection.isNone()); | 61 EXPECT_FALSE(selection.isNone()); |
| 62 EXPECT_TRUE(selection.isCaret()); | 62 EXPECT_TRUE(selection.isCaret()); |
| 63 | 63 |
| 64 RefPtrWillBeRawPtr<Range> range = selection.firstRange(); | 64 RefPtrWillBeRawPtr<Range> range = firstRangeOf(selection); |
| 65 EXPECT_EQ(0, range->startOffset()); | 65 EXPECT_EQ(0, range->startOffset()); |
| 66 EXPECT_EQ(0, range->endOffset()); | 66 EXPECT_EQ(0, range->endOffset()); |
| 67 EXPECT_EQ("", range->text()); | 67 EXPECT_EQ("", range->text()); |
| 68 testComposedTreePositionsToEqualToDOMTreePositions(selection); | 68 testComposedTreePositionsToEqualToDOMTreePositions(selection); |
| 69 } | 69 } |
| 70 | 70 |
| 71 TEST_F(VisibleSelectionTest, ShadowCrossing) | 71 TEST_F(VisibleSelectionTest, ShadowCrossing) |
| 72 { | 72 { |
| 73 const char* bodyContent = "<p id='host'>00<b id='one'>11</b><b id='two'>22</
b>33</p>"; | 73 const char* bodyContent = "<p id='host'>00<b id='one'>11</b><b id='two'>22</
b>33</p>"; |
| 74 const char* shadowContent = "<a><span id='s4'>44</span><content select=#two>
</content><span id='s5'>55</span><content select=#one></content><span id='s6'>66
</span></a>"; | 74 const char* shadowContent = "<a><span id='s4'>44</span><content select=#two>
</content><span id='s5'>55</span><content select=#one></content><span id='s6'>66
</span></a>"; |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 { | 134 { |
| 135 setBodyContent(LOREM_IPSUM); | 135 setBodyContent(LOREM_IPSUM); |
| 136 | 136 |
| 137 VisibleSelection selection; | 137 VisibleSelection selection; |
| 138 | 138 |
| 139 // Beginning of a word. | 139 // Beginning of a word. |
| 140 { | 140 { |
| 141 setSelection(selection, 0); | 141 setSelection(selection, 0); |
| 142 selection.expandUsingGranularity(WordGranularity); | 142 selection.expandUsingGranularity(WordGranularity); |
| 143 | 143 |
| 144 RefPtrWillBeRawPtr<Range> range = selection.firstRange(); | 144 RefPtrWillBeRawPtr<Range> range = firstRangeOf(selection); |
| 145 EXPECT_EQ(0, range->startOffset()); | 145 EXPECT_EQ(0, range->startOffset()); |
| 146 EXPECT_EQ(5, range->endOffset()); | 146 EXPECT_EQ(5, range->endOffset()); |
| 147 EXPECT_EQ("Lorem", range->text()); | 147 EXPECT_EQ("Lorem", range->text()); |
| 148 testComposedTreePositionsToEqualToDOMTreePositions(selection); | 148 testComposedTreePositionsToEqualToDOMTreePositions(selection); |
| 149 | 149 |
| 150 } | 150 } |
| 151 | 151 |
| 152 // Middle of a word. | 152 // Middle of a word. |
| 153 { | 153 { |
| 154 setSelection(selection, 8); | 154 setSelection(selection, 8); |
| 155 selection.expandUsingGranularity(WordGranularity); | 155 selection.expandUsingGranularity(WordGranularity); |
| 156 | 156 |
| 157 RefPtrWillBeRawPtr<Range> range = selection.firstRange(); | 157 RefPtrWillBeRawPtr<Range> range = firstRangeOf(selection); |
| 158 EXPECT_EQ(6, range->startOffset()); | 158 EXPECT_EQ(6, range->startOffset()); |
| 159 EXPECT_EQ(11, range->endOffset()); | 159 EXPECT_EQ(11, range->endOffset()); |
| 160 EXPECT_EQ("ipsum", range->text()); | 160 EXPECT_EQ("ipsum", range->text()); |
| 161 testComposedTreePositionsToEqualToDOMTreePositions(selection); | 161 testComposedTreePositionsToEqualToDOMTreePositions(selection); |
| 162 | 162 |
| 163 } | 163 } |
| 164 | 164 |
| 165 // End of a word. | 165 // End of a word. |
| 166 // FIXME: that sounds buggy, we might want to select the word _before_ inste
ad | 166 // FIXME: that sounds buggy, we might want to select the word _before_ inste
ad |
| 167 // of the space... | 167 // of the space... |
| 168 { | 168 { |
| 169 setSelection(selection, 5); | 169 setSelection(selection, 5); |
| 170 selection.expandUsingGranularity(WordGranularity); | 170 selection.expandUsingGranularity(WordGranularity); |
| 171 | 171 |
| 172 RefPtrWillBeRawPtr<Range> range = selection.firstRange(); | 172 RefPtrWillBeRawPtr<Range> range = firstRangeOf(selection); |
| 173 EXPECT_EQ(5, range->startOffset()); | 173 EXPECT_EQ(5, range->startOffset()); |
| 174 EXPECT_EQ(6, range->endOffset()); | 174 EXPECT_EQ(6, range->endOffset()); |
| 175 EXPECT_EQ(" ", range->text()); | 175 EXPECT_EQ(" ", range->text()); |
| 176 testComposedTreePositionsToEqualToDOMTreePositions(selection); | 176 testComposedTreePositionsToEqualToDOMTreePositions(selection); |
| 177 } | 177 } |
| 178 | 178 |
| 179 // Before comma. | 179 // Before comma. |
| 180 // FIXME: that sounds buggy, we might want to select the word _before_ inste
ad | 180 // FIXME: that sounds buggy, we might want to select the word _before_ inste
ad |
| 181 // of the comma. | 181 // of the comma. |
| 182 { | 182 { |
| 183 setSelection(selection, 26); | 183 setSelection(selection, 26); |
| 184 selection.expandUsingGranularity(WordGranularity); | 184 selection.expandUsingGranularity(WordGranularity); |
| 185 | 185 |
| 186 RefPtrWillBeRawPtr<Range> range = selection.firstRange(); | 186 RefPtrWillBeRawPtr<Range> range = firstRangeOf(selection); |
| 187 EXPECT_EQ(26, range->startOffset()); | 187 EXPECT_EQ(26, range->startOffset()); |
| 188 EXPECT_EQ(27, range->endOffset()); | 188 EXPECT_EQ(27, range->endOffset()); |
| 189 EXPECT_EQ(",", range->text()); | 189 EXPECT_EQ(",", range->text()); |
| 190 testComposedTreePositionsToEqualToDOMTreePositions(selection); | 190 testComposedTreePositionsToEqualToDOMTreePositions(selection); |
| 191 } | 191 } |
| 192 | 192 |
| 193 // After comma. | 193 // After comma. |
| 194 { | 194 { |
| 195 setSelection(selection, 27); | 195 setSelection(selection, 27); |
| 196 selection.expandUsingGranularity(WordGranularity); | 196 selection.expandUsingGranularity(WordGranularity); |
| 197 | 197 |
| 198 RefPtrWillBeRawPtr<Range> range = selection.firstRange(); | 198 RefPtrWillBeRawPtr<Range> range = firstRangeOf(selection); |
| 199 EXPECT_EQ(27, range->startOffset()); | 199 EXPECT_EQ(27, range->startOffset()); |
| 200 EXPECT_EQ(28, range->endOffset()); | 200 EXPECT_EQ(28, range->endOffset()); |
| 201 EXPECT_EQ(" ", range->text()); | 201 EXPECT_EQ(" ", range->text()); |
| 202 testComposedTreePositionsToEqualToDOMTreePositions(selection); | 202 testComposedTreePositionsToEqualToDOMTreePositions(selection); |
| 203 } | 203 } |
| 204 | 204 |
| 205 // When selecting part of a word. | 205 // When selecting part of a word. |
| 206 { | 206 { |
| 207 setSelection(selection, 0, 1); | 207 setSelection(selection, 0, 1); |
| 208 selection.expandUsingGranularity(WordGranularity); | 208 selection.expandUsingGranularity(WordGranularity); |
| 209 | 209 |
| 210 RefPtrWillBeRawPtr<Range> range = selection.firstRange(); | 210 RefPtrWillBeRawPtr<Range> range = firstRangeOf(selection); |
| 211 EXPECT_EQ(0, range->startOffset()); | 211 EXPECT_EQ(0, range->startOffset()); |
| 212 EXPECT_EQ(5, range->endOffset()); | 212 EXPECT_EQ(5, range->endOffset()); |
| 213 EXPECT_EQ("Lorem", range->text()); | 213 EXPECT_EQ("Lorem", range->text()); |
| 214 testComposedTreePositionsToEqualToDOMTreePositions(selection); | 214 testComposedTreePositionsToEqualToDOMTreePositions(selection); |
| 215 } | 215 } |
| 216 | 216 |
| 217 // When selecting part of two words. | 217 // When selecting part of two words. |
| 218 { | 218 { |
| 219 setSelection(selection, 2, 8); | 219 setSelection(selection, 2, 8); |
| 220 selection.expandUsingGranularity(WordGranularity); | 220 selection.expandUsingGranularity(WordGranularity); |
| 221 | 221 |
| 222 RefPtrWillBeRawPtr<Range> range = selection.firstRange(); | 222 RefPtrWillBeRawPtr<Range> range = firstRangeOf(selection); |
| 223 EXPECT_EQ(0, range->startOffset()); | 223 EXPECT_EQ(0, range->startOffset()); |
| 224 EXPECT_EQ(11, range->endOffset()); | 224 EXPECT_EQ(11, range->endOffset()); |
| 225 EXPECT_EQ("Lorem ipsum", range->text()); | 225 EXPECT_EQ("Lorem ipsum", range->text()); |
| 226 testComposedTreePositionsToEqualToDOMTreePositions(selection); | 226 testComposedTreePositionsToEqualToDOMTreePositions(selection); |
| 227 } | 227 } |
| 228 } | 228 } |
| 229 | 229 |
| 230 } // namespace blink | 230 } // namespace blink |
| OLD | NEW |