| 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 "bindings/core/v8/V8BindingForTesting.h" |
| 8 #include "core/dom/Element.h" | 9 #include "core/dom/Element.h" |
| 9 #include "core/dom/NodeList.h" | 10 #include "core/dom/NodeList.h" |
| 10 #include "core/dom/Text.h" | 11 #include "core/dom/Text.h" |
| 11 #include "core/editing/EditingTestBase.h" | 12 #include "core/editing/EditingTestBase.h" |
| 12 #include "core/frame/Settings.h" | 13 #include "core/frame/Settings.h" |
| 13 #include "core/html/HTMLBodyElement.h" | 14 #include "core/html/HTMLBodyElement.h" |
| 14 #include "core/html/HTMLDocument.h" | 15 #include "core/html/HTMLDocument.h" |
| 15 #include "core/html/HTMLElement.h" | 16 #include "core/html/HTMLElement.h" |
| 16 #include "core/html/HTMLHtmlElement.h" | 17 #include "core/html/HTMLHtmlElement.h" |
| 17 #include "platform/heap/Handle.h" | 18 #include "platform/heap/Handle.h" |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 Element* const result = document().createElement("div"); | 57 Element* const result = document().createElement("div"); |
| 57 result->appendChild(range->extractContents(ASSERT_NO_EXCEPTION)); | 58 result->appendChild(range->extractContents(ASSERT_NO_EXCEPTION)); |
| 58 | 59 |
| 59 EXPECT_EQ("<b>abc</b>", result->innerHTML()) | 60 EXPECT_EQ("<b>abc</b>", result->innerHTML()) |
| 60 << "DOM mutation event handler should not affect result."; | 61 << "DOM mutation event handler should not affect result."; |
| 61 EXPECT_EQ("<span>DEF</span>", spanElement->outerHTML()) | 62 EXPECT_EQ("<span>DEF</span>", spanElement->outerHTML()) |
| 62 << "DOM mutation event handler should be executed."; | 63 << "DOM mutation event handler should be executed."; |
| 63 } | 64 } |
| 64 | 65 |
| 65 TEST_F(RangeTest, SplitTextNodeRangeWithinText) { | 66 TEST_F(RangeTest, SplitTextNodeRangeWithinText) { |
| 67 V8TestingScope scope; |
| 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 V8TestingScope scope; |
| 109 |
| 105 document().body()->setInnerHTML( | 110 document().body()->setInnerHTML( |
| 106 "<span id=\"outer\">0<span id=\"inner-left\">1</span>SPLITME<span " | 111 "<span id=\"outer\">0<span id=\"inner-left\">1</span>SPLITME<span " |
| 107 "id=\"inner-right\">2</span>3</span>"); | 112 "id=\"inner-right\">2</span>3</span>"); |
| 108 | 113 |
| 109 Element* outer = document().getElementById(AtomicString::fromUTF8("outer")); | 114 Element* outer = document().getElementById(AtomicString::fromUTF8("outer")); |
| 110 Element* innerLeft = | 115 Element* innerLeft = |
| 111 document().getElementById(AtomicString::fromUTF8("inner-left")); | 116 document().getElementById(AtomicString::fromUTF8("inner-left")); |
| 112 Element* innerRight = | 117 Element* innerRight = |
| 113 document().getElementById(AtomicString::fromUTF8("inner-right")); | 118 document().getElementById(AtomicString::fromUTF8("inner-right")); |
| 114 Text* oldText = toText(outer->childNodes()->item(2)); | 119 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); | 224 text->deleteData(0, 3, ASSERT_NO_EXCEPTION); |
| 220 | 225 |
| 221 EXPECT_TRUE(range->boundaryPointsValid()); | 226 EXPECT_TRUE(range->boundaryPointsValid()); |
| 222 EXPECT_EQ(span2, range->startContainer()); | 227 EXPECT_EQ(span2, range->startContainer()); |
| 223 EXPECT_EQ(0u, range->startOffset()); | 228 EXPECT_EQ(0u, range->startOffset()); |
| 224 EXPECT_EQ(div, range->endContainer()); | 229 EXPECT_EQ(div, range->endContainer()); |
| 225 EXPECT_EQ(2u, range->endOffset()); | 230 EXPECT_EQ(2u, range->endOffset()); |
| 226 } | 231 } |
| 227 | 232 |
| 228 } // namespace blink | 233 } // namespace blink |
| OLD | NEW |