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

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

Issue 2890313003: Commands preserve handles (Closed)
Patch Set: added test Created 3 years, 7 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 "core/editing/FrameSelection.h" 5 #include "core/editing/FrameSelection.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include "bindings/core/v8/ExceptionState.h" 8 #include "bindings/core/v8/ExceptionState.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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 Node* const text = sample->firstChild(); 62 Node* const text = sample->firstChild();
63 Selection().SetSelectedRange( 63 Selection().SetSelectedRange(
64 EphemeralRange(Position(text, 3), Position(text, 6)), VP_DEFAULT_AFFINITY, 64 EphemeralRange(Position(text, 3), Position(text, 6)), VP_DEFAULT_AFFINITY,
65 SelectionDirectionalMode::kNonDirectional, 0); 65 SelectionDirectionalMode::kNonDirectional, 0);
66 sample->setAttribute(HTMLNames::styleAttr, "display:none"); 66 sample->setAttribute(HTMLNames::styleAttr, "display:none");
67 // Move |VisibleSelection| before "abc". 67 // Move |VisibleSelection| before "abc".
68 UpdateAllLifecyclePhases(); 68 UpdateAllLifecyclePhases();
69 const EphemeralRange& range = 69 const EphemeralRange& range =
70 FirstEphemeralRangeOf(Selection().ComputeVisibleSelectionInDOMTree()); 70 FirstEphemeralRangeOf(Selection().ComputeVisibleSelectionInDOMTree());
71 EXPECT_EQ(Position(sample->nextSibling(), 0), range.StartPosition()) 71 EXPECT_EQ(Position(sample->nextSibling(), 0), range.StartPosition())
72 << "firstRagne() should return current selection value"; 72 << "firstRange() should return current selection value";
73 EXPECT_EQ(Position(sample->nextSibling(), 0), range.EndPosition()); 73 EXPECT_EQ(Position(sample->nextSibling(), 0), range.EndPosition());
74 } 74 }
75 75
76 TEST_F(FrameSelectionTest, SetValidSelection) { 76 TEST_F(FrameSelectionTest, SetValidSelection) {
77 Text* text = AppendTextNode("Hello, World!"); 77 Text* text = AppendTextNode("Hello, World!");
78 GetDocument().View()->UpdateAllLifecyclePhases(); 78 GetDocument().View()->UpdateAllLifecyclePhases();
79 Selection().SetSelection( 79 Selection().SetSelection(
80 SelectionInDOMTree::Builder() 80 SelectionInDOMTree::Builder()
81 .SetBaseAndExtent(Position(text, 0), Position(text, 5)) 81 .SetBaseAndExtent(Position(text, 0), Position(text, 5))
82 .Build()); 82 .Build());
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 SetBodyContent("<div id=sample>abc</div>"); 273 SetBodyContent("<div id=sample>abc</div>");
274 Element* sample = GetDocument().getElementById("sample"); 274 Element* sample = GetDocument().getElementById("sample");
275 const Position end_of_text(sample->firstChild(), 3); 275 const Position end_of_text(sample->firstChild(), 3);
276 Selection().SetSelection(SelectionInDOMTree::Builder() 276 Selection().SetSelection(SelectionInDOMTree::Builder()
277 .Collapse(end_of_text) 277 .Collapse(end_of_text)
278 .SetIsHandleVisible(false) 278 .SetIsHandleVisible(false)
279 .Build()); 279 .Build());
280 EXPECT_FALSE(Selection().IsHandleVisible()); 280 EXPECT_FALSE(Selection().IsHandleVisible());
281 Selection().SelectAll(); 281 Selection().SelectAll();
282 EXPECT_FALSE(Selection().IsHandleVisible()) 282 EXPECT_FALSE(Selection().IsHandleVisible())
283 << "If handles weren't present before" 283 << "If handles weren't present before "
284 "selectAll. Then they shouldn't be present" 284 "selectAll. Then they shouldn't be present "
285 "after it."; 285 "after it.";
286 286
287 Selection().SetSelection(SelectionInDOMTree::Builder() 287 Selection().SetSelection(SelectionInDOMTree::Builder()
288 .Collapse(end_of_text) 288 .Collapse(end_of_text)
289 .SetIsHandleVisible(true) 289 .SetIsHandleVisible(true)
290 .Build()); 290 .Build());
291 EXPECT_TRUE(Selection().IsHandleVisible()); 291 EXPECT_TRUE(Selection().IsHandleVisible());
292 Selection().SelectAll(); 292 Selection().SelectAll();
293 EXPECT_TRUE(Selection().IsHandleVisible()) 293 EXPECT_TRUE(Selection().IsHandleVisible())
294 << "If handles were present before" 294 << "If handles were present before "
295 "selectAll. Then they should be present" 295 "selectAll. Then they should be present "
296 "after it."; 296 "after it.";
297 } 297 }
298 298
299 TEST_F(FrameSelectionTest, BoldCommandPreservesHandle) {
300 SetBodyContent("<div id=sample>abc</div>");
301 Element* sample = GetDocument().getElementById("sample");
302 const Position end_of_text(sample->firstChild(), 3);
303 Selection().SetSelection(SelectionInDOMTree::Builder()
304 .Collapse(end_of_text)
305 .SetIsHandleVisible(false)
306 .Build());
307 EXPECT_FALSE(Selection().IsHandleVisible());
308 Selection().SelectAll();
309 GetDocument().execCommand("bold", false, "", ASSERT_NO_EXCEPTION);
310 EXPECT_FALSE(Selection().IsHandleVisible())
311 << "If handles weren't present before "
312 "bold command. Then they shouldn't "
313 "be present after it.";
314
315 Selection().SetSelection(SelectionInDOMTree::Builder()
316 .Collapse(end_of_text)
317 .SetIsHandleVisible(true)
318 .Build());
319 EXPECT_TRUE(Selection().IsHandleVisible());
320 Selection().SelectAll();
321 GetDocument().execCommand("bold", false, "", ASSERT_NO_EXCEPTION);
322 EXPECT_TRUE(Selection().IsHandleVisible())
323 << "If handles were present before "
324 "bold command. Then they should "
325 "be present after it.";
326 }
327
299 TEST_F(FrameSelectionTest, SetSelectedRangeHidesHandle) { 328 TEST_F(FrameSelectionTest, SetSelectedRangeHidesHandle) {
300 Text* text = AppendTextNode("Hello, World!"); 329 Text* text = AppendTextNode("Hello, World!");
301 GetDocument().View()->UpdateAllLifecyclePhases(); 330 GetDocument().View()->UpdateAllLifecyclePhases();
302 Selection().SetSelection( 331 Selection().SetSelection(
303 SelectionInDOMTree::Builder() 332 SelectionInDOMTree::Builder()
304 .SetBaseAndExtent(Position(text, 0), Position(text, 5)) 333 .SetBaseAndExtent(Position(text, 0), Position(text, 5))
305 .SetIsHandleVisible(false) 334 .SetIsHandleVisible(false)
306 .Build()); 335 .Build());
307 336
308 Selection().SetSelectedRange( 337 Selection().SetSelectedRange(
(...skipping 613 matching lines...) Expand 10 before | Expand all | Expand 10 after
922 EXPECT_FALSE(Selection().IsHidden()); 951 EXPECT_FALSE(Selection().IsHidden());
923 952
924 Element* const alink = GetDocument().getElementById("alink"); 953 Element* const alink = GetDocument().getElementById("alink");
925 alink->focus(); 954 alink->focus();
926 EXPECT_TRUE(Selection().GetSelectionInDOMTree().IsRange()); 955 EXPECT_TRUE(Selection().GetSelectionInDOMTree().IsRange());
927 EXPECT_FALSE(Selection().SelectionHasFocus()); 956 EXPECT_FALSE(Selection().SelectionHasFocus());
928 EXPECT_FALSE(Selection().IsHidden()); // Range still visible. 957 EXPECT_FALSE(Selection().IsHidden()); // Range still visible.
929 } 958 }
930 959
931 } // namespace blink 960 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698