Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "base/strings/utf_string_conversions.h" | |
| 5 #include "chrome/browser/extensions/extension_apitest.h" | 6 #include "chrome/browser/extensions/extension_apitest.h" |
| 7 #include "chrome/browser/ui/input_method/input_method_engine.h" | |
| 6 #include "chrome/browser/ui/views/frame/browser_view.h" | 8 #include "chrome/browser/ui/views/frame/browser_view.h" |
| 7 #include "chrome/common/chrome_switches.h" | 9 #include "chrome/common/chrome_switches.h" |
| 10 #include "extensions/test/extension_test_message_listener.h" | |
| 8 #include "ui/aura/window.h" | 11 #include "ui/aura/window.h" |
| 9 #include "ui/aura/window_tree_host.h" | 12 #include "ui/aura/window_tree_host.h" |
| 10 #include "ui/base/ime/dummy_text_input_client.h" | 13 #include "ui/base/ime/dummy_text_input_client.h" |
| 14 #include "ui/base/ime/ime_bridge.h" | |
| 11 #include "ui/base/ime/input_method.h" | 15 #include "ui/base/ime/input_method.h" |
| 16 #include "ui/base/ime/mock_ime_input_context_handler.h" | |
| 12 | 17 |
| 13 namespace extensions { | 18 namespace extensions { |
| 14 | 19 |
| 15 class InputImeApiTest : public ExtensionApiTest { | 20 class InputImeApiTest : public ExtensionApiTest { |
| 16 public: | 21 public: |
| 17 InputImeApiTest() {} | 22 InputImeApiTest() {} |
| 18 | 23 |
| 24 // extensions::ExtensionApiTest | |
| 25 void SetUpOnMainThread() override; | |
| 26 | |
| 19 protected: | 27 protected: |
| 20 void SetUpCommandLine(base::CommandLine* command_line) override { | 28 void SetUpCommandLine(base::CommandLine* command_line) override { |
| 21 ExtensionApiTest::SetUpCommandLine(command_line); | 29 ExtensionApiTest::SetUpCommandLine(command_line); |
| 22 command_line->AppendSwitch(switches::kEnableInputImeAPI); | 30 command_line->AppendSwitch(switches::kEnableInputImeAPI); |
| 23 } | 31 } |
| 24 | 32 |
| 33 ui::InputMethod* input_method; | |
| 34 | |
| 25 private: | 35 private: |
| 26 DISALLOW_COPY_AND_ASSIGN(InputImeApiTest); | 36 DISALLOW_COPY_AND_ASSIGN(InputImeApiTest); |
| 27 }; | 37 }; |
| 28 | 38 |
| 39 void InputImeApiTest::SetUpOnMainThread() { | |
| 40 BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser()); | |
| 41 input_method = browser_view->GetNativeWindow()->GetHost()->GetInputMethod(); | |
| 42 } | |
| 43 | |
| 29 IN_PROC_BROWSER_TEST_F(InputImeApiTest, CreateWindowTest) { | 44 IN_PROC_BROWSER_TEST_F(InputImeApiTest, CreateWindowTest) { |
| 30 // Manipulates the focused text input client because the follow cursor | 45 // Manipulates the focused text input client because the follow cursor |
| 31 // window requires the text input focus. | 46 // window requires the text input focus. |
| 32 BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser()); | |
| 33 ui::InputMethod* input_method = | |
| 34 browser_view->GetNativeWindow()->GetHost()->GetInputMethod(); | |
| 35 scoped_ptr<ui::DummyTextInputClient> client( | 47 scoped_ptr<ui::DummyTextInputClient> client( |
| 36 new ui::DummyTextInputClient(ui::TEXT_INPUT_TYPE_TEXT)); | 48 new ui::DummyTextInputClient(ui::TEXT_INPUT_TYPE_TEXT)); |
| 37 input_method->SetFocusedTextInputClient(client.get()); | 49 input_method->SetFocusedTextInputClient(client.get()); |
| 38 | 50 |
| 39 ASSERT_TRUE(RunExtensionTest("input_ime_nonchromeos")) << message_; | 51 ASSERT_TRUE(RunExtensionTest("input_ime_nonchromeos")) << message_; |
| 40 | |
| 41 input_method->DetachTextInputClient(client.get()); | 52 input_method->DetachTextInputClient(client.get()); |
| 42 } | 53 } |
| 43 | 54 |
| 55 IN_PROC_BROWSER_TEST_F(InputImeApiTest, FocusBlurTest) { | |
|
Shu Chen
2016/03/11 01:47:25
Please combine all the tests as a single api test.
Azure Wei
2016/03/16 03:07:24
Test for setComposition/onCompositionBoundsChange
| |
| 56 ExtensionTestMessageListener focus_listener("get_focus_event", false); | |
| 57 ExtensionTestMessageListener blur_listener("get_blur_event", false); | |
| 58 scoped_ptr<ui::DummyTextInputClient> client1( | |
| 59 new ui::DummyTextInputClient(ui::TEXT_INPUT_TYPE_TEXT)); | |
| 60 scoped_ptr<ui::DummyTextInputClient> client2( | |
| 61 new ui::DummyTextInputClient(ui::TEXT_INPUT_TYPE_TEXT)); | |
| 62 input_method->SetFocusedTextInputClient(client1.get()); | |
| 63 | |
| 64 ASSERT_TRUE(RunExtensionTest("input_ime_nonchromeos")) << message_; | |
| 65 | |
| 66 ASSERT_TRUE(focus_listener.WaitUntilSatisfied()) << message_; | |
| 67 | |
| 68 // Focus to the second text input client. | |
| 69 input_method->SetFocusedTextInputClient(client2.get()); | |
| 70 ASSERT_TRUE(blur_listener.WaitUntilSatisfied()) << message_; | |
| 71 } | |
| 72 | |
| 73 IN_PROC_BROWSER_TEST_F(InputImeApiTest, CommitTextAndSetCompositionTest) { | |
| 74 scoped_ptr<ui::MockIMEInputContextHandler> mock_input_context( | |
| 75 new ui::MockIMEInputContextHandler()); | |
| 76 ui::IMEBridge::Get()->SetInputContextHandler(mock_input_context.get()); | |
| 77 | |
| 78 ASSERT_TRUE(RunExtensionTest("input_ime_nonchromeos")) << message_; | |
| 79 | |
| 80 // Test input.ime.commitText API. | |
| 81 ASSERT_EQ(mock_input_context->commit_text_call_count(), 1); | |
| 82 ASSERT_EQ(mock_input_context->last_commit_text(), "test_commit_text"); | |
| 83 | |
| 84 // Test input.ime.setComposition API. | |
| 85 ASSERT_EQ(mock_input_context->update_preedit_text_call_count(), 1); | |
| 86 ui::MockIMEInputContextHandler::UpdateCompositionTextArg set_composition_arg = | |
| 87 mock_input_context->last_update_composition_arg(); | |
| 88 ASSERT_EQ(set_composition_arg.composition_text.text, | |
| 89 base::UTF8ToUTF16("test_composition_text")); | |
| 90 gfx::Range selection(2, 2); | |
| 91 ASSERT_EQ(set_composition_arg.composition_text.selection, selection); | |
| 92 ASSERT_EQ(set_composition_arg.cursor_pos, 2U); | |
| 93 ASSERT_TRUE(set_composition_arg.is_visible); | |
| 94 } | |
| 95 | |
| 96 IN_PROC_BROWSER_TEST_F(InputImeApiTest, CompositionBoundsChangeTest) { | |
| 97 ASSERT_TRUE(RunExtensionTest("input_ime_nonchromeos")) << message_; | |
| 98 } | |
| 99 | |
| 44 } // namespace extensions | 100 } // namespace extensions |
| OLD | NEW |