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

Side by Side Diff: third_party/WebKit/Source/core/editing/VisibleSelectionTest.cpp

Issue 2178243002: Make ExceptionState parameter of ContainerNode::querySelector() as an optional parameter (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 2016-07-26T10:56:52 Created 4 years, 4 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
OLDNEW
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/editing/VisibleSelection.h" 5 #include "core/editing/VisibleSelection.h"
6 6
7 #include "core/dom/Range.h" 7 #include "core/dom/Range.h"
8 #include "core/editing/EditingTestBase.h" 8 #include "core/editing/EditingTestBase.h"
9 #include "core/editing/SelectionAdjuster.h" 9 #include "core/editing/SelectionAdjuster.h"
10 10
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 } 167 }
168 168
169 TEST_F(VisibleSelectionTest, ShadowCrossing) 169 TEST_F(VisibleSelectionTest, ShadowCrossing)
170 { 170 {
171 const char* bodyContent = "<p id='host'>00<b id='one'>11</b><b id='two'>22</ b>33</p>"; 171 const char* bodyContent = "<p id='host'>00<b id='one'>11</b><b id='two'>22</ b>33</p>";
172 const char* shadowContent = "<a><span id='s4'>44</span><content select=#two> </content><span id='s5'>55</span><content select=#one></content><span id='s6'>66 </span></a>"; 172 const char* shadowContent = "<a><span id='s4'>44</span><content select=#two> </content><span id='s5'>55</span><content select=#one></content><span id='s6'>66 </span></a>";
173 setBodyContent(bodyContent); 173 setBodyContent(bodyContent);
174 ShadowRoot* shadowRoot = setShadowContent(shadowContent, "host"); 174 ShadowRoot* shadowRoot = setShadowContent(shadowContent, "host");
175 175
176 Element* body = document().body(); 176 Element* body = document().body();
177 Element* host = body->querySelector("#host", ASSERT_NO_EXCEPTION); 177 Element* host = body->querySelector("#host");
178 Element* one = body->querySelector("#one", ASSERT_NO_EXCEPTION); 178 Element* one = body->querySelector("#one");
179 Element* six = shadowRoot->querySelector("#s6", ASSERT_NO_EXCEPTION); 179 Element* six = shadowRoot->querySelector("#s6");
180 180
181 VisibleSelection selection(Position::firstPositionInNode(one), Position::las tPositionInNode(shadowRoot)); 181 VisibleSelection selection(Position::firstPositionInNode(one), Position::las tPositionInNode(shadowRoot));
182 VisibleSelectionInFlatTree selectionInFlatTree(PositionInFlatTree::firstPosi tionInNode(one), PositionInFlatTree::lastPositionInNode(host)); 182 VisibleSelectionInFlatTree selectionInFlatTree(PositionInFlatTree::firstPosi tionInNode(one), PositionInFlatTree::lastPositionInNode(host));
183 183
184 EXPECT_EQ(Position(host, PositionAnchorType::BeforeAnchor), selection.start( )); 184 EXPECT_EQ(Position(host, PositionAnchorType::BeforeAnchor), selection.start( ));
185 EXPECT_EQ(Position(one->firstChild(), 0), selection.end()); 185 EXPECT_EQ(Position(one->firstChild(), 0), selection.end());
186 EXPECT_EQ(PositionInFlatTree(one->firstChild(), 0), selectionInFlatTree.star t()); 186 EXPECT_EQ(PositionInFlatTree(one->firstChild(), 0), selectionInFlatTree.star t());
187 EXPECT_EQ(PositionInFlatTree(six->firstChild(), 2), selectionInFlatTree.end( )); 187 EXPECT_EQ(PositionInFlatTree(six->firstChild(), 2), selectionInFlatTree.end( ));
188 } 188 }
189 189
190 TEST_F(VisibleSelectionTest, ShadowV0DistributedNodes) 190 TEST_F(VisibleSelectionTest, ShadowV0DistributedNodes)
191 { 191 {
192 const char* bodyContent = "<p id='host'>00<b id='one'>11</b><b id='two'>22</ b>33</p>"; 192 const char* bodyContent = "<p id='host'>00<b id='one'>11</b><b id='two'>22</ b>33</p>";
193 const char* shadowContent = "<a><span id='s4'>44</span><content select=#two> </content><span id='s5'>55</span><content select=#one></content><span id='s6'>66 </span></a>"; 193 const char* shadowContent = "<a><span id='s4'>44</span><content select=#two> </content><span id='s5'>55</span><content select=#one></content><span id='s6'>66 </span></a>";
194 setBodyContent(bodyContent); 194 setBodyContent(bodyContent);
195 ShadowRoot* shadowRoot = setShadowContent(shadowContent, "host"); 195 ShadowRoot* shadowRoot = setShadowContent(shadowContent, "host");
196 196
197 Element* body = document().body(); 197 Element* body = document().body();
198 Element* one = body->querySelector("#one", ASSERT_NO_EXCEPTION); 198 Element* one = body->querySelector("#one");
199 Element* two = body->querySelector("#two", ASSERT_NO_EXCEPTION); 199 Element* two = body->querySelector("#two");
200 Element* five = shadowRoot->querySelector("#s5", ASSERT_NO_EXCEPTION); 200 Element* five = shadowRoot->querySelector("#s5");
201 201
202 VisibleSelection selection(Position::firstPositionInNode(one), Position::las tPositionInNode(two)); 202 VisibleSelection selection(Position::firstPositionInNode(one), Position::las tPositionInNode(two));
203 VisibleSelectionInFlatTree selectionInFlatTree(PositionInFlatTree::firstPosi tionInNode(one), PositionInFlatTree::lastPositionInNode(two)); 203 VisibleSelectionInFlatTree selectionInFlatTree(PositionInFlatTree::firstPosi tionInNode(one), PositionInFlatTree::lastPositionInNode(two));
204 204
205 EXPECT_EQ(Position(one->firstChild(), 0), selection.start()); 205 EXPECT_EQ(Position(one->firstChild(), 0), selection.start());
206 EXPECT_EQ(Position(two->firstChild(), 2), selection.end()); 206 EXPECT_EQ(Position(two->firstChild(), 2), selection.end());
207 EXPECT_EQ(PositionInFlatTree(five->firstChild(), 0), selectionInFlatTree.sta rt()); 207 EXPECT_EQ(PositionInFlatTree(five->firstChild(), 0), selectionInFlatTree.sta rt());
208 EXPECT_EQ(PositionInFlatTree(five->firstChild(), 2), selectionInFlatTree.end ()); 208 EXPECT_EQ(PositionInFlatTree(five->firstChild(), 2), selectionInFlatTree.end ());
209 } 209 }
210 210
211 TEST_F(VisibleSelectionTest, ShadowNested) 211 TEST_F(VisibleSelectionTest, ShadowNested)
212 { 212 {
213 const char* bodyContent = "<p id='host'>00<b id='one'>11</b><b id='two'>22</ b>33</p>"; 213 const char* bodyContent = "<p id='host'>00<b id='one'>11</b><b id='two'>22</ b>33</p>";
214 const char* shadowContent = "<a><span id='s4'>44</span><content select=#two> </content><span id='s5'>55</span><content select=#one></content><span id='s6'>66 </span></a>"; 214 const char* shadowContent = "<a><span id='s4'>44</span><content select=#two> </content><span id='s5'>55</span><content select=#one></content><span id='s6'>66 </span></a>";
215 const char* shadowContent2 = "<span id='s7'>77</span><content></content><spa n id='s8'>88</span>"; 215 const char* shadowContent2 = "<span id='s7'>77</span><content></content><spa n id='s8'>88</span>";
216 setBodyContent(bodyContent); 216 setBodyContent(bodyContent);
217 ShadowRoot* shadowRoot = setShadowContent(shadowContent, "host"); 217 ShadowRoot* shadowRoot = setShadowContent(shadowContent, "host");
218 ShadowRoot* shadowRoot2 = createShadowRootForElementWithIDAndSetInnerHTML(*s hadowRoot, "s5", shadowContent2); 218 ShadowRoot* shadowRoot2 = createShadowRootForElementWithIDAndSetInnerHTML(*s hadowRoot, "s5", shadowContent2);
219 219
220 // Flat tree is something like below: 220 // Flat tree is something like below:
221 // <p id="host"> 221 // <p id="host">
222 // <span id="s4">44</span> 222 // <span id="s4">44</span>
223 // <b id="two">22</b> 223 // <b id="two">22</b>
224 // <span id="s5"><span id="s7">77>55</span id="s8">88</span> 224 // <span id="s5"><span id="s7">77>55</span id="s8">88</span>
225 // <b id="one">11</b> 225 // <b id="one">11</b>
226 // <span id="s6">66</span> 226 // <span id="s6">66</span>
227 // </p> 227 // </p>
228 Element* body = document().body(); 228 Element* body = document().body();
229 Element* host = body->querySelector("#host", ASSERT_NO_EXCEPTION); 229 Element* host = body->querySelector("#host");
230 Element* one = body->querySelector("#one", ASSERT_NO_EXCEPTION); 230 Element* one = body->querySelector("#one");
231 Element* eight = shadowRoot2->querySelector("#s8", ASSERT_NO_EXCEPTION); 231 Element* eight = shadowRoot2->querySelector("#s8");
232 232
233 VisibleSelection selection(Position::firstPositionInNode(one), Position::las tPositionInNode(shadowRoot2)); 233 VisibleSelection selection(Position::firstPositionInNode(one), Position::las tPositionInNode(shadowRoot2));
234 VisibleSelectionInFlatTree selectionInFlatTree(PositionInFlatTree::firstPosi tionInNode(one), PositionInFlatTree::afterNode(eight)); 234 VisibleSelectionInFlatTree selectionInFlatTree(PositionInFlatTree::firstPosi tionInNode(one), PositionInFlatTree::afterNode(eight));
235 235
236 EXPECT_EQ(Position(host, PositionAnchorType::BeforeAnchor), selection.start( )); 236 EXPECT_EQ(Position(host, PositionAnchorType::BeforeAnchor), selection.start( ));
237 EXPECT_EQ(Position(one->firstChild(), 0), selection.end()); 237 EXPECT_EQ(Position(one->firstChild(), 0), selection.end());
238 EXPECT_EQ(PositionInFlatTree(eight->firstChild(), 2), selectionInFlatTree.st art()); 238 EXPECT_EQ(PositionInFlatTree(eight->firstChild(), 2), selectionInFlatTree.st art());
239 EXPECT_EQ(PositionInFlatTree(eight->firstChild(), 2), selectionInFlatTree.en d()); 239 EXPECT_EQ(PositionInFlatTree(eight->firstChild(), 2), selectionInFlatTree.en d());
240 } 240 }
241 241
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 // Simulates to restore selection from undo stack. 370 // Simulates to restore selection from undo stack.
371 selection.validatePositionsIfNeeded(); 371 selection.validatePositionsIfNeeded();
372 EXPECT_EQ(Position(sample->firstChild(), 0), selection.start()); 372 EXPECT_EQ(Position(sample->firstChild(), 0), selection.start());
373 373
374 VisibleSelectionInFlatTree selectionInFlatTree; 374 VisibleSelectionInFlatTree selectionInFlatTree;
375 SelectionAdjuster::adjustSelectionInFlatTree(&selectionInFlatTree, selection ); 375 SelectionAdjuster::adjustSelectionInFlatTree(&selectionInFlatTree, selection );
376 EXPECT_EQ(PositionInFlatTree(sample->firstChild(), 0), selectionInFlatTree.s tart()); 376 EXPECT_EQ(PositionInFlatTree(sample->firstChild(), 0), selectionInFlatTree.s tart());
377 } 377 }
378 378
379 } // namespace blink 379 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698