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

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

Issue 2161373002: Make FrameCaret to retrieve caret position from SelectionEditor (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 2016-07-20T13:32:26 Created 4 years, 5 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 | « third_party/WebKit/Source/core/editing/FrameSelection.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/frame/FrameView.h" 13 #include "core/frame/FrameView.h"
13 #include "core/html/HTMLBodyElement.h" 14 #include "core/html/HTMLBodyElement.h"
14 #include "core/html/HTMLDocument.h" 15 #include "core/html/HTMLDocument.h"
15 #include "core/layout/LayoutView.h" 16 #include "core/layout/LayoutView.h"
16 #include "core/paint/PaintInfo.h" 17 #include "core/paint/PaintInfo.h"
17 #include "core/paint/PaintLayer.h" 18 #include "core/paint/PaintLayer.h"
18 #include "core/testing/DummyPageHolder.h" 19 #include "core/testing/DummyPageHolder.h"
19 #include "platform/graphics/paint/DrawingRecorder.h" 20 #include "platform/graphics/paint/DrawingRecorder.h"
20 #include "platform/graphics/paint/PaintController.h" 21 #include "platform/graphics/paint/PaintController.h"
21 #include "testing/gtest/include/gtest/gtest.h" 22 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 10 matching lines...) Expand all
32 FrameSelection& selection() const; 33 FrameSelection& selection() const;
33 const VisibleSelection& visibleSelectionInDOMTree() const { return selection ().selection(); } 34 const VisibleSelection& visibleSelectionInDOMTree() const { return selection ().selection(); }
34 const VisibleSelectionInFlatTree& visibleSelectionInFlatTree() const { retur n selection().selectionInFlatTree(); } 35 const VisibleSelectionInFlatTree& visibleSelectionInFlatTree() const { retur n selection().selectionInFlatTree(); }
35 36
36 Text* appendTextNode(const String& data); 37 Text* appendTextNode(const String& data);
37 int layoutCount() const { return dummyPageHolder().frameView().layoutCount() ; } 38 int layoutCount() const { return dummyPageHolder().frameView().layoutCount() ; }
38 39
39 bool shouldPaintCaretForTesting() const { return selection().shouldPaintCare tForTesting(); } 40 bool shouldPaintCaretForTesting() const { return selection().shouldPaintCare tForTesting(); }
40 bool isPreviousCaretDirtyForTesting() const { return selection().isPreviousC aretDirtyForTesting(); } 41 bool isPreviousCaretDirtyForTesting() const { return selection().isPreviousC aretDirtyForTesting(); }
41 42
43 PositionWithAffinity caretPosition() const
44 {
45 return selection().m_frameCaret->caretPosition();
46 }
47
42 private: 48 private:
43 Persistent<Text> m_textNode; 49 Persistent<Text> m_textNode;
44 }; 50 };
45 51
46 void FrameSelectionTest::setSelection(const VisibleSelection& newSelection) 52 void FrameSelectionTest::setSelection(const VisibleSelection& newSelection)
47 { 53 {
48 dummyPageHolder().frame().selection().setSelection(newSelection); 54 dummyPageHolder().frame().selection().setSelection(newSelection);
49 } 55 }
50 56
51 FrameSelection& FrameSelectionTest::selection() const 57 FrameSelection& FrameSelectionTest::selection() const
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 } 272 }
267 273
268 TEST_F(FrameSelectionTest, SelectAllWithUnselectableRoot) 274 TEST_F(FrameSelectionTest, SelectAllWithUnselectableRoot)
269 { 275 {
270 Element* select = document().createElement("select", ASSERT_NO_EXCEPTION); 276 Element* select = document().createElement("select", ASSERT_NO_EXCEPTION);
271 document().replaceChild(select, document().documentElement()); 277 document().replaceChild(select, document().documentElement());
272 selection().selectAll(); 278 selection().selectAll();
273 EXPECT_TRUE(selection().isNone()) << "Nothing should be selected if the cont ent of the documentElement is not selctable."; 279 EXPECT_TRUE(selection().isNone()) << "Nothing should be selected if the cont ent of the documentElement is not selctable.";
274 } 280 }
275 281
282 TEST_F(FrameSelectionTest, updateIfNeededAndFrameCaret)
283 {
284 setBodyContent("<style id=sample></style>");
285 document().setDesignMode("on");
286 Element* sample = document().getElementById("sample");
287 setSelection(VisibleSelection(Position(sample, 0)));
yoichio 2016/07/20 09:10:06 Confirm selection().start() and caretPosition().po
yosin_UTC9 2016/07/20 09:27:33 Done.
288 document().body()->remove();
289 selection().updateIfNeeded();
290
291 // TODO(yosin): Once lazy canonicalization implemented, selection.start
292 // should be Position(HTML, 0).
293 EXPECT_EQ(Position(), selection().start())
294 << "updateIfNeeded() makes selection to null.";
295 EXPECT_EQ(Position(), caretPosition().position())
296 << "caret position and selection.start should be same.";
297 }
298
276 } // namespace blink 299 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/editing/FrameSelection.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698