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" |
6 #include "chrome/browser/ui/views/frame/browser_view.h" | 7 #include "chrome/browser/ui/views/frame/browser_view.h" |
7 #include "chrome/common/chrome_switches.h" | 8 #include "chrome/common/chrome_switches.h" |
| 9 #include "extensions/test/extension_test_message_listener.h" |
8 #include "ui/aura/window.h" | 10 #include "ui/aura/window.h" |
9 #include "ui/aura/window_tree_host.h" | 11 #include "ui/aura/window_tree_host.h" |
10 #include "ui/base/ime/dummy_text_input_client.h" | 12 #include "ui/base/ime/dummy_text_input_client.h" |
11 #include "ui/base/ime/input_method.h" | 13 #include "ui/base/ime/input_method.h" |
12 | 14 |
13 namespace extensions { | 15 namespace extensions { |
14 | 16 |
15 class InputImeApiTest : public ExtensionApiTest { | 17 class InputImeApiTest : public ExtensionApiTest { |
16 public: | 18 public: |
17 InputImeApiTest() {} | 19 InputImeApiTest() {} |
18 | 20 |
| 21 // extensions::ExtensionApiTest: |
| 22 void SetUpOnMainThread() override; |
| 23 |
19 protected: | 24 protected: |
20 void SetUpCommandLine(base::CommandLine* command_line) override { | 25 void SetUpCommandLine(base::CommandLine* command_line) override { |
21 ExtensionApiTest::SetUpCommandLine(command_line); | 26 ExtensionApiTest::SetUpCommandLine(command_line); |
22 command_line->AppendSwitch(switches::kEnableInputImeAPI); | 27 command_line->AppendSwitch(switches::kEnableInputImeAPI); |
23 } | 28 } |
24 | 29 |
| 30 ui::InputMethod* input_method; |
| 31 |
25 private: | 32 private: |
26 DISALLOW_COPY_AND_ASSIGN(InputImeApiTest); | 33 DISALLOW_COPY_AND_ASSIGN(InputImeApiTest); |
27 }; | 34 }; |
28 | 35 |
29 IN_PROC_BROWSER_TEST_F(InputImeApiTest, CreateWindowTest) { | 36 void InputImeApiTest::SetUpOnMainThread() { |
| 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) { |
30 // Manipulates the focused text input client because the follow cursor | 42 // Manipulates the focused text input client because the follow cursor |
31 // window requires the text input focus. | 43 // window requires the text input focus. |
32 BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser()); | 44 ExtensionTestMessageListener focus_listener("get_focus_event", false); |
33 ui::InputMethod* input_method = | 45 ExtensionTestMessageListener blur_listener("get_blur_event", false); |
34 browser_view->GetNativeWindow()->GetHost()->GetInputMethod(); | 46 |
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 | 52 |
41 // Test the input.ime.sendKeyEvents API. | 53 // Test the input.ime.sendKeyEvents API. |
42 ASSERT_EQ(client->insert_char_count(), 1); | 54 ASSERT_EQ(client->insert_char_count(), 1); |
43 ASSERT_EQ(client->last_insert_char(), L'a'); | 55 ASSERT_EQ(client->last_insert_char(), L'a'); |
44 | 56 |
| 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 |
45 input_method->DetachTextInputClient(client.get()); | 69 input_method->DetachTextInputClient(client.get()); |
46 } | 70 } |
47 | 71 |
| 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 |
48 } // namespace extensions | 82 } // namespace extensions |
OLD | NEW |