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

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

Issue 2375383005: Prune CreateVisibleSelectionDeprecated from unit test files (Closed)
Patch Set: Created 4 years, 2 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
« no previous file with comments | « no previous file | third_party/WebKit/Source/core/editing/GranularityStrategyTest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "core/editing/FrameSelection.h" 5 #include "core/editing/FrameSelection.h"
6 6
7 #include "bindings/core/v8/ExceptionStatePlaceholder.h" 7 #include "bindings/core/v8/ExceptionStatePlaceholder.h"
8 #include "core/dom/Document.h" 8 #include "core/dom/Document.h"
9 #include "core/dom/Element.h" 9 #include "core/dom/Element.h"
10 #include "core/dom/Text.h" 10 #include "core/dom/Text.h"
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 Text* FrameSelectionTest::appendTextNode(const String& data) 61 Text* FrameSelectionTest::appendTextNode(const String& data)
62 { 62 {
63 Text* text = document().createTextNode(data); 63 Text* text = document().createTextNode(data);
64 document().body()->appendChild(text); 64 document().body()->appendChild(text);
65 return text; 65 return text;
66 } 66 }
67 67
68 TEST_F(FrameSelectionTest, SetValidSelection) 68 TEST_F(FrameSelectionTest, SetValidSelection)
69 { 69 {
70 Text* text = appendTextNode("Hello, World!"); 70 Text* text = appendTextNode("Hello, World!");
71 VisibleSelection validSelection = createVisibleSelectionDeprecated(Position( text, 0), Position(text, 5)); 71 document().view()->updateAllLifecyclePhases();
72 VisibleSelection validSelection = createVisibleSelection(Position(text, 0), Position(text, 5));
72 EXPECT_FALSE(validSelection.isNone()); 73 EXPECT_FALSE(validSelection.isNone());
73 setSelection(validSelection); 74 setSelection(validSelection);
74 EXPECT_FALSE(selection().isNone()); 75 EXPECT_FALSE(selection().isNone());
75 } 76 }
76 77
77 TEST_F(FrameSelectionTest, InvalidateCaretRect) 78 TEST_F(FrameSelectionTest, InvalidateCaretRect)
78 { 79 {
79 Text* text = appendTextNode("Hello, World!"); 80 Text* text = appendTextNode("Hello, World!");
80 document().view()->updateAllLifecyclePhases(); 81 document().view()->updateAllLifecyclePhases();
81 82
82 VisibleSelection validSelection = createVisibleSelectionDeprecated(Position( text, 0), Position(text, 0)); 83 VisibleSelection validSelection = createVisibleSelection(Position(text, 0), Position(text, 0));
83 setSelection(validSelection); 84 setSelection(validSelection);
84 selection().setCaretRectNeedsUpdate(); 85 selection().setCaretRectNeedsUpdate();
85 EXPECT_TRUE(selection().isCaretBoundsDirty()); 86 EXPECT_TRUE(selection().isCaretBoundsDirty());
86 selection().invalidateCaretRect(); 87 selection().invalidateCaretRect();
87 EXPECT_FALSE(selection().isCaretBoundsDirty()); 88 EXPECT_FALSE(selection().isCaretBoundsDirty());
88 89
89 document().body()->removeChild(text); 90 document().body()->removeChild(text);
90 document().updateStyleAndLayoutIgnorePendingStylesheets(); 91 document().updateStyleAndLayoutIgnorePendingStylesheets();
91 selection().setCaretRectNeedsUpdate(); 92 selection().setCaretRectNeedsUpdate();
92 EXPECT_TRUE(selection().isCaretBoundsDirty()); 93 EXPECT_TRUE(selection().isCaretBoundsDirty());
93 selection().invalidateCaretRect(); 94 selection().invalidateCaretRect();
94 EXPECT_FALSE(selection().isCaretBoundsDirty()); 95 EXPECT_FALSE(selection().isCaretBoundsDirty());
95 } 96 }
96 97
97 TEST_F(FrameSelectionTest, PaintCaretShouldNotLayout) 98 TEST_F(FrameSelectionTest, PaintCaretShouldNotLayout)
98 { 99 {
99 Text* text = appendTextNode("Hello, World!"); 100 Text* text = appendTextNode("Hello, World!");
100 document().view()->updateAllLifecyclePhases(); 101 document().view()->updateAllLifecyclePhases();
101 102
102 document().body()->setContentEditable("true", ASSERT_NO_EXCEPTION); 103 document().body()->setContentEditable("true", ASSERT_NO_EXCEPTION);
103 document().body()->focus(); 104 document().body()->focus();
104 EXPECT_TRUE(document().body()->focused()); 105 EXPECT_TRUE(document().body()->focused());
105 106
106 VisibleSelection validSelection = createVisibleSelectionDeprecated(Position( text, 0), Position(text, 0)); 107 VisibleSelection validSelection = createVisibleSelection(Position(text, 0), Position(text, 0));
107 selection().setCaretVisible(true); 108 selection().setCaretVisible(true);
108 setSelection(validSelection); 109 setSelection(validSelection);
109 EXPECT_TRUE(selection().isCaret()); 110 EXPECT_TRUE(selection().isCaret());
110 EXPECT_TRUE(shouldPaintCaretForTesting()); 111 EXPECT_TRUE(shouldPaintCaretForTesting());
111 112
112 int startCount = layoutCount(); 113 int startCount = layoutCount();
113 { 114 {
114 // To force layout in next updateLayout calling, widen view. 115 // To force layout in next updateLayout calling, widen view.
115 FrameView& frameView = dummyPageHolder().frameView(); 116 FrameView& frameView = dummyPageHolder().frameView();
116 IntRect frameRect = frameView.frameRect(); 117 IntRect frameRect = frameView.frameRect();
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 } 201 }
201 202
202 TEST_F(FrameSelectionTest, ModifyExtendWithFlatTree) 203 TEST_F(FrameSelectionTest, ModifyExtendWithFlatTree)
203 { 204 {
204 setBodyContent("<span id=host></span>one"); 205 setBodyContent("<span id=host></span>one");
205 setShadowContent("two<content></content>", "host"); 206 setShadowContent("two<content></content>", "host");
206 Element* host = document().getElementById("host"); 207 Element* host = document().getElementById("host");
207 Node* const two = FlatTreeTraversal::firstChild(*host); 208 Node* const two = FlatTreeTraversal::firstChild(*host);
208 // Select "two" for selection in DOM tree 209 // Select "two" for selection in DOM tree
209 // Select "twoone" for selection in Flat tree 210 // Select "twoone" for selection in Flat tree
210 selection().setSelection(createVisibleSelectionDeprecated(PositionInFlatTree (host, 0), PositionInFlatTree(document().body(), 2))); 211 selection().setSelection(createVisibleSelection(PositionInFlatTree(host, 0), PositionInFlatTree(document().body(), 2)));
211 selection().modify(FrameSelection::AlterationExtend, DirectionForward, WordG ranularity); 212 selection().modify(FrameSelection::AlterationExtend, DirectionForward, WordG ranularity);
212 EXPECT_EQ(Position(two, 0), visibleSelectionInDOMTree().start()); 213 EXPECT_EQ(Position(two, 0), visibleSelectionInDOMTree().start());
213 EXPECT_EQ(Position(two, 3), visibleSelectionInDOMTree().end()); 214 EXPECT_EQ(Position(two, 3), visibleSelectionInDOMTree().end());
214 EXPECT_EQ(PositionInFlatTree(two, 0), visibleSelectionInFlatTree().start()); 215 EXPECT_EQ(PositionInFlatTree(two, 0), visibleSelectionInFlatTree().start());
215 EXPECT_EQ(PositionInFlatTree(two, 3), visibleSelectionInFlatTree().end()); 216 EXPECT_EQ(PositionInFlatTree(two, 3), visibleSelectionInFlatTree().end());
216 } 217 }
217 218
218 TEST_F(FrameSelectionTest, ModifyWithUserTriggered) 219 TEST_F(FrameSelectionTest, ModifyWithUserTriggered)
219 { 220 {
220 setBodyContent("<div id=sample>abc</div>"); 221 setBodyContent("<div id=sample>abc</div>");
221 Element* sample = document().getElementById("sample"); 222 Element* sample = document().getElementById("sample");
222 const Position endOfText(sample->firstChild(), 3); 223 const Position endOfText(sample->firstChild(), 3);
223 selection().setSelection(createVisibleSelectionDeprecated(endOfText)); 224 selection().setSelection(createVisibleSelection(endOfText));
224 225
225 EXPECT_FALSE(selection().modify(FrameSelection::AlterationMove, DirectionFor ward, CharacterGranularity, NotUserTriggered)) 226 EXPECT_FALSE(selection().modify(FrameSelection::AlterationMove, DirectionFor ward, CharacterGranularity, NotUserTriggered))
226 << "Selection.modify() returns false for non-user-triggered call when se lection isn't modified."; 227 << "Selection.modify() returns false for non-user-triggered call when se lection isn't modified.";
227 EXPECT_EQ(endOfText, selection().start()) 228 EXPECT_EQ(endOfText, selection().start())
228 << "Selection isn't modified"; 229 << "Selection isn't modified";
229 230
230 EXPECT_TRUE(selection().modify(FrameSelection::AlterationMove, DirectionForw ard, CharacterGranularity, UserTriggered)) 231 EXPECT_TRUE(selection().modify(FrameSelection::AlterationMove, DirectionForw ard, CharacterGranularity, UserTriggered))
231 << "Selection.modify() returns true for user-triggered call"; 232 << "Selection.modify() returns true for user-triggered call";
232 EXPECT_EQ(endOfText, selection().start()) 233 EXPECT_EQ(endOfText, selection().start())
233 << "Selection isn't modified"; 234 << "Selection isn't modified";
234 } 235 }
235 236
236 TEST_F(FrameSelectionTest, MoveRangeSelectionTest) 237 TEST_F(FrameSelectionTest, MoveRangeSelectionTest)
237 { 238 {
238 // "Foo Bar Baz," 239 // "Foo Bar Baz,"
239 Text* text = appendTextNode("Foo Bar Baz,"); 240 Text* text = appendTextNode("Foo Bar Baz,");
240 updateAllLifecyclePhases(); 241 updateAllLifecyclePhases();
241 242
242 // Itinitializes with "Foo B|a>r Baz," (| means start and > means end). 243 // Itinitializes with "Foo B|a>r Baz," (| means start and > means end).
243 selection().setSelection(createVisibleSelectionDeprecated(Position(text, 5), Position(text, 6))); 244 selection().setSelection(createVisibleSelection(Position(text, 5), Position( text, 6)));
244 EXPECT_EQ_SELECTED_TEXT("a"); 245 EXPECT_EQ_SELECTED_TEXT("a");
245 246
246 // "Foo B|ar B>az," with the Character granularity. 247 // "Foo B|ar B>az," with the Character granularity.
247 selection().moveRangeSelection(createVisiblePosition(Position(text, 5)), cre ateVisiblePosition(Position(text, 9)), CharacterGranularity); 248 selection().moveRangeSelection(createVisiblePosition(Position(text, 5)), cre ateVisiblePosition(Position(text, 9)), CharacterGranularity);
248 EXPECT_EQ_SELECTED_TEXT("ar B"); 249 EXPECT_EQ_SELECTED_TEXT("ar B");
249 // "Foo B|ar B>az," with the Word granularity. 250 // "Foo B|ar B>az," with the Word granularity.
250 selection().moveRangeSelection(createVisiblePosition(Position(text, 5)), cre ateVisiblePosition(Position(text, 9)), WordGranularity); 251 selection().moveRangeSelection(createVisiblePosition(Position(text, 5)), cre ateVisiblePosition(Position(text, 9)), WordGranularity);
251 EXPECT_EQ_SELECTED_TEXT("Bar Baz"); 252 EXPECT_EQ_SELECTED_TEXT("Bar Baz");
252 // "Fo<o B|ar Baz," with the Character granularity. 253 // "Fo<o B|ar Baz," with the Character granularity.
253 selection().moveRangeSelection(createVisiblePosition(Position(text, 5)), cre ateVisiblePosition(Position(text, 2)), CharacterGranularity); 254 selection().moveRangeSelection(createVisiblePosition(Position(text, 5)), cre ateVisiblePosition(Position(text, 2)), CharacterGranularity);
254 EXPECT_EQ_SELECTED_TEXT("o B"); 255 EXPECT_EQ_SELECTED_TEXT("o B");
255 // "Fo<o B|ar Baz," with the Word granularity. 256 // "Fo<o B|ar Baz," with the Word granularity.
256 selection().moveRangeSelection(createVisiblePosition(Position(text, 5)), cre ateVisiblePosition(Position(text, 2)), WordGranularity); 257 selection().moveRangeSelection(createVisiblePosition(Position(text, 5)), cre ateVisiblePosition(Position(text, 2)), WordGranularity);
257 EXPECT_EQ_SELECTED_TEXT("Foo Bar"); 258 EXPECT_EQ_SELECTED_TEXT("Foo Bar");
258 } 259 }
259 260
260 TEST_F(FrameSelectionTest, setNonDirectionalSelectionIfNeeded) 261 TEST_F(FrameSelectionTest, setNonDirectionalSelectionIfNeeded)
261 { 262 {
262 const char* bodyContent = "<span id=top>top</span><span id=host></span>"; 263 const char* bodyContent = "<span id=top>top</span><span id=host></span>";
263 const char* shadowContent = "<span id=bottom>bottom</span>"; 264 const char* shadowContent = "<span id=bottom>bottom</span>";
264 setBodyContent(bodyContent); 265 setBodyContent(bodyContent);
265 ShadowRoot* shadowRoot = setShadowContent(shadowContent, "host"); 266 ShadowRoot* shadowRoot = setShadowContent(shadowContent, "host");
266 267
267 Node* top = document().getElementById("top")->firstChild(); 268 Node* top = document().getElementById("top")->firstChild();
268 Node* bottom = shadowRoot->getElementById("bottom")->firstChild(); 269 Node* bottom = shadowRoot->getElementById("bottom")->firstChild();
269 Node* host = document().getElementById("host"); 270 Node* host = document().getElementById("host");
270 271
271 // top to bottom 272 // top to bottom
272 selection().setNonDirectionalSelectionIfNeeded(createVisibleSelectionDepreca ted(PositionInFlatTree(top, 1), PositionInFlatTree(bottom, 3)), CharacterGranula rity); 273 selection().setNonDirectionalSelectionIfNeeded(createVisibleSelection(Positi onInFlatTree(top, 1), PositionInFlatTree(bottom, 3)), CharacterGranularity);
273 EXPECT_EQ(Position(top, 1), visibleSelectionInDOMTree().base()); 274 EXPECT_EQ(Position(top, 1), visibleSelectionInDOMTree().base());
274 EXPECT_EQ(Position::beforeNode(host), visibleSelectionInDOMTree().extent()); 275 EXPECT_EQ(Position::beforeNode(host), visibleSelectionInDOMTree().extent());
275 EXPECT_EQ(Position(top, 1), visibleSelectionInDOMTree().start()); 276 EXPECT_EQ(Position(top, 1), visibleSelectionInDOMTree().start());
276 EXPECT_EQ(Position(top, 3), visibleSelectionInDOMTree().end()); 277 EXPECT_EQ(Position(top, 3), visibleSelectionInDOMTree().end());
277 278
278 EXPECT_EQ(PositionInFlatTree(top, 1), visibleSelectionInFlatTree().base()); 279 EXPECT_EQ(PositionInFlatTree(top, 1), visibleSelectionInFlatTree().base());
279 EXPECT_EQ(PositionInFlatTree(bottom, 3), visibleSelectionInFlatTree().extent ()); 280 EXPECT_EQ(PositionInFlatTree(bottom, 3), visibleSelectionInFlatTree().extent ());
280 EXPECT_EQ(PositionInFlatTree(top, 1), visibleSelectionInFlatTree().start()); 281 EXPECT_EQ(PositionInFlatTree(top, 1), visibleSelectionInFlatTree().start());
281 EXPECT_EQ(PositionInFlatTree(bottom, 3), visibleSelectionInFlatTree().end()) ; 282 EXPECT_EQ(PositionInFlatTree(bottom, 3), visibleSelectionInFlatTree().end()) ;
282 283
283 // bottom to top 284 // bottom to top
284 selection().setNonDirectionalSelectionIfNeeded(createVisibleSelectionDepreca ted(PositionInFlatTree(bottom, 3), PositionInFlatTree(top, 1)), CharacterGranula rity); 285 selection().setNonDirectionalSelectionIfNeeded(createVisibleSelection(Positi onInFlatTree(bottom, 3), PositionInFlatTree(top, 1)), CharacterGranularity);
285 EXPECT_EQ(Position(bottom, 3), visibleSelectionInDOMTree().base()); 286 EXPECT_EQ(Position(bottom, 3), visibleSelectionInDOMTree().base());
286 EXPECT_EQ(Position::beforeNode(bottom->parentNode()), visibleSelectionInDOMT ree().extent()); 287 EXPECT_EQ(Position::beforeNode(bottom->parentNode()), visibleSelectionInDOMT ree().extent());
287 EXPECT_EQ(Position(bottom, 0), visibleSelectionInDOMTree().start()); 288 EXPECT_EQ(Position(bottom, 0), visibleSelectionInDOMTree().start());
288 EXPECT_EQ(Position(bottom, 3), visibleSelectionInDOMTree().end()); 289 EXPECT_EQ(Position(bottom, 3), visibleSelectionInDOMTree().end());
289 290
290 EXPECT_EQ(PositionInFlatTree(bottom, 3), visibleSelectionInFlatTree().base() ); 291 EXPECT_EQ(PositionInFlatTree(bottom, 3), visibleSelectionInFlatTree().base() );
291 EXPECT_EQ(PositionInFlatTree(top, 1), visibleSelectionInFlatTree().extent()) ; 292 EXPECT_EQ(PositionInFlatTree(top, 1), visibleSelectionInFlatTree().extent()) ;
292 EXPECT_EQ(PositionInFlatTree(top, 1), visibleSelectionInFlatTree().start()); 293 EXPECT_EQ(PositionInFlatTree(top, 1), visibleSelectionInFlatTree().start());
293 EXPECT_EQ(PositionInFlatTree(bottom, 3), visibleSelectionInFlatTree().end()) ; 294 EXPECT_EQ(PositionInFlatTree(bottom, 3), visibleSelectionInFlatTree().end()) ;
294 } 295 }
295 296
296 TEST_F(FrameSelectionTest, SelectAllWithUnselectableRoot) 297 TEST_F(FrameSelectionTest, SelectAllWithUnselectableRoot)
297 { 298 {
298 Element* select = document().createElement("select", ASSERT_NO_EXCEPTION); 299 Element* select = document().createElement("select", ASSERT_NO_EXCEPTION);
299 document().replaceChild(select, document().documentElement()); 300 document().replaceChild(select, document().documentElement());
300 selection().selectAll(); 301 selection().selectAll();
301 EXPECT_TRUE(selection().isNone()) << "Nothing should be selected if the cont ent of the documentElement is not selctable."; 302 EXPECT_TRUE(selection().isNone()) << "Nothing should be selected if the cont ent of the documentElement is not selctable.";
302 } 303 }
303 304
304 TEST_F(FrameSelectionTest, updateIfNeededAndFrameCaret) 305 TEST_F(FrameSelectionTest, updateIfNeededAndFrameCaret)
305 { 306 {
306 setBodyContent("<style id=sample></style>"); 307 setBodyContent("<style id=sample></style>");
307 document().setDesignMode("on"); 308 document().setDesignMode("on");
309 updateAllLifecyclePhases();
308 Element* sample = document().getElementById("sample"); 310 Element* sample = document().getElementById("sample");
309 setSelection(createVisibleSelectionDeprecated(Position(sample, 0))); 311 setSelection(createVisibleSelection(Position(sample, 0)));
310 EXPECT_EQ(Position(document().body(), 0), selection().start()); 312 EXPECT_EQ(Position(document().body(), 0), selection().start());
311 EXPECT_EQ(selection().start(), caretPosition().position()); 313 EXPECT_EQ(selection().start(), caretPosition().position());
312 document().body()->remove(); 314 document().body()->remove();
313 // TODO(yosin): Once lazy canonicalization implemented, selection.start 315 // TODO(yosin): Once lazy canonicalization implemented, selection.start
314 // should be Position(HTML, 0). 316 // should be Position(HTML, 0).
315 EXPECT_EQ(Position(document().documentElement(), 1), selection().start()); 317 EXPECT_EQ(Position(document().documentElement(), 1), selection().start());
316 EXPECT_EQ(selection().start(), caretPosition().position()); 318 EXPECT_EQ(selection().start(), caretPosition().position());
317 selection().updateIfNeeded(); 319 selection().updateIfNeeded();
318 320
319 // TODO(yosin): Once lazy canonicalization implemented, selection.start 321 // TODO(yosin): Once lazy canonicalization implemented, selection.start
320 // should be Position(HTML, 0). 322 // should be Position(HTML, 0).
321 EXPECT_EQ(Position(), selection().start()) 323 EXPECT_EQ(Position(), selection().start())
322 << "updateIfNeeded() makes selection to null."; 324 << "updateIfNeeded() makes selection to null.";
323 EXPECT_EQ(selection().start(), caretPosition().position()); 325 EXPECT_EQ(selection().start(), caretPosition().position());
324 } 326 }
325 327
326 } // namespace blink 328 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Source/core/editing/GranularityStrategyTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698