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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « Source/core/editing/VisibleUnits.cpp ('k') | Source/core/editing/htmlediting.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "config.h"
6 #include "core/editing/VisibleUnits.h"
7
8 #include "core/editing/EditingTestBase.h"
9 #include "core/editing/VisiblePosition.h"
10
11 namespace blink {
12
13 namespace {
14
15 PositionWithAffinity positionWithAffinityInDOMTree(Node& anchor, int offset, EAf finity affinity = DOWNSTREAM)
16 {
17 return PositionWithAffinity(canonicalPositionOf(Position(&anchor, offset, Po sition::PositionIsOffsetInAnchor)), affinity);
18 }
19
20 PositionInComposedTreeWithAffinity positionWithAffinityInComposedTree(Node& anch or, int offset, EAffinity affinity = DOWNSTREAM)
21 {
22 return PositionInComposedTreeWithAffinity(canonicalPositionOf(PositionInComp osedTree(&anchor, offset, PositionInComposedTree::PositionIsOffsetInAnchor)), af finity);
23 }
24
25 } // namespace
26
27 class VisibleUnitsTest : public EditingTestBase {
28 };
29
30 TEST_F(VisibleUnitsTest, inSameLine)
31 {
32 const char* bodyContent = "<p id='host'>00<b id='one'>11</b><b id='two'>22</ b>33</p>";
33 const char* shadowContent = "<div><span id='s4'>44</span><content select=#tw o></content><br><span id='s5'>55</span><br><content select=#one></content><span id='s6'>66</span></div>";
34 setBodyContent(bodyContent);
35 RefPtrWillBeRawPtr<ShadowRoot> shadowRoot = setShadowContent(shadowContent);
36 updateLayoutAndStyleForPainting();
37
38 RefPtrWillBeRawPtr<Element> body = document().body();
39 RefPtrWillBeRawPtr<Element> one = body->querySelector("#one", ASSERT_NO_EXCE PTION);
40 RefPtrWillBeRawPtr<Element> two = body->querySelector("#two", ASSERT_NO_EXCE PTION);
41 RefPtrWillBeRawPtr<Element> four = shadowRoot->querySelector("#s4", ASSERT_N O_EXCEPTION);
42 RefPtrWillBeRawPtr<Element> five = shadowRoot->querySelector("#s5", ASSERT_N O_EXCEPTION);
43
44 EXPECT_TRUE(inSameLine(positionWithAffinityInDOMTree(*one, 0), positionWithA ffinityInDOMTree(*two, 0)));
45 EXPECT_TRUE(inSameLine(positionWithAffinityInDOMTree(*one->firstChild(), 0), positionWithAffinityInDOMTree(*two->firstChild(), 0)));
46 EXPECT_FALSE(inSameLine(positionWithAffinityInDOMTree(*one->firstChild(), 0) , positionWithAffinityInDOMTree(*five->firstChild(), 0)));
47 EXPECT_FALSE(inSameLine(positionWithAffinityInDOMTree(*two->firstChild(), 0) , positionWithAffinityInDOMTree(*four->firstChild(), 0)));
48
49 EXPECT_FALSE(inSameLine(positionWithAffinityInComposedTree(*one, 0), positio nWithAffinityInComposedTree(*two, 0)));
50 EXPECT_FALSE(inSameLine(positionWithAffinityInComposedTree(*one->firstChild( ), 0), positionWithAffinityInComposedTree(*two->firstChild(), 0)));
51 EXPECT_FALSE(inSameLine(positionWithAffinityInComposedTree(*one->firstChild( ), 0), positionWithAffinityInComposedTree(*five->firstChild(), 0)));
52 EXPECT_TRUE(inSameLine(positionWithAffinityInComposedTree(*two->firstChild() , 0), positionWithAffinityInComposedTree(*four->firstChild(), 0)));
53 }
54
55 } // namespace blink
OLDNEW
« 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