Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 "core/dom/Range.h" | 5 #include "core/dom/Range.h" |
| 6 | 6 |
| 7 #include "bindings/core/v8/ExceptionState.h" | 7 #include "bindings/core/v8/ExceptionState.h" |
| 8 #include "core/dom/Element.h" | 8 #include "core/dom/Element.h" |
| 9 #include "core/dom/NodeList.h" | 9 #include "core/dom/NodeList.h" |
| 10 #include "core/dom/Text.h" | 10 #include "core/dom/Text.h" |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 56 Element* const result = document().createElement("div"); | 56 Element* const result = document().createElement("div"); |
| 57 result->appendChild(range->extractContents(ASSERT_NO_EXCEPTION)); | 57 result->appendChild(range->extractContents(ASSERT_NO_EXCEPTION)); |
| 58 | 58 |
| 59 EXPECT_EQ("<b>abc</b>", result->innerHTML()) | 59 EXPECT_EQ("<b>abc</b>", result->innerHTML()) |
| 60 << "DOM mutation event handler should not affect result."; | 60 << "DOM mutation event handler should not affect result."; |
| 61 EXPECT_EQ("<span>DEF</span>", spanElement->outerHTML()) | 61 EXPECT_EQ("<span>DEF</span>", spanElement->outerHTML()) |
| 62 << "DOM mutation event handler should be executed."; | 62 << "DOM mutation event handler should be executed."; |
| 63 } | 63 } |
| 64 | 64 |
| 65 TEST_F(RangeTest, SplitTextNodeRangeWithinText) { | 65 TEST_F(RangeTest, SplitTextNodeRangeWithinText) { |
| 66 ScriptState* scriptState = ScriptState::forMainWorld(&frame()); | |
| 67 ScriptState::Scope scope(scriptState); | |
|
haraken
2017/03/08 09:25:25
Can we use V8TestingScope instead?
The same comme
adithyas
2017/03/08 18:20:10
Yup, fixed.
| |
| 68 | |
| 66 document().body()->setInnerHTML("1234"); | 69 document().body()->setInnerHTML("1234"); |
| 67 Text* oldText = toText(document().body()->firstChild()); | 70 Text* oldText = toText(document().body()->firstChild()); |
| 68 | 71 |
| 69 Range* range04 = Range::create(document(), oldText, 0, oldText, 4); | 72 Range* range04 = Range::create(document(), oldText, 0, oldText, 4); |
| 70 Range* range02 = Range::create(document(), oldText, 0, oldText, 2); | 73 Range* range02 = Range::create(document(), oldText, 0, oldText, 2); |
| 71 Range* range22 = Range::create(document(), oldText, 2, oldText, 2); | 74 Range* range22 = Range::create(document(), oldText, 2, oldText, 2); |
| 72 Range* range24 = Range::create(document(), oldText, 2, oldText, 4); | 75 Range* range24 = Range::create(document(), oldText, 2, oldText, 4); |
| 73 | 76 |
| 74 oldText->splitText(2, ASSERT_NO_EXCEPTION); | 77 oldText->splitText(2, ASSERT_NO_EXCEPTION); |
| 75 Text* newText = toText(oldText->nextSibling()); | 78 Text* newText = toText(oldText->nextSibling()); |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 95 EXPECT_EQ(2u, range22->endOffset()); | 98 EXPECT_EQ(2u, range22->endOffset()); |
| 96 | 99 |
| 97 EXPECT_TRUE(range24->boundaryPointsValid()); | 100 EXPECT_TRUE(range24->boundaryPointsValid()); |
| 98 EXPECT_EQ(oldText, range24->startContainer()); | 101 EXPECT_EQ(oldText, range24->startContainer()); |
| 99 EXPECT_EQ(2u, range24->startOffset()); | 102 EXPECT_EQ(2u, range24->startOffset()); |
| 100 EXPECT_EQ(newText, range24->endContainer()); | 103 EXPECT_EQ(newText, range24->endContainer()); |
| 101 EXPECT_EQ(2u, range24->endOffset()); | 104 EXPECT_EQ(2u, range24->endOffset()); |
| 102 } | 105 } |
| 103 | 106 |
| 104 TEST_F(RangeTest, SplitTextNodeRangeOutsideText) { | 107 TEST_F(RangeTest, SplitTextNodeRangeOutsideText) { |
| 108 ScriptState* scriptState = ScriptState::forMainWorld(&frame()); | |
| 109 ScriptState::Scope scope(scriptState); | |
| 110 | |
| 105 document().body()->setInnerHTML( | 111 document().body()->setInnerHTML( |
| 106 "<span id=\"outer\">0<span id=\"inner-left\">1</span>SPLITME<span " | 112 "<span id=\"outer\">0<span id=\"inner-left\">1</span>SPLITME<span " |
| 107 "id=\"inner-right\">2</span>3</span>"); | 113 "id=\"inner-right\">2</span>3</span>"); |
| 108 | 114 |
| 109 Element* outer = document().getElementById(AtomicString::fromUTF8("outer")); | 115 Element* outer = document().getElementById(AtomicString::fromUTF8("outer")); |
| 110 Element* innerLeft = | 116 Element* innerLeft = |
| 111 document().getElementById(AtomicString::fromUTF8("inner-left")); | 117 document().getElementById(AtomicString::fromUTF8("inner-left")); |
| 112 Element* innerRight = | 118 Element* innerRight = |
| 113 document().getElementById(AtomicString::fromUTF8("inner-right")); | 119 document().getElementById(AtomicString::fromUTF8("inner-right")); |
| 114 Text* oldText = toText(outer->childNodes()->item(2)); | 120 Text* oldText = toText(outer->childNodes()->item(2)); |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 219 text->deleteData(0, 3, ASSERT_NO_EXCEPTION); | 225 text->deleteData(0, 3, ASSERT_NO_EXCEPTION); |
| 220 | 226 |
| 221 EXPECT_TRUE(range->boundaryPointsValid()); | 227 EXPECT_TRUE(range->boundaryPointsValid()); |
| 222 EXPECT_EQ(span2, range->startContainer()); | 228 EXPECT_EQ(span2, range->startContainer()); |
| 223 EXPECT_EQ(0u, range->startOffset()); | 229 EXPECT_EQ(0u, range->startOffset()); |
| 224 EXPECT_EQ(div, range->endContainer()); | 230 EXPECT_EQ(div, range->endContainer()); |
| 225 EXPECT_EQ(2u, range->endOffset()); | 231 EXPECT_EQ(2u, range->endOffset()); |
| 226 } | 232 } |
| 227 | 233 |
| 228 } // namespace blink | 234 } // namespace blink |
| OLD | NEW |