OLD | NEW |
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" |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 | 62 |
63 TEST_F(FrameSelectionTest, SetValidSelection) | 63 TEST_F(FrameSelectionTest, SetValidSelection) |
64 { | 64 { |
65 Text* text = appendTextNode("Hello, World!"); | 65 Text* text = appendTextNode("Hello, World!"); |
66 VisibleSelection validSelection(Position(text, 0), Position(text, 5)); | 66 VisibleSelection validSelection(Position(text, 0), Position(text, 5)); |
67 EXPECT_FALSE(validSelection.isNone()); | 67 EXPECT_FALSE(validSelection.isNone()); |
68 setSelection(validSelection); | 68 setSelection(validSelection); |
69 EXPECT_FALSE(selection().isNone()); | 69 EXPECT_FALSE(selection().isNone()); |
70 } | 70 } |
71 | 71 |
72 TEST_F(FrameSelectionTest, SetInvalidSelection) | |
73 { | |
74 // Create a new document without frame by using DOMImplementation. | |
75 DocumentInit dummy; | |
76 Document* documentWithoutFrame = Document::create(); | |
77 Element* body = HTMLBodyElement::create(*documentWithoutFrame); | |
78 documentWithoutFrame->appendChild(body); | |
79 Text* anotherText = documentWithoutFrame->createTextNode("Hello, another wor
ld"); | |
80 body->appendChild(anotherText); | |
81 | |
82 // Create a new VisibleSelection for the new document without frame and | |
83 // update FrameSelection with the selection. | |
84 VisibleSelection invalidSelection; | |
85 invalidSelection.setWithoutValidation(Position(anotherText, 0), Position(ano
therText, 5)); | |
86 setSelection(invalidSelection); | |
87 | |
88 EXPECT_TRUE(selection().isNone()); | |
89 } | |
90 | |
91 TEST_F(FrameSelectionTest, InvalidateCaretRect) | 72 TEST_F(FrameSelectionTest, InvalidateCaretRect) |
92 { | 73 { |
93 Text* text = appendTextNode("Hello, World!"); | 74 Text* text = appendTextNode("Hello, World!"); |
94 document().view()->updateAllLifecyclePhases(); | 75 document().view()->updateAllLifecyclePhases(); |
95 | 76 |
96 VisibleSelection validSelection(Position(text, 0), Position(text, 0)); | 77 VisibleSelection validSelection(Position(text, 0), Position(text, 0)); |
97 setSelection(validSelection); | 78 setSelection(validSelection); |
98 selection().setCaretRectNeedsUpdate(); | 79 selection().setCaretRectNeedsUpdate(); |
99 EXPECT_TRUE(selection().isCaretBoundsDirty()); | 80 EXPECT_TRUE(selection().isCaretBoundsDirty()); |
100 selection().invalidateCaretRect(); | 81 selection().invalidateCaretRect(); |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
286 | 267 |
287 TEST_F(FrameSelectionTest, SelectAllWithUnselectableRoot) | 268 TEST_F(FrameSelectionTest, SelectAllWithUnselectableRoot) |
288 { | 269 { |
289 Element* select = document().createElement("select", ASSERT_NO_EXCEPTION); | 270 Element* select = document().createElement("select", ASSERT_NO_EXCEPTION); |
290 document().replaceChild(select, document().documentElement()); | 271 document().replaceChild(select, document().documentElement()); |
291 selection().selectAll(); | 272 selection().selectAll(); |
292 EXPECT_TRUE(selection().isNone()) << "Nothing should be selected if the cont
ent of the documentElement is not selctable."; | 273 EXPECT_TRUE(selection().isNone()) << "Nothing should be selected if the cont
ent of the documentElement is not selctable."; |
293 } | 274 } |
294 | 275 |
295 } // namespace blink | 276 } // namespace blink |
OLD | NEW |