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 "chrome/browser/extensions/api/input_ime/input_ime_api_nonchromeos.h" | 5 #include "chrome/browser/extensions/api/input_ime/input_ime_api_nonchromeos.h" |
6 #include "chrome/browser/extensions/extension_apitest.h" | 6 #include "chrome/browser/extensions/extension_apitest.h" |
7 #include "chrome/browser/ui/views/frame/browser_view.h" | 7 #include "chrome/browser/ui/views/frame/browser_view.h" |
8 #include "chrome/common/chrome_switches.h" | 8 #include "chrome/common/chrome_switches.h" |
9 #include "chrome/test/base/ui_test_utils.h" | |
9 #include "ui/aura/window.h" | 10 #include "ui/aura/window.h" |
10 #include "ui/aura/window_tree_host.h" | 11 #include "ui/aura/window_tree_host.h" |
11 #include "ui/base/ime/dummy_text_input_client.h" | 12 #include "ui/base/ime/dummy_text_input_client.h" |
12 #include "ui/base/ime/input_method.h" | 13 #include "ui/base/ime/input_method.h" |
13 | 14 |
14 namespace extensions { | 15 namespace extensions { |
15 | 16 |
16 class InputImeApiTest : public ExtensionApiTest { | 17 class InputImeApiTest : public ExtensionApiTest { |
17 public: | 18 public: |
18 InputImeApiTest() {} | 19 InputImeApiTest() {} |
(...skipping 19 matching lines...) Expand all Loading... | |
38 input_method->SetFocusedTextInputClient(client.get()); | 39 input_method->SetFocusedTextInputClient(client.get()); |
39 ExtensionFunction::ScopedUserGestureForTests scoped_user_gesture; | 40 ExtensionFunction::ScopedUserGestureForTests scoped_user_gesture; |
40 InputImeActivateFunction::disable_bubble_for_testing_ = true; | 41 InputImeActivateFunction::disable_bubble_for_testing_ = true; |
41 | 42 |
42 ASSERT_TRUE(RunExtensionTest("input_ime_nonchromeos")) << message_; | 43 ASSERT_TRUE(RunExtensionTest("input_ime_nonchromeos")) << message_; |
43 | 44 |
44 // Test the input.ime.sendKeyEvents API. | 45 // Test the input.ime.sendKeyEvents API. |
45 ASSERT_EQ(client->insert_char_count(), 1); | 46 ASSERT_EQ(client->insert_char_count(), 1); |
46 ASSERT_EQ(client->last_insert_char(), L'a'); | 47 ASSERT_EQ(client->last_insert_char(), L'a'); |
47 | 48 |
49 std::vector<ui::KeyEvent*> key_events = input_method->GetKeyEventsForTest(); | |
50 ASSERT_EQ(key_events.size(), 5U); | |
51 ASSERT_EQ(key_events[0]->key_code(), ui::VKEY_A); | |
52 ASSERT_EQ(key_events[2]->key_code(), ui::VKEY_A); | |
53 ASSERT_EQ(key_events[4]->key_code(), ui::VKEY_TAB); | |
54 | |
48 input_method->DetachTextInputClient(client.get()); | 55 input_method->DetachTextInputClient(client.get()); |
49 } | 56 } |
50 | 57 |
58 IN_PROC_BROWSER_TEST_F(InputImeApiTest, SendKeyEventsOnSpecialPages) { | |
59 // Navigates to special page that sendKeyEvents API has limition with. | |
60 ui_test_utils::NavigateToURL(browser(), GURL("chrome://flags")); | |
61 | |
62 BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser()); | |
63 ui::InputMethod* input_method = | |
64 browser_view->GetNativeWindow()->GetHost()->GetInputMethod(); | |
65 std::unique_ptr<ui::DummyTextInputClient> client( | |
66 new ui::DummyTextInputClient(ui::TEXT_INPUT_TYPE_TEXT)); | |
67 input_method->SetFocusedTextInputClient(client.get()); | |
68 ExtensionFunction::ScopedUserGestureForTests scoped_user_gesture; | |
69 InputImeActivateFunction::disable_bubble_for_testing_ = true; | |
70 | |
71 ASSERT_TRUE(RunExtensionTest("input_ime_nonchromeos")) << message_; | |
72 | |
73 std::vector<ui::KeyEvent*> key_events = input_method->GetKeyEventsForTest(); | |
74 ASSERT_EQ(key_events.size(), 2U); | |
Devlin
2016/06/22 16:33:12
switch the order here: expected, actual
Azure Wei
2016/06/23 02:45:23
Done.
| |
75 ASSERT_EQ(key_events[0]->key_code(), ui::VKEY_A); | |
76 } | |
77 | |
51 } // namespace extensions | 78 } // namespace extensions |
OLD | NEW |