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

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

Issue 2857173003: Remove DocumentMarkerController::MarkersInRange() (Closed)
Patch Set: Remove MarkersInRange() Created 3 years, 7 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/InputMethodController.h" 5 #include "core/editing/InputMethodController.h"
6 6
7 #include <memory> 7 #include <memory>
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/Range.h" 10 #include "core/dom/Range.h"
(...skipping 14 matching lines...) Expand all
25 class InputMethodControllerTest : public ::testing::Test { 25 class InputMethodControllerTest : public ::testing::Test {
26 protected: 26 protected:
27 InputMethodController& Controller() { 27 InputMethodController& Controller() {
28 return GetFrame().GetInputMethodController(); 28 return GetFrame().GetInputMethodController();
29 } 29 }
30 Document& GetDocument() const { return *document_; } 30 Document& GetDocument() const { return *document_; }
31 LocalFrame& GetFrame() const { return dummy_page_holder_->GetFrame(); } 31 LocalFrame& GetFrame() const { return dummy_page_holder_->GetFrame(); }
32 Element* InsertHTMLElement(const char* element_code, const char* element_id); 32 Element* InsertHTMLElement(const char* element_code, const char* element_id);
33 void CreateHTMLWithCompositionInputEventListeners(); 33 void CreateHTMLWithCompositionInputEventListeners();
34 void CreateHTMLWithCompositionEndEventListener(const SelectionType); 34 void CreateHTMLWithCompositionEndEventListener(const SelectionType);
35 int NumMarkersInRange(const EphemeralRange&, DocumentMarker::MarkerTypes);
35 36
36 private: 37 private:
37 void SetUp() override; 38 void SetUp() override;
38 39
39 std::unique_ptr<DummyPageHolder> dummy_page_holder_; 40 std::unique_ptr<DummyPageHolder> dummy_page_holder_;
40 Persistent<Document> document_; 41 Persistent<Document> document_;
41 }; 42 };
42 43
43 void InputMethodControllerTest::SetUp() { 44 void InputMethodControllerTest::SetUp() {
44 dummy_page_holder_ = DummyPageHolder::Create(IntSize(800, 600)); 45 dummy_page_holder_ = DummyPageHolder::Create(IntSize(800, 600));
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 "});"); 111 "});");
111 break; 112 break;
112 default: 113 default:
113 NOTREACHED(); 114 NOTREACHED();
114 } 115 }
115 GetDocument().body()->AppendChild(script); 116 GetDocument().body()->AppendChild(script);
116 GetDocument().View()->UpdateAllLifecyclePhases(); 117 GetDocument().View()->UpdateAllLifecyclePhases();
117 editable->focus(); 118 editable->focus();
118 } 119 }
119 120
121 int InputMethodControllerTest::NumMarkersInRange(
122 const EphemeralRange& range,
123 DocumentMarker::MarkerTypes marker_types) {
124 int node_count = 0;
125 for (Node& node : range.Nodes()) {
126 node_count +=
127 GetDocument().Markers().MarkersFor(&node, marker_types).size();
128 }
129 return node_count;
130 }
131
120 TEST_F(InputMethodControllerTest, BackspaceFromEndOfInput) { 132 TEST_F(InputMethodControllerTest, BackspaceFromEndOfInput) {
121 HTMLInputElement* input = 133 HTMLInputElement* input =
122 toHTMLInputElement(InsertHTMLElement("<input id='sample'>", "sample")); 134 toHTMLInputElement(InsertHTMLElement("<input id='sample'>", "sample"));
123 135
124 input->setValue("fooX"); 136 input->setValue("fooX");
125 GetDocument().UpdateStyleAndLayout(); 137 GetDocument().UpdateStyleAndLayout();
126 Controller().SetEditableSelectionOffsets(PlainTextRange(4, 4)); 138 Controller().SetEditableSelectionOffsets(PlainTextRange(4, 4));
127 EXPECT_STREQ("fooX", input->value().Utf8().data()); 139 EXPECT_STREQ("fooX", input->value().Utf8().data());
128 Controller().ExtendSelectionAndDelete(0, 0); 140 Controller().ExtendSelectionAndDelete(0, 0);
129 EXPECT_STREQ("fooX", input->value().Utf8().data()); 141 EXPECT_STREQ("fooX", input->value().Utf8().data());
(...skipping 1271 matching lines...) Expand 10 before | Expand all | Expand 10 after
1401 Controller().FinishComposingText(InputMethodController::kKeepSelection); 1413 Controller().FinishComposingText(InputMethodController::kKeepSelection);
1402 GetFrame().GetEditor().InsertLineBreak(); 1414 GetFrame().GetEditor().InsertLineBreak();
1403 1415
1404 Controller().SetCompositionFromExistingText(underlines, 8, 8); 1416 Controller().SetCompositionFromExistingText(underlines, 8, 8);
1405 1417
1406 underlines.push_back(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0)); 1418 underlines.push_back(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0));
1407 Controller().SetComposition(String("world"), underlines, 0, 0); 1419 Controller().SetComposition(String("world"), underlines, 0, 0);
1408 ASSERT_EQ(1u, GetDocument().Markers().Markers().size()); 1420 ASSERT_EQ(1u, GetDocument().Markers().Markers().size());
1409 1421
1410 // Verify composition underline shows up on the second line, not the first 1422 // Verify composition underline shows up on the second line, not the first
1411 ASSERT_EQ(0u, GetDocument() 1423 ASSERT_EQ(0, NumMarkersInRange(PlainTextRange(0, 5).CreateRange(*div),
1412 .Markers() 1424 DocumentMarker::AllMarkers()));
1413 .MarkersInRange(PlainTextRange(0, 5).CreateRange(*div), 1425 ASSERT_EQ(1, NumMarkersInRange(PlainTextRange(6, 11).CreateRange(*div),
1414 DocumentMarker::AllMarkers()) 1426 DocumentMarker::AllMarkers()));
1415 .size());
1416 ASSERT_EQ(1u, GetDocument()
1417 .Markers()
1418 .MarkersInRange(PlainTextRange(6, 11).CreateRange(*div),
1419 DocumentMarker::AllMarkers())
1420 .size());
1421 1427
1422 // Verify marker has correct start/end offsets (measured from the beginning 1428 // Verify marker has correct start/end offsets (measured from the beginning
1423 // of the node, which is the beginning of the line) 1429 // of the node, which is the beginning of the line)
1424 EXPECT_EQ(0u, GetDocument().Markers().Markers()[0]->StartOffset()); 1430 EXPECT_EQ(0u, GetDocument().Markers().Markers()[0]->StartOffset());
1425 EXPECT_EQ(5u, GetDocument().Markers().Markers()[0]->EndOffset()); 1431 EXPECT_EQ(5u, GetDocument().Markers().Markers()[0]->EndOffset());
1426 } 1432 }
1427 1433
1428 TEST_F(InputMethodControllerTest, SelectionWhenFocusChangeFinishesComposition) { 1434 TEST_F(InputMethodControllerTest, SelectionWhenFocusChangeFinishesComposition) {
1429 GetDocument().GetSettings()->SetScriptEnabled(true); 1435 GetDocument().GetSettings()->SetScriptEnabled(true);
1430 Element* editable = 1436 Element* editable =
(...skipping 541 matching lines...) Expand 10 before | Expand all | Expand 10 after
1972 // Set selection before BODY(editable). 1978 // Set selection before BODY(editable).
1973 GetFrame().Selection().SetSelection( 1979 GetFrame().Selection().SetSelection(
1974 SelectionInDOMTree::Builder() 1980 SelectionInDOMTree::Builder()
1975 .Collapse(Position(GetDocument().documentElement(), 0)) 1981 .Collapse(Position(GetDocument().documentElement(), 0))
1976 .Build()); 1982 .Build());
1977 1983
1978 EXPECT_EQ(kWebTextInputTypeContentEditable, Controller().TextInputType()); 1984 EXPECT_EQ(kWebTextInputTypeContentEditable, Controller().TextInputType());
1979 } 1985 }
1980 1986
1981 } // namespace blink 1987 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698