Chromium Code Reviews| Index: third_party/WebKit/Source/core/editing/RelocatablePositionTest.cpp |
| diff --git a/third_party/WebKit/Source/core/editing/RelocatablePositionTest.cpp b/third_party/WebKit/Source/core/editing/RelocatablePositionTest.cpp |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..3862b698012d085c2ea48c4291bc2c85dffea2bb |
| --- /dev/null |
| +++ b/third_party/WebKit/Source/core/editing/RelocatablePositionTest.cpp |
| @@ -0,0 +1,34 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "core/editing/RelocatablePosition.h" |
| + |
| +#include "core/editing/EditingTestBase.h" |
| +#include "core/editing/VisiblePosition.h" |
| + |
| +namespace blink { |
| + |
| +class RelocatablePositionTest : public EditingTestBase { |
| +}; |
| + |
| +TEST_F(RelocatablePositionTest, position) |
| +{ |
| + const char* bodyContent = "<b>foo</b><textarea>bar</textarea>"; |
|
yosin_UTC9
2016/07/06 07:48:19
nit: You don't need to have |bodyContent|.
Xiaocheng
2016/07/06 08:00:06
Done.
|
| + setBodyContent(bodyContent); |
| + |
| + Node* b = document().querySelector("b", ASSERT_NO_EXCEPTION); |
|
yosin_UTC9
2016/07/06 07:48:19
nit: please avoid to use one letter variable name.
Xiaocheng
2016/07/06 08:00:06
Done.
|
| + Node* textarea = document().querySelector("textarea", ASSERT_NO_EXCEPTION); |
| + |
| + RelocatablePosition relocatablePosition(Position(textarea, PositionAnchorType::BeforeAnchor)); |
| + document().body()->removeChild(textarea); |
|
yosin_UTC9
2016/07/06 07:48:19
nit: |textarea->remove()| is easier.
Xiaocheng
2016/07/06 08:00:06
Done.
|
| + |
| + // RelocatablePosition should track the given Position even if its original |
| + // anchor node is moved away from the document. |
| + Position expectedPosition(b, PositionAnchorType::AfterAnchor); |
| + Position trackedPosition = relocatablePosition.position(); |
| + EXPECT_TRUE(trackedPosition.anchorNode()->inShadowIncludingDocument()); |
| + EXPECT_EQ(createVisiblePosition(expectedPosition).deepEquivalent(), createVisiblePosition(trackedPosition).deepEquivalent()); |
| +} |
| + |
| +} // namespace blink |