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

Side by Side Diff: third_party/WebKit/Source/web/tests/TextFinderTest.cpp

Issue 1605863002: Restart search in page when new text is found. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: small clean up Created 4 years, 10 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 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "web/TextFinder.h" 5 #include "web/TextFinder.h"
6 6
7 #include "bindings/core/v8/ExceptionStatePlaceholder.h" 7 #include "bindings/core/v8/ExceptionStatePlaceholder.h"
8 #include "core/dom/Document.h" 8 #include "core/dom/Document.h"
9 #include "core/dom/NodeList.h" 9 #include "core/dom/NodeList.h"
10 #include "core/dom/Range.h" 10 #include "core/dom/Range.h"
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 TEST_F(TextFinderTest, FindTextSimple) 69 TEST_F(TextFinderTest, FindTextSimple)
70 { 70 {
71 document().body()->setInnerHTML("XXXXFindMeYYYYfindmeZZZZ", ASSERT_NO_EXCEPT ION); 71 document().body()->setInnerHTML("XXXXFindMeYYYYfindmeZZZZ", ASSERT_NO_EXCEPT ION);
72 Node* textNode = document().body()->firstChild(); 72 Node* textNode = document().body()->firstChild();
73 73
74 int identifier = 0; 74 int identifier = 0;
75 WebString searchText(String("FindMe")); 75 WebString searchText(String("FindMe"));
76 WebFindOptions findOptions; // Default. 76 WebFindOptions findOptions; // Default.
77 bool wrapWithinFrame = true; 77 bool wrapWithinFrame = true;
78 WebRect* selectionRect = nullptr; 78 WebRect* selectionRect = nullptr;
79 bool* activeNow = nullptr;
79 80
80 ASSERT_TRUE(textFinder().find(identifier, searchText, findOptions, wrapWithi nFrame, selectionRect)); 81 ASSERT_TRUE(textFinder().find(identifier, searchText, findOptions, wrapWithi nFrame, selectionRect, activeNow));
81 Range* activeMatch = textFinder().activeMatch(); 82 Range* activeMatch = textFinder().activeMatch();
82 ASSERT_TRUE(activeMatch); 83 ASSERT_TRUE(activeMatch);
83 EXPECT_EQ(textNode, activeMatch->startContainer()); 84 EXPECT_EQ(textNode, activeMatch->startContainer());
84 EXPECT_EQ(4, activeMatch->startOffset()); 85 EXPECT_EQ(4, activeMatch->startOffset());
85 EXPECT_EQ(textNode, activeMatch->endContainer()); 86 EXPECT_EQ(textNode, activeMatch->endContainer());
86 EXPECT_EQ(10, activeMatch->endOffset()); 87 EXPECT_EQ(10, activeMatch->endOffset());
87 88
88 findOptions.findNext = true; 89 findOptions.findNext = true;
89 ASSERT_TRUE(textFinder().find(identifier, searchText, findOptions, wrapWithi nFrame, selectionRect)); 90 ASSERT_TRUE(textFinder().find(identifier, searchText, findOptions, wrapWithi nFrame, selectionRect, activeNow));
90 activeMatch = textFinder().activeMatch(); 91 activeMatch = textFinder().activeMatch();
91 ASSERT_TRUE(activeMatch); 92 ASSERT_TRUE(activeMatch);
92 EXPECT_EQ(textNode, activeMatch->startContainer()); 93 EXPECT_EQ(textNode, activeMatch->startContainer());
93 EXPECT_EQ(14, activeMatch->startOffset()); 94 EXPECT_EQ(14, activeMatch->startOffset());
94 EXPECT_EQ(textNode, activeMatch->endContainer()); 95 EXPECT_EQ(textNode, activeMatch->endContainer());
95 EXPECT_EQ(20, activeMatch->endOffset()); 96 EXPECT_EQ(20, activeMatch->endOffset());
96 97
97 // Should wrap to the first match. 98 // Should wrap to the first match.
98 ASSERT_TRUE(textFinder().find(identifier, searchText, findOptions, wrapWithi nFrame, selectionRect)); 99 ASSERT_TRUE(textFinder().find(identifier, searchText, findOptions, wrapWithi nFrame, selectionRect, activeNow));
99 activeMatch = textFinder().activeMatch(); 100 activeMatch = textFinder().activeMatch();
100 ASSERT_TRUE(activeMatch); 101 ASSERT_TRUE(activeMatch);
101 EXPECT_EQ(textNode, activeMatch->startContainer()); 102 EXPECT_EQ(textNode, activeMatch->startContainer());
102 EXPECT_EQ(4, activeMatch->startOffset()); 103 EXPECT_EQ(4, activeMatch->startOffset());
103 EXPECT_EQ(textNode, activeMatch->endContainer()); 104 EXPECT_EQ(textNode, activeMatch->endContainer());
104 EXPECT_EQ(10, activeMatch->endOffset()); 105 EXPECT_EQ(10, activeMatch->endOffset());
105 106
106 // Search in the reverse order. 107 // Search in the reverse order.
107 identifier = 1; 108 identifier = 1;
108 findOptions = WebFindOptions(); 109 findOptions = WebFindOptions();
109 findOptions.forward = false; 110 findOptions.forward = false;
110 111
111 ASSERT_TRUE(textFinder().find(identifier, searchText, findOptions, wrapWithi nFrame, selectionRect)); 112 ASSERT_TRUE(textFinder().find(identifier, searchText, findOptions, wrapWithi nFrame, selectionRect, activeNow));
112 activeMatch = textFinder().activeMatch(); 113 activeMatch = textFinder().activeMatch();
113 ASSERT_TRUE(activeMatch); 114 ASSERT_TRUE(activeMatch);
114 EXPECT_EQ(textNode, activeMatch->startContainer()); 115 EXPECT_EQ(textNode, activeMatch->startContainer());
115 EXPECT_EQ(14, activeMatch->startOffset()); 116 EXPECT_EQ(14, activeMatch->startOffset());
116 EXPECT_EQ(textNode, activeMatch->endContainer()); 117 EXPECT_EQ(textNode, activeMatch->endContainer());
117 EXPECT_EQ(20, activeMatch->endOffset()); 118 EXPECT_EQ(20, activeMatch->endOffset());
118 119
119 findOptions.findNext = true; 120 findOptions.findNext = true;
120 ASSERT_TRUE(textFinder().find(identifier, searchText, findOptions, wrapWithi nFrame, selectionRect)); 121 ASSERT_TRUE(textFinder().find(identifier, searchText, findOptions, wrapWithi nFrame, selectionRect, activeNow));
121 activeMatch = textFinder().activeMatch(); 122 activeMatch = textFinder().activeMatch();
122 ASSERT_TRUE(activeMatch); 123 ASSERT_TRUE(activeMatch);
123 EXPECT_EQ(textNode, activeMatch->startContainer()); 124 EXPECT_EQ(textNode, activeMatch->startContainer());
124 EXPECT_EQ(4, activeMatch->startOffset()); 125 EXPECT_EQ(4, activeMatch->startOffset());
125 EXPECT_EQ(textNode, activeMatch->endContainer()); 126 EXPECT_EQ(textNode, activeMatch->endContainer());
126 EXPECT_EQ(10, activeMatch->endOffset()); 127 EXPECT_EQ(10, activeMatch->endOffset());
127 128
128 // Wrap to the first match (last occurence in the document). 129 // Wrap to the first match (last occurence in the document).
129 ASSERT_TRUE(textFinder().find(identifier, searchText, findOptions, wrapWithi nFrame, selectionRect)); 130 ASSERT_TRUE(textFinder().find(identifier, searchText, findOptions, wrapWithi nFrame, selectionRect, activeNow));
130 activeMatch = textFinder().activeMatch(); 131 activeMatch = textFinder().activeMatch();
131 ASSERT_TRUE(activeMatch); 132 ASSERT_TRUE(activeMatch);
132 EXPECT_EQ(textNode, activeMatch->startContainer()); 133 EXPECT_EQ(textNode, activeMatch->startContainer());
133 EXPECT_EQ(14, activeMatch->startOffset()); 134 EXPECT_EQ(14, activeMatch->startOffset());
134 EXPECT_EQ(textNode, activeMatch->endContainer()); 135 EXPECT_EQ(textNode, activeMatch->endContainer());
135 EXPECT_EQ(20, activeMatch->endOffset()); 136 EXPECT_EQ(20, activeMatch->endOffset());
136 } 137 }
137 138
138 TEST_F(TextFinderTest, FindTextAutosizing) 139 TEST_F(TextFinderTest, FindTextAutosizing)
139 { 140 {
140 document().body()->setInnerHTML("XXXXFindMeYYYYfindmeZZZZ", ASSERT_NO_EXCEPT ION); 141 document().body()->setInnerHTML("XXXXFindMeYYYYfindmeZZZZ", ASSERT_NO_EXCEPT ION);
141 142
142 int identifier = 0; 143 int identifier = 0;
143 WebString searchText(String("FindMe")); 144 WebString searchText(String("FindMe"));
144 WebFindOptions findOptions; // Default. 145 WebFindOptions findOptions; // Default.
145 bool wrapWithinFrame = true; 146 bool wrapWithinFrame = true;
146 WebRect* selectionRect = nullptr; 147 WebRect* selectionRect = nullptr;
148 bool* activeNow = nullptr;
147 149
148 // Set viewport scale to 20 in order to simulate zoom-in 150 // Set viewport scale to 20 in order to simulate zoom-in
149 VisualViewport& visualViewport = document().page()->frameHost().visualViewpo rt(); 151 VisualViewport& visualViewport = document().page()->frameHost().visualViewpo rt();
150 visualViewport.setScale(20); 152 visualViewport.setScale(20);
151 153
152 // Enforce autosizing 154 // Enforce autosizing
153 document().settings()->setTextAutosizingEnabled(true); 155 document().settings()->setTextAutosizingEnabled(true);
154 document().settings()->setTextAutosizingWindowSizeOverride(IntSize(20, 20)); 156 document().settings()->setTextAutosizingWindowSizeOverride(IntSize(20, 20));
155 document().textAutosizer()->updatePageInfo(); 157 document().textAutosizer()->updatePageInfo();
156 158
157 // In case of autosizing, scale _should_ change 159 // In case of autosizing, scale _should_ change
158 ASSERT_TRUE(textFinder().find(identifier, searchText, findOptions, wrapWithi nFrame, selectionRect)); 160 ASSERT_TRUE(textFinder().find(identifier, searchText, findOptions, wrapWithi nFrame, selectionRect, activeNow));
159 ASSERT_TRUE(textFinder().activeMatch()); 161 ASSERT_TRUE(textFinder().activeMatch());
160 ASSERT_EQ(1, visualViewport.scale()); // in this case to 1 162 ASSERT_EQ(1, visualViewport.scale()); // in this case to 1
161 163
162 // Disable autosizing and reset scale to 20 164 // Disable autosizing and reset scale to 20
163 visualViewport.setScale(20); 165 visualViewport.setScale(20);
164 document().settings()->setTextAutosizingEnabled(false); 166 document().settings()->setTextAutosizingEnabled(false);
165 document().textAutosizer()->updatePageInfo(); 167 document().textAutosizer()->updatePageInfo();
166 168
167 ASSERT_TRUE(textFinder().find(identifier, searchText, findOptions, wrapWithi nFrame, selectionRect)); 169 ASSERT_TRUE(textFinder().find(identifier, searchText, findOptions, wrapWithi nFrame, selectionRect, activeNow));
168 ASSERT_TRUE(textFinder().activeMatch()); 170 ASSERT_TRUE(textFinder().activeMatch());
169 ASSERT_EQ(20, visualViewport.scale()); 171 ASSERT_EQ(20, visualViewport.scale());
170 } 172 }
171 173
172 TEST_F(TextFinderTest, FindTextNotFound) 174 TEST_F(TextFinderTest, FindTextNotFound)
173 { 175 {
174 document().body()->setInnerHTML("XXXXFindMeYYYYfindmeZZZZ", ASSERT_NO_EXCEPT ION); 176 document().body()->setInnerHTML("XXXXFindMeYYYYfindmeZZZZ", ASSERT_NO_EXCEPT ION);
175 177
176 int identifier = 0; 178 int identifier = 0;
177 WebString searchText(String("Boo")); 179 WebString searchText(String("Boo"));
178 WebFindOptions findOptions; // Default. 180 WebFindOptions findOptions; // Default.
179 bool wrapWithinFrame = true; 181 bool wrapWithinFrame = true;
180 WebRect* selectionRect = nullptr; 182 WebRect* selectionRect = nullptr;
183 bool* activeNow = nullptr;
181 184
182 EXPECT_FALSE(textFinder().find(identifier, searchText, findOptions, wrapWith inFrame, selectionRect)); 185 EXPECT_FALSE(textFinder().find(identifier, searchText, findOptions, wrapWith inFrame, selectionRect, activeNow));
183 EXPECT_FALSE(textFinder().activeMatch()); 186 EXPECT_FALSE(textFinder().activeMatch());
184 } 187 }
185 188
186 TEST_F(TextFinderTest, FindTextInShadowDOM) 189 TEST_F(TextFinderTest, FindTextInShadowDOM)
187 { 190 {
188 document().body()->setInnerHTML("<b>FOO</b><i>foo</i>", ASSERT_NO_EXCEPTION) ; 191 document().body()->setInnerHTML("<b>FOO</b><i>foo</i>", ASSERT_NO_EXCEPTION) ;
189 RefPtrWillBeRawPtr<ShadowRoot> shadowRoot = document().body()->createShadowR ootInternal(ShadowRootType::V0, ASSERT_NO_EXCEPTION); 192 RefPtrWillBeRawPtr<ShadowRoot> shadowRoot = document().body()->createShadowR ootInternal(ShadowRootType::V0, ASSERT_NO_EXCEPTION);
190 shadowRoot->setInnerHTML("<content select=\"i\"></content><u>Foo</u><content ></content>", ASSERT_NO_EXCEPTION); 193 shadowRoot->setInnerHTML("<content select=\"i\"></content><u>Foo</u><content ></content>", ASSERT_NO_EXCEPTION);
191 Node* textInBElement = document().body()->firstChild()->firstChild(); 194 Node* textInBElement = document().body()->firstChild()->firstChild();
192 Node* textInIElement = document().body()->lastChild()->firstChild(); 195 Node* textInIElement = document().body()->lastChild()->firstChild();
193 Node* textInUElement = shadowRoot->childNodes()->item(1)->firstChild(); 196 Node* textInUElement = shadowRoot->childNodes()->item(1)->firstChild();
194 197
195 int identifier = 0; 198 int identifier = 0;
196 WebString searchText(String("foo")); 199 WebString searchText(String("foo"));
197 WebFindOptions findOptions; // Default. 200 WebFindOptions findOptions; // Default.
198 bool wrapWithinFrame = true; 201 bool wrapWithinFrame = true;
199 WebRect* selectionRect = nullptr; 202 WebRect* selectionRect = nullptr;
203 bool* activeNow = nullptr;
200 204
201 // TextIterator currently returns the matches in the composed treeorder, so 205 // TextIterator currently returns the matches in the composed treeorder, so
202 // in this case the matches will be returned in the order of 206 // in this case the matches will be returned in the order of
203 // <i> -> <u> -> <b>. 207 // <i> -> <u> -> <b>.
204 ASSERT_TRUE(textFinder().find(identifier, searchText, findOptions, wrapWithi nFrame, selectionRect)); 208 ASSERT_TRUE(textFinder().find(identifier, searchText, findOptions, wrapWithi nFrame, selectionRect, activeNow));
205 Range* activeMatch = textFinder().activeMatch(); 209 Range* activeMatch = textFinder().activeMatch();
206 ASSERT_TRUE(activeMatch); 210 ASSERT_TRUE(activeMatch);
207 EXPECT_EQ(textInIElement, activeMatch->startContainer()); 211 EXPECT_EQ(textInIElement, activeMatch->startContainer());
208 EXPECT_EQ(0, activeMatch->startOffset()); 212 EXPECT_EQ(0, activeMatch->startOffset());
209 EXPECT_EQ(textInIElement, activeMatch->endContainer()); 213 EXPECT_EQ(textInIElement, activeMatch->endContainer());
210 EXPECT_EQ(3, activeMatch->endOffset()); 214 EXPECT_EQ(3, activeMatch->endOffset());
211 215
212 findOptions.findNext = true; 216 findOptions.findNext = true;
213 ASSERT_TRUE(textFinder().find(identifier, searchText, findOptions, wrapWithi nFrame, selectionRect)); 217 ASSERT_TRUE(textFinder().find(identifier, searchText, findOptions, wrapWithi nFrame, selectionRect, activeNow));
214 activeMatch = textFinder().activeMatch(); 218 activeMatch = textFinder().activeMatch();
215 ASSERT_TRUE(activeMatch); 219 ASSERT_TRUE(activeMatch);
216 EXPECT_EQ(textInUElement, activeMatch->startContainer()); 220 EXPECT_EQ(textInUElement, activeMatch->startContainer());
217 EXPECT_EQ(0, activeMatch->startOffset()); 221 EXPECT_EQ(0, activeMatch->startOffset());
218 EXPECT_EQ(textInUElement, activeMatch->endContainer()); 222 EXPECT_EQ(textInUElement, activeMatch->endContainer());
219 EXPECT_EQ(3, activeMatch->endOffset()); 223 EXPECT_EQ(3, activeMatch->endOffset());
220 224
221 ASSERT_TRUE(textFinder().find(identifier, searchText, findOptions, wrapWithi nFrame, selectionRect)); 225 ASSERT_TRUE(textFinder().find(identifier, searchText, findOptions, wrapWithi nFrame, selectionRect, activeNow));
222 activeMatch = textFinder().activeMatch(); 226 activeMatch = textFinder().activeMatch();
223 ASSERT_TRUE(activeMatch); 227 ASSERT_TRUE(activeMatch);
224 EXPECT_EQ(textInBElement, activeMatch->startContainer()); 228 EXPECT_EQ(textInBElement, activeMatch->startContainer());
225 EXPECT_EQ(0, activeMatch->startOffset()); 229 EXPECT_EQ(0, activeMatch->startOffset());
226 EXPECT_EQ(textInBElement, activeMatch->endContainer()); 230 EXPECT_EQ(textInBElement, activeMatch->endContainer());
227 EXPECT_EQ(3, activeMatch->endOffset()); 231 EXPECT_EQ(3, activeMatch->endOffset());
228 232
229 // Should wrap to the first match. 233 // Should wrap to the first match.
230 ASSERT_TRUE(textFinder().find(identifier, searchText, findOptions, wrapWithi nFrame, selectionRect)); 234 ASSERT_TRUE(textFinder().find(identifier, searchText, findOptions, wrapWithi nFrame, selectionRect, activeNow));
231 activeMatch = textFinder().activeMatch(); 235 activeMatch = textFinder().activeMatch();
232 ASSERT_TRUE(activeMatch); 236 ASSERT_TRUE(activeMatch);
233 EXPECT_EQ(textInIElement, activeMatch->startContainer()); 237 EXPECT_EQ(textInIElement, activeMatch->startContainer());
234 EXPECT_EQ(0, activeMatch->startOffset()); 238 EXPECT_EQ(0, activeMatch->startOffset());
235 EXPECT_EQ(textInIElement, activeMatch->endContainer()); 239 EXPECT_EQ(textInIElement, activeMatch->endContainer());
236 EXPECT_EQ(3, activeMatch->endOffset()); 240 EXPECT_EQ(3, activeMatch->endOffset());
237 241
238 // Fresh search in the reverse order. 242 // Fresh search in the reverse order.
239 identifier = 1; 243 identifier = 1;
240 findOptions = WebFindOptions(); 244 findOptions = WebFindOptions();
241 findOptions.forward = false; 245 findOptions.forward = false;
242 246
243 ASSERT_TRUE(textFinder().find(identifier, searchText, findOptions, wrapWithi nFrame, selectionRect)); 247 ASSERT_TRUE(textFinder().find(identifier, searchText, findOptions, wrapWithi nFrame, selectionRect, activeNow));
244 activeMatch = textFinder().activeMatch(); 248 activeMatch = textFinder().activeMatch();
245 ASSERT_TRUE(activeMatch); 249 ASSERT_TRUE(activeMatch);
246 EXPECT_EQ(textInBElement, activeMatch->startContainer()); 250 EXPECT_EQ(textInBElement, activeMatch->startContainer());
247 EXPECT_EQ(0, activeMatch->startOffset()); 251 EXPECT_EQ(0, activeMatch->startOffset());
248 EXPECT_EQ(textInBElement, activeMatch->endContainer()); 252 EXPECT_EQ(textInBElement, activeMatch->endContainer());
249 EXPECT_EQ(3, activeMatch->endOffset()); 253 EXPECT_EQ(3, activeMatch->endOffset());
250 254
251 findOptions.findNext = true; 255 findOptions.findNext = true;
252 ASSERT_TRUE(textFinder().find(identifier, searchText, findOptions, wrapWithi nFrame, selectionRect)); 256 ASSERT_TRUE(textFinder().find(identifier, searchText, findOptions, wrapWithi nFrame, selectionRect, activeNow));
253 activeMatch = textFinder().activeMatch(); 257 activeMatch = textFinder().activeMatch();
254 ASSERT_TRUE(activeMatch); 258 ASSERT_TRUE(activeMatch);
255 EXPECT_EQ(textInUElement, activeMatch->startContainer()); 259 EXPECT_EQ(textInUElement, activeMatch->startContainer());
256 EXPECT_EQ(0, activeMatch->startOffset()); 260 EXPECT_EQ(0, activeMatch->startOffset());
257 EXPECT_EQ(textInUElement, activeMatch->endContainer()); 261 EXPECT_EQ(textInUElement, activeMatch->endContainer());
258 EXPECT_EQ(3, activeMatch->endOffset()); 262 EXPECT_EQ(3, activeMatch->endOffset());
259 263
260 ASSERT_TRUE(textFinder().find(identifier, searchText, findOptions, wrapWithi nFrame, selectionRect)); 264 ASSERT_TRUE(textFinder().find(identifier, searchText, findOptions, wrapWithi nFrame, selectionRect, activeNow));
261 activeMatch = textFinder().activeMatch(); 265 activeMatch = textFinder().activeMatch();
262 ASSERT_TRUE(activeMatch); 266 ASSERT_TRUE(activeMatch);
263 EXPECT_EQ(textInIElement, activeMatch->startContainer()); 267 EXPECT_EQ(textInIElement, activeMatch->startContainer());
264 EXPECT_EQ(0, activeMatch->startOffset()); 268 EXPECT_EQ(0, activeMatch->startOffset());
265 EXPECT_EQ(textInIElement, activeMatch->endContainer()); 269 EXPECT_EQ(textInIElement, activeMatch->endContainer());
266 EXPECT_EQ(3, activeMatch->endOffset()); 270 EXPECT_EQ(3, activeMatch->endOffset());
267 271
268 // And wrap. 272 // And wrap.
269 ASSERT_TRUE(textFinder().find(identifier, searchText, findOptions, wrapWithi nFrame, selectionRect)); 273 ASSERT_TRUE(textFinder().find(identifier, searchText, findOptions, wrapWithi nFrame, selectionRect, activeNow));
270 activeMatch = textFinder().activeMatch(); 274 activeMatch = textFinder().activeMatch();
271 ASSERT_TRUE(activeMatch); 275 ASSERT_TRUE(activeMatch);
272 EXPECT_EQ(textInBElement, activeMatch->startContainer()); 276 EXPECT_EQ(textInBElement, activeMatch->startContainer());
273 EXPECT_EQ(0, activeMatch->startOffset()); 277 EXPECT_EQ(0, activeMatch->startOffset());
274 EXPECT_EQ(textInBElement, activeMatch->endContainer()); 278 EXPECT_EQ(textInBElement, activeMatch->endContainer());
275 EXPECT_EQ(3, activeMatch->endOffset()); 279 EXPECT_EQ(3, activeMatch->endOffset());
276 } 280 }
277 281
278 TEST_F(TextFinderTest, ScopeTextMatchesSimple) 282 TEST_F(TextFinderTest, ScopeTextMatchesSimple)
279 { 283 {
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
387 391
388 EXPECT_EQ(3, textFinder().totalMatchCount()); 392 EXPECT_EQ(3, textFinder().totalMatchCount());
389 WebVector<WebFloatRect> matchRects; 393 WebVector<WebFloatRect> matchRects;
390 textFinder().findMatchRects(matchRects); 394 textFinder().findMatchRects(matchRects);
391 ASSERT_EQ(3u, matchRects.size()); 395 ASSERT_EQ(3u, matchRects.size());
392 EXPECT_EQ(findInPageRect(textNode, 0, textNode, 2), matchRects[0]); 396 EXPECT_EQ(findInPageRect(textNode, 0, textNode, 2), matchRects[0]);
393 EXPECT_EQ(findInPageRect(textNode, 2, textNode, 4), matchRects[1]); 397 EXPECT_EQ(findInPageRect(textNode, 2, textNode, 4), matchRects[1]);
394 EXPECT_EQ(findInPageRect(textNode, 4, textNode, 6), matchRects[2]); 398 EXPECT_EQ(findInPageRect(textNode, 4, textNode, 6), matchRects[2]);
395 } 399 }
396 400
401 TEST_F(TextFinderTest, FindTextJavaScriptUpdatesDOM)
402 {
403 document().body()->setInnerHTML("<b>XXXXFindMeYYYY</b><i></i>", ASSERT_NO_EX CEPTION);
404
405 int identifier = 0;
406 WebString searchText(String("FindMe"));
407 WebFindOptions findOptions; // Default.
408 bool wrapWithinFrame = true;
409 WebRect* selectionRect = nullptr;
410 bool activeNow;
411
412 textFinder().resetMatchCount();
413 textFinder().scopeStringMatches(identifier, searchText, findOptions, true);
414 while (textFinder().scopingInProgress())
415 runPendingTasks();
416
417 findOptions.findNext = true;
418 ASSERT_TRUE(textFinder().find(identifier, searchText, findOptions, wrapWithi nFrame, selectionRect, &activeNow));
419 EXPECT_TRUE(activeNow);
420 ASSERT_TRUE(textFinder().find(identifier, searchText, findOptions, wrapWithi nFrame, selectionRect, &activeNow));
421 EXPECT_TRUE(activeNow);
422
423 // Add new text to DOM and try FindNext.
424 Element* iElement = toElement(document().body()->lastChild());
425 ASSERT_TRUE(iElement);
426 iElement->setInnerHTML("ZZFindMe", ASSERT_NO_EXCEPTION);
427
428 ASSERT_TRUE(textFinder().find(identifier, searchText, findOptions, wrapWithi nFrame, selectionRect, &activeNow));
429 Range* activeMatch = textFinder().activeMatch();
430 ASSERT_TRUE(activeMatch);
431 EXPECT_FALSE(activeNow);
432 EXPECT_EQ(2, activeMatch->startOffset());
433 EXPECT_EQ(8, activeMatch->endOffset());
434
435 // Restart full search and check that added text is found.
436 findOptions.findNext = false;
437 textFinder().resetMatchCount();
438 textFinder().cancelPendingScopingEffort();
439 textFinder().scopeStringMatches(identifier, searchText, findOptions, true);
440 while (textFinder().scopingInProgress())
441 runPendingTasks();
442 EXPECT_EQ(2, textFinder().totalMatchCount());
443
444 WebVector<WebFloatRect> matchRects;
445 textFinder().findMatchRects(matchRects);
446 ASSERT_EQ(2u, matchRects.size());
447 Node* textInBElement = document().body()->firstChild()->firstChild();
448 Node* textInIElement = document().body()->lastChild()->firstChild();
449 EXPECT_EQ(findInPageRect(textInBElement, 4, textInBElement, 10), matchRects[ 0]);
450 EXPECT_EQ(findInPageRect(textInIElement, 2, textInIElement, 8), matchRects[1 ]);
451 }
452
397 class TextFinderFakeTimerTest : public TextFinderTest { 453 class TextFinderFakeTimerTest : public TextFinderTest {
398 protected: 454 protected:
399 // A simple platform that mocks out the clock. 455 // A simple platform that mocks out the clock.
400 class TimeProxyPlatform : public TestingPlatformSupport { 456 class TimeProxyPlatform : public TestingPlatformSupport {
401 public: 457 public:
402 TimeProxyPlatform() 458 TimeProxyPlatform()
403 : m_timeCounter(m_oldPlatform->currentTimeSeconds()) 459 : m_timeCounter(m_oldPlatform->currentTimeSeconds())
404 { 460 {
405 } 461 }
406 462
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
455 // There will be only one iteration before timeout, because increment 511 // There will be only one iteration before timeout, because increment
456 // of the TimeProxyPlatform timer is greater than timeout threshold. 512 // of the TimeProxyPlatform timer is greater than timeout threshold.
457 textFinder().scopeStringMatches(identifier, searchPattern, findOptions, true ); 513 textFinder().scopeStringMatches(identifier, searchPattern, findOptions, true );
458 while (textFinder().scopingInProgress()) 514 while (textFinder().scopingInProgress())
459 runPendingTasks(); 515 runPendingTasks();
460 516
461 EXPECT_EQ(4, textFinder().totalMatchCount()); 517 EXPECT_EQ(4, textFinder().totalMatchCount());
462 } 518 }
463 519
464 } // namespace blink 520 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698