| 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" | |
| 6 #include "chrome/browser/extensions/extension_apitest.h" | 5 #include "chrome/browser/extensions/extension_apitest.h" |
| 7 #include "chrome/browser/ui/views/frame/browser_view.h" | 6 #include "chrome/browser/ui/views/frame/browser_view.h" |
| 8 #include "chrome/common/chrome_switches.h" | 7 #include "chrome/common/chrome_switches.h" |
| 9 #include "extensions/test/extension_test_message_listener.h" | |
| 10 #include "ui/aura/window.h" | 8 #include "ui/aura/window.h" |
| 11 #include "ui/aura/window_tree_host.h" | 9 #include "ui/aura/window_tree_host.h" |
| 12 #include "ui/base/ime/dummy_text_input_client.h" | 10 #include "ui/base/ime/dummy_text_input_client.h" |
| 13 #include "ui/base/ime/input_method.h" | 11 #include "ui/base/ime/input_method.h" |
| 14 | 12 |
| 15 namespace extensions { | 13 namespace extensions { |
| 16 | 14 |
| 17 class InputImeApiTest : public ExtensionApiTest { | 15 class InputImeApiTest : public ExtensionApiTest { |
| 18 public: | 16 public: |
| 19 InputImeApiTest() {} | 17 InputImeApiTest() {} |
| 20 | 18 |
| 21 // extensions::ExtensionApiTest: | |
| 22 void SetUpOnMainThread() override; | |
| 23 | |
| 24 protected: | 19 protected: |
| 25 void SetUpCommandLine(base::CommandLine* command_line) override { | 20 void SetUpCommandLine(base::CommandLine* command_line) override { |
| 26 ExtensionApiTest::SetUpCommandLine(command_line); | 21 ExtensionApiTest::SetUpCommandLine(command_line); |
| 27 command_line->AppendSwitch(switches::kEnableInputImeAPI); | 22 command_line->AppendSwitch(switches::kEnableInputImeAPI); |
| 28 } | 23 } |
| 29 | 24 |
| 30 ui::InputMethod* input_method; | |
| 31 | |
| 32 private: | 25 private: |
| 33 DISALLOW_COPY_AND_ASSIGN(InputImeApiTest); | 26 DISALLOW_COPY_AND_ASSIGN(InputImeApiTest); |
| 34 }; | 27 }; |
| 35 | 28 |
| 36 void InputImeApiTest::SetUpOnMainThread() { | 29 IN_PROC_BROWSER_TEST_F(InputImeApiTest, CreateWindowTest) { |
| 37 BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser()); | |
| 38 input_method = browser_view->GetNativeWindow()->GetHost()->GetInputMethod(); | |
| 39 } | |
| 40 | |
| 41 IN_PROC_BROWSER_TEST_F(InputImeApiTest, BasicApiTest) { | |
| 42 // Manipulates the focused text input client because the follow cursor | 30 // Manipulates the focused text input client because the follow cursor |
| 43 // window requires the text input focus. | 31 // window requires the text input focus. |
| 44 ExtensionTestMessageListener focus_listener("get_focus_event", false); | 32 BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser()); |
| 45 ExtensionTestMessageListener blur_listener("get_blur_event", false); | 33 ui::InputMethod* input_method = |
| 46 | 34 browser_view->GetNativeWindow()->GetHost()->GetInputMethod(); |
| 47 scoped_ptr<ui::DummyTextInputClient> client( | 35 scoped_ptr<ui::DummyTextInputClient> client( |
| 48 new ui::DummyTextInputClient(ui::TEXT_INPUT_TYPE_TEXT)); | 36 new ui::DummyTextInputClient(ui::TEXT_INPUT_TYPE_TEXT)); |
| 49 input_method->SetFocusedTextInputClient(client.get()); | 37 input_method->SetFocusedTextInputClient(client.get()); |
| 50 | 38 |
| 51 ASSERT_TRUE(RunExtensionTest("input_ime_nonchromeos")) << message_; | 39 ASSERT_TRUE(RunExtensionTest("input_ime_nonchromeos")) << message_; |
| 52 | 40 |
| 53 // Test the input.ime.sendKeyEvents API. | 41 // Test the input.ime.sendKeyEvents API. |
| 54 ASSERT_EQ(client->insert_char_count(), 1); | 42 ASSERT_EQ(client->insert_char_count(), 1); |
| 55 ASSERT_EQ(client->last_insert_char(), L'a'); | 43 ASSERT_EQ(client->last_insert_char(), L'a'); |
| 56 | 44 |
| 57 // Test the input.ime.commitText API. | |
| 58 ASSERT_EQ(client->insert_text_count(), 1); | |
| 59 ASSERT_EQ(client->last_insert_text(), base::UTF8ToUTF16("test_commit_text")); | |
| 60 | |
| 61 // Test the input.ime.onFocus and onBlur APIs. | |
| 62 ASSERT_TRUE(focus_listener.WaitUntilSatisfied()) << message_; | |
| 63 // Focus to the second text input client. | |
| 64 scoped_ptr<ui::DummyTextInputClient> client2( | |
| 65 new ui::DummyTextInputClient(ui::TEXT_INPUT_TYPE_TEXT)); | |
| 66 input_method->SetFocusedTextInputClient(client2.get()); | |
| 67 ASSERT_TRUE(blur_listener.WaitUntilSatisfied()) << message_; | |
| 68 | |
| 69 input_method->DetachTextInputClient(client.get()); | 45 input_method->DetachTextInputClient(client.get()); |
| 70 } | 46 } |
| 71 | 47 |
| 72 IN_PROC_BROWSER_TEST_F(InputImeApiTest, CompostionTextTest) { | |
| 73 ExtensionTestMessageListener compsition_listener("finish_composition_test", | |
| 74 false); | |
| 75 | |
| 76 // Test the input.ime.setComposition and onCompositionBoundsChanged API. | |
| 77 ASSERT_TRUE(RunExtensionTest("input_ime_nonchromeos")) << message_; | |
| 78 | |
| 79 ASSERT_TRUE(compsition_listener.WaitUntilSatisfied()) << message_; | |
| 80 }; | |
| 81 | |
| 82 } // namespace extensions | 48 } // namespace extensions |
| OLD | NEW |