| 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..b432aefc0ec7d1d83da129ebc5b0f8b12b28371b
|
| --- /dev/null
|
| +++ b/Source/core/editing/InputMethodControllerTest.cpp
|
| @@ -0,0 +1,72 @@
|
| +// 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/testing/DummyPageHolder.h"
|
| +#include <gtest/gtest.h>
|
| +
|
| +using namespace WebCore;
|
| +
|
| +namespace WebCore {
|
| +
|
| +class InputMethodControllerTest : public ::testing::Test {
|
| +protected:
|
| + 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>"
|
| + "<script>"
|
| + "document.getElementById('target').addEventListener('compositionstart', function(event) {"
|
| + " event.preventDefault();"
|
| + "});"
|
| + "</script>");
|
| + document().updateLayout();
|
| + RefPtrWillBeRawPtr<Element> input = document().getElementById("target");
|
| + document().setFocusedElement(input);
|
| + frame().selection().moveTo(Position(toText(input->firstChild()), 0), DOWNSTREAM);
|
| + frame().inputMethodController().setComposition("bar", Vector<CompositionUnderline>(), 0, 0);
|
| + EXPECT_STREQ("foo", input->textContent().utf8().data());
|
| +}
|
| +
|
| +} // namespace WebCore
|
|
|