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

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

Issue 2948133004: [MarkersIntersectingRange #2] Add DocumentMarkerController::MarkersIntersectingRange() (Closed)
Patch Set: Remove MarkersIntersectingRangeHelper() from header file Created 3 years, 5 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 | « third_party/WebKit/Source/core/editing/markers/DocumentMarkerController.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2013, Google Inc. All rights reserved. 2 * Copyright (c) 2013, Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 MarkerController().RemoveSpellingMarkersUnderWords({"foo"}); 305 MarkerController().RemoveSpellingMarkersUnderWords({"foo"});
306 306
307 // RemoveSpellingMarkersUnderWords does not remove text match marker. 307 // RemoveSpellingMarkersUnderWords does not remove text match marker.
308 ASSERT_EQ(1u, MarkerController().Markers().size()); 308 ASSERT_EQ(1u, MarkerController().Markers().size());
309 const DocumentMarker& marker = *MarkerController().Markers()[0]; 309 const DocumentMarker& marker = *MarkerController().Markers()[0];
310 EXPECT_EQ(0u, marker.StartOffset()); 310 EXPECT_EQ(0u, marker.StartOffset());
311 EXPECT_EQ(3u, marker.EndOffset()); 311 EXPECT_EQ(3u, marker.EndOffset());
312 EXPECT_EQ(DocumentMarker::kTextMatch, marker.GetType()); 312 EXPECT_EQ(DocumentMarker::kTextMatch, marker.GetType());
313 } 313 }
314 314
315 TEST_F(DocumentMarkerControllerTest, MarkersIntersectingRange) {
316 SetBodyContent("<div contenteditable>123456789</div>");
317 Element* div = GetDocument().QuerySelector("div");
318 Node* text = div->firstChild();
319
320 // Add a spelling marker on "123"
321 MarkerController().AddSpellingMarker(
322 EphemeralRange(Position(text, 0), Position(text, 3)));
323 // Add a text match marker on "456"
324 MarkerController().AddTextMatchMarker(
325 EphemeralRange(Position(text, 3), Position(text, 6)),
326 TextMatchMarker::MatchStatus::kInactive);
327 // Add a grammar marker on "789"
328 MarkerController().AddSpellingMarker(
329 EphemeralRange(Position(text, 6), Position(text, 9)));
330
331 // Query for spellcheck markers intersecting "3456". The text match marker
332 // should not be returned, nor should the spelling marker touching the range.
333 const HeapVector<std::pair<Member<Node>, Member<DocumentMarker>>>& results =
334 MarkerController().MarkersIntersectingRange(
335 EphemeralRangeInFlatTree(PositionInFlatTree(text, 2),
336 PositionInFlatTree(text, 6)),
337 DocumentMarker::MisspellingMarkers());
338
339 EXPECT_EQ(1u, results.size());
340 EXPECT_EQ(DocumentMarker::kSpelling, results[0].second->GetType());
341 EXPECT_EQ(0u, results[0].second->StartOffset());
342 EXPECT_EQ(3u, results[0].second->EndOffset());
343 }
344
345 TEST_F(DocumentMarkerControllerTest, MarkersIntersectingCollapsedRange) {
346 SetBodyContent("<div contenteditable>123456789</div>");
347 Element* div = GetDocument().QuerySelector("div");
348 Node* text = div->firstChild();
349
350 // Add a spelling marker on "123"
351 MarkerController().AddSpellingMarker(
352 EphemeralRange(Position(text, 0), Position(text, 3)));
353
354 // Query for spellcheck markers containing the position between "1" and "2"
355 const HeapVector<std::pair<Member<Node>, Member<DocumentMarker>>>& results =
356 MarkerController().MarkersIntersectingRange(
357 EphemeralRangeInFlatTree(PositionInFlatTree(text, 1),
358 PositionInFlatTree(text, 1)),
359 DocumentMarker::MisspellingMarkers());
360
361 EXPECT_EQ(1u, results.size());
362 EXPECT_EQ(DocumentMarker::kSpelling, results[0].second->GetType());
363 EXPECT_EQ(0u, results[0].second->StartOffset());
364 EXPECT_EQ(3u, results[0].second->EndOffset());
365 }
366
367 TEST_F(DocumentMarkerControllerTest, MarkersIntersectingRangeWithShadowDOM) {
368 // Set up some shadow elements in a way we know doesn't work properly when
369 // using EphemeralRange instead of EphemeralRangeInFlatTree:
370 // <div>not shadow</div>
371 // <div> (shadow DOM host)
372 // #shadow-root
373 // <div>shadow1</div>
374 // <div>shadow2</div>
375 // Caling MarkersIntersectingRange with an EphemeralRange starting in the
376 // "not shadow" text and ending in the "shadow1" text will crash.
377 SetBodyContent(
378 "<div id=\"not_shadow\">not shadow</div><div id=\"shadow_root\" />");
379 ShadowRoot* shadow_root = SetShadowContent(
380 "<div id=\"shadow1\">shadow1</div><div id=\"shadow2\">shadow2</div>",
381 "shadow_root");
382
383 Element* not_shadow_div = GetDocument().QuerySelector("#not_shadow");
384 Node* not_shadow_text = not_shadow_div->firstChild();
385
386 Element* shadow1 = shadow_root->QuerySelector("#shadow1");
387 Node* shadow1_text = shadow1->firstChild();
388
389 MarkerController().AddTextMatchMarker(
390 EphemeralRange(Position(not_shadow_text, 0),
391 Position(not_shadow_text, 10)),
392 TextMatchMarker::MatchStatus::kInactive);
393
394 const HeapVector<std::pair<Member<Node>, Member<DocumentMarker>>>& results =
395 MarkerController().MarkersIntersectingRange(
396 EphemeralRangeInFlatTree(PositionInFlatTree(not_shadow_text, 9),
397 PositionInFlatTree(shadow1_text, 1)),
398 DocumentMarker::kTextMatch);
399 EXPECT_EQ(1u, results.size());
400 }
401
315 } // namespace blink 402 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/editing/markers/DocumentMarkerController.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698