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

Unified Diff: third_party/WebKit/Source/core/editing/PlainTextRangeTest.cpp

Issue 1847583003: Fix setComposingText when newCursorPosition != 1 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Modified some C++ unit tests Created 4 years, 8 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/editing/PlainTextRangeTest.cpp
diff --git a/third_party/WebKit/Source/core/editing/PlainTextRangeTest.cpp b/third_party/WebKit/Source/core/editing/PlainTextRangeTest.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..529a69d16efad22af741f5d7f377e94fae74d23a
--- /dev/null
+++ b/third_party/WebKit/Source/core/editing/PlainTextRangeTest.cpp
@@ -0,0 +1,138 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "core/editing/PlainTextRange.h"
+
+#include "core/dom/Element.h"
+#include "core/dom/Range.h"
+#include "core/editing/FrameSelection.h"
+#include "core/editing/InputMethodController.h"
+#include "core/frame/LocalFrame.h"
+#include "core/html/HTMLDocument.h"
+#include "core/html/HTMLInputElement.h"
+#include "core/testing/DummyPageHolder.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace blink {
+
+class PlainTextRangeTest : public ::testing::Test {
+protected:
+ HTMLDocument& document() const { return *m_document; }
+ LocalFrame& frame() const { return m_dummyPageHolder->frame(); }
+ Element* insertHTMLElement(const char* elementCode, const char* elementId);
+
+private:
+ void SetUp() override;
+
+ OwnPtr<DummyPageHolder> m_dummyPageHolder;
+ Persistent<HTMLDocument> m_document;
+};
+
+void PlainTextRangeTest::SetUp()
+{
+ m_dummyPageHolder = DummyPageHolder::create(IntSize(800, 600));
+ m_document = toHTMLDocument(&m_dummyPageHolder->document());
+ ASSERT(m_document);
+}
+
+Element* PlainTextRangeTest::insertHTMLElement(
+ const char* elementCode, const char* elementId)
+{
+ document().write(elementCode);
+ document().updateLayout();
+ Element* element = document().getElementById(elementId);
+ element->focus();
+ return element;
+}
+
+TEST_F(PlainTextRangeTest, CreateDifferentRanges)
Changwan Ryu 2016/04/05 07:50:37 CreateRange?
yabinh 2016/04/05 08:06:42 Acknowledged.
+{
+ // Since the cursor never exceeds the left boundary, our test should focus on right boundary cases.
+ HTMLInputElement* input = toHTMLInputElement(
+ insertHTMLElement("<input id='sample'>", "sample"));
+
+ input->setValue("hello");
+ Element* rootEditableElement = frame().selection().rootEditableElement();
+ EXPECT_TRUE(rootEditableElement);
+
+ // Start and End are on thEphemeralRangee right boundary
+ EphemeralRange range = PlainTextRange(5, 5).createRange(*rootEditableElement);
+ EXPECT_EQ(5, range.startPosition().computeOffsetInContainerNode());
+ EXPECT_EQ(5, range.endPosition().computeOffsetInContainerNode());
+
+ // Start is on the right boundary, and End exceeds right boundary
+ range = PlainTextRange(5, 10).createRange(*rootEditableElement);
+ EXPECT_EQ(5, range.startPosition().computeOffsetInContainerNode());
+ EXPECT_EQ(5, range.endPosition().computeOffsetInContainerNode());
+
+ // Start and End exceed the right boundary
+ range = PlainTextRange(10, 10).createRange(*rootEditableElement);
+ EXPECT_EQ(5, range.startPosition().computeOffsetInContainerNode());
+ EXPECT_EQ(5, range.endPosition().computeOffsetInContainerNode());
+
+ input->setValue("");
+ rootEditableElement = frame().selection().rootEditableElement();
+ EXPECT_TRUE(rootEditableElement);
+
+ // Start and End are on thEphemeralRangee right boundary
+ range = PlainTextRange(0, 0).createRange(*rootEditableElement);
+ EXPECT_EQ(0, range.startPosition().computeOffsetInContainerNode());
+ EXPECT_EQ(0, range.endPosition().computeOffsetInContainerNode());
+
+ // Start is on the right boundary, and End exceeds right boundary
+ range = PlainTextRange(0, 10).createRange(*rootEditableElement);
+ EXPECT_EQ(0, range.startPosition().computeOffsetInContainerNode());
+ EXPECT_EQ(0, range.endPosition().computeOffsetInContainerNode());
+
+ // Start and End exceed the right boundary
+ range = PlainTextRange(10, 10).createRange(*rootEditableElement);
+ EXPECT_EQ(0, range.startPosition().computeOffsetInContainerNode());
+ EXPECT_EQ(0, range.endPosition().computeOffsetInContainerNode());
+}
+
+TEST_F(PlainTextRangeTest, CreateDifferentRangesForSelection)
Changwan Ryu 2016/04/05 07:50:37 CreateRangeForSelection should be enough? Could y
yabinh 2016/04/05 08:06:42 Acknowledged.
+{
+ // Since the cursor never exceeds the left boundary, our test should focus on right boundary cases.
+ HTMLInputElement* input = toHTMLInputElement(
+ insertHTMLElement("<input id='sample'>", "sample"));
+
+ input->setValue("hello");
+ Element* rootEditableElement = frame().selection().rootEditableElement();
+ EXPECT_TRUE(rootEditableElement);
+
+ // Start and End are on the right boundary
Changwan Ryu 2016/04/05 07:50:37 no need to capitalize E and you need to add a peri
yabinh 2016/04/05 08:06:41 Acknowledged.
+ EphemeralRange range = PlainTextRange(5, 5).createRangeForSelection(*rootEditableElement);
+ EXPECT_EQ(5, range.startPosition().computeOffsetInContainerNode());
+ EXPECT_EQ(5, range.endPosition().computeOffsetInContainerNode());
+
+ // Start is on the right boundary, and End exceeds right boundary
+ range = PlainTextRange(5, 10).createRangeForSelection(*rootEditableElement);
+ EXPECT_EQ(5, range.startPosition().computeOffsetInContainerNode());
+ EXPECT_EQ(5, range.endPosition().computeOffsetInContainerNode());
+
+ // Start and End exceed the right boundary
+ range = PlainTextRange(10, 10).createRangeForSelection(*rootEditableElement);
+ EXPECT_EQ(5, range.startPosition().computeOffsetInContainerNode());
+ EXPECT_EQ(5, range.endPosition().computeOffsetInContainerNode());
+
+ input->setValue("");
+ rootEditableElement = frame().selection().rootEditableElement();
+ EXPECT_TRUE(rootEditableElement);
+
+ // Start and End are on the right boundary
+ range = PlainTextRange(0, 0).createRangeForSelection(*rootEditableElement);
+ EXPECT_EQ(0, range.startPosition().computeOffsetInContainerNode());
+ EXPECT_EQ(0, range.endPosition().computeOffsetInContainerNode());
+
+ // Start is on the right boundary, and End exceeds right boundary
+ range = PlainTextRange(0, 10).createRangeForSelection(*rootEditableElement);
+ EXPECT_EQ(0, range.startPosition().computeOffsetInContainerNode());
+ EXPECT_EQ(0, range.endPosition().computeOffsetInContainerNode());
+
+ // Start and End exceed the right boundary
+ range = PlainTextRange(10, 10).createRangeForSelection(*rootEditableElement);
+ EXPECT_EQ(0, range.startPosition().computeOffsetInContainerNode());
+ EXPECT_EQ(0, range.endPosition().computeOffsetInContainerNode());
+}
+}

Powered by Google App Engine
This is Rietveld 408576698