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 18 matching lines...) Expand all Loading... |
29 */ | 29 */ |
30 | 30 |
31 #include "core/editing/markers/DocumentMarkerController.h" | 31 #include "core/editing/markers/DocumentMarkerController.h" |
32 | 32 |
33 #include <memory> | 33 #include <memory> |
34 #include "bindings/core/v8/ExceptionState.h" | 34 #include "bindings/core/v8/ExceptionState.h" |
35 #include "core/dom/Document.h" | 35 #include "core/dom/Document.h" |
36 #include "core/dom/Range.h" | 36 #include "core/dom/Range.h" |
37 #include "core/dom/Text.h" | 37 #include "core/dom/Text.h" |
38 #include "core/editing/EphemeralRange.h" | 38 #include "core/editing/EphemeralRange.h" |
| 39 #include "core/editing/PlainTextRange.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 | 45 |
45 namespace blink { | 46 namespace blink { |
46 | 47 |
47 class DocumentMarkerControllerTest : public ::testing::Test { | 48 class DocumentMarkerControllerTest : public ::testing::Test { |
48 protected: | 49 protected: |
49 DocumentMarkerControllerTest() | 50 DocumentMarkerControllerTest() |
50 : m_dummyPageHolder(DummyPageHolder::create(IntSize(800, 600))) {} | 51 : m_dummyPageHolder(DummyPageHolder::create(IntSize(800, 600))) {} |
51 | 52 |
52 Document& document() const { return m_dummyPageHolder->document(); } | 53 Document& document() const { return m_dummyPageHolder->document(); } |
53 DocumentMarkerController& markerController() const { | 54 DocumentMarkerController& markerController() const { |
54 return document().markers(); | 55 return document().markers(); |
55 } | 56 } |
56 | 57 |
57 Text* createTextNode(const char*); | 58 Text* createTextNode(const char*); |
58 void markNodeContents(Node*); | 59 void markNodeContents(Node*); |
59 void markNodeContentsWithComposition(Node*); | |
60 void setBodyInnerHTML(const char*); | 60 void setBodyInnerHTML(const char*); |
61 | 61 |
62 private: | 62 private: |
63 std::unique_ptr<DummyPageHolder> m_dummyPageHolder; | 63 std::unique_ptr<DummyPageHolder> m_dummyPageHolder; |
64 }; | 64 }; |
65 | 65 |
66 Text* DocumentMarkerControllerTest::createTextNode(const char* textContents) { | 66 Text* DocumentMarkerControllerTest::createTextNode(const char* textContents) { |
67 return document().createTextNode(String::fromUTF8(textContents)); | 67 return document().createTextNode(String::fromUTF8(textContents)); |
68 } | 68 } |
69 | 69 |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 // Try to make active a marker that doesn't exist. | 225 // Try to make active a marker that doesn't exist. |
226 EXPECT_FALSE(markerController().setTextMatchMarkersActive(range, true)); | 226 EXPECT_FALSE(markerController().setTextMatchMarkersActive(range, true)); |
227 | 227 |
228 // Add a marker and try it once more. | 228 // Add a marker and try it once more. |
229 markerController().addTextMatchMarker( | 229 markerController().addTextMatchMarker( |
230 range, TextMatchMarker::MatchStatus::kInactive); | 230 range, TextMatchMarker::MatchStatus::kInactive); |
231 EXPECT_EQ(1u, markerController().markers().size()); | 231 EXPECT_EQ(1u, markerController().markers().size()); |
232 EXPECT_TRUE(markerController().setTextMatchMarkersActive(range, true)); | 232 EXPECT_TRUE(markerController().setTextMatchMarkersActive(range, true)); |
233 } | 233 } |
234 | 234 |
| 235 TEST_F(DocumentMarkerControllerTest, MarkersInRange) { |
| 236 setBodyInnerHTML("<b>range, not in range</b>"); |
| 237 document().updateStyleAndLayout(); |
| 238 Element* bElement = toElement(document().body()->firstChild()); |
| 239 EphemeralRange markerRange = PlainTextRange(0, 5).createRange(*bElement); |
| 240 markerController().addTextMatchMarker(markerRange, false); |
| 241 |
| 242 DocumentMarkerVector results; |
| 243 |
| 244 // Checking a zero-length range inside a DocumentMarker should return the |
| 245 // marker |
| 246 EphemeralRange rangeToCheck1 = PlainTextRange(2, 2).createRange(*bElement); |
| 247 results = document().markers().markersInRange(rangeToCheck1, |
| 248 DocumentMarker::AllMarkers()); |
| 249 EXPECT_EQ(1u, results.size()); |
| 250 |
| 251 // Checking a non-zero length range on the endpoint of a DocumentMarker |
| 252 // shouldn't return anything |
| 253 EphemeralRange rangeToCheck2 = PlainTextRange(0, 0).createRange(*bElement); |
| 254 results = document().markers().markersInRange(rangeToCheck2, |
| 255 DocumentMarker::AllMarkers()); |
| 256 EXPECT_EQ(0u, results.size()); |
| 257 |
| 258 // Checking a non-zero length that overlaps a DocumentMarker should return |
| 259 // that marker |
| 260 EphemeralRange rangeToCheck3 = PlainTextRange(4, 6).createRange(*bElement); |
| 261 results = document().markers().markersInRange(rangeToCheck3, |
| 262 DocumentMarker::AllMarkers()); |
| 263 EXPECT_EQ(1u, results.size()); |
| 264 } |
| 265 |
| 266 TEST_F(DocumentMarkerControllerTest, MarkersInRangeInclusive) { |
| 267 setBodyInnerHTML("<b>range, not in range</b>"); |
| 268 document().updateStyleAndLayout(); |
| 269 Element* bElement = toElement(document().body()->firstChild()); |
| 270 EphemeralRange markerRange = PlainTextRange(0, 5).createRange(*bElement); |
| 271 markerController().addTextMatchMarker(markerRange, false); |
| 272 |
| 273 DocumentMarkerVector results; |
| 274 |
| 275 // Checking a zero-length range inside a DocumentMarker should return the |
| 276 // marker |
| 277 EphemeralRange rangeToCheck1 = PlainTextRange(2, 2).createRange(*bElement); |
| 278 results = document().markers().markersInRangeInclusive( |
| 279 rangeToCheck1, DocumentMarker::AllMarkers()); |
| 280 EXPECT_EQ(1u, results.size()); |
| 281 |
| 282 // Checking a zero length range touching a DocumentMarker should return the |
| 283 // marker |
| 284 EphemeralRange rangeToCheck2 = PlainTextRange(0, 0).createRange(*bElement); |
| 285 results = document().markers().markersInRangeInclusive( |
| 286 rangeToCheck2, DocumentMarker::AllMarkers()); |
| 287 EXPECT_EQ(1u, results.size()); |
| 288 |
| 289 // Checking a non-zero length that overlaps a DocumentMarker should return |
| 290 // that marker |
| 291 EphemeralRange rangeToCheck3 = PlainTextRange(4, 6).createRange(*bElement); |
| 292 results = document().markers().markersInRangeInclusive( |
| 293 rangeToCheck3, DocumentMarker::AllMarkers()); |
| 294 EXPECT_EQ(1u, results.size()); |
| 295 |
| 296 // Checking a zero-length range not touching a DocumentMarker shouldn't return |
| 297 // anything |
| 298 EphemeralRange rangeToCheck4 = PlainTextRange(6, 6).createRange(*bElement); |
| 299 results = document().markers().markersInRangeInclusive( |
| 300 rangeToCheck4, DocumentMarker::AllMarkers()); |
| 301 EXPECT_EQ(0u, results.size()); |
| 302 } |
| 303 |
235 } // namespace blink | 304 } // namespace blink |
OLD | NEW |