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/ExceptionStatePlaceholder.h" | 7 #include "bindings/core/v8/ExceptionStatePlaceholder.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" |
| 11 #include "core/editing/FrameSelection.h" | |
|
yosin_UTC9
2016/08/19 06:02:43
nit: RangeTest.cpp should not include files in "in
Xiaocheng
2016/08/19 06:37:45
Whoops, I forgot to remove them.
| |
| 12 #include "core/frame/LocalFrame.h" | |
| 11 #include "core/html/HTMLBodyElement.h" | 13 #include "core/html/HTMLBodyElement.h" |
| 12 #include "core/html/HTMLDocument.h" | 14 #include "core/html/HTMLDocument.h" |
| 13 #include "core/html/HTMLElement.h" | 15 #include "core/html/HTMLElement.h" |
| 14 #include "core/html/HTMLHtmlElement.h" | 16 #include "core/html/HTMLHtmlElement.h" |
| 15 #include "platform/heap/Handle.h" | 17 #include "platform/heap/Handle.h" |
| 16 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
| 17 #include "wtf/Compiler.h" | 19 #include "wtf/Compiler.h" |
| 18 #include "wtf/RefPtr.h" | 20 #include "wtf/RefPtr.h" |
| 19 #include "wtf/text/AtomicString.h" | 21 #include "wtf/text/AtomicString.h" |
| 20 | 22 |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 148 | 150 |
| 149 Document* anotherDocument = Document::create(); | 151 Document* anotherDocument = Document::create(); |
| 150 anotherDocument->appendChild(foo); | 152 anotherDocument->appendChild(foo); |
| 151 | 153 |
| 152 EXPECT_EQ(bar, range->startContainer()); | 154 EXPECT_EQ(bar, range->startContainer()); |
| 153 EXPECT_EQ(0, range->startOffset()); | 155 EXPECT_EQ(0, range->startOffset()); |
| 154 EXPECT_EQ(foo, range->endContainer()); | 156 EXPECT_EQ(foo, range->endContainer()); |
| 155 EXPECT_EQ(1, range->endOffset()); | 157 EXPECT_EQ(1, range->endOffset()); |
| 156 } | 158 } |
| 157 | 159 |
| 160 // Regression test for crbug.com/639184 | |
| 161 TEST_F(RangeTest, NotMarkedValidByIrrelevantTextInsert) | |
| 162 { | |
| 163 document().body()->setInnerHTML("<div><span id=span1>foo</span>bar<span id=s pan2>baz</span></div>", ASSERT_NO_EXCEPTION); | |
| 164 | |
| 165 Element* div = document().querySelector("div"); | |
| 166 Element* span1 = document().getElementById("span1"); | |
| 167 Element* span2 = document().getElementById("span2"); | |
| 168 Text* text = toText(div->childNodes()->item(1)); | |
| 169 | |
| 170 Range* range = Range::create(document(), span2, 0, div, 3); | |
| 171 | |
| 172 div->removeChild(span1, ASSERT_NO_EXCEPTION); | |
| 173 text->insertData(0, "bar", ASSERT_NO_EXCEPTION); | |
| 174 | |
| 175 EXPECT_TRUE(range->boundaryPointsValid()); | |
| 176 EXPECT_EQ(span2, range->startContainer()); | |
| 177 EXPECT_EQ(0, range->startOffset()); | |
| 178 EXPECT_EQ(div, range->endContainer()); | |
| 179 EXPECT_EQ(2, range->endOffset()); | |
| 180 } | |
| 181 | |
| 182 // Regression test for crbug.com/639184 | |
| 183 TEST_F(RangeTest, NotMarkedValidByIrrelevantTextRemove) | |
| 184 { | |
| 185 document().body()->setInnerHTML("<div><span id=span1>foofoo</span>bar<span i d=span2>baz</span></div>", ASSERT_NO_EXCEPTION); | |
| 186 | |
| 187 Element* div = document().querySelector("div"); | |
| 188 Element* span1 = document().getElementById("span1"); | |
| 189 Element* span2 = document().getElementById("span2"); | |
| 190 Text* text = toText(div->childNodes()->item(1)); | |
| 191 | |
| 192 Range* range = Range::create(document(), span2, 0, div, 3); | |
| 193 | |
| 194 div->removeChild(span1, ASSERT_NO_EXCEPTION); | |
| 195 text->deleteData(0, 3, ASSERT_NO_EXCEPTION); | |
| 196 | |
| 197 EXPECT_TRUE(range->boundaryPointsValid()); | |
| 198 EXPECT_EQ(span2, range->startContainer()); | |
| 199 EXPECT_EQ(0, range->startOffset()); | |
| 200 EXPECT_EQ(div, range->endContainer()); | |
| 201 EXPECT_EQ(2, range->endOffset()); | |
| 202 } | |
| 203 | |
| 158 } // namespace blink | 204 } // namespace blink |
| OLD | NEW |