summaryrefslogtreecommitdiff
path: root/chromium/third_party/blink/renderer/core/editing/relocatable_position_test.cc
blob: b65dccd840d621dc1b4f688849a8253a20f8d6e4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// 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 "third_party/blink/renderer/core/editing/relocatable_position.h"

#include "third_party/blink/renderer/core/editing/testing/editing_test_base.h"
#include "third_party/blink/renderer/core/editing/visible_position.h"

namespace blink {

class RelocatablePositionTest : public EditingTestBase {};

TEST_F(RelocatablePositionTest, position) {
  SetBodyContent("<b>foo</b><textarea>bar</textarea>");
  Node* boldface = GetDocument().QuerySelector("b");
  Node* textarea = GetDocument().QuerySelector("textarea");

  RelocatablePosition relocatable_position(
      Position(textarea, PositionAnchorType::kBeforeAnchor));
  textarea->remove();
  GetDocument().UpdateStyleAndLayout(DocumentUpdateReason::kTest);

  // RelocatablePosition should track the given Position even if its original
  // anchor node is moved away from the document.
  Position expected_position(boldface, PositionAnchorType::kAfterAnchor);
  Position tracked_position = relocatable_position.GetPosition();
  EXPECT_TRUE(tracked_position.AnchorNode()->isConnected());
  EXPECT_EQ(CreateVisiblePosition(expected_position).DeepEquivalent(),
            CreateVisiblePosition(tracked_position).DeepEquivalent());
}

}  // namespace blink