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

Side by Side Diff: third_party/WebKit/Source/core/editing/iterators/TextIteratorTest.cpp

Issue 2397033002: Reflow comments in //third_party/WebKit/Source/core/editing/iterators (Closed)
Patch Set: Created 4 years, 2 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 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 iterate<FlatTree>(TextIteratorEntersTextControls)); 166 iterate<FlatTree>(TextIteratorEntersTextControls));
167 } 167 }
168 168
169 TEST_F(TextIteratorTest, NotEnteringShadowTree) { 169 TEST_F(TextIteratorTest, NotEnteringShadowTree) {
170 static const char* bodyContent = 170 static const char* bodyContent =
171 "<div>Hello, <span id='host'>text</span> iterator.</div>"; 171 "<div>Hello, <span id='host'>text</span> iterator.</div>";
172 static const char* shadowContent = "<span>shadow</span>"; 172 static const char* shadowContent = "<span>shadow</span>";
173 setBodyContent(bodyContent); 173 setBodyContent(bodyContent);
174 createShadowRootForElementWithIDAndSetInnerHTML(document(), "host", 174 createShadowRootForElementWithIDAndSetInnerHTML(document(), "host",
175 shadowContent); 175 shadowContent);
176 // TextIterator doesn't emit "text" since its layoutObject is not created. The shadow tree is ignored. 176 // TextIterator doesn't emit "text" since its layoutObject is not created. The
177 // shadow tree is ignored.
177 EXPECT_EQ("[Hello, ][ iterator.]", iterate<DOMTree>()); 178 EXPECT_EQ("[Hello, ][ iterator.]", iterate<DOMTree>());
178 EXPECT_EQ("[Hello, ][shadow][ iterator.]", iterate<FlatTree>()); 179 EXPECT_EQ("[Hello, ][shadow][ iterator.]", iterate<FlatTree>());
179 } 180 }
180 181
181 TEST_F(TextIteratorTest, NotEnteringShadowTreeWithMultipleShadowTrees) { 182 TEST_F(TextIteratorTest, NotEnteringShadowTreeWithMultipleShadowTrees) {
182 static const char* bodyContent = 183 static const char* bodyContent =
183 "<div>Hello, <span id='host'>text</span> iterator.</div>"; 184 "<div>Hello, <span id='host'>text</span> iterator.</div>";
184 static const char* shadowContent1 = "<span>first shadow</span>"; 185 static const char* shadowContent1 = "<span>first shadow</span>";
185 static const char* shadowContent2 = "<span>second shadow</span>"; 186 static const char* shadowContent2 = "<span>second shadow</span>";
186 setBodyContent(bodyContent); 187 setBodyContent(bodyContent);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 EXPECT_EQ("[Hello, ][shadow ][text][ iterator.]", iterate<FlatTree>()); 222 EXPECT_EQ("[Hello, ][shadow ][text][ iterator.]", iterate<FlatTree>());
222 } 223 }
223 224
224 TEST_F(TextIteratorTest, EnteringShadowTreeWithOption) { 225 TEST_F(TextIteratorTest, EnteringShadowTreeWithOption) {
225 static const char* bodyContent = 226 static const char* bodyContent =
226 "<div>Hello, <span id='host'>text</span> iterator.</div>"; 227 "<div>Hello, <span id='host'>text</span> iterator.</div>";
227 static const char* shadowContent = "<span>shadow</span>"; 228 static const char* shadowContent = "<span>shadow</span>";
228 setBodyContent(bodyContent); 229 setBodyContent(bodyContent);
229 createShadowRootForElementWithIDAndSetInnerHTML(document(), "host", 230 createShadowRootForElementWithIDAndSetInnerHTML(document(), "host",
230 shadowContent); 231 shadowContent);
231 // TextIterator emits "shadow" since TextIteratorEntersOpenShadowRoots is spec ified. 232 // TextIterator emits "shadow" since TextIteratorEntersOpenShadowRoots is
233 // specified.
232 EXPECT_EQ("[Hello, ][shadow][ iterator.]", 234 EXPECT_EQ("[Hello, ][shadow][ iterator.]",
233 iterate<DOMTree>(TextIteratorEntersOpenShadowRoots)); 235 iterate<DOMTree>(TextIteratorEntersOpenShadowRoots));
234 EXPECT_EQ("[Hello, ][shadow][ iterator.]", 236 EXPECT_EQ("[Hello, ][shadow][ iterator.]",
235 iterate<FlatTree>(TextIteratorEntersOpenShadowRoots)); 237 iterate<FlatTree>(TextIteratorEntersOpenShadowRoots));
236 } 238 }
237 239
238 TEST_F(TextIteratorTest, EnteringShadowTreeWithMultipleShadowTreesWithOption) { 240 TEST_F(TextIteratorTest, EnteringShadowTreeWithMultipleShadowTreesWithOption) {
239 static const char* bodyContent = 241 static const char* bodyContent =
240 "<div>Hello, <span id='host'>text</span> iterator.</div>"; 242 "<div>Hello, <span id='host'>text</span> iterator.</div>";
241 static const char* shadowContent1 = "<span>first shadow</span>"; 243 static const char* shadowContent1 = "<span>first shadow</span>";
242 static const char* shadowContent2 = "<span>second shadow</span>"; 244 static const char* shadowContent2 = "<span>second shadow</span>";
243 setBodyContent(bodyContent); 245 setBodyContent(bodyContent);
244 createShadowRootForElementWithIDAndSetInnerHTML(document(), "host", 246 createShadowRootForElementWithIDAndSetInnerHTML(document(), "host",
245 shadowContent1); 247 shadowContent1);
246 createShadowRootForElementWithIDAndSetInnerHTML(document(), "host", 248 createShadowRootForElementWithIDAndSetInnerHTML(document(), "host",
247 shadowContent2); 249 shadowContent2);
248 // The first isn't emitted because a layoutObject for the first is not created . 250 // The first isn't emitted because a layoutObject for the first is not
251 // created.
249 EXPECT_EQ("[Hello, ][second shadow][ iterator.]", 252 EXPECT_EQ("[Hello, ][second shadow][ iterator.]",
250 iterate<DOMTree>(TextIteratorEntersOpenShadowRoots)); 253 iterate<DOMTree>(TextIteratorEntersOpenShadowRoots));
251 EXPECT_EQ("[Hello, ][second shadow][ iterator.]", 254 EXPECT_EQ("[Hello, ][second shadow][ iterator.]",
252 iterate<FlatTree>(TextIteratorEntersOpenShadowRoots)); 255 iterate<FlatTree>(TextIteratorEntersOpenShadowRoots));
253 } 256 }
254 257
255 TEST_F(TextIteratorTest, EnteringShadowTreeWithNestedShadowTreesWithOption) { 258 TEST_F(TextIteratorTest, EnteringShadowTreeWithNestedShadowTreesWithOption) {
256 static const char* bodyContent = 259 static const char* bodyContent =
257 "<div>Hello, <span id='host-in-document'>text</span> iterator.</div>"; 260 "<div>Hello, <span id='host-in-document'>text</span> iterator.</div>";
258 static const char* shadowContent1 = 261 static const char* shadowContent1 =
259 "<span>first <span id='host-in-shadow'>shadow</span></span>"; 262 "<span>first <span id='host-in-shadow'>shadow</span></span>";
260 static const char* shadowContent2 = "<span>second shadow</span>"; 263 static const char* shadowContent2 = "<span>second shadow</span>";
261 setBodyContent(bodyContent); 264 setBodyContent(bodyContent);
262 ShadowRoot* shadowRoot1 = createShadowRootForElementWithIDAndSetInnerHTML( 265 ShadowRoot* shadowRoot1 = createShadowRootForElementWithIDAndSetInnerHTML(
263 document(), "host-in-document", shadowContent1); 266 document(), "host-in-document", shadowContent1);
264 createShadowRootForElementWithIDAndSetInnerHTML( 267 createShadowRootForElementWithIDAndSetInnerHTML(
265 *shadowRoot1, "host-in-shadow", shadowContent2); 268 *shadowRoot1, "host-in-shadow", shadowContent2);
266 EXPECT_EQ("[Hello, ][first ][second shadow][ iterator.]", 269 EXPECT_EQ("[Hello, ][first ][second shadow][ iterator.]",
267 iterate<DOMTree>(TextIteratorEntersOpenShadowRoots)); 270 iterate<DOMTree>(TextIteratorEntersOpenShadowRoots));
268 EXPECT_EQ("[Hello, ][first ][second shadow][ iterator.]", 271 EXPECT_EQ("[Hello, ][first ][second shadow][ iterator.]",
269 iterate<FlatTree>(TextIteratorEntersOpenShadowRoots)); 272 iterate<FlatTree>(TextIteratorEntersOpenShadowRoots));
270 } 273 }
271 274
272 TEST_F(TextIteratorTest, 275 TEST_F(TextIteratorTest,
273 EnteringShadowTreeWithContentInsertionPointWithOption) { 276 EnteringShadowTreeWithContentInsertionPointWithOption) {
274 static const char* bodyContent = 277 static const char* bodyContent =
275 "<div>Hello, <span id='host'>text</span> iterator.</div>"; 278 "<div>Hello, <span id='host'>text</span> iterator.</div>";
276 static const char* shadowContent = 279 static const char* shadowContent =
277 "<span><content>content</content> shadow</span>"; 280 "<span><content>content</content> shadow</span>";
278 // In this case a layoutObject for "text" is created, and emitted AFTER any no des in the shadow tree. 281 // In this case a layoutObject for "text" is created, and emitted AFTER any
279 // This order does not match the order of the rendered texts, but at this mome nt it's the expected behavior. 282 // nodes in the shadow tree. This order does not match the order of the
280 // FIXME: Fix this. We probably need pure-renderer-based implementation of Tex tIterator to achieve this. 283 // rendered texts, but at this moment it's the expected behavior.
284 // FIXME: Fix this. We probably need pure-renderer-based implementation of
285 // TextIterator to achieve this.
281 setBodyContent(bodyContent); 286 setBodyContent(bodyContent);
282 createShadowRootForElementWithIDAndSetInnerHTML(document(), "host", 287 createShadowRootForElementWithIDAndSetInnerHTML(document(), "host",
283 shadowContent); 288 shadowContent);
284 EXPECT_EQ("[Hello, ][ shadow][text][ iterator.]", 289 EXPECT_EQ("[Hello, ][ shadow][text][ iterator.]",
285 iterate<DOMTree>(TextIteratorEntersOpenShadowRoots)); 290 iterate<DOMTree>(TextIteratorEntersOpenShadowRoots));
286 EXPECT_EQ("[Hello, ][text][ shadow][ iterator.]", 291 EXPECT_EQ("[Hello, ][text][ shadow][ iterator.]",
287 iterate<FlatTree>(TextIteratorEntersOpenShadowRoots)); 292 iterate<FlatTree>(TextIteratorEntersOpenShadowRoots));
288 } 293 }
289 294
290 TEST_F(TextIteratorTest, StartingAtNodeInShadowRoot) { 295 TEST_F(TextIteratorTest, StartingAtNodeInShadowRoot) {
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
365 "<div id='host'>" 370 "<div id='host'>"
366 "<div>Am I visible?</div>" 371 "<div>Am I visible?</div>"
367 "</div>"; 372 "</div>";
368 static const char* shadowContent = 373 static const char* shadowContent =
369 "<div style='overflow: hidden; width: 200px; height: 0;'>" 374 "<div style='overflow: hidden; width: 200px; height: 0;'>"
370 "<content></content>" 375 "<content></content>"
371 "</div>"; 376 "</div>";
372 setBodyContent(bodyContent); 377 setBodyContent(bodyContent);
373 createShadowRootForElementWithIDAndSetInnerHTML(document(), "host", 378 createShadowRootForElementWithIDAndSetInnerHTML(document(), "host",
374 shadowContent); 379 shadowContent);
375 // FIXME: The text below is actually invisible but TextIterator currently thin ks it's visible. 380 // FIXME: The text below is actually invisible but TextIterator currently
381 // thinks it's visible.
376 EXPECT_EQ("[\n][Am I visible?]", 382 EXPECT_EQ("[\n][Am I visible?]",
377 iterate<DOMTree>(TextIteratorEntersOpenShadowRoots)); 383 iterate<DOMTree>(TextIteratorEntersOpenShadowRoots));
378 EXPECT_EQ("", iterate<FlatTree>(TextIteratorEntersOpenShadowRoots)); 384 EXPECT_EQ("", iterate<FlatTree>(TextIteratorEntersOpenShadowRoots));
379 } 385 }
380 386
381 TEST_F(TextIteratorTest, IgnoresContainersClipDistributed) { 387 TEST_F(TextIteratorTest, IgnoresContainersClipDistributed) {
382 static const char* bodyContent = 388 static const char* bodyContent =
383 "<div id='host' style='overflow: hidden; width: 200px; height: 0;'>" 389 "<div id='host' style='overflow: hidden; width: 200px; height: 0;'>"
384 "<div>Nobody can find me!</div>" 390 "<div>Nobody can find me!</div>"
385 "</div>"; 391 "</div>";
386 static const char* shadowContent = 392 static const char* shadowContent =
387 "<div style='position: absolute; width: 200px; height: 200px; top: 0; " 393 "<div style='position: absolute; width: 200px; height: 200px; top: 0; "
388 "right: 0;'>" 394 "right: 0;'>"
389 "<content></content>" 395 "<content></content>"
390 "</div>"; 396 "</div>";
391 setBodyContent(bodyContent); 397 setBodyContent(bodyContent);
392 createShadowRootForElementWithIDAndSetInnerHTML(document(), "host", 398 createShadowRootForElementWithIDAndSetInnerHTML(document(), "host",
393 shadowContent); 399 shadowContent);
394 // FIXME: The text below is actually visible but TextIterator currently thinks it's invisible. 400 // FIXME: The text below is actually visible but TextIterator currently thinks
401 // it's invisible.
395 // [\n][Nobody can find me!] 402 // [\n][Nobody can find me!]
396 EXPECT_EQ("", iterate<DOMTree>(TextIteratorEntersOpenShadowRoots)); 403 EXPECT_EQ("", iterate<DOMTree>(TextIteratorEntersOpenShadowRoots));
397 EXPECT_EQ("[Nobody can find me!]", 404 EXPECT_EQ("[Nobody can find me!]",
398 iterate<FlatTree>(TextIteratorEntersOpenShadowRoots)); 405 iterate<FlatTree>(TextIteratorEntersOpenShadowRoots));
399 } 406 }
400 407
401 TEST_F(TextIteratorTest, EmitsReplacementCharForInput) { 408 TEST_F(TextIteratorTest, EmitsReplacementCharForInput) {
402 static const char* bodyContent = 409 static const char* bodyContent =
403 "<div contenteditable='true'>" 410 "<div contenteditable='true'>"
404 "Before" 411 "Before"
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
627 setBodyContent( 634 setBodyContent(
628 "<div style='width: 2em;'><b><i id='foo'>foo </i></b> bar</div>"); 635 "<div style='width: 2em;'><b><i id='foo'>foo </i></b> bar</div>");
629 Element* div = document().querySelector("div"); 636 Element* div = document().querySelector("div");
630 Position start(document().getElementById("foo")->firstChild(), 0); 637 Position start(document().getElementById("foo")->firstChild(), 0);
631 Position end(div->lastChild(), 4); 638 Position end(div->lastChild(), 4);
632 EXPECT_EQ("foo bar", plainText(EphemeralRange(start, end), 639 EXPECT_EQ("foo bar", plainText(EphemeralRange(start, end),
633 TextIteratorEmitsImageAltText)); 640 TextIteratorEmitsImageAltText));
634 } 641 }
635 642
636 } // namespace blink 643 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698