Chromium Code Reviews| 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/InputMethodController.h" | 5 #include "core/editing/InputMethodController.h" |
| 6 | 6 |
| 7 #include "core/dom/Element.h" | 7 #include "core/dom/Element.h" |
| 8 #include "core/dom/Range.h" | 8 #include "core/dom/Range.h" |
| 9 #include "core/editing/FrameSelection.h" | 9 #include "core/editing/FrameSelection.h" |
| 10 #include "core/frame/LocalFrame.h" | 10 #include "core/frame/LocalFrame.h" |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 39 Element* InputMethodControllerTest::insertHTMLElement( | 39 Element* InputMethodControllerTest::insertHTMLElement( |
| 40 const char* elementCode, const char* elementId) | 40 const char* elementCode, const char* elementId) |
| 41 { | 41 { |
| 42 document().write(elementCode); | 42 document().write(elementCode); |
| 43 document().updateLayout(); | 43 document().updateLayout(); |
| 44 Element* element = document().getElementById(elementId); | 44 Element* element = document().getElementById(elementId); |
| 45 element->focus(); | 45 element->focus(); |
| 46 return element; | 46 return element; |
| 47 } | 47 } |
| 48 | 48 |
| 49 TEST_F(InputMethodControllerTest, CreateDifferentRanges) | |
| 50 { | |
| 51 HTMLInputElement* input = toHTMLInputElement( | |
| 52 insertHTMLElement("<input id='sample'>", "sample")); | |
| 53 | |
| 54 input->setValue("hello"); | |
| 55 Element* rootEditableElement = frame().selection().rootEditableElement(); | |
| 56 EXPECT_TRUE(rootEditableElement); | |
| 57 | |
| 58 // In InputMethodController::setComposition, we are sure that End >= Start > = 0. Our tests can base on this fact. | |
| 59 // Start and End are on the left boundary | |
| 60 EphemeralRange range = PlainTextRange(0, 0).createRange(*rootEditableElement ); | |
| 61 EXPECT_EQ(0u, range.startPosition().computeOffsetInContainerNode()); | |
| 62 EXPECT_EQ(0u, range.endPosition().computeOffsetInContainerNode()); | |
| 63 | |
| 64 // Start is on the left boundary, and End is on the right boundary | |
|
Changwan Ryu
2016/04/04 06:23:13
The below code seems to belong to PlainTextRange t
yabinh
2016/04/04 08:31:51
OK. I'll create a new file to put the test.
| |
| 65 range = PlainTextRange(0, 5).createRange(*rootEditableElement); | |
| 66 EXPECT_EQ(0u, range.startPosition().computeOffsetInContainerNode()); | |
| 67 EXPECT_EQ(5u, range.endPosition().computeOffsetInContainerNode()); | |
| 68 | |
| 69 // Start is on the left boundary, and End exceeds right boundary | |
| 70 range = PlainTextRange(0, 10).createRange(*rootEditableElement); | |
| 71 EXPECT_EQ(0u, range.startPosition().computeOffsetInContainerNode()); | |
| 72 EXPECT_EQ(5u, range.endPosition().computeOffsetInContainerNode()); | |
| 73 | |
| 74 // Start and End are on the right boundary | |
| 75 range = PlainTextRange(5, 5).createRange(*rootEditableElement); | |
| 76 EXPECT_EQ(5u, range.startPosition().computeOffsetInContainerNode()); | |
| 77 EXPECT_EQ(5u, range.endPosition().computeOffsetInContainerNode()); | |
| 78 | |
| 79 // Start is on the right boundary, and End exceeds right boundary | |
| 80 range = PlainTextRange(5, 10).createRange(*rootEditableElement); | |
| 81 EXPECT_EQ(5u, range.startPosition().computeOffsetInContainerNode()); | |
| 82 EXPECT_EQ(5u, range.endPosition().computeOffsetInContainerNode()); | |
| 83 | |
| 84 // Start and End exceed the right boundary | |
| 85 range = PlainTextRange(10, 10).createRange(*rootEditableElement); | |
| 86 EXPECT_EQ(5u, range.startPosition().computeOffsetInContainerNode()); | |
| 87 EXPECT_EQ(5u, range.endPosition().computeOffsetInContainerNode()); | |
| 88 } | |
| 89 | |
| 90 TEST_F(InputMethodControllerTest, CreateDifferentRangesForSelection) | |
| 91 { | |
| 92 HTMLInputElement* input = toHTMLInputElement( | |
| 93 insertHTMLElement("<input id='sample'>", "sample")); | |
| 94 | |
| 95 input->setValue("hello"); | |
| 96 Element* rootEditableElement = frame().selection().rootEditableElement(); | |
| 97 EXPECT_TRUE(rootEditableElement); | |
| 98 | |
| 99 // In InputMethodController::setComposition, we are sure that End >= Start > = 0. Our tests can base on this fact. | |
| 100 // Start and End are on the left boundary | |
| 101 EphemeralRange range = PlainTextRange(0, 0).createRangeForSelection(*rootEdi tableElement); | |
| 102 EXPECT_EQ(0u, range.startPosition().computeOffsetInContainerNode()); | |
| 103 EXPECT_EQ(0u, range.endPosition().computeOffsetInContainerNode()); | |
| 104 | |
| 105 // Start is on the left boundary, and End is on the right boundary | |
| 106 range = PlainTextRange(0, 5).createRangeForSelection(*rootEditableElement); | |
| 107 EXPECT_EQ(0u, range.startPosition().computeOffsetInContainerNode()); | |
| 108 EXPECT_EQ(5u, range.endPosition().computeOffsetInContainerNode()); | |
| 109 | |
| 110 // Start is on the left boundary, and End exceeds right boundary | |
| 111 range = PlainTextRange(0, 10).createRangeForSelection(*rootEditableElement); | |
| 112 EXPECT_EQ(0u, range.startPosition().computeOffsetInContainerNode()); | |
| 113 EXPECT_EQ(5u, range.endPosition().computeOffsetInContainerNode()); | |
| 114 | |
| 115 // Start and End are on the right boundary | |
| 116 range = PlainTextRange(5, 5).createRangeForSelection(*rootEditableElement); | |
| 117 EXPECT_EQ(5u, range.startPosition().computeOffsetInContainerNode()); | |
| 118 EXPECT_EQ(5u, range.endPosition().computeOffsetInContainerNode()); | |
| 119 | |
| 120 // Start is on the right boundary, and End exceeds right boundary | |
| 121 range = PlainTextRange(5, 10).createRangeForSelection(*rootEditableElement); | |
| 122 EXPECT_EQ(5u, range.startPosition().computeOffsetInContainerNode()); | |
| 123 EXPECT_EQ(5u, range.endPosition().computeOffsetInContainerNode()); | |
| 124 | |
| 125 // Start and End exceed the right boundary | |
| 126 range = PlainTextRange(10, 10).createRangeForSelection(*rootEditableElement) ; | |
| 127 EXPECT_EQ(5u, range.startPosition().computeOffsetInContainerNode()); | |
| 128 EXPECT_EQ(5u, range.endPosition().computeOffsetInContainerNode()); | |
| 129 } | |
| 130 | |
| 49 TEST_F(InputMethodControllerTest, BackspaceFromEndOfInput) | 131 TEST_F(InputMethodControllerTest, BackspaceFromEndOfInput) |
| 50 { | 132 { |
| 51 HTMLInputElement* input = toHTMLInputElement( | 133 HTMLInputElement* input = toHTMLInputElement( |
| 52 insertHTMLElement("<input id='sample'>", "sample")); | 134 insertHTMLElement("<input id='sample'>", "sample")); |
| 53 | 135 |
| 54 input->setValue("fooX"); | 136 input->setValue("fooX"); |
| 55 controller().setEditableSelectionOffsets(PlainTextRange(4, 4)); | 137 controller().setEditableSelectionOffsets(PlainTextRange(4, 4)); |
| 56 EXPECT_STREQ("fooX", input->value().utf8().data()); | 138 EXPECT_STREQ("fooX", input->value().utf8().data()); |
| 57 controller().extendSelectionAndDelete(0, 0); | 139 controller().extendSelectionAndDelete(0, 0); |
| 58 EXPECT_STREQ("fooX", input->value().utf8().data()); | 140 EXPECT_STREQ("fooX", input->value().utf8().data()); |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 184 | 266 |
| 185 Vector<CompositionUnderline> underlines; | 267 Vector<CompositionUnderline> underlines; |
| 186 underlines.append(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0)); | 268 underlines.append(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0)); |
| 187 controller().setComposition("foo", underlines, 0, 3); | 269 controller().setComposition("foo", underlines, 0, 3); |
| 188 controller().confirmComposition(); | 270 controller().confirmComposition(); |
| 189 | 271 |
| 190 EXPECT_STREQ("foo", input->value().utf8().data()); | 272 EXPECT_STREQ("foo", input->value().utf8().data()); |
| 191 } | 273 } |
| 192 | 274 |
| 193 } // namespace blink | 275 } // namespace blink |
| OLD | NEW |