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 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 return range.release(); | 124 return range.release(); |
125 } | 125 } |
126 | 126 |
127 Vector<String> createVectorString(const char* const* rawStrings, size_t size) | 127 Vector<String> createVectorString(const char* const* rawStrings, size_t size) |
128 { | 128 { |
129 Vector<String> result; | 129 Vector<String> result; |
130 result.append(rawStrings, size); | 130 result.append(rawStrings, size); |
131 return result; | 131 return result; |
132 } | 132 } |
133 | 133 |
134 PassRefPtr<ShadowRoot> createShadowRootForElementWithIDAndSetInnerHTML(TreeScope
& scope, const char* hostElementID, const char* shadowRootContent) | 134 PassRefPtrWillBeRawPtr<ShadowRoot> createShadowRootForElementWithIDAndSetInnerHT
ML(TreeScope& scope, const char* hostElementID, const char* shadowRootContent) |
135 { | 135 { |
136 RefPtr<ShadowRoot> shadowRoot = scope.getElementById(AtomicString::fromUTF8(
hostElementID))->createShadowRoot(ASSERT_NO_EXCEPTION); | 136 RefPtrWillBeRawPtr<ShadowRoot> shadowRoot = scope.getElementById(AtomicStrin
g::fromUTF8(hostElementID))->createShadowRoot(ASSERT_NO_EXCEPTION); |
137 shadowRoot->setInnerHTML(String::fromUTF8(shadowRootContent), ASSERT_NO_EXCE
PTION); | 137 shadowRoot->setInnerHTML(String::fromUTF8(shadowRootContent), ASSERT_NO_EXCE
PTION); |
138 return shadowRoot.release(); | 138 return shadowRoot.release(); |
139 } | 139 } |
140 | 140 |
141 TEST_F(TextIteratorTest, BasicIteration) | 141 TEST_F(TextIteratorTest, BasicIteration) |
142 { | 142 { |
143 static const char* input = "<p>Hello, \ntext</p><p>iterator.</p>"; | 143 static const char* input = "<p>Hello, \ntext</p><p>iterator.</p>"; |
144 static const char* expectedTextChunksRawString[] = { | 144 static const char* expectedTextChunksRawString[] = { |
145 "Hello, ", | 145 "Hello, ", |
146 "text", | 146 "text", |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
258 static const char* bodyContent = "<div>Hello, <span id=\"host-in-document\">
text</span> iterator.</div>"; | 258 static const char* bodyContent = "<div>Hello, <span id=\"host-in-document\">
text</span> iterator.</div>"; |
259 static const char* shadowContent1 = "<span>first <span id=\"host-in-shadow\"
>shadow</span></span>"; | 259 static const char* shadowContent1 = "<span>first <span id=\"host-in-shadow\"
>shadow</span></span>"; |
260 static const char* shadowContent2 = "<span>second shadow</span>"; | 260 static const char* shadowContent2 = "<span>second shadow</span>"; |
261 static const char* expectedTextChunksRawString[] = { | 261 static const char* expectedTextChunksRawString[] = { |
262 "Hello, ", | 262 "Hello, ", |
263 " iterator." | 263 " iterator." |
264 }; | 264 }; |
265 Vector<String> expectedTextChunks = createVectorString(expectedTextChunksRaw
String, WTF_ARRAY_LENGTH(expectedTextChunksRawString)); | 265 Vector<String> expectedTextChunks = createVectorString(expectedTextChunksRaw
String, WTF_ARRAY_LENGTH(expectedTextChunksRawString)); |
266 | 266 |
267 setBodyInnerHTML(bodyContent); | 267 setBodyInnerHTML(bodyContent); |
268 RefPtr<ShadowRoot> shadowRoot1 = createShadowRootForElementWithIDAndSetInner
HTML(document(), "host-in-document", shadowContent1); | 268 RefPtrWillBeRawPtr<ShadowRoot> shadowRoot1 = createShadowRootForElementWithI
DAndSetInnerHTML(document(), "host-in-document", shadowContent1); |
269 createShadowRootForElementWithIDAndSetInnerHTML(*shadowRoot1, "host-in-shado
w", shadowContent2); | 269 createShadowRootForElementWithIDAndSetInnerHTML(*shadowRoot1, "host-in-shado
w", shadowContent2); |
270 | 270 |
271 EXPECT_EQ(expectedTextChunks, iterate()); | 271 EXPECT_EQ(expectedTextChunks, iterate()); |
272 } | 272 } |
273 | 273 |
274 TEST_F(TextIteratorTest, NotEnteringShadowTreeWithContentInsertionPoint) | 274 TEST_F(TextIteratorTest, NotEnteringShadowTreeWithContentInsertionPoint) |
275 { | 275 { |
276 static const char* bodyContent = "<div>Hello, <span id=\"host\">text</span>
iterator.</div>"; | 276 static const char* bodyContent = "<div>Hello, <span id=\"host\">text</span>
iterator.</div>"; |
277 static const char* shadowContent = "<span>shadow <content>content</content><
/span>"; | 277 static const char* shadowContent = "<span>shadow <content>content</content><
/span>"; |
278 static const char* expectedTextChunksRawString[] = { | 278 static const char* expectedTextChunksRawString[] = { |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
331 static const char* shadowContent2 = "<span>second shadow</span>"; | 331 static const char* shadowContent2 = "<span>second shadow</span>"; |
332 static const char* expectedTextChunksRawString[] = { | 332 static const char* expectedTextChunksRawString[] = { |
333 "Hello, ", | 333 "Hello, ", |
334 "first ", | 334 "first ", |
335 "second shadow", | 335 "second shadow", |
336 " iterator." | 336 " iterator." |
337 }; | 337 }; |
338 Vector<String> expectedTextChunks = createVectorString(expectedTextChunksRaw
String, WTF_ARRAY_LENGTH(expectedTextChunksRawString)); | 338 Vector<String> expectedTextChunks = createVectorString(expectedTextChunksRaw
String, WTF_ARRAY_LENGTH(expectedTextChunksRawString)); |
339 | 339 |
340 setBodyInnerHTML(bodyContent); | 340 setBodyInnerHTML(bodyContent); |
341 RefPtr<ShadowRoot> shadowRoot1 = createShadowRootForElementWithIDAndSetInner
HTML(document(), "host-in-document", shadowContent1); | 341 RefPtrWillBeRawPtr<ShadowRoot> shadowRoot1 = createShadowRootForElementWithI
DAndSetInnerHTML(document(), "host-in-document", shadowContent1); |
342 createShadowRootForElementWithIDAndSetInnerHTML(*shadowRoot1, "host-in-shado
w", shadowContent2); | 342 createShadowRootForElementWithIDAndSetInnerHTML(*shadowRoot1, "host-in-shado
w", shadowContent2); |
343 | 343 |
344 EXPECT_EQ(expectedTextChunks, iterate(TextIteratorEntersAuthorShadowRoots)); | 344 EXPECT_EQ(expectedTextChunks, iterate(TextIteratorEntersAuthorShadowRoots)); |
345 } | 345 } |
346 | 346 |
347 TEST_F(TextIteratorTest, EnteringShadowTreeWithContentInsertionPointWithOption) | 347 TEST_F(TextIteratorTest, EnteringShadowTreeWithContentInsertionPointWithOption) |
348 { | 348 { |
349 static const char* bodyContent = "<div>Hello, <span id=\"host\">text</span>
iterator.</div>"; | 349 static const char* bodyContent = "<div>Hello, <span id=\"host\">text</span>
iterator.</div>"; |
350 static const char* shadowContent = "<span><content>content</content> shadow<
/span>"; | 350 static const char* shadowContent = "<span><content>content</content> shadow<
/span>"; |
351 // In this case a renderer for "text" is created, and emitted AFTER any node
s in the shadow tree. | 351 // In this case a renderer for "text" is created, and emitted AFTER any node
s in the shadow tree. |
(...skipping 18 matching lines...) Expand all Loading... |
370 static const char* bodyContent = "<div id=\"outer\">Hello, <span id=\"host\"
>text</span> iterator.</div>"; | 370 static const char* bodyContent = "<div id=\"outer\">Hello, <span id=\"host\"
>text</span> iterator.</div>"; |
371 static const char* shadowContent = "<span><content>content</content> shadow<
/span>"; | 371 static const char* shadowContent = "<span><content>content</content> shadow<
/span>"; |
372 static const char* expectedTextChunksRawString[] = { | 372 static const char* expectedTextChunksRawString[] = { |
373 " shadow", | 373 " shadow", |
374 "text", | 374 "text", |
375 " iterator." | 375 " iterator." |
376 }; | 376 }; |
377 Vector<String> expectedTextChunks = createVectorString(expectedTextChunksRaw
String, WTF_ARRAY_LENGTH(expectedTextChunksRawString)); | 377 Vector<String> expectedTextChunks = createVectorString(expectedTextChunksRaw
String, WTF_ARRAY_LENGTH(expectedTextChunksRawString)); |
378 | 378 |
379 setBodyInnerHTML(bodyContent); | 379 setBodyInnerHTML(bodyContent); |
380 RefPtr<ShadowRoot> shadowRoot = createShadowRootForElementWithIDAndSetInnerH
TML(document(), "host", shadowContent); | 380 RefPtrWillBeRawPtr<ShadowRoot> shadowRoot = createShadowRootForElementWithID
AndSetInnerHTML(document(), "host", shadowContent); |
381 Node* outerDiv = document().getElementById("outer"); | 381 Node* outerDiv = document().getElementById("outer"); |
382 Node* spanInShadow = shadowRoot->firstChild(); | 382 Node* spanInShadow = shadowRoot->firstChild(); |
383 Position start(spanInShadow, Position::PositionIsBeforeChildren); | 383 Position start(spanInShadow, Position::PositionIsBeforeChildren); |
384 Position end(outerDiv, Position::PositionIsAfterChildren); | 384 Position end(outerDiv, Position::PositionIsAfterChildren); |
385 | 385 |
386 EXPECT_EQ(expectedTextChunks, iteratePartial(start, end, TextIteratorEntersA
uthorShadowRoots)); | 386 EXPECT_EQ(expectedTextChunks, iteratePartial(start, end, TextIteratorEntersA
uthorShadowRoots)); |
387 } | 387 } |
388 | 388 |
389 TEST_F(TextIteratorTest, FinishingAtNodeInShadowRoot) | 389 TEST_F(TextIteratorTest, FinishingAtNodeInShadowRoot) |
390 { | 390 { |
391 static const char* bodyContent = "<div id=\"outer\">Hello, <span id=\"host\"
>text</span> iterator.</div>"; | 391 static const char* bodyContent = "<div id=\"outer\">Hello, <span id=\"host\"
>text</span> iterator.</div>"; |
392 static const char* shadowContent = "<span><content>content</content> shadow<
/span>"; | 392 static const char* shadowContent = "<span><content>content</content> shadow<
/span>"; |
393 static const char* expectedTextChunksRawString[] = { | 393 static const char* expectedTextChunksRawString[] = { |
394 "Hello, ", | 394 "Hello, ", |
395 " shadow" | 395 " shadow" |
396 }; | 396 }; |
397 Vector<String> expectedTextChunks = createVectorString(expectedTextChunksRaw
String, WTF_ARRAY_LENGTH(expectedTextChunksRawString)); | 397 Vector<String> expectedTextChunks = createVectorString(expectedTextChunksRaw
String, WTF_ARRAY_LENGTH(expectedTextChunksRawString)); |
398 | 398 |
399 setBodyInnerHTML(bodyContent); | 399 setBodyInnerHTML(bodyContent); |
400 RefPtr<ShadowRoot> shadowRoot = createShadowRootForElementWithIDAndSetInnerH
TML(document(), "host", shadowContent); | 400 RefPtrWillBeRawPtr<ShadowRoot> shadowRoot = createShadowRootForElementWithID
AndSetInnerHTML(document(), "host", shadowContent); |
401 Node* outerDiv = document().getElementById("outer"); | 401 Node* outerDiv = document().getElementById("outer"); |
402 Node* spanInShadow = shadowRoot->firstChild(); | 402 Node* spanInShadow = shadowRoot->firstChild(); |
403 Position start(outerDiv, Position::PositionIsBeforeChildren); | 403 Position start(outerDiv, Position::PositionIsBeforeChildren); |
404 Position end(spanInShadow, Position::PositionIsAfterChildren); | 404 Position end(spanInShadow, Position::PositionIsAfterChildren); |
405 | 405 |
406 EXPECT_EQ(expectedTextChunks, iteratePartial(start, end, TextIteratorEntersA
uthorShadowRoots)); | 406 EXPECT_EQ(expectedTextChunks, iteratePartial(start, end, TextIteratorEntersA
uthorShadowRoots)); |
407 } | 407 } |
408 | 408 |
409 TEST_F(TextIteratorTest, FullyClipsContents) | 409 TEST_F(TextIteratorTest, FullyClipsContents) |
410 { | 410 { |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
511 static const UChar* invalidUStrings[] = { invalid1, invalid2, invalid3 }; | 511 static const UChar* invalidUStrings[] = { invalid1, invalid2, invalid3 }; |
512 | 512 |
513 for (size_t i = 0; i < WTF_ARRAY_LENGTH(invalidUStrings); ++i) { | 513 for (size_t i = 0; i < WTF_ARRAY_LENGTH(invalidUStrings); ++i) { |
514 String invalidTarget(invalidUStrings[i]); | 514 String invalidTarget(invalidUStrings[i]); |
515 RefPtrWillBeRawPtr<Range> actualRange = findPlainText(range.get(), inval
idTarget, 0); | 515 RefPtrWillBeRawPtr<Range> actualRange = findPlainText(range.get(), inval
idTarget, 0); |
516 EXPECT_TRUE(areRangesEqual(expectedRange.get(), actualRange.get())); | 516 EXPECT_TRUE(areRangesEqual(expectedRange.get(), actualRange.get())); |
517 } | 517 } |
518 } | 518 } |
519 | 519 |
520 } | 520 } |
OLD | NEW |