| 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/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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 TEST_F(VisibleSelectionTest, appendTrailingWhitespaceWithAfterAnchor) { | 75 TEST_F(VisibleSelectionTest, appendTrailingWhitespaceWithAfterAnchor) { |
| 76 SetBodyContent( | 76 SetBodyContent( |
| 77 "<input type=checkbox>" | 77 "<input type=checkbox>" |
| 78 "<div style='user-select:none'>abc</div>"); | 78 "<div style='user-select:none'>abc</div>"); |
| 79 Element* const input = GetDocument().QuerySelector("input"); | 79 Element* const input = GetDocument().QuerySelector("input"); |
| 80 | 80 |
| 81 // Simulate double-clicking "abc". | 81 // Simulate double-clicking "abc". |
| 82 // TODO(editing-dev): We should remove above comment once we fix [1]. | 82 // TODO(editing-dev): We should remove above comment once we fix [1]. |
| 83 // [1] http://crbug.com/701657 double-click on user-select:none should not | 83 // [1] http://crbug.com/701657 double-click on user-select:none should not |
| 84 // compute selection. | 84 // compute selection. |
| 85 VisibleSelection selection = | 85 const VisibleSelection selection = |
| 86 CreateVisibleSelection(SelectionInDOMTree::Builder() | 86 CreateVisibleSelection(SelectionInDOMTree::Builder() |
| 87 .Collapse(Position::BeforeNode(*input)) | 87 .Collapse(Position::BeforeNode(*input)) |
| 88 .Extend(Position::AfterNode(*input)) | 88 .Extend(Position::AfterNode(*input)) |
| 89 .SetGranularity(kWordGranularity) | 89 .SetGranularity(kWordGranularity) |
| 90 .Build()); | 90 .Build()); |
| 91 selection.AppendTrailingWhitespace(); | 91 const VisibleSelection result = selection.AppendTrailingWhitespace(); |
| 92 | 92 |
| 93 EXPECT_EQ(Position::BeforeNode(*input), selection.Start()); | 93 EXPECT_EQ(Position::BeforeNode(*input), result.Start()); |
| 94 EXPECT_EQ(Position::AfterNode(*input), selection.End()); | 94 EXPECT_EQ(Position::AfterNode(*input), result.End()); |
| 95 } | 95 } |
| 96 | 96 |
| 97 TEST_F(VisibleSelectionTest, expandUsingGranularity) { | 97 TEST_F(VisibleSelectionTest, expandUsingGranularity) { |
| 98 const char* body_content = | 98 const char* body_content = |
| 99 "<span id=host><a id=one>1</a><a id=two>22</a></span>"; | 99 "<span id=host><a id=one>1</a><a id=two>22</a></span>"; |
| 100 const char* shadow_content = | 100 const char* shadow_content = |
| 101 "<p><b id=three>333</b><content select=#two></content><b " | 101 "<p><b id=three>333</b><content select=#two></content><b " |
| 102 "id=four>4444</b><span id=space> </span><content " | 102 "id=four>4444</b><span id=space> </span><content " |
| 103 "select=#one></content><b id=five>55555</b></p>"; | 103 "select=#one></content><b id=five>55555</b></p>"; |
| 104 SetBodyContent(body_content); | 104 SetBodyContent(body_content); |
| (...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 532 Element* host = GetDocument().getElementById("host"); | 532 Element* host = GetDocument().getElementById("host"); |
| 533 host->AppendChild(sample); | 533 host->AppendChild(sample); |
| 534 GetDocument().UpdateStyleAndLayout(); | 534 GetDocument().UpdateStyleAndLayout(); |
| 535 | 535 |
| 536 // Simulates to restore selection from undo stack. | 536 // Simulates to restore selection from undo stack. |
| 537 selection = CreateVisibleSelection(selection.AsSelection()); | 537 selection = CreateVisibleSelection(selection.AsSelection()); |
| 538 EXPECT_EQ(Position(sample->firstChild(), 0), selection.Start()); | 538 EXPECT_EQ(Position(sample->firstChild(), 0), selection.Start()); |
| 539 } | 539 } |
| 540 | 540 |
| 541 } // namespace blink | 541 } // namespace blink |
| OLD | NEW |