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

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

Issue 2692093003: Rewrite DocumentMarkerController to use SynchronousMutationObserver (Closed)
Patch Set: Don't try to use -1 as default value for unsigned int Created 3 years, 10 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/InputMethodController.h" 5 #include "core/editing/InputMethodController.h"
6 6
7 #include "core/dom/Document.h" 7 #include "core/dom/Document.h"
8 #include "core/dom/Element.h" 8 #include "core/dom/Element.h"
9 #include "core/dom/Range.h" 9 #include "core/dom/Range.h"
10 #include "core/editing/Editor.h" 10 #include "core/editing/Editor.h"
(...skipping 1178 matching lines...) Expand 10 before | Expand all | Expand 10 after
1189 underlines.push_back(CompositionUnderline(1, 11, Color(255, 0, 0), false, 0)); 1189 underlines.push_back(CompositionUnderline(1, 11, Color(255, 0, 0), false, 0));
1190 1190
1191 controller().commitText(String("string"), underlines, 0); 1191 controller().commitText(String("string"), underlines, 0);
1192 1192
1193 ASSERT_EQ(1u, document().markers().markers().size()); 1193 ASSERT_EQ(1u, document().markers().markers().size());
1194 1194
1195 EXPECT_EQ(9u, document().markers().markers()[0]->startOffset()); 1195 EXPECT_EQ(9u, document().markers().markers()[0]->startOffset());
1196 EXPECT_EQ(15u, document().markers().markers()[0]->endOffset()); 1196 EXPECT_EQ(15u, document().markers().markers()[0]->endOffset());
1197 } 1197 }
1198 1198
1199 TEST_F(InputMethodControllerTest, WhitespaceFixupAroundMarker) {
1200 Element* div = insertHTMLElement(
1201 "<div id='sample' contenteditable>Initial text blah</div>", "sample");
1202
1203 // Add marker under "text" (use TextMatch since Composition markers don't
1204 // persist across editing operations)
1205 EphemeralRange markerRange = PlainTextRange(8, 12).createRange(*div);
1206 document().markers().addMarker(markerRange.startPosition(),
1207 markerRange.endPosition(),
1208 DocumentMarker::TextMatch);
1209 // Delete "Initial"
1210 Vector<CompositionUnderline> emptyUnderlines;
1211 controller().setCompositionFromExistingText(emptyUnderlines, 0, 7);
1212 controller().commitText(String(""), emptyUnderlines, 0);
1213
1214 // Delete "blah"
1215 controller().setCompositionFromExistingText(emptyUnderlines, 6, 10);
1216 controller().commitText(String(""), emptyUnderlines, 0);
1217
1218 // Check that the marker is still attached to "text" and doesn't include
1219 // either space around it
1220 EXPECT_EQ(1u, document().markers().markers().size());
1221 EXPECT_EQ(1u, document().markers().markers()[0]->startOffset());
1222 EXPECT_EQ(5u, document().markers().markers()[0]->endOffset());
1223 }
1224
1225 TEST_F(InputMethodControllerTest, WhitespaceFixupAroundMarker2) {
1226 Element* div = insertHTMLElement(
1227 "<div id='sample' contenteditable>Initial text blah</div>", "sample");
1228
1229 // Add marker under " text" (use TextMatch since Composition markers don't
1230 // persist across editing operations)
1231 EphemeralRange markerRange = PlainTextRange(7, 12).createRange(*div);
1232 document().markers().addMarker(markerRange.startPosition(),
1233 markerRange.endPosition(),
1234 DocumentMarker::TextMatch);
1235 // Delete "Initial"
1236 Vector<CompositionUnderline> emptyUnderlines;
1237 controller().setCompositionFromExistingText(emptyUnderlines, 0, 7);
1238 controller().commitText(String(""), emptyUnderlines, 0);
1239
1240 // Delete "blah"
1241 controller().setCompositionFromExistingText(emptyUnderlines, 6, 10);
1242 controller().commitText(String(""), emptyUnderlines, 0);
1243
1244 // before "text" but not the space after
1245 EXPECT_EQ(1u, document().markers().markers().size());
1246 EXPECT_EQ(0u, document().markers().markers()[0]->startOffset());
1247 EXPECT_EQ(5u, document().markers().markers()[0]->endOffset());
1248 }
1249
1250 TEST_F(InputMethodControllerTest, WhitespaceFixupAroundMarker3) {
1251 Element* div = insertHTMLElement(
1252 "<div id='sample' contenteditable>Initial text blah</div>", "sample");
1253
1254 // Add marker under "text " (use TextMatch since Composition markers don't
1255 // persist across editing operations)
1256 EphemeralRange markerRange = PlainTextRange(8, 13).createRange(*div);
1257 document().markers().addMarker(markerRange.startPosition(),
1258 markerRange.endPosition(),
1259 DocumentMarker::TextMatch);
1260 // Delete "Initial"
1261 Vector<CompositionUnderline> emptyUnderlines;
1262 controller().setCompositionFromExistingText(emptyUnderlines, 0, 7);
1263 controller().commitText(String(""), emptyUnderlines, 0);
1264
1265 // Delete "blah"
1266 controller().setCompositionFromExistingText(emptyUnderlines, 6, 10);
1267 controller().commitText(String(""), emptyUnderlines, 0);
1268
1269 // Check that the marker is still attached to "text " and includes the space
1270 // after "text" but not the space before
1271 EXPECT_EQ(1u, document().markers().markers().size());
1272 EXPECT_EQ(1u, document().markers().markers()[0]->startOffset());
1273 EXPECT_EQ(6u, document().markers().markers()[0]->endOffset());
1274 }
1275
1276 TEST_F(InputMethodControllerTest, WhitespaceFixupAroundMarker4) {
1277 Element* div = insertHTMLElement(
1278 "<div id='sample' contenteditable>Initial text blah</div>", "sample");
1279
1280 // Add marker under " text " (use TextMatch since Composition markers don't
1281 // persist across editing operations)
1282 EphemeralRange markerRange = PlainTextRange(7, 13).createRange(*div);
1283 document().markers().addMarker(markerRange.startPosition(),
1284 markerRange.endPosition(),
1285 DocumentMarker::TextMatch);
1286
1287 // Delete "Initial"
1288 Vector<CompositionUnderline> emptyUnderlines;
1289 controller().setCompositionFromExistingText(emptyUnderlines, 0, 7);
1290 controller().commitText(String(""), emptyUnderlines, 0);
1291
1292 // Delete "blah"
1293 controller().setCompositionFromExistingText(emptyUnderlines, 6, 10);
1294 controller().commitText(String(""), emptyUnderlines, 0);
1295
1296 // Check that the marker is still attached to " text " and includes both the
1297 // space before "text" and the space after
1298 EXPECT_EQ(1u, document().markers().markers().size());
1299 EXPECT_EQ(0u, document().markers().markers()[0]->startOffset());
1300 EXPECT_EQ(6u, document().markers().markers()[0]->endOffset());
1301 }
1302
1303 TEST_F(InputMethodControllerTest, ReplaceStartOfMarker) {
1304 Element* div = insertHTMLElement(
1305 "<div id='sample' contenteditable>Initial text</div>", "sample");
1306
1307 // Add marker under "Initial text"
1308 EphemeralRange markerRange = PlainTextRange(0, 12).createRange(*div);
1309 document().markers().addMarker(markerRange.startPosition(),
1310 markerRange.endPosition(),
1311 DocumentMarker::TextMatch);
1312
1313 // Replace "Initial" with "Original"
1314 Vector<CompositionUnderline> emptyUnderlines;
1315 controller().setCompositionFromExistingText(emptyUnderlines, 0, 7);
1316 controller().commitText(String("Original"), emptyUnderlines, 0);
1317
1318 // Verify marker is under "Original text"
1319 EXPECT_EQ(1u, document().markers().markers().size());
1320 EXPECT_EQ(0u, document().markers().markers()[0]->startOffset());
1321 EXPECT_EQ(13u, document().markers().markers()[0]->endOffset());
1322 }
1323
1324 TEST_F(InputMethodControllerTest, ReplaceEndOfMarker) {
1325 Element* div = insertHTMLElement(
1326 "<div id='sample' contenteditable>Initial text</div>", "sample");
1327
1328 // Add marker under "Initial text"
1329 EphemeralRange markerRange = PlainTextRange(0, 12).createRange(*div);
1330 document().markers().addMarker(markerRange.startPosition(),
1331 markerRange.endPosition(),
1332 DocumentMarker::TextMatch);
1333
1334 // Replace "text" with "string"
1335 Vector<CompositionUnderline> emptyUnderlines;
1336 controller().setCompositionFromExistingText(emptyUnderlines, 8, 12);
1337 controller().commitText(String("string"), emptyUnderlines, 0);
1338
1339 // Verify marker is under "Initial string"
1340 EXPECT_EQ(1u, document().markers().markers().size());
1341 EXPECT_EQ(0u, document().markers().markers()[0]->startOffset());
1342 EXPECT_EQ(14u, document().markers().markers()[0]->endOffset());
1343 }
1344
1345 TEST_F(InputMethodControllerTest, ReplaceEntireMarker) {
1346 Element* div = insertHTMLElement(
1347 "<div id='sample' contenteditable>Initial text</div>", "sample");
1348
1349 // Add marker under "text"
1350 EphemeralRange markerRange = PlainTextRange(8, 12).createRange(*div);
1351 document().markers().addMarker(markerRange.startPosition(),
1352 markerRange.endPosition(),
1353 DocumentMarker::TextMatch);
1354
1355 // Replace "text" with "string"
1356 Vector<CompositionUnderline> emptyUnderlines;
1357 controller().setCompositionFromExistingText(emptyUnderlines, 8, 12);
1358 controller().commitText(String("string"), emptyUnderlines, 0);
1359
1360 // Verify marker is under "string"
1361 EXPECT_EQ(1u, document().markers().markers().size());
1362 EXPECT_EQ(8u, document().markers().markers()[0]->startOffset());
1363 EXPECT_EQ(14u, document().markers().markers()[0]->endOffset());
1364 }
1365
1366 TEST_F(InputMethodControllerTest, ReplaceTextWithMarkerAtBeginning) {
1367 Element* div = insertHTMLElement(
1368 "<div id='sample' contenteditable>Initial text</div>", "sample");
1369
1370 // Add marker under "Initial"
1371 EphemeralRange markerRange = PlainTextRange(0, 7).createRange(*div);
1372 document().markers().addMarker(markerRange.startPosition(),
1373 markerRange.endPosition(),
1374 DocumentMarker::TextMatch);
1375
1376 EXPECT_EQ(1u, document().markers().markers().size());
1377
1378 // Replace "Initial text" with "New string"
1379 Vector<CompositionUnderline> emptyUnderlines;
1380 controller().setCompositionFromExistingText(emptyUnderlines, 0, 12);
1381 controller().commitText(String("New string"), emptyUnderlines, 0);
1382
1383 // Verify marker was removed
1384 EXPECT_EQ(0u, document().markers().markers().size());
1385 }
1386
1387 TEST_F(InputMethodControllerTest, ReplaceTextWithMarkerAtEnd) {
1388 Element* div = insertHTMLElement(
1389 "<div id='sample' contenteditable>Initial text</div>", "sample");
1390
1391 // Add marker under "text"
1392 EphemeralRange markerRange = PlainTextRange(8, 12).createRange(*div);
1393 document().markers().addMarker(markerRange.startPosition(),
1394 markerRange.endPosition(),
1395 DocumentMarker::TextMatch);
1396
1397 EXPECT_EQ(1u, document().markers().markers().size());
1398
1399 // Replace "Initial text" with "New string"
1400 Vector<CompositionUnderline> emptyUnderlines;
1401 controller().setCompositionFromExistingText(emptyUnderlines, 0, 12);
1402 controller().commitText(String("New string"), emptyUnderlines, 0);
1403
1404 // Verify marker was removed
1405 EXPECT_EQ(0u, document().markers().markers().size());
1406 }
1407
1199 } // namespace blink 1408 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698