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

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

Issue 2665923002: Modify DocumentMarkerController to support overlapping and nested DocumentMarkers (Closed)
Patch Set: Use range-for statement in setMarkersActive() 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
« no previous file with comments | « no previous file | third_party/WebKit/Source/core/editing/markers/DocumentMarkerController.cpp » ('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/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, DeleteStartOfMarker) {
1200 Element* div = insertHTMLElement(
1201 "<div id='sample' contenteditable>Initial text.</div>", "sample");
1202
1203 // Add marker to "Initial"
1204 EphemeralRange markerRange = PlainTextRange(0, 7).createRange(*div);
1205 document().markers().addMarker(markerRange.startPosition(),
1206 markerRange.endPosition(),
1207 DocumentMarker::TextMatch);
1208
1209 Vector<CompositionUnderline> emptyUnderlines;
1210 // Set composition to "Ini"
1211 controller().setCompositionFromExistingText(emptyUnderlines, 0, 3);
1212 // Delete "Ini"
1213 controller().commitText(String(""), emptyUnderlines, 0);
1214
1215 // Check that the marker is still attached to "tial"
1216 EXPECT_EQ(1u, document().markers().markers().size());
1217 EXPECT_EQ(0u, document().markers().markers()[0]->startOffset());
1218 EXPECT_EQ(4u, document().markers().markers()[0]->endOffset());
1219 }
1220
1221 TEST_F(InputMethodControllerTest, DeleteBeforeStartOfMarker) {
1222 Element* div = insertHTMLElement(
1223 "<div id='sample' contenteditable>Initial text.</div>", "sample");
1224
1225 // Add marker to "text"
1226 EphemeralRange markerRange = PlainTextRange(8, 12).createRange(*div);
1227 document().markers().addMarker(markerRange.startPosition(),
1228 markerRange.endPosition(),
1229 DocumentMarker::TextMatch);
1230
1231 Vector<CompositionUnderline> emptyUnderlines;
1232 // Set composition to "Initial"
1233 controller().setCompositionFromExistingText(emptyUnderlines, 0, 7);
1234
1235 // Delete "Initial"
1236 controller().commitText(String(""), emptyUnderlines, 0);
1237
1238 // Check that the marker is still attached to "text"
1239 EXPECT_EQ(1u, document().markers().markers().size());
1240 EXPECT_EQ(1u, document().markers().markers()[0]->startOffset());
1241 EXPECT_EQ(5u, document().markers().markers()[0]->endOffset());
1242 }
1243
1244 TEST_F(InputMethodControllerTest, DeleteBeforeAndIncludingStartOfMarker) {
1245 Element* div = insertHTMLElement(
1246 "<div id='sample' contenteditable>Initial text.</div>", "sample");
1247
1248 // Add marker to "text"
1249 EphemeralRange markerRange = PlainTextRange(8, 12).createRange(*div);
1250 document().markers().addMarker(markerRange.startPosition(),
1251 markerRange.endPosition(),
1252 DocumentMarker::TextMatch);
1253
1254 Vector<CompositionUnderline> emptyUnderlines;
1255 // Set composition to "Initial te"
1256 controller().setCompositionFromExistingText(emptyUnderlines, 0, 10);
1257
1258 // Delete "Initial te"
1259 controller().commitText(String(""), emptyUnderlines, 0);
1260
1261 // Check that the marker is still attached to "xt"
1262 EXPECT_EQ(1u, document().markers().markers().size());
1263 EXPECT_EQ(0u, document().markers().markers()[0]->startOffset());
1264 EXPECT_EQ(2u, document().markers().markers()[0]->endOffset());
1265 }
1266
1267 TEST_F(InputMethodControllerTest, DeleteEndOfMarker) {
1268 Element* div = insertHTMLElement(
1269 "<div id='sample' contenteditable>Initial text.</div>", "sample");
1270
1271 // Add marker to "text"
1272 EphemeralRange markerRange = PlainTextRange(8, 12).createRange(*div);
1273 document().markers().addMarker(markerRange.startPosition(),
1274 markerRange.endPosition(),
1275 DocumentMarker::TextMatch);
1276
1277 Vector<CompositionUnderline> emptyUnderlines;
1278 // Set composition to "xt."
1279 controller().setCompositionFromExistingText(emptyUnderlines, 10, 13);
1280
1281 // Delete "xt."
1282 controller().commitText(String(""), emptyUnderlines, 0);
1283
1284 // Check that the marker is still attached to "te"
1285 EXPECT_EQ(1u, document().markers().markers().size());
1286 EXPECT_EQ(8u, document().markers().markers()[0]->startOffset());
1287 EXPECT_EQ(10u, document().markers().markers()[0]->endOffset());
1288 }
1289
1290 TEST_F(InputMethodControllerTest, DeleteBeforeEndOfMarker) {
1291 Element* div = insertHTMLElement(
1292 "<div id='sample' contenteditable>Initial text.</div>", "sample");
1293
1294 // Add marker to "text"
1295 EphemeralRange markerRange = PlainTextRange(8, 12).createRange(*div);
1296 document().markers().addMarker(markerRange.startPosition(),
1297 markerRange.endPosition(),
1298 DocumentMarker::TextMatch);
1299
1300 Vector<CompositionUnderline> emptyUnderlines;
1301 // Set composition to "Initial"
1302 controller().setCompositionFromExistingText(emptyUnderlines, 0, 7);
1303
1304 // Delete "Initial"
1305 controller().commitText(String(""), emptyUnderlines, 0);
1306
1307 // Check that the marker is still attached to "text"
1308 EXPECT_EQ(1u, document().markers().markers().size());
1309 EXPECT_EQ(1u, document().markers().markers()[0]->startOffset());
1310 EXPECT_EQ(5u, document().markers().markers()[0]->endOffset());
1311 }
1312
1313 TEST_F(InputMethodControllerTest, DeleteSplittingNestedMarkers) {
1314 Element* div = insertHTMLElement(
1315 "<div id='sample' contenteditable>Initial text.</div>", "sample");
1316
1317 EphemeralRange markerRange = PlainTextRange(0, 6).createRange(*div);
1318 document().markers().addMarker(markerRange.startPosition(),
1319 markerRange.endPosition(),
1320 DocumentMarker::TextMatch);
1321
1322 markerRange = PlainTextRange(1, 9).createRange(*div);
1323 document().markers().addMarker(markerRange.startPosition(),
1324 markerRange.endPosition(),
1325 DocumentMarker::TextMatch);
1326
1327 markerRange = PlainTextRange(2, 3).createRange(*div);
1328 document().markers().addMarker(markerRange.startPosition(),
1329 markerRange.endPosition(),
1330 DocumentMarker::TextMatch);
1331
1332 Vector<CompositionUnderline> emptyUnderlines;
1333 controller().setCompositionFromExistingText(emptyUnderlines, 5, 7);
1334
1335 controller().commitText(String(""), emptyUnderlines, 0);
1336
1337 EXPECT_EQ(4u, document().markers().markers().size());
1338
1339 EXPECT_EQ(0u, document().markers().markers()[0]->startOffset());
1340 EXPECT_EQ(5u, document().markers().markers()[0]->endOffset());
1341
1342 EXPECT_EQ(1u, document().markers().markers()[1]->startOffset());
1343 EXPECT_EQ(5u, document().markers().markers()[1]->endOffset());
1344
1345 EXPECT_EQ(2u, document().markers().markers()[2]->startOffset());
1346 EXPECT_EQ(3u, document().markers().markers()[2]->endOffset());
1347
1348 EXPECT_EQ(5u, document().markers().markers()[3]->startOffset());
1349 EXPECT_EQ(7u, document().markers().markers()[3]->endOffset());
1350 }
1351
1199 } // namespace blink 1352 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Source/core/editing/markers/DocumentMarkerController.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698