| 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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 #include "platform/geometry/IntSize.h" | 44 #include "platform/geometry/IntSize.h" |
| 45 #include "wtf/Compiler.h" | 45 #include "wtf/Compiler.h" |
| 46 #include "wtf/OwnPtr.h" | 46 #include "wtf/OwnPtr.h" |
| 47 #include "wtf/PassRefPtr.h" | 47 #include "wtf/PassRefPtr.h" |
| 48 #include "wtf/RefPtr.h" | 48 #include "wtf/RefPtr.h" |
| 49 #include "wtf/StdLibExtras.h" | 49 #include "wtf/StdLibExtras.h" |
| 50 #include "wtf/testing/WTFTestHelpers.h" | 50 #include "wtf/testing/WTFTestHelpers.h" |
| 51 #include <gtest/gtest.h> | 51 #include <gtest/gtest.h> |
| 52 #include <string> | 52 #include <string> |
| 53 | 53 |
| 54 using namespace blink; | 54 namespace blink { |
| 55 | |
| 56 namespace { | |
| 57 | 55 |
| 58 struct DOMTree : NodeTraversal { | 56 struct DOMTree : NodeTraversal { |
| 59 using PositionType = Position; | 57 using PositionType = Position; |
| 60 using TextIteratorType = TextIterator; | 58 using TextIteratorType = TextIterator; |
| 61 }; | 59 }; |
| 62 | 60 |
| 63 struct ComposedTree : ComposedTreeTraversal { | 61 struct ComposedTree : ComposedTreeTraversal { |
| 64 using PositionType = PositionInComposedTree; | 62 using PositionType = PositionInComposedTree; |
| 65 using TextIteratorType = TextIteratorInComposedTree; | 63 using TextIteratorType = TextIteratorInComposedTree; |
| 66 }; | 64 }; |
| 67 | 65 |
| 68 class TextIteratorTest : public ::testing::Test { | 66 class TextIteratorTest : public ::testing::Test { |
| 69 protected: | 67 protected: |
| 70 virtual void SetUp() override; | 68 void SetUp() override; |
| 71 | 69 |
| 72 HTMLDocument& document() const { return *m_document; } | 70 HTMLDocument& document() const { return *m_document; } |
| 73 | 71 |
| 74 template <typename Tree> | 72 template <typename Tree> |
| 75 std::string iterate(TextIteratorBehavior = TextIteratorDefaultBehavior); | 73 std::string iterate(TextIteratorBehavior = TextIteratorDefaultBehavior); |
| 76 | 74 |
| 77 template <typename Tree> | 75 template <typename Tree> |
| 78 std::string iteratePartial(const typename Tree::PositionType& start, const t
ypename Tree::PositionType& end, TextIteratorBehavior = TextIteratorDefaultBehav
ior); | 76 std::string iteratePartial(const typename Tree::PositionType& start, const t
ypename Tree::PositionType& end, TextIteratorBehavior = TextIteratorDefaultBehav
ior); |
| 79 | 77 |
| 80 void setBodyInnerHTML(const char*); | 78 void setBodyInnerHTML(const char*); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 document().body()->setInnerHTML(String::fromUTF8(bodyContent), ASSERT_NO_EXC
EPTION); | 130 document().body()->setInnerHTML(String::fromUTF8(bodyContent), ASSERT_NO_EXC
EPTION); |
| 133 } | 131 } |
| 134 | 132 |
| 135 PassRefPtrWillBeRawPtr<Range> TextIteratorTest::getBodyRange() const | 133 PassRefPtrWillBeRawPtr<Range> TextIteratorTest::getBodyRange() const |
| 136 { | 134 { |
| 137 RefPtrWillBeRawPtr<Range> range(Range::create(document())); | 135 RefPtrWillBeRawPtr<Range> range(Range::create(document())); |
| 138 range->selectNode(document().body()); | 136 range->selectNode(document().body()); |
| 139 return range.release(); | 137 return range.release(); |
| 140 } | 138 } |
| 141 | 139 |
| 142 PassRefPtrWillBeRawPtr<ShadowRoot> createShadowRootForElementWithIDAndSetInnerHT
ML(TreeScope& scope, const char* hostElementID, const char* shadowRootContent) | 140 static PassRefPtrWillBeRawPtr<ShadowRoot> createShadowRootForElementWithIDAndSet
InnerHTML(TreeScope& scope, const char* hostElementID, const char* shadowRootCon
tent) |
| 143 { | 141 { |
| 144 RefPtrWillBeRawPtr<ShadowRoot> shadowRoot = scope.getElementById(AtomicStrin
g::fromUTF8(hostElementID))->createShadowRoot(ASSERT_NO_EXCEPTION); | 142 RefPtrWillBeRawPtr<ShadowRoot> shadowRoot = scope.getElementById(AtomicStrin
g::fromUTF8(hostElementID))->createShadowRoot(ASSERT_NO_EXCEPTION); |
| 145 shadowRoot->setInnerHTML(String::fromUTF8(shadowRootContent), ASSERT_NO_EXCE
PTION); | 143 shadowRoot->setInnerHTML(String::fromUTF8(shadowRootContent), ASSERT_NO_EXCE
PTION); |
| 146 return shadowRoot.release(); | 144 return shadowRoot.release(); |
| 147 } | 145 } |
| 148 | 146 |
| 149 TEST_F(TextIteratorTest, BitStackOverflow) | 147 TEST_F(TextIteratorTest, BitStackOverflow) |
| 150 { | 148 { |
| 151 const unsigned bitsInWord = sizeof(unsigned) * 8; | 149 const unsigned bitsInWord = sizeof(unsigned) * 8; |
| 152 BitStack bs; | 150 BitStack bs; |
| (...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 477 document().view()->updateLayoutAndStyleForPainting(); | 475 document().view()->updateLayoutAndStyleForPainting(); |
| 478 | 476 |
| 479 Node* divNode = document().getElementById("div"); | 477 Node* divNode = document().getElementById("div"); |
| 480 RefPtrWillBeRawPtr<Range> entireRange = Range::create(document(), divNode, 0
, divNode, 3); | 478 RefPtrWillBeRawPtr<Range> entireRange = Range::create(document(), divNode, 0
, divNode, 3); |
| 481 | 479 |
| 482 RefPtrWillBeRawPtr<Range> subrange = TextIterator::subrange(entireRange.get(
), 2, 3); | 480 RefPtrWillBeRawPtr<Range> subrange = TextIterator::subrange(entireRange.get(
), 2, 3); |
| 483 EXPECT_EQ(0, subrange->startOffset()); | 481 EXPECT_EQ(0, subrange->startOffset()); |
| 484 EXPECT_EQ(3, subrange->endOffset()); | 482 EXPECT_EQ(3, subrange->endOffset()); |
| 485 } | 483 } |
| 486 | 484 |
| 487 } | 485 } // namespace blink |
| OLD | NEW |