Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(846)

Unified Diff: Source/core/editing/VisibleUnitsTest.cpp

Issue 1203613003: Make inSameLine() in VisibleUnits.cpp to work with positions in composed tree (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: 2015-06-24T17:52:54 Get rid of redundant explict in RenderedPosition Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/core/editing/VisibleUnits.cpp ('k') | Source/core/editing/htmlediting.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/editing/VisibleUnitsTest.cpp
diff --git a/Source/core/editing/VisibleUnitsTest.cpp b/Source/core/editing/VisibleUnitsTest.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..e53f20a5f402f4ac42cf9cb83bca4216969248af
--- /dev/null
+++ b/Source/core/editing/VisibleUnitsTest.cpp
@@ -0,0 +1,55 @@
+// Copyright 2015 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 "config.h"
+#include "core/editing/VisibleUnits.h"
+
+#include "core/editing/EditingTestBase.h"
+#include "core/editing/VisiblePosition.h"
+
+namespace blink {
+
+namespace {
+
+PositionWithAffinity positionWithAffinityInDOMTree(Node& anchor, int offset, EAffinity affinity = DOWNSTREAM)
+{
+ return PositionWithAffinity(canonicalPositionOf(Position(&anchor, offset, Position::PositionIsOffsetInAnchor)), affinity);
+}
+
+PositionInComposedTreeWithAffinity positionWithAffinityInComposedTree(Node& anchor, int offset, EAffinity affinity = DOWNSTREAM)
+{
+ return PositionInComposedTreeWithAffinity(canonicalPositionOf(PositionInComposedTree(&anchor, offset, PositionInComposedTree::PositionIsOffsetInAnchor)), affinity);
+}
+
+} // namespace
+
+class VisibleUnitsTest : public EditingTestBase {
+};
+
+TEST_F(VisibleUnitsTest, inSameLine)
+{
+ const char* bodyContent = "<p id='host'>00<b id='one'>11</b><b id='two'>22</b>33</p>";
+ const char* shadowContent = "<div><span id='s4'>44</span><content select=#two></content><br><span id='s5'>55</span><br><content select=#one></content><span id='s6'>66</span></div>";
+ setBodyContent(bodyContent);
+ RefPtrWillBeRawPtr<ShadowRoot> shadowRoot = setShadowContent(shadowContent);
+ updateLayoutAndStyleForPainting();
+
+ RefPtrWillBeRawPtr<Element> body = document().body();
+ RefPtrWillBeRawPtr<Element> one = body->querySelector("#one", ASSERT_NO_EXCEPTION);
+ RefPtrWillBeRawPtr<Element> two = body->querySelector("#two", ASSERT_NO_EXCEPTION);
+ RefPtrWillBeRawPtr<Element> four = shadowRoot->querySelector("#s4", ASSERT_NO_EXCEPTION);
+ RefPtrWillBeRawPtr<Element> five = shadowRoot->querySelector("#s5", ASSERT_NO_EXCEPTION);
+
+ EXPECT_TRUE(inSameLine(positionWithAffinityInDOMTree(*one, 0), positionWithAffinityInDOMTree(*two, 0)));
+ EXPECT_TRUE(inSameLine(positionWithAffinityInDOMTree(*one->firstChild(), 0), positionWithAffinityInDOMTree(*two->firstChild(), 0)));
+ EXPECT_FALSE(inSameLine(positionWithAffinityInDOMTree(*one->firstChild(), 0), positionWithAffinityInDOMTree(*five->firstChild(), 0)));
+ EXPECT_FALSE(inSameLine(positionWithAffinityInDOMTree(*two->firstChild(), 0), positionWithAffinityInDOMTree(*four->firstChild(), 0)));
+
+ EXPECT_FALSE(inSameLine(positionWithAffinityInComposedTree(*one, 0), positionWithAffinityInComposedTree(*two, 0)));
+ EXPECT_FALSE(inSameLine(positionWithAffinityInComposedTree(*one->firstChild(), 0), positionWithAffinityInComposedTree(*two->firstChild(), 0)));
+ EXPECT_FALSE(inSameLine(positionWithAffinityInComposedTree(*one->firstChild(), 0), positionWithAffinityInComposedTree(*five->firstChild(), 0)));
+ EXPECT_TRUE(inSameLine(positionWithAffinityInComposedTree(*two->firstChild(), 0), positionWithAffinityInComposedTree(*four->firstChild(), 0)));
+}
+
+} // namespace blink
« no previous file with comments | « Source/core/editing/VisibleUnits.cpp ('k') | Source/core/editing/htmlediting.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698