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

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

Issue 2829543002: [DMC #5] Add SpellCheckMarkerListImpl (Closed)
Patch Set: Leave method implementations in DocumentMarkerListEditor but change signatures Created 3 years, 7 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
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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 65
66 Text* DocumentMarkerControllerTest::CreateTextNode(const char* text_contents) { 66 Text* DocumentMarkerControllerTest::CreateTextNode(const char* text_contents) {
67 return GetDocument().createTextNode(String::FromUTF8(text_contents)); 67 return GetDocument().createTextNode(String::FromUTF8(text_contents));
68 } 68 }
69 69
70 void DocumentMarkerControllerTest::MarkNodeContents(Node* node) { 70 void DocumentMarkerControllerTest::MarkNodeContents(Node* node) {
71 // Force layoutObjects to be created; TextIterator, which is used in 71 // Force layoutObjects to be created; TextIterator, which is used in
72 // DocumentMarkerControllerTest::addMarker(), needs them. 72 // DocumentMarkerControllerTest::addMarker(), needs them.
73 GetDocument().UpdateStyleAndLayout(); 73 GetDocument().UpdateStyleAndLayout();
74 auto range = EphemeralRange::RangeOfContents(*node); 74 auto range = EphemeralRange::RangeOfContents(*node);
75 MarkerController().AddMarker(range.StartPosition(), range.EndPosition(), 75 MarkerController().AddTextMatchMarker(range,
Xiaocheng 2017/04/27 22:04:38 Are these the only sites creating markers of wrong
rlanday 2017/04/27 22:22:23 No, these are actually correctly creating Spelling
76 DocumentMarker::kSpelling); 76 DocumentMarker::MatchStatus::kInactive);
77 } 77 }
78 78
79 void DocumentMarkerControllerTest::SetBodyInnerHTML(const char* body_content) { 79 void DocumentMarkerControllerTest::SetBodyInnerHTML(const char* body_content) {
80 GetDocument().body()->setInnerHTML(String::FromUTF8(body_content)); 80 GetDocument().body()->setInnerHTML(String::FromUTF8(body_content));
81 } 81 }
82 82
83 TEST_F(DocumentMarkerControllerTest, DidMoveToNewDocument) { 83 TEST_F(DocumentMarkerControllerTest, DidMoveToNewDocument) {
84 SetBodyInnerHTML("<b><i>foo</i></b>"); 84 SetBodyInnerHTML("<b><i>foo</i></b>");
85 Element* parent = ToElement(GetDocument().body()->firstChild()->firstChild()); 85 Element* parent = ToElement(GetDocument().body()->firstChild()->firstChild());
86 MarkNodeContents(parent); 86 MarkNodeContents(parent);
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 // No more reference to marked node. 188 // No more reference to marked node.
189 ThreadState::Current()->CollectAllGarbage(); 189 ThreadState::Current()->CollectAllGarbage();
190 EXPECT_EQ(0u, MarkerController().Markers().size()); 190 EXPECT_EQ(0u, MarkerController().Markers().size());
191 } 191 }
192 192
193 TEST_F(DocumentMarkerControllerTest, UpdateRenderedRects) { 193 TEST_F(DocumentMarkerControllerTest, UpdateRenderedRects) {
194 SetBodyInnerHTML("<div style='margin: 100px'>foo</div>"); 194 SetBodyInnerHTML("<div style='margin: 100px'>foo</div>");
195 Element* div = ToElement(GetDocument().body()->firstChild()); 195 Element* div = ToElement(GetDocument().body()->firstChild());
196 MarkNodeContents(div); 196 MarkNodeContents(div);
197 Vector<IntRect> rendered_rects = 197 Vector<IntRect> rendered_rects =
198 MarkerController().RenderedRectsForMarkers(DocumentMarker::kSpelling); 198 MarkerController().RenderedRectsForMarkers(DocumentMarker::kTextMatch);
199 EXPECT_EQ(1u, rendered_rects.size()); 199 EXPECT_EQ(1u, rendered_rects.size());
200 200
201 div->setAttribute(HTMLNames::styleAttr, "margin: 200px"); 201 div->setAttribute(HTMLNames::styleAttr, "margin: 200px");
202 GetDocument().UpdateStyleAndLayout(); 202 GetDocument().UpdateStyleAndLayout();
203 Vector<IntRect> new_rendered_rects = 203 Vector<IntRect> new_rendered_rects =
204 MarkerController().RenderedRectsForMarkers(DocumentMarker::kSpelling); 204 MarkerController().RenderedRectsForMarkers(DocumentMarker::kTextMatch);
205 EXPECT_EQ(1u, new_rendered_rects.size()); 205 EXPECT_EQ(1u, new_rendered_rects.size());
206 EXPECT_NE(rendered_rects[0], new_rendered_rects[0]); 206 EXPECT_NE(rendered_rects[0], new_rendered_rects[0]);
207 } 207 }
208 208
209 TEST_F(DocumentMarkerControllerTest, CompositionMarkersNotMerged) { 209 TEST_F(DocumentMarkerControllerTest, CompositionMarkersNotMerged) {
210 SetBodyInnerHTML("<div style='margin: 100px'>foo</div>"); 210 SetBodyInnerHTML("<div style='margin: 100px'>foo</div>");
211 Node* text = GetDocument().body()->firstChild()->firstChild(); 211 Node* text = GetDocument().body()->firstChild()->firstChild();
212 GetDocument().UpdateStyleAndLayout(); 212 GetDocument().UpdateStyleAndLayout();
213 MarkerController().AddCompositionMarker(Position(text, 0), Position(text, 1), 213 MarkerController().AddCompositionMarker(Position(text, 0), Position(text, 1),
214 Color::kBlack, false, Color::kBlack); 214 Color::kBlack, false, Color::kBlack);
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 315
316 // RemoveSpellingMarkersUnderWords does not remove text match marker. 316 // RemoveSpellingMarkersUnderWords does not remove text match marker.
317 ASSERT_EQ(1u, MarkerController().Markers().size()); 317 ASSERT_EQ(1u, MarkerController().Markers().size());
318 const DocumentMarker& marker = *MarkerController().Markers()[0]; 318 const DocumentMarker& marker = *MarkerController().Markers()[0];
319 EXPECT_EQ(0u, marker.StartOffset()); 319 EXPECT_EQ(0u, marker.StartOffset());
320 EXPECT_EQ(3u, marker.EndOffset()); 320 EXPECT_EQ(3u, marker.EndOffset());
321 EXPECT_EQ(DocumentMarker::kTextMatch, marker.GetType()); 321 EXPECT_EQ(DocumentMarker::kTextMatch, marker.GetType());
322 } 322 }
323 323
324 } // namespace blink 324 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698