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

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

Issue 2200833007: Change return value of FrameSelection::modify() to prevent unnecessary window scrolling (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 2016-08-05T13:02:14 Created 4 years, 4 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 | « third_party/WebKit/Source/core/editing/FrameSelection.cpp ('k') | no next file » | 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 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 // Select "two" for selection in DOM tree 171 // Select "two" for selection in DOM tree
172 // Select "twoone" for selection in Flat tree 172 // Select "twoone" for selection in Flat tree
173 selection().setSelection(VisibleSelectionInFlatTree(PositionInFlatTree(host, 0), PositionInFlatTree(document().body(), 2))); 173 selection().setSelection(VisibleSelectionInFlatTree(PositionInFlatTree(host, 0), PositionInFlatTree(document().body(), 2)));
174 selection().modify(FrameSelection::AlterationExtend, DirectionForward, WordG ranularity); 174 selection().modify(FrameSelection::AlterationExtend, DirectionForward, WordG ranularity);
175 EXPECT_EQ(Position(two, 0), visibleSelectionInDOMTree().start()); 175 EXPECT_EQ(Position(two, 0), visibleSelectionInDOMTree().start());
176 EXPECT_EQ(Position(two, 3), visibleSelectionInDOMTree().end()); 176 EXPECT_EQ(Position(two, 3), visibleSelectionInDOMTree().end());
177 EXPECT_EQ(PositionInFlatTree(two, 0), visibleSelectionInFlatTree().start()); 177 EXPECT_EQ(PositionInFlatTree(two, 0), visibleSelectionInFlatTree().start());
178 EXPECT_EQ(PositionInFlatTree(two, 3), visibleSelectionInFlatTree().end()); 178 EXPECT_EQ(PositionInFlatTree(two, 3), visibleSelectionInFlatTree().end());
179 } 179 }
180 180
181 TEST_F(FrameSelectionTest, ModifyWithUserTriggered)
182 {
183 setBodyContent("<div id=sample>abc</div>");
184 Element* sample = document().getElementById("sample");
185 const Position endOfText(sample->firstChild(), 3);
186 selection().setSelection(VisibleSelection(endOfText));
187
188 EXPECT_FALSE(selection().modify(FrameSelection::AlterationMove, DirectionFor ward, CharacterGranularity, NotUserTriggered))
189 << "Selection.modify() returns false for non-user-triggered call when se lection isn't modified.";
190 EXPECT_EQ(endOfText, selection().start())
191 << "Selection isn't modified";
192
193 EXPECT_TRUE(selection().modify(FrameSelection::AlterationMove, DirectionForw ard, CharacterGranularity, UserTriggered))
194 << "Selection.modify() returns true for user-triggered call";
195 EXPECT_EQ(endOfText, selection().start())
196 << "Selection isn't modified";
197 }
198
181 TEST_F(FrameSelectionTest, MoveRangeSelectionTest) 199 TEST_F(FrameSelectionTest, MoveRangeSelectionTest)
182 { 200 {
183 // "Foo Bar Baz," 201 // "Foo Bar Baz,"
184 Text* text = appendTextNode("Foo Bar Baz,"); 202 Text* text = appendTextNode("Foo Bar Baz,");
185 // Itinitializes with "Foo B|a>r Baz," (| means start and > means end). 203 // Itinitializes with "Foo B|a>r Baz," (| means start and > means end).
186 selection().setSelection(VisibleSelection(Position(text, 5), Position(text, 6))); 204 selection().setSelection(VisibleSelection(Position(text, 5), Position(text, 6)));
187 EXPECT_EQ_SELECTED_TEXT("a"); 205 EXPECT_EQ_SELECTED_TEXT("a");
188 206
189 // "Foo B|ar B>az," with the Character granularity. 207 // "Foo B|ar B>az," with the Character granularity.
190 selection().moveRangeSelection(createVisiblePosition(Position(text, 5)), cre ateVisiblePosition(Position(text, 9)), CharacterGranularity); 208 selection().moveRangeSelection(createVisiblePosition(Position(text, 5)), cre ateVisiblePosition(Position(text, 9)), CharacterGranularity);
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 selection().updateIfNeeded(); 278 selection().updateIfNeeded();
261 279
262 // TODO(yosin): Once lazy canonicalization implemented, selection.start 280 // TODO(yosin): Once lazy canonicalization implemented, selection.start
263 // should be Position(HTML, 0). 281 // should be Position(HTML, 0).
264 EXPECT_EQ(Position(), selection().start()) 282 EXPECT_EQ(Position(), selection().start())
265 << "updateIfNeeded() makes selection to null."; 283 << "updateIfNeeded() makes selection to null.";
266 EXPECT_EQ(selection().start(), caretPosition().position()); 284 EXPECT_EQ(selection().start(), caretPosition().position());
267 } 285 }
268 286
269 } // namespace blink 287 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/editing/FrameSelection.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698