Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(460)

Side by Side Diff: Source/core/editing/FrameSelectionTest.cpp

Issue 988023005: Implementing directional selection strategy in Blink. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/FrameSelection.h" 6 #include "core/editing/FrameSelection.h"
7 7
8 #include "bindings/core/v8/ExceptionStatePlaceholder.h" 8 #include "bindings/core/v8/ExceptionStatePlaceholder.h"
9 #include "core/dom/Document.h" 9 #include "core/dom/Document.h"
10 #include "core/dom/Element.h" 10 #include "core/dom/Element.h"
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 // "Foo| Bar Baz," 152 // "Foo| Bar Baz,"
153 EXPECT_TRUE(selection().selectWordAroundPosition(VisiblePosition(Position(te xt, 3)))); 153 EXPECT_TRUE(selection().selectWordAroundPosition(VisiblePosition(Position(te xt, 3))));
154 EXPECT_EQ_SELECTED_TEXT("Foo"); 154 EXPECT_EQ_SELECTED_TEXT("Foo");
155 // "Foo Bar | Baz," 155 // "Foo Bar | Baz,"
156 EXPECT_FALSE(selection().selectWordAroundPosition(VisiblePosition(Position(t ext, 13)))); 156 EXPECT_FALSE(selection().selectWordAroundPosition(VisiblePosition(Position(t ext, 13))));
157 // "Foo Bar Baz|," 157 // "Foo Bar Baz|,"
158 EXPECT_TRUE(selection().selectWordAroundPosition(VisiblePosition(Position(te xt, 22)))); 158 EXPECT_TRUE(selection().selectWordAroundPosition(VisiblePosition(Position(te xt, 22))));
159 EXPECT_EQ_SELECTED_TEXT("Baz"); 159 EXPECT_EQ_SELECTED_TEXT("Baz");
160 } 160 }
161 161
162 // TODO: Same test for RTL
163 TEST_F(FrameSelectionTest, MoveRangeSelectionExtent)
164 {
165 RefPtrWillBeRawPtr<Text> text = document().createTextNode("abcdef ghij kl mn opqr stuvwx yzab,");
166 document().body()->appendChild(text);
167
168 // "abcdef ghij kl mno|p>qr stuvwx yzab," (| means start and > means end).
169 selection().setSelection(VisibleSelection(Position(text, 18), Position(text, 19)));
170 EXPECT_EQ_SELECTED_TEXT("p");
171 // "abcdef ghij kl mno|pq>r stuvwx yzab," - expand selection using character granularity
172 // until the end of the word is reached.
173 selection().moveRangeSelectionExtent(VisiblePosition(Position(text, 20)));
174 EXPECT_EQ_SELECTED_TEXT("pq");
175 // "abcdef ghij kl mno|pqr> stuvwx yzab,"
176 selection().moveRangeSelectionExtent(VisiblePosition(Position(text, 21)));
177 EXPECT_EQ_SELECTED_TEXT("pqr");
178 // "abcdef ghij kl mno|pqr >stuvwx yzab," - confirm selection doesn't
179 // jump over the beginning of the word.
180 selection().moveRangeSelectionExtent(VisiblePosition(Position(text, 22)));
181 EXPECT_EQ_SELECTED_TEXT("pqr ");
182 // "abcdef ghij kl mno|pqr s>tuvwx yzab," - confirm selection switches to wo rd granularity.
183 selection().moveRangeSelectionExtent(VisiblePosition(Position(text, 23)));
184 EXPECT_EQ_SELECTED_TEXT("pqr stuvwx");
185 // "abcdef ghij kl mno|pqr stu>vwx yzab," - selection stays the same.
186 selection().moveRangeSelectionExtent(VisiblePosition(Position(text, 25)));
187 EXPECT_EQ_SELECTED_TEXT("pqr stuvwx");
188 // "abcdef ghij kl mno|pqr stuvwx yz>ab," - next word.
189 selection().moveRangeSelectionExtent(VisiblePosition(Position(text, 31)));
190 EXPECT_EQ_SELECTED_TEXT("pqr stuvwx yzab");
191 // "abcdef ghij kl mno|pqr stuvwx y>zab," - move back one character -
192 // confirm switch to character granularity.
193 selection().moveRangeSelectionExtent(VisiblePosition(Position(text, 30)));
194 EXPECT_EQ_SELECTED_TEXT("pqr stuvwx y");
195 // "abcdef ghij kl mno|pqr stuvwx yz>ab," - stay in character granularity
196 // if the user moves the position within the word.
197 selection().moveRangeSelectionExtent(VisiblePosition(Position(text, 31)));
198 EXPECT_EQ_SELECTED_TEXT("pqr stuvwx yz");
199 // "abcdef ghij kl mno|pqr stuvwx >yzab,"
200 selection().moveRangeSelectionExtent(VisiblePosition(Position(text, 29)));
201 EXPECT_EQ_SELECTED_TEXT("pqr stuvwx ");
202 // "abcdef ghij kl mno|pqr stuvwx y>zab,"
203 selection().moveRangeSelectionExtent(VisiblePosition(Position(text, 30)));
204 EXPECT_EQ_SELECTED_TEXT("pqr stuvwx y");
205 // "abcdef ghij kl mno|pqr stuv>wx yzab,"
206 selection().moveRangeSelectionExtent(VisiblePosition(Position(text, 26)));
207 EXPECT_EQ_SELECTED_TEXT("pqr stuv");
208 // "abcdef ghij kl mno|pqr stuvw>x yzab,"
209 selection().moveRangeSelectionExtent(VisiblePosition(Position(text, 27)));
210 EXPECT_EQ_SELECTED_TEXT("pqr stuvw");
211 // "abcdef ghij kl mno|pqr stuvwx y>zab," - switch to word granularity
212 // after expanding beyond the word boundary
213 selection().moveRangeSelectionExtent(VisiblePosition(Position(text, 30)));
214 EXPECT_EQ_SELECTED_TEXT("pqr stuvwx yzab");
215 // "abcdef ghij kl mn<o|pqr stuvwx yzab," - over to the other side of the ba se
216 // - stay in character granularity until the beginning of the word is passed .
217 selection().moveRangeSelectionExtent(VisiblePosition(Position(text, 17)));
218 EXPECT_EQ_SELECTED_TEXT("o");
219 // "abcdef ghij kl m<no|pqr stuvwx yzab,"
220 selection().moveRangeSelectionExtent(VisiblePosition(Position(text, 16)));
221 EXPECT_EQ_SELECTED_TEXT("no");
222 // "abcdef ghij kl <mno|pqr stuvwx yzab,"
223 selection().moveRangeSelectionExtent(VisiblePosition(Position(text, 15)));
224 EXPECT_EQ_SELECTED_TEXT("mno");
225 // "abcdef ghij kl mn<o|pqr stuvwx yzab,"
226 selection().moveRangeSelectionExtent(VisiblePosition(Position(text, 17)));
227 EXPECT_EQ_SELECTED_TEXT("o");
228 // "abcdef ghij k<l mno|pqr stuvwx yzab," - switch to word granularity
229 selection().moveRangeSelectionExtent(VisiblePosition(Position(text, 13)));
230 EXPECT_EQ_SELECTED_TEXT("kl mno");
231 // "abcd<ef ghij kl mno|pqr stuvwx yzab,"
232 selection().moveRangeSelectionExtent(VisiblePosition(Position(text, 4)));
233 EXPECT_EQ_SELECTED_TEXT("abcdef ghij kl mno");
234 // "abcde<f ghij kl mno|pqr stuvwx yzab," - decrease selection -
235 // switch back to character granularity.
236 selection().moveRangeSelectionExtent(VisiblePosition(Position(text, 5)));
237 EXPECT_EQ_SELECTED_TEXT("f ghij kl mno");
238 // "abcdef ghij kl mn<o|pqr stuvwx yzab,"
239 selection().moveRangeSelectionExtent(VisiblePosition(Position(text, 17)));
240 EXPECT_EQ_SELECTED_TEXT("o");
241 // "abcdef ghij kl m<no|pqr stuvwx yzab,"
242 selection().moveRangeSelectionExtent(VisiblePosition(Position(text, 16)));
243 EXPECT_EQ_SELECTED_TEXT("no");
244 // "abcdef ghij k<l mno|pqr stuvwx yzab,"
245 selection().moveRangeSelectionExtent(VisiblePosition(Position(text, 13)));
246 EXPECT_EQ_SELECTED_TEXT("kl mno");
247
248 // Make sure we switch to word granularity right away when starting on a
249 // word boundary and extending.
250 // "abcdef ghij kl |mnopqr >stuvwx yzab," (| means start and > means end).
251 selection().setSelection(VisibleSelection(Position(text, 15), Position(text, 22)));
252 EXPECT_EQ_SELECTED_TEXT("mnopqr ");
253 // "abcdef ghij kl |mnopqr s>tuvwx yzab,"
254 selection().moveRangeSelectionExtent(VisiblePosition(Position(text, 23)));
255 EXPECT_EQ_SELECTED_TEXT("mnopqr stuvwx");
256
257 // Make sure we start in character granularity when moving extent over to th e other
258 // side of the base.
259 // "abcdef| ghij> kl mnopqr stuvwx yzab," (| means start and > means end).
260 selection().setSelection(VisibleSelection(Position(text, 6), Position(text, 11)));
261 EXPECT_EQ_SELECTED_TEXT(" ghij");
262 // "abcde<f| ghij kl mnopqr stuvwx yzab,"
263 selection().moveRangeSelectionExtent(VisiblePosition(Position(text, 5)));
264 EXPECT_EQ_SELECTED_TEXT("f");
265
266 // Make sure we switch to word granularity when moving over to the other
267 // side of the base and then passing over the word boundary.
268 // "abcdef |ghij> kl mnopqr stuvwx yzab,"
269 selection().setSelection(VisibleSelection(Position(text, 7), Position(text, 11)));
270 EXPECT_EQ_SELECTED_TEXT("ghij");
271 // "abcdef< |ghij kl mnopqr stuvwx yzab,"
272 selection().moveRangeSelectionExtent(VisiblePosition(Position(text, 6)));
273 EXPECT_EQ_SELECTED_TEXT(" ");
274 // "abcde<f |ghij kl mnopqr stuvwx yzab,"
275 selection().moveRangeSelectionExtent(VisiblePosition(Position(text, 5)));
276 EXPECT_EQ_SELECTED_TEXT("abcdef ");
277 }
278
279 /*
162 TEST_F(FrameSelectionTest, MoveRangeSelectionExtent) 280 TEST_F(FrameSelectionTest, MoveRangeSelectionExtent)
163 { 281 {
164 // "Foo Bar Baz," 282 // "Foo Bar Baz,"
165 RefPtrWillBeRawPtr<Text> text = document().createTextNode("Foo Bar Baz,"); 283 RefPtrWillBeRawPtr<Text> text = document().createTextNode("Foo Bar Baz,");
166 document().body()->appendChild(text); 284 document().body()->appendChild(text);
167 // "Foo B|a>r Baz," (| means start and > means end). 285 // "Foo B|a>r Baz," (| means start and > means end).
168 selection().setSelection(VisibleSelection(Position(text, 5), Position(text, 6))); 286 selection().setSelection(VisibleSelection(Position(text, 5), Position(text, 6)));
169 EXPECT_EQ_SELECTED_TEXT("a"); 287 EXPECT_EQ_SELECTED_TEXT("a");
170 // "Foo B|ar B>az," with the Character granularity. 288 // "Foo B|ar B>az," with the Character granularity.
171 selection().moveRangeSelectionExtent(VisiblePosition(Position(text, 9)), Cha racterGranularity); 289 selection().moveRangeSelectionExtent(VisiblePosition(Position(text, 9)), Cha racterGranularity);
(...skipping 24 matching lines...) Expand all
196 // "Foo B|ar B>az," with the Word granularity. 314 // "Foo B|ar B>az," with the Word granularity.
197 selection().moveRangeSelection(VisiblePosition(Position(text, 5)), VisiblePo sition(Position(text, 9)), WordGranularity); 315 selection().moveRangeSelection(VisiblePosition(Position(text, 5)), VisiblePo sition(Position(text, 9)), WordGranularity);
198 EXPECT_EQ_SELECTED_TEXT("Bar Baz"); 316 EXPECT_EQ_SELECTED_TEXT("Bar Baz");
199 // "Fo<o B|ar Baz," with the Character granularity. 317 // "Fo<o B|ar Baz," with the Character granularity.
200 selection().moveRangeSelection(VisiblePosition(Position(text, 5)), VisiblePo sition(Position(text, 2)), CharacterGranularity); 318 selection().moveRangeSelection(VisiblePosition(Position(text, 5)), VisiblePo sition(Position(text, 2)), CharacterGranularity);
201 EXPECT_EQ_SELECTED_TEXT("o B"); 319 EXPECT_EQ_SELECTED_TEXT("o B");
202 // "Fo<o B|ar Baz," with the Word granularity. 320 // "Fo<o B|ar Baz," with the Word granularity.
203 selection().moveRangeSelection(VisiblePosition(Position(text, 5)), VisiblePo sition(Position(text, 2)), WordGranularity); 321 selection().moveRangeSelection(VisiblePosition(Position(text, 5)), VisiblePo sition(Position(text, 2)), WordGranularity);
204 EXPECT_EQ_SELECTED_TEXT("Foo Bar"); 322 EXPECT_EQ_SELECTED_TEXT("Foo Bar");
205 } 323 }
206 324 */
207 } 325 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698