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

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

Issue 2325553002: Restore a collapsed leading space of text used for line break (Closed)
Patch Set: Add gtests Created 4 years, 3 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/iterators/TextIterator.h » ('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 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 // Select "two" for selection in DOM tree 204 // Select "two" for selection in DOM tree
205 // Select "twoone" for selection in Flat tree 205 // Select "twoone" for selection in Flat tree
206 selection().setSelection(VisibleSelectionInFlatTree(PositionInFlatTree(host, 0), PositionInFlatTree(document().body(), 2))); 206 selection().setSelection(VisibleSelectionInFlatTree(PositionInFlatTree(host, 0), PositionInFlatTree(document().body(), 2)));
207 selection().modify(FrameSelection::AlterationExtend, DirectionForward, WordG ranularity); 207 selection().modify(FrameSelection::AlterationExtend, DirectionForward, WordG ranularity);
208 EXPECT_EQ(Position(two, 0), visibleSelectionInDOMTree().start()); 208 EXPECT_EQ(Position(two, 0), visibleSelectionInDOMTree().start());
209 EXPECT_EQ(Position(two, 3), visibleSelectionInDOMTree().end()); 209 EXPECT_EQ(Position(two, 3), visibleSelectionInDOMTree().end());
210 EXPECT_EQ(PositionInFlatTree(two, 0), visibleSelectionInFlatTree().start()); 210 EXPECT_EQ(PositionInFlatTree(two, 0), visibleSelectionInFlatTree().start());
211 EXPECT_EQ(PositionInFlatTree(two, 3), visibleSelectionInFlatTree().end()); 211 EXPECT_EQ(PositionInFlatTree(two, 3), visibleSelectionInFlatTree().end());
212 } 212 }
213 213
214 TEST_F(FrameSelectionTest, PreserveLeadingSpaceWhenCopySelection)
215 {
216 setBodyContent("<div id='sample' style='width: 2em;'><b><i>foo</i></b> bar</ div>");
217 Element* sample = document().getElementById("sample");
218 VisibleSelection validSelection(Position(sample->firstChild()->firstChild()- >firstChild(), 0), Position(sample->lastChild(), 4));
yosin_UTC9 2016/09/14 05:13:52 Please use |plainText()| instead of |FrameSelectio
joone 2016/09/14 07:09:13 Done.
219 setSelection(validSelection);
220 EXPECT_EQ("<b style=\"color: rgb(0, 0, 0); font-family: &quot;&quot;; font-s ize: medium; font-style: normal; font-variant-ligatures: normal; "
221 "font-variant-caps: normal; letter-spacing: normal; orphans: 2; text-ali gn: start; text-indent: 0px; text-transform: none; white-space: "
222 "normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; t ext-decoration-style: initial; text-decoration-color: initial;\">"
223 "<i>foo</i></b><span style=\"color: rgb(0, 0, 0); font-family: &quot;&qu ot;; font-size: medium; font-style: normal; font-variant-ligatures: "
224 "normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; "
225 "white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke- width: 0px; text-decoration-style: initial; text-decoration-color: initial; "
226 "display: inline !important; float: none;\"><span class=\"Apple-converte d-space\">\xC2\xA0</span>bar</span>", WebString(selection().selectedHTMLForClipb oard()).utf8())
227 << "The markup of the selection is different";
228 }
229
214 TEST_F(FrameSelectionTest, ModifyWithUserTriggered) 230 TEST_F(FrameSelectionTest, ModifyWithUserTriggered)
215 { 231 {
216 setBodyContent("<div id=sample>abc</div>"); 232 setBodyContent("<div id=sample>abc</div>");
217 Element* sample = document().getElementById("sample"); 233 Element* sample = document().getElementById("sample");
218 const Position endOfText(sample->firstChild(), 3); 234 const Position endOfText(sample->firstChild(), 3);
219 selection().setSelection(VisibleSelection(endOfText)); 235 selection().setSelection(VisibleSelection(endOfText));
220 236
221 EXPECT_FALSE(selection().modify(FrameSelection::AlterationMove, DirectionFor ward, CharacterGranularity, NotUserTriggered)) 237 EXPECT_FALSE(selection().modify(FrameSelection::AlterationMove, DirectionFor ward, CharacterGranularity, NotUserTriggered))
222 << "Selection.modify() returns false for non-user-triggered call when se lection isn't modified."; 238 << "Selection.modify() returns false for non-user-triggered call when se lection isn't modified.";
223 EXPECT_EQ(endOfText, selection().start()) 239 EXPECT_EQ(endOfText, selection().start())
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
311 selection().updateIfNeeded(); 327 selection().updateIfNeeded();
312 328
313 // TODO(yosin): Once lazy canonicalization implemented, selection.start 329 // TODO(yosin): Once lazy canonicalization implemented, selection.start
314 // should be Position(HTML, 0). 330 // should be Position(HTML, 0).
315 EXPECT_EQ(Position(), selection().start()) 331 EXPECT_EQ(Position(), selection().start())
316 << "updateIfNeeded() makes selection to null."; 332 << "updateIfNeeded() makes selection to null.";
317 EXPECT_EQ(selection().start(), caretPosition().position()); 333 EXPECT_EQ(selection().start(), caretPosition().position());
318 } 334 }
319 335
320 } // namespace blink 336 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Source/core/editing/iterators/TextIterator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698