OLD | NEW |
---|---|
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 12 matching lines...) Expand all Loading... | |
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 */ | 29 */ |
30 | 30 |
31 #include "core/editing/markers/DocumentMarkerController.h" | 31 #include "core/editing/markers/DocumentMarkerController.h" |
32 | 32 |
33 #include <memory> | |
rlanday
2017/04/10 22:39:43
This is a git cl format thing...
yosin_UTC9
2017/04/11 01:18:58
Yes, we need to put standard C/C++ header before u
| |
33 #include "bindings/core/v8/ExceptionState.h" | 34 #include "bindings/core/v8/ExceptionState.h" |
34 #include "core/dom/Document.h" | 35 #include "core/dom/Document.h" |
35 #include "core/dom/Range.h" | 36 #include "core/dom/Range.h" |
36 #include "core/dom/Text.h" | 37 #include "core/dom/Text.h" |
37 #include "core/editing/EphemeralRange.h" | 38 #include "core/editing/EphemeralRange.h" |
38 #include "core/editing/markers/RenderedDocumentMarker.h" | 39 #include "core/editing/markers/RenderedDocumentMarker.h" |
39 #include "core/html/HTMLElement.h" | 40 #include "core/html/HTMLElement.h" |
40 #include "core/testing/DummyPageHolder.h" | 41 #include "core/testing/DummyPageHolder.h" |
41 #include "testing/gtest/include/gtest/gtest.h" | 42 #include "testing/gtest/include/gtest/gtest.h" |
42 #include "wtf/PassRefPtr.h" | 43 #include "wtf/PassRefPtr.h" |
43 #include "wtf/RefPtr.h" | 44 #include "wtf/RefPtr.h" |
44 #include <memory> | |
45 | 45 |
46 namespace blink { | 46 namespace blink { |
47 | 47 |
48 class DocumentMarkerControllerTest : public ::testing::Test { | 48 class DocumentMarkerControllerTest : public ::testing::Test { |
49 protected: | 49 protected: |
50 DocumentMarkerControllerTest() | 50 DocumentMarkerControllerTest() |
51 : dummy_page_holder_(DummyPageHolder::Create(IntSize(800, 600))) {} | 51 : dummy_page_holder_(DummyPageHolder::Create(IntSize(800, 600))) {} |
52 | 52 |
53 Document& GetDocument() const { return dummy_page_holder_->GetDocument(); } | 53 Document& GetDocument() const { return dummy_page_holder_->GetDocument(); } |
54 DocumentMarkerController& MarkerController() const { | 54 DocumentMarkerController& MarkerController() const { |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
257 // Try to make active a marker that doesn't exist. | 257 // Try to make active a marker that doesn't exist. |
258 EXPECT_FALSE(MarkerController().SetMarkersActive(range, true)); | 258 EXPECT_FALSE(MarkerController().SetMarkersActive(range, true)); |
259 | 259 |
260 // Add a marker and try it once more. | 260 // Add a marker and try it once more. |
261 MarkerController().AddTextMatchMarker(range, | 261 MarkerController().AddTextMatchMarker(range, |
262 DocumentMarker::MatchStatus::kInactive); | 262 DocumentMarker::MatchStatus::kInactive); |
263 EXPECT_EQ(1u, MarkerController().Markers().size()); | 263 EXPECT_EQ(1u, MarkerController().Markers().size()); |
264 EXPECT_TRUE(MarkerController().SetMarkersActive(range, true)); | 264 EXPECT_TRUE(MarkerController().SetMarkersActive(range, true)); |
265 } | 265 } |
266 | 266 |
267 TEST_F(DocumentMarkerControllerTest, | |
268 RemoveStartOfMarkerDoRemovePartiallyOverlapping) { | |
269 SetBodyInnerHTML("<b>abc</b>"); | |
270 GetDocument().UpdateStyleAndLayout(); | |
271 Node* b_element = GetDocument().body()->FirstChild(); | |
272 Node* text = b_element->firstChild(); | |
273 | |
274 // Add marker under "abc" | |
275 EphemeralRange marker_range = | |
276 EphemeralRange(Position(text, 0), Position(text, 3)); | |
277 GetDocument().Markers().AddTextMatchMarker( | |
278 marker_range, DocumentMarker::MatchStatus::kInactive); | |
279 | |
280 // Remove markers that overlap "a" | |
281 marker_range = EphemeralRange(Position(text, 0), Position(text, 1)); | |
282 GetDocument().Markers().RemoveMarkers( | |
283 marker_range, DocumentMarker::AllMarkers(), | |
284 DocumentMarkerController::kRemovePartiallyOverlappingMarker); | |
285 | |
286 EXPECT_EQ(0u, MarkerController().Markers().size()); | |
287 } | |
288 | |
289 TEST_F(DocumentMarkerControllerTest, | |
290 RemoveStartOfMarkerDontRemovePartiallyOverlapping) { | |
291 SetBodyInnerHTML("<b>abc</b>"); | |
292 GetDocument().UpdateStyleAndLayout(); | |
293 Node* b_element = GetDocument().body()->FirstChild(); | |
yosin_UTC9
2017/04/11 01:18:58
Wow, we have both Node::firstChild() and Container
| |
294 Node* text = b_element->firstChild(); | |
295 | |
296 // Add marker under "abc" | |
297 EphemeralRange marker_range = | |
298 EphemeralRange(Position(text, 0), Position(text, 3)); | |
299 GetDocument().Markers().AddTextMatchMarker( | |
300 marker_range, DocumentMarker::MatchStatus::kInactive); | |
301 | |
302 // Remove portion of marker that overlaps "a" | |
303 marker_range = EphemeralRange(Position(text, 0), Position(text, 1)); | |
304 GetDocument().Markers().RemoveMarkers( | |
305 marker_range, DocumentMarker::AllMarkers(), | |
306 DocumentMarkerController::kDoNotRemovePartiallyOverlappingMarker); | |
307 | |
308 EXPECT_EQ(1u, MarkerController().Markers().size()); | |
309 | |
310 EXPECT_EQ(1u, MarkerController().Markers()[0]->StartOffset()); | |
311 EXPECT_EQ(3u, MarkerController().Markers()[0]->EndOffset()); | |
312 } | |
313 | |
314 TEST_F(DocumentMarkerControllerTest, | |
315 RemoveMiddleOfMarkerDoRemovePartiallyOverlapping) { | |
316 SetBodyInnerHTML("<b>abc</b>"); | |
317 GetDocument().UpdateStyleAndLayout(); | |
318 Node* b_element = GetDocument().body()->FirstChild(); | |
319 Node* text = b_element->firstChild(); | |
320 | |
321 // Add marker under "abc" | |
322 EphemeralRange marker_range = | |
323 EphemeralRange(Position(text, 0), Position(text, 3)); | |
324 GetDocument().Markers().AddTextMatchMarker( | |
325 marker_range, DocumentMarker::MatchStatus::kInactive); | |
326 | |
327 // Remove markers that overlap "b" | |
328 marker_range = EphemeralRange(Position(text, 1), Position(text, 2)); | |
329 GetDocument().Markers().RemoveMarkers( | |
330 marker_range, DocumentMarker::AllMarkers(), | |
331 DocumentMarkerController::kRemovePartiallyOverlappingMarker); | |
332 | |
333 EXPECT_EQ(0u, MarkerController().Markers().size()); | |
334 } | |
335 | |
336 TEST_F(DocumentMarkerControllerTest, | |
337 RemoveMiddleOfMarkerDontRemovePartiallyOverlapping) { | |
338 SetBodyInnerHTML("<b>abc</b>"); | |
339 GetDocument().UpdateStyleAndLayout(); | |
340 Node* b_element = GetDocument().body()->FirstChild(); | |
341 Node* text = b_element->firstChild(); | |
342 | |
343 // Add marker under "abc" | |
344 EphemeralRange marker_range = | |
345 EphemeralRange(Position(text, 0), Position(text, 3)); | |
346 GetDocument().Markers().AddTextMatchMarker( | |
347 marker_range, DocumentMarker::MatchStatus::kInactive); | |
348 | |
349 // Remove portion of marker that overlaps "b" | |
350 marker_range = EphemeralRange(Position(text, 1), Position(text, 2)); | |
351 GetDocument().Markers().RemoveMarkers( | |
352 marker_range, DocumentMarker::AllMarkers(), | |
353 DocumentMarkerController::kDoNotRemovePartiallyOverlappingMarker); | |
354 | |
355 EXPECT_EQ(2u, MarkerController().Markers().size()); | |
356 | |
357 EXPECT_EQ(0u, MarkerController().Markers()[0]->StartOffset()); | |
358 EXPECT_EQ(1u, MarkerController().Markers()[0]->EndOffset()); | |
359 | |
360 EXPECT_EQ(2u, MarkerController().Markers()[1]->StartOffset()); | |
361 EXPECT_EQ(3u, MarkerController().Markers()[1]->EndOffset()); | |
362 } | |
363 | |
364 TEST_F(DocumentMarkerControllerTest, | |
365 RemoveEndOfMarkerDoRemovePartiallyOverlapping) { | |
366 SetBodyInnerHTML("<b>abc</b>"); | |
367 GetDocument().UpdateStyleAndLayout(); | |
368 Node* b_element = GetDocument().body()->FirstChild(); | |
369 Node* text = b_element->firstChild(); | |
370 | |
371 // Add marker under "abc" | |
372 EphemeralRange marker_range = | |
373 EphemeralRange(Position(text, 0), Position(text, 3)); | |
374 GetDocument().Markers().AddTextMatchMarker( | |
375 marker_range, DocumentMarker::MatchStatus::kInactive); | |
376 | |
377 // Remove markers that overlap "c" | |
378 marker_range = EphemeralRange(Position(text, 2), Position(text, 3)); | |
379 GetDocument().Markers().RemoveMarkers( | |
380 marker_range, DocumentMarker::AllMarkers(), | |
381 DocumentMarkerController::kRemovePartiallyOverlappingMarker); | |
382 | |
383 EXPECT_EQ(0u, MarkerController().Markers().size()); | |
384 } | |
385 | |
386 TEST_F(DocumentMarkerControllerTest, | |
387 RemoveEndOfMarkerDontRemovePartiallyOverlapping) { | |
388 SetBodyInnerHTML("<b>abc</b>"); | |
389 GetDocument().UpdateStyleAndLayout(); | |
390 Node* b_element = GetDocument().body()->FirstChild(); | |
391 Node* text = b_element->firstChild(); | |
392 | |
393 // Add marker under "abc" | |
394 EphemeralRange marker_range = | |
395 EphemeralRange(Position(text, 0), Position(text, 3)); | |
396 GetDocument().Markers().AddTextMatchMarker( | |
397 marker_range, DocumentMarker::MatchStatus::kInactive); | |
398 | |
399 // Remove portion of marker that overlaps "c" | |
400 marker_range = EphemeralRange(Position(text, 2), Position(text, 3)); | |
401 GetDocument().Markers().RemoveMarkers( | |
402 marker_range, DocumentMarker::AllMarkers(), | |
403 DocumentMarkerController::kDoNotRemovePartiallyOverlappingMarker); | |
404 | |
405 EXPECT_EQ(1u, MarkerController().Markers().size()); | |
406 | |
407 EXPECT_EQ(0u, MarkerController().Markers()[0]->StartOffset()); | |
408 EXPECT_EQ(2u, MarkerController().Markers()[0]->EndOffset()); | |
409 } | |
410 | |
267 } // namespace blink | 411 } // namespace blink |
OLD | NEW |