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

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

Issue 2692093003: Rewrite DocumentMarkerController to use SynchronousMutationObserver (Closed)
Patch Set: 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 document().markers().showMarkers();
1288
1289 // Delete "Initial"
1290 Vector<CompositionUnderline> emptyUnderlines;
1291 controller().setCompositionFromExistingText(emptyUnderlines, 0, 7);
1292 controller().commitText(String(""), emptyUnderlines, 0);
1293
1294 document().markers().showMarkers();
1295
1296 // Delete "blah"
1297 controller().setCompositionFromExistingText(emptyUnderlines, 6, 10);
1298 controller().commitText(String(""), emptyUnderlines, 0);
1299
1300 document().markers().showMarkers();
1301
1302 // Check that the marker is still attached to " text " and includes both the
1303 // space before "text" and the space after
1304 EXPECT_EQ(1u, document().markers().markers().size());
1305 EXPECT_EQ(0u, document().markers().markers()[0]->startOffset());
1306 EXPECT_EQ(6u, document().markers().markers()[0]->endOffset());
1307 }
1308
1309 TEST_F(InputMethodControllerTest, ReplaceStartOfMarker) {
1310 Element* div = insertHTMLElement(
1311 "<div id='sample' contenteditable>Initial text</div>", "sample");
1312
1313 // Add marker under "Initial text"
1314 EphemeralRange markerRange = PlainTextRange(0, 12).createRange(*div);
1315 document().markers().addMarker(markerRange.startPosition(),
1316 markerRange.endPosition(),
1317 DocumentMarker::TextMatch);
1318
1319 // Replace "Initial" with "Original"
1320 Vector<CompositionUnderline> emptyUnderlines;
1321 controller().setCompositionFromExistingText(emptyUnderlines, 0, 7);
1322 controller().commitText(String("Original"), emptyUnderlines, 0);
1323
1324 // Verify marker is under "Original text"
1325 EXPECT_EQ(1u, document().markers().markers().size());
1326 EXPECT_EQ(0u, document().markers().markers()[0]->startOffset());
1327 EXPECT_EQ(13u, document().markers().markers()[0]->endOffset());
1328 }
1329
1330 TEST_F(InputMethodControllerTest, ReplaceEndOfMarker) {
1331 Element* div = insertHTMLElement(
1332 "<div id='sample' contenteditable>Initial text</div>", "sample");
1333
1334 // Add marker under "Initial text"
1335 EphemeralRange markerRange = PlainTextRange(0, 12).createRange(*div);
1336 document().markers().addMarker(markerRange.startPosition(),
1337 markerRange.endPosition(),
1338 DocumentMarker::TextMatch);
1339
1340 // Replace "text" with "string"
1341 Vector<CompositionUnderline> emptyUnderlines;
1342 controller().setCompositionFromExistingText(emptyUnderlines, 8, 12);
1343 controller().commitText(String("string"), emptyUnderlines, 0);
1344
1345 // Verify marker is under "Initial string"
1346 EXPECT_EQ(1u, document().markers().markers().size());
1347 EXPECT_EQ(0u, document().markers().markers()[0]->startOffset());
1348 EXPECT_EQ(14u, document().markers().markers()[0]->endOffset());
1349 }
1350
1351 TEST_F(InputMethodControllerTest, ReplaceEntireMarker) {
1352 Element* div = insertHTMLElement(
1353 "<div id='sample' contenteditable>Initial text</div>", "sample");
1354
1355 // Add marker under "text"
1356 EphemeralRange markerRange = PlainTextRange(8, 12).createRange(*div);
1357 document().markers().addMarker(markerRange.startPosition(),
1358 markerRange.endPosition(),
1359 DocumentMarker::TextMatch);
1360
1361 // Replace "text" with "string"
1362 Vector<CompositionUnderline> emptyUnderlines;
1363 controller().setCompositionFromExistingText(emptyUnderlines, 8, 12);
1364 controller().commitText(String("string"), emptyUnderlines, 0);
1365
1366 // Verify marker is under "string"
1367 EXPECT_EQ(1u, document().markers().markers().size());
1368 EXPECT_EQ(8u, document().markers().markers()[0]->startOffset());
1369 EXPECT_EQ(14u, document().markers().markers()[0]->endOffset());
1370 }
1371
1372 TEST_F(InputMethodControllerTest, ReplaceTextWithMarkerAtBeginning) {
1373 Element* div = insertHTMLElement(
1374 "<div id='sample' contenteditable>Initial text</div>", "sample");
1375
1376 // Add marker under "Initial"
1377 EphemeralRange markerRange = PlainTextRange(0, 7).createRange(*div);
1378 document().markers().addMarker(markerRange.startPosition(),
1379 markerRange.endPosition(),
1380 DocumentMarker::TextMatch);
1381
1382 EXPECT_EQ(1u, document().markers().markers().size());
1383
1384 // Replace "Initial text" with "New string"
1385 Vector<CompositionUnderline> emptyUnderlines;
1386 controller().setCompositionFromExistingText(emptyUnderlines, 0, 12);
1387 controller().commitText(String("New string"), emptyUnderlines, 0);
1388
1389 // Verify marker was removed
1390 EXPECT_EQ(0u, document().markers().markers().size());
1391 }
1392
1393 TEST_F(InputMethodControllerTest, ReplaceTextWithMarkerAtEnd) {
1394 Element* div = insertHTMLElement(
1395 "<div id='sample' contenteditable>Initial text</div>", "sample");
1396
1397 // Add marker under "text"
1398 EphemeralRange markerRange = PlainTextRange(8, 12).createRange(*div);
1399 document().markers().addMarker(markerRange.startPosition(),
1400 markerRange.endPosition(),
1401 DocumentMarker::TextMatch);
1402
1403 EXPECT_EQ(1u, document().markers().markers().size());
1404
1405 // Replace "Initial text" with "New string"
1406 Vector<CompositionUnderline> emptyUnderlines;
1407 controller().setCompositionFromExistingText(emptyUnderlines, 0, 12);
1408 controller().commitText(String("New string"), emptyUnderlines, 0);
1409
1410 // Verify marker was removed
1411 EXPECT_EQ(0u, document().markers().markers().size());
1412 }
1413
1199 } // namespace blink 1414 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698