| 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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 { |
| 55 return GetDocument().Markers(); | 55 return GetDocument().Markers(); |
| 56 } | 56 } |
| 57 | 57 |
| 58 Text* CreateTextNode(const char*); | 58 Text* CreateTextNode(const char*); |
| 59 void MarkNodeContents(Node*); | 59 void MarkNodeContents(Node*); |
| 60 void MarkNodeContentsTextMatch(Node*); |
| 60 void SetBodyInnerHTML(const char*); | 61 void SetBodyInnerHTML(const char*); |
| 61 | 62 |
| 62 private: | 63 private: |
| 63 std::unique_ptr<DummyPageHolder> dummy_page_holder_; | 64 std::unique_ptr<DummyPageHolder> dummy_page_holder_; |
| 64 }; | 65 }; |
| 65 | 66 |
| 66 Text* DocumentMarkerControllerTest::CreateTextNode(const char* text_contents) { | 67 Text* DocumentMarkerControllerTest::CreateTextNode(const char* text_contents) { |
| 67 return GetDocument().createTextNode(String::FromUTF8(text_contents)); | 68 return GetDocument().createTextNode(String::FromUTF8(text_contents)); |
| 68 } | 69 } |
| 69 | 70 |
| 70 void DocumentMarkerControllerTest::MarkNodeContents(Node* node) { | 71 void DocumentMarkerControllerTest::MarkNodeContents(Node* node) { |
| 71 // Force layoutObjects to be created; TextIterator, which is used in | 72 // Force layoutObjects to be created; TextIterator, which is used in |
| 72 // DocumentMarkerControllerTest::addMarker(), needs them. | 73 // DocumentMarkerControllerTest::addMarker(), needs them. |
| 73 GetDocument().UpdateStyleAndLayout(); | 74 GetDocument().UpdateStyleAndLayout(); |
| 74 auto range = EphemeralRange::RangeOfContents(*node); | 75 auto range = EphemeralRange::RangeOfContents(*node); |
| 75 MarkerController().AddMarker(range.StartPosition(), range.EndPosition(), | 76 MarkerController().AddMarker(range.StartPosition(), range.EndPosition(), |
| 76 DocumentMarker::kSpelling); | 77 DocumentMarker::kSpelling); |
| 77 } | 78 } |
| 78 | 79 |
| 80 void DocumentMarkerControllerTest::MarkNodeContentsTextMatch(Node* node) { |
| 81 // Force layoutObjects to be created; TextIterator, which is used in |
| 82 // DocumentMarkerControllerTest::addMarker(), needs them. |
| 83 GetDocument().UpdateStyleAndLayout(); |
| 84 auto range = EphemeralRange::RangeOfContents(*node); |
| 85 MarkerController().AddTextMatchMarker(range, |
| 86 DocumentMarker::MatchStatus::kActive); |
| 87 } |
| 88 |
| 79 void DocumentMarkerControllerTest::SetBodyInnerHTML(const char* body_content) { | 89 void DocumentMarkerControllerTest::SetBodyInnerHTML(const char* body_content) { |
| 80 GetDocument().body()->setInnerHTML(String::FromUTF8(body_content)); | 90 GetDocument().body()->setInnerHTML(String::FromUTF8(body_content)); |
| 81 } | 91 } |
| 82 | 92 |
| 83 TEST_F(DocumentMarkerControllerTest, DidMoveToNewDocument) { | 93 TEST_F(DocumentMarkerControllerTest, DidMoveToNewDocument) { |
| 84 SetBodyInnerHTML("<b><i>foo</i></b>"); | 94 SetBodyInnerHTML("<b><i>foo</i></b>"); |
| 85 Element* parent = ToElement(GetDocument().body()->firstChild()->firstChild()); | 95 Element* parent = ToElement(GetDocument().body()->firstChild()->firstChild()); |
| 86 MarkNodeContents(parent); | 96 MarkNodeContents(parent); |
| 87 EXPECT_EQ(1u, MarkerController().Markers().size()); | 97 EXPECT_EQ(1u, MarkerController().Markers().size()); |
| 88 Persistent<Document> another_document = Document::Create(); | 98 Persistent<Document> another_document = Document::Create(); |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 SetBodyInnerHTML(""); | 196 SetBodyInnerHTML(""); |
| 187 } | 197 } |
| 188 // No more reference to marked node. | 198 // No more reference to marked node. |
| 189 ThreadState::Current()->CollectAllGarbage(); | 199 ThreadState::Current()->CollectAllGarbage(); |
| 190 EXPECT_EQ(0u, MarkerController().Markers().size()); | 200 EXPECT_EQ(0u, MarkerController().Markers().size()); |
| 191 } | 201 } |
| 192 | 202 |
| 193 TEST_F(DocumentMarkerControllerTest, UpdateRenderedRects) { | 203 TEST_F(DocumentMarkerControllerTest, UpdateRenderedRects) { |
| 194 SetBodyInnerHTML("<div style='margin: 100px'>foo</div>"); | 204 SetBodyInnerHTML("<div style='margin: 100px'>foo</div>"); |
| 195 Element* div = ToElement(GetDocument().body()->firstChild()); | 205 Element* div = ToElement(GetDocument().body()->firstChild()); |
| 196 MarkNodeContents(div); | 206 MarkNodeContentsTextMatch(div); |
| 197 Vector<IntRect> rendered_rects = | 207 Vector<IntRect> rendered_rects = |
| 198 MarkerController().RenderedRectsForMarkers(DocumentMarker::kSpelling); | 208 MarkerController().RenderedRectsForMarkers(DocumentMarker::kTextMatch); |
| 199 EXPECT_EQ(1u, rendered_rects.size()); | 209 EXPECT_EQ(1u, rendered_rects.size()); |
| 200 | 210 |
| 201 div->setAttribute(HTMLNames::styleAttr, "margin: 200px"); | 211 div->setAttribute(HTMLNames::styleAttr, "margin: 200px"); |
| 202 GetDocument().UpdateStyleAndLayout(); | 212 GetDocument().UpdateStyleAndLayout(); |
| 203 Vector<IntRect> new_rendered_rects = | 213 Vector<IntRect> new_rendered_rects = |
| 204 MarkerController().RenderedRectsForMarkers(DocumentMarker::kSpelling); | 214 MarkerController().RenderedRectsForMarkers(DocumentMarker::kTextMatch); |
| 205 EXPECT_EQ(1u, new_rendered_rects.size()); | 215 EXPECT_EQ(1u, new_rendered_rects.size()); |
| 206 EXPECT_NE(rendered_rects[0], new_rendered_rects[0]); | 216 EXPECT_NE(rendered_rects[0], new_rendered_rects[0]); |
| 207 } | 217 } |
| 208 | 218 |
| 209 TEST_F(DocumentMarkerControllerTest, CompositionMarkersNotMerged) { | 219 TEST_F(DocumentMarkerControllerTest, CompositionMarkersNotMerged) { |
| 210 SetBodyInnerHTML("<div style='margin: 100px'>foo</div>"); | 220 SetBodyInnerHTML("<div style='margin: 100px'>foo</div>"); |
| 211 Node* text = GetDocument().body()->firstChild()->firstChild(); | 221 Node* text = GetDocument().body()->firstChild()->firstChild(); |
| 212 GetDocument().UpdateStyleAndLayout(); | 222 GetDocument().UpdateStyleAndLayout(); |
| 213 MarkerController().AddCompositionMarker(Position(text, 0), Position(text, 1), | 223 MarkerController().AddCompositionMarker(Position(text, 0), Position(text, 1), |
| 214 Color::kBlack, false, Color::kBlack); | 224 Color::kBlack, false, Color::kBlack); |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 315 | 325 |
| 316 // RemoveSpellingMarkersUnderWords does not remove text match marker. | 326 // RemoveSpellingMarkersUnderWords does not remove text match marker. |
| 317 ASSERT_EQ(1u, MarkerController().Markers().size()); | 327 ASSERT_EQ(1u, MarkerController().Markers().size()); |
| 318 const DocumentMarker& marker = *MarkerController().Markers()[0]; | 328 const DocumentMarker& marker = *MarkerController().Markers()[0]; |
| 319 EXPECT_EQ(0u, marker.StartOffset()); | 329 EXPECT_EQ(0u, marker.StartOffset()); |
| 320 EXPECT_EQ(3u, marker.EndOffset()); | 330 EXPECT_EQ(3u, marker.EndOffset()); |
| 321 EXPECT_EQ(DocumentMarker::kTextMatch, marker.GetType()); | 331 EXPECT_EQ(DocumentMarker::kTextMatch, marker.GetType()); |
| 322 } | 332 } |
| 323 | 333 |
| 324 } // namespace blink | 334 } // namespace blink |
| OLD | NEW |