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

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

Issue 2441573002: Move setNonDirectionalSelectionIfNeeded() to SelectionController from FrameSelection (Closed)
Patch Set: 2016-10-21T15:43:37 Created 4 years, 2 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/FrameSelection.h" 5 #include "core/editing/FrameSelection.h"
6 6
7 #include "bindings/core/v8/ExceptionStatePlaceholder.h" 7 #include "bindings/core/v8/ExceptionStatePlaceholder.h"
8 #include "core/dom/Document.h" 8 #include "core/dom/Document.h"
9 #include "core/dom/Element.h" 9 #include "core/dom/Element.h"
10 #include "core/dom/Text.h" 10 #include "core/dom/Text.h"
11 #include "core/editing/EditingTestBase.h" 11 #include "core/editing/EditingTestBase.h"
12 #include "core/editing/FrameCaret.h" 12 #include "core/editing/FrameCaret.h"
13 #include "core/editing/SelectionController.h"
13 #include "core/frame/FrameView.h" 14 #include "core/frame/FrameView.h"
14 #include "core/html/HTMLBodyElement.h" 15 #include "core/html/HTMLBodyElement.h"
16 #include "core/input/EventHandler.h"
15 #include "core/layout/LayoutView.h" 17 #include "core/layout/LayoutView.h"
16 #include "core/paint/PaintInfo.h" 18 #include "core/paint/PaintInfo.h"
17 #include "core/paint/PaintLayer.h" 19 #include "core/paint/PaintLayer.h"
18 #include "core/testing/DummyPageHolder.h" 20 #include "core/testing/DummyPageHolder.h"
19 #include "platform/graphics/paint/DrawingRecorder.h" 21 #include "platform/graphics/paint/DrawingRecorder.h"
20 #include "platform/graphics/paint/PaintController.h" 22 #include "platform/graphics/paint/PaintController.h"
21 #include "testing/gtest/include/gtest/gtest.h" 23 #include "testing/gtest/include/gtest/gtest.h"
22 #include "wtf/PassRefPtr.h" 24 #include "wtf/PassRefPtr.h"
23 #include "wtf/RefPtr.h" 25 #include "wtf/RefPtr.h"
24 #include "wtf/StdLibExtras.h" 26 #include "wtf/StdLibExtras.h"
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 createVisiblePosition(Position(text, 2)), 268 createVisiblePosition(Position(text, 2)),
267 CharacterGranularity); 269 CharacterGranularity);
268 EXPECT_EQ_SELECTED_TEXT("o B"); 270 EXPECT_EQ_SELECTED_TEXT("o B");
269 // "Fo<o B|ar Baz," with the Word granularity. 271 // "Fo<o B|ar Baz," with the Word granularity.
270 selection().moveRangeSelection(createVisiblePosition(Position(text, 5)), 272 selection().moveRangeSelection(createVisiblePosition(Position(text, 5)),
271 createVisiblePosition(Position(text, 2)), 273 createVisiblePosition(Position(text, 2)),
272 WordGranularity); 274 WordGranularity);
273 EXPECT_EQ_SELECTED_TEXT("Foo Bar"); 275 EXPECT_EQ_SELECTED_TEXT("Foo Bar");
274 } 276 }
275 277
276 TEST_F(FrameSelectionTest, setNonDirectionalSelectionIfNeeded) { 278 // TODO(yosin): We should move |SelectionControllerTest" to
279 // "SelectionControllerTest.cpp"
280 class SelectionControllerTest : public EditingTestBase {
281 protected:
282 SelectionControllerTest() = default;
283
284 const VisibleSelection& visibleSelectionInDOMTree() const {
285 return selection().selection();
286 }
287
288 const VisibleSelectionInFlatTree& visibleSelectionInFlatTree() const {
289 return selection().selectionInFlatTree();
290 }
291
292 void setNonDirectionalSelectionIfNeeded(const VisibleSelectionInFlatTree&,
293 TextGranularity);
294
295 private:
296 DISALLOW_COPY_AND_ASSIGN(SelectionControllerTest);
297 };
298
299 // TODO(yosin): We should move this function to "SelectionControllerTest.cpp"
300 void SelectionControllerTest::setNonDirectionalSelectionIfNeeded(
301 const VisibleSelectionInFlatTree& newSelection,
302 TextGranularity granularity) {
303 frame()
304 .eventHandler()
305 .selectionController()
306 .setNonDirectionalSelectionIfNeeded(
307 newSelection, granularity, SelectionController::DoNotAdjustEndpoints);
308 }
309
310 // TODO(yosin): We should move this test to "SelectionControllerTest.cpp"
311 TEST_F(SelectionControllerTest, setNonDirectionalSelectionIfNeeded) {
277 const char* bodyContent = "<span id=top>top</span><span id=host></span>"; 312 const char* bodyContent = "<span id=top>top</span><span id=host></span>";
278 const char* shadowContent = "<span id=bottom>bottom</span>"; 313 const char* shadowContent = "<span id=bottom>bottom</span>";
279 setBodyContent(bodyContent); 314 setBodyContent(bodyContent);
280 ShadowRoot* shadowRoot = setShadowContent(shadowContent, "host"); 315 ShadowRoot* shadowRoot = setShadowContent(shadowContent, "host");
281 316
282 Node* top = document().getElementById("top")->firstChild(); 317 Node* top = document().getElementById("top")->firstChild();
283 Node* bottom = shadowRoot->getElementById("bottom")->firstChild(); 318 Node* bottom = shadowRoot->getElementById("bottom")->firstChild();
284 Node* host = document().getElementById("host"); 319 Node* host = document().getElementById("host");
285 320
286 // top to bottom 321 // top to bottom
287 selection().setNonDirectionalSelectionIfNeeded( 322 setNonDirectionalSelectionIfNeeded(
288 createVisibleSelection(SelectionInFlatTree::Builder() 323 createVisibleSelection(SelectionInFlatTree::Builder()
289 .collapse(PositionInFlatTree(top, 1)) 324 .collapse(PositionInFlatTree(top, 1))
290 .extend(PositionInFlatTree(bottom, 3)) 325 .extend(PositionInFlatTree(bottom, 3))
291 .build()), 326 .build()),
292 CharacterGranularity); 327 CharacterGranularity);
293 EXPECT_EQ(Position(top, 1), visibleSelectionInDOMTree().base()); 328 EXPECT_EQ(Position(top, 1), visibleSelectionInDOMTree().base());
294 EXPECT_EQ(Position::beforeNode(host), visibleSelectionInDOMTree().extent()); 329 EXPECT_EQ(Position::beforeNode(host), visibleSelectionInDOMTree().extent());
295 EXPECT_EQ(Position(top, 1), visibleSelectionInDOMTree().start()); 330 EXPECT_EQ(Position(top, 1), visibleSelectionInDOMTree().start());
296 EXPECT_EQ(Position(top, 3), visibleSelectionInDOMTree().end()); 331 EXPECT_EQ(Position(top, 3), visibleSelectionInDOMTree().end());
297 332
298 EXPECT_EQ(PositionInFlatTree(top, 1), visibleSelectionInFlatTree().base()); 333 EXPECT_EQ(PositionInFlatTree(top, 1), visibleSelectionInFlatTree().base());
299 EXPECT_EQ(PositionInFlatTree(bottom, 3), 334 EXPECT_EQ(PositionInFlatTree(bottom, 3),
300 visibleSelectionInFlatTree().extent()); 335 visibleSelectionInFlatTree().extent());
301 EXPECT_EQ(PositionInFlatTree(top, 1), visibleSelectionInFlatTree().start()); 336 EXPECT_EQ(PositionInFlatTree(top, 1), visibleSelectionInFlatTree().start());
302 EXPECT_EQ(PositionInFlatTree(bottom, 3), visibleSelectionInFlatTree().end()); 337 EXPECT_EQ(PositionInFlatTree(bottom, 3), visibleSelectionInFlatTree().end());
303 338
304 // bottom to top 339 // bottom to top
305 selection().setNonDirectionalSelectionIfNeeded( 340 setNonDirectionalSelectionIfNeeded(
306 createVisibleSelection(SelectionInFlatTree::Builder() 341 createVisibleSelection(SelectionInFlatTree::Builder()
307 .collapse(PositionInFlatTree(bottom, 3)) 342 .collapse(PositionInFlatTree(bottom, 3))
308 .extend(PositionInFlatTree(top, 1)) 343 .extend(PositionInFlatTree(top, 1))
309 .build()), 344 .build()),
310 CharacterGranularity); 345 CharacterGranularity);
311 EXPECT_EQ(Position(bottom, 3), visibleSelectionInDOMTree().base()); 346 EXPECT_EQ(Position(bottom, 3), visibleSelectionInDOMTree().base());
312 EXPECT_EQ(Position::beforeNode(bottom->parentNode()), 347 EXPECT_EQ(Position::beforeNode(bottom->parentNode()),
313 visibleSelectionInDOMTree().extent()); 348 visibleSelectionInDOMTree().extent());
314 EXPECT_EQ(Position(bottom, 0), visibleSelectionInDOMTree().start()); 349 EXPECT_EQ(Position(bottom, 0), visibleSelectionInDOMTree().start());
315 EXPECT_EQ(Position(bottom, 3), visibleSelectionInDOMTree().end()); 350 EXPECT_EQ(Position(bottom, 3), visibleSelectionInDOMTree().end());
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
347 selection().updateIfNeeded(); 382 selection().updateIfNeeded();
348 383
349 // TODO(yosin): Once lazy canonicalization implemented, selection.start 384 // TODO(yosin): Once lazy canonicalization implemented, selection.start
350 // should be Position(HTML, 0). 385 // should be Position(HTML, 0).
351 EXPECT_EQ(Position(), selection().start()) 386 EXPECT_EQ(Position(), selection().start())
352 << "updateIfNeeded() makes selection to null."; 387 << "updateIfNeeded() makes selection to null.";
353 EXPECT_EQ(selection().start(), caretPosition().position()); 388 EXPECT_EQ(selection().start(), caretPosition().position());
354 } 389 }
355 390
356 } // namespace blink 391 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698