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

Side by Side 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-06T09:53:36 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 unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "config.h"
6 #include "core/editing/InputMethodController.h"
7
8 #include "core/dom/Text.h"
9 #include "core/editing/FrameSelection.h"
10 #include "core/frame/LocalFrame.h"
11 #include "core/frame/Settings.h"
12 #include "core/html/HTMLDocument.h"
13 #include "core/html/HTMLElement.h"
14 #include "core/testing/DummyPageHolder.h"
15 #include <gtest/gtest.h>
16
17 using namespace WebCore;
18
19 namespace WebCore {
20
21 class InputMethodControllerTest : public ::testing::Test {
22 protected:
23 HTMLDocument& document() const { return *m_document; }
24 LocalFrame& frame() const { return m_dummyPageHolder->frame(); }
25
26 private:
27 virtual void SetUp() OVERRIDE;
28
29 OwnPtr<DummyPageHolder> m_dummyPageHolder;
30 HTMLDocument* m_document;
31 };
32
33 void InputMethodControllerTest::SetUp()
34 {
35 m_dummyPageHolder = DummyPageHolder::create(IntSize(800, 600));
36 m_document = toHTMLDocument(&m_dummyPageHolder->document());
37 ASSERT(m_document);
38 }
39
40 } // namespace WebCore
41
42 namespace {
43
44 using namespace WebCore;
45
46 TEST_F(InputMethodControllerTest, setComposition)
47 {
48 document().write("<div contenteditable='true' id='target'>foo</div>");
49 RefPtrWillBeRawPtr<Element> input = document().getElementById("target");
50 frame().selection().moveTo(Position(toText(input->firstChild()), 0), DOWNSTR EAM);
51 frame().inputMethodController().setComposition("bar", Vector<CompositionUnde rline>(), 0, 0);
52 EXPECT_STREQ("barfoo", input->textContent().utf8().data());
53 }
54
55 TEST_F(InputMethodControllerTest, setCompositionCancelCompositionStart)
56 {
57 frame().settings()->setScriptEnabled(true);
58 document().write("<div contenteditable='true' id='target'>foo</div>"
59 "<script>"
60 "document.getElementById('target').addEventListener('compositionstart', function(event) {"
61 " event.preventDefault();"
62 "});"
63 "</script>");
64 document().updateLayout();
65 RefPtrWillBeRawPtr<Element> input = document().getElementById("target");
66 document().setFocusedElement(input);
67 frame().selection().moveTo(Position(toText(input->firstChild()), 0), DOWNSTR EAM);
68 frame().inputMethodController().setComposition("bar", Vector<CompositionUnde rline>(), 0, 0);
69 EXPECT_STREQ("foo", input->textContent().utf8().data());
70 }
71
72 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698