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

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

Issue 2782823002: Make InsertIncrementalTextCommand to handle surrogate pair (Closed)
Patch Set: 2017-03-29T16:13:30 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
(Empty)
1 // Copyright (c) 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "core/editing/commands/InsertIncrementalTextCommand.h"
6
7 #include "core/editing/EditingTestBase.h"
8 #include "core/editing/FrameSelection.h"
9
10 namespace blink {
11
12 class InsertIncrementalTextCommandTest : public EditingTestBase {};
13
14 // http://crbug.com/706166
15 TEST_F(InsertIncrementalTextCommandTest, SurrogatePairsReplace) {
16 setBodyContent("<div id=sample contenteditable><a>a</a>b&#x1F63A;</div>");
17 Element* const sample = document().getElementById("sample");
18 const String newText(Vector<UChar>{0xD83D, 0xDE38}); // U+1F638
19 selection().setSelection(SelectionInDOMTree::Builder()
20 .collapse(Position(sample->lastChild(), 1))
21 .extend(Position(sample->lastChild(), 3))
22 .build());
23 CompositeEditCommand* const command =
24 InsertIncrementalTextCommand::create(document(), newText);
25 command->apply();
26
27 EXPECT_EQ(String(Vector<UChar>{'b', 0xD83D, 0xDE38}),
28 sample->lastChild()->nodeValue())
29 << "Replace 'U+D83D U+DE3A (U+1F63A) with 'U+D83D U+DE38'(U+1F638)";
30 }
31
32 TEST_F(InsertIncrementalTextCommandTest, SurrogatePairsNoReplace) {
33 setBodyContent("<div id=sample contenteditable><a>a</a>b&#x1F63A;</div>");
34 Element* const sample = document().getElementById("sample");
35 const String newText(Vector<UChar>{0xD83D, 0xDE3A}); // U+1F63A
36 selection().setSelection(SelectionInDOMTree::Builder()
37 .collapse(Position(sample->lastChild(), 1))
38 .extend(Position(sample->lastChild(), 3))
39 .build());
40 CompositeEditCommand* const command =
41 InsertIncrementalTextCommand::create(document(), newText);
42 command->apply();
43
44 EXPECT_EQ(String(Vector<UChar>{'b', 0xD83D, 0xDE3A}),
45 sample->lastChild()->nodeValue())
46 << "Replace 'U+D83D U+DE3A(U+1F63A) with 'U+D83D U+DE3A'(U+1F63A)";
47 }
48
49 // http://crbug.com/706166
50 TEST_F(InsertIncrementalTextCommandTest, SurrogatePairsTwo) {
51 setBodyContent(
52 "<div id=sample contenteditable><a>a</a>b&#x1F63A;&#x1F63A;</div>");
53 Element* const sample = document().getElementById("sample");
54 const String newText(Vector<UChar>{0xD83D, 0xDE38}); // U+1F638
55 selection().setSelection(SelectionInDOMTree::Builder()
56 .collapse(Position(sample->lastChild(), 1))
57 .extend(Position(sample->lastChild(), 5))
58 .build());
59 CompositeEditCommand* const command =
60 InsertIncrementalTextCommand::create(document(), newText);
61 command->apply();
62
63 EXPECT_EQ(String(Vector<UChar>{'b', 0xD83D, 0xDE38}),
64 sample->lastChild()->nodeValue())
65 << "Replace 'U+1F63A U+1F63A with U+1F638";
66 }
67
68 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698