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

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

Issue 2776983003: Expand FrameSelection/SelectionEditor::firstRange() (Closed)
Patch Set: Created 3 years, 8 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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 private: 49 private:
50 Persistent<Text> m_textNode; 50 Persistent<Text> m_textNode;
51 }; 51 };
52 52
53 Text* FrameSelectionTest::appendTextNode(const String& data) { 53 Text* FrameSelectionTest::appendTextNode(const String& data) {
54 Text* text = document().createTextNode(data); 54 Text* text = document().createTextNode(data);
55 document().body()->appendChild(text); 55 document().body()->appendChild(text);
56 return text; 56 return text;
57 } 57 }
58 58
59 TEST_F(FrameSelectionTest, FirstRange) { 59 TEST_F(FrameSelectionTest, FirstEphemeralRangeOf) {
60 setBodyContent("<div id=sample>0123456789</div>abc"); 60 setBodyContent("<div id=sample>0123456789</div>abc");
61 Element* const sample = document().getElementById("sample"); 61 Element* const sample = document().getElementById("sample");
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::NonDirectional, 0); 65 SelectionDirectionalMode::NonDirectional, 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 Range* const range = selection().firstRange(); 69 const EphemeralRange& range =
70 EXPECT_EQ(Position(sample->nextSibling(), 0), range->startPosition()) 70 firstEphemeralRangeOf(selection().computeVisibleSelectionInDOMTree());
71 EXPECT_EQ(Position(sample->nextSibling(), 0), range.startPosition())
71 << "firstRagne() should return current selection value"; 72 << "firstRagne() should return current selection value";
72 EXPECT_EQ(Position(sample->nextSibling(), 0), range->endPosition()); 73 EXPECT_EQ(Position(sample->nextSibling(), 0), range.endPosition());
73 } 74 }
74 75
75 TEST_F(FrameSelectionTest, SetValidSelection) { 76 TEST_F(FrameSelectionTest, SetValidSelection) {
76 Text* text = appendTextNode("Hello, World!"); 77 Text* text = appendTextNode("Hello, World!");
77 document().view()->updateAllLifecyclePhases(); 78 document().view()->updateAllLifecyclePhases();
78 selection().setSelection( 79 selection().setSelection(
79 SelectionInDOMTree::Builder() 80 SelectionInDOMTree::Builder()
80 .setBaseAndExtent(Position(text, 0), Position(text, 5)) 81 .setBaseAndExtent(Position(text, 0), Position(text, 5))
81 .build()); 82 .build());
82 EXPECT_FALSE( 83 EXPECT_FALSE(
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 selection().setSelectedRange( 320 selection().setSelectedRange(
320 EphemeralRange(Position(text, 0), Position(text, 12)), 321 EphemeralRange(Position(text, 0), Position(text, 12)),
321 VP_DEFAULT_AFFINITY, SelectionDirectionalMode::NonDirectional, 0); 322 VP_DEFAULT_AFFINITY, SelectionDirectionalMode::NonDirectional, 0);
322 323
323 EXPECT_TRUE(selection().isHandleVisible()) 324 EXPECT_TRUE(selection().isHandleVisible())
324 << "If handles were present before" 325 << "If handles were present before"
325 "selectSetSelectedRange they should be present after it."; 326 "selectSetSelectedRange they should be present after it.";
326 } 327 }
327 328
328 } // namespace blink 329 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/editing/FrameSelection.cpp ('k') | third_party/WebKit/Source/core/editing/SelectionEditor.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698