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

Unified Diff: Source/core/editing/InputMethodControllerTest.cpp

Issue 311053008: CANCEL: Make "compositionstart" event cancelable (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: 2014-06-18T10:53:48 Created 6 years, 6 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
« no previous file with comments | « Source/core/editing/InputMethodController.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/editing/InputMethodControllerTest.cpp
diff --git a/Source/core/editing/InputMethodControllerTest.cpp b/Source/core/editing/InputMethodControllerTest.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..7afca2e5d536504ef65026cc46cd41cf27e34b8f
--- /dev/null
+++ b/Source/core/editing/InputMethodControllerTest.cpp
@@ -0,0 +1,114 @@
+// Copyright 2014 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 "config.h"
+#include "core/editing/InputMethodController.h"
+
+#include "core/dom/Text.h"
+#include "core/editing/FrameSelection.h"
+#include "core/frame/LocalFrame.h"
+#include "core/frame/Settings.h"
+#include "core/html/HTMLDocument.h"
+#include "core/html/HTMLElement.h"
+#include "core/html/HTMLInputElement.h"
+#include "core/testing/DummyPageHolder.h"
+#include <gtest/gtest.h>
+
+using namespace WebCore;
+
+namespace WebCore {
+
+class InputMethodControllerTest : public ::testing::Test {
+protected:
+ InputMethodController& controller() { return frame().inputMethodController(); }
+ HTMLDocument& document() const { return *m_document; }
+ LocalFrame& frame() const { return m_dummyPageHolder->frame(); }
+
+private:
+ virtual void SetUp() OVERRIDE;
+
+ OwnPtr<DummyPageHolder> m_dummyPageHolder;
+ HTMLDocument* m_document;
+};
+
+void InputMethodControllerTest::SetUp()
+{
+ m_dummyPageHolder = DummyPageHolder::create(IntSize(800, 600));
+ m_document = toHTMLDocument(&m_dummyPageHolder->document());
+ ASSERT(m_document);
+}
+
+} // namespace WebCore
+
+namespace {
+
+using namespace WebCore;
+
+TEST_F(InputMethodControllerTest, setComposition)
+{
+ document().write("<div contenteditable='true' id='target'>foo</div>");
+ RefPtrWillBeRawPtr<Element> input = document().getElementById("target");
+ frame().selection().moveTo(Position(toText(input->firstChild()), 0), DOWNSTREAM);
+ frame().inputMethodController().setComposition("bar", Vector<CompositionUnderline>(), 0, 0);
+ EXPECT_STREQ("barfoo", input->textContent().utf8().data());
+}
+
+TEST_F(InputMethodControllerTest, setCompositionCancelCompositionStart)
+{
+ frame().settings()->setScriptEnabled(true);
+ document().write("<div contenteditable='true' id='target'>foo</div>"
+ "<div id='compositionend'></div>"
+ "<script>"
+ "var target = document.getElementById('target');"
+ "target.addEventListener('compositionstart', function(event) {"
+ " event.preventDefault();"
+ "});"
+ "target.addEventListener('compositionend', function(event) {"
+ " document.getElementById('compositionend').textContent = '1';"
+ "});"
+ "</script>");
+ document().updateLayout();
+ RefPtrWillBeRawPtr<Element> target = document().getElementById("target");
+ document().setFocusedElement(target);
+ frame().selection().moveTo(Position(toText(target->firstChild()), 0), DOWNSTREAM);
+ frame().inputMethodController().setComposition("bar", Vector<CompositionUnderline>(), 0, 0);
+ EXPECT_STREQ("foo", target->textContent().utf8().data());
+
+ RefPtrWillBeRawPtr<Element> endEvent = document().getElementById("compositionend");
+ EXPECT_STREQ("1", endEvent->textContent().utf8().data());
+}
+
+TEST_F(InputMethodControllerTest, BackspaceFromEndOfInput)
+{
+ document().write("<input id='sample'>");
+ HTMLInputElement* input = toHTMLInputElement(document().getElementById("sample"));
+ document().updateLayout();
+ input->focus();
+
+ input->setValue("fooX");
+ controller().setEditableSelectionOffsets(PlainTextRange(4, 4));
+ EXPECT_STREQ("fooX", input->value().utf8().data());
+ controller().extendSelectionAndDelete(1, 0);
+ EXPECT_STREQ("foo", input->value().utf8().data());
+
+ input->setValue(String::fromUTF8("foo\xE2\x98\x85")); // U+2605 == "black star"
+ EXPECT_STREQ("foo\xE2\x98\x85", input->value().utf8().data());
+ controller().extendSelectionAndDelete(1, 0);
+ EXPECT_STREQ("foo", input->value().utf8().data());
+
+ input->setValue(String::fromUTF8("foo\xF0\x9F\x8F\x86")); // U+1F3C6 == "trophy"
+ controller().setEditableSelectionOffsets(PlainTextRange(4, 4));
+ EXPECT_STREQ("foo\xF0\x9F\x8F\x86", input->value().utf8().data());
+ controller().extendSelectionAndDelete(1, 0);
+ EXPECT_STREQ("foo", input->value().utf8().data());
+
+ input->setValue(String::fromUTF8("foo\xE0\xB8\x81\xE0\xB9\x89")); // composed U+0E01 "ka kai" + U+0E49 "mai tho"
+ controller().setEditableSelectionOffsets(PlainTextRange(4, 4));
+ EXPECT_STREQ("foo\xE0\xB8\x81\xE0\xB9\x89", input->value().utf8().data());
+ controller().extendSelectionAndDelete(1, 0);
+ EXPECT_STREQ("foo", input->value().utf8().data());
+
+}
+
+} // namespace WebCore
« no previous file with comments | « Source/core/editing/InputMethodController.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698