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

Side by Side Diff: chrome/browser/ui/views/ime/input_ime_apitest_nonchromeos.cc

Issue 2077783002: Make limitations for input.ime.sendKeyEvents API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Check lastError of sendKeyEvents. Created 4 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
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() {}
19 20
20 protected: 21 protected:
21 void SetUpCommandLine(base::CommandLine* command_line) override { 22 void SetUpCommandLine(base::CommandLine* command_line) override {
22 ExtensionApiTest::SetUpCommandLine(command_line); 23 ExtensionApiTest::SetUpCommandLine(command_line);
23 command_line->AppendSwitch(switches::kEnableInputImeAPI); 24 command_line->AppendSwitch(switches::kEnableInputImeAPI);
24 } 25 }
25 26
27 // Sets the private flag of |track_key_events_for_testing_| in InputMethod.
28 void SetTrackKeyEvents(ui::InputMethod* input_method, bool track) {
29 input_method->track_key_events_for_testing_ = track;
30 }
31
32 // Returns the tracked key events of using input.ime.sendKeyEvents API.
33 std::vector<ui::KeyEvent*> GetKeyEvents(ui::InputMethod* input_method) {
34 return input_method->GetKeyEventsForTesting();
35 }
36
26 private: 37 private:
27 DISALLOW_COPY_AND_ASSIGN(InputImeApiTest); 38 DISALLOW_COPY_AND_ASSIGN(InputImeApiTest);
28 }; 39 };
29 40
30 IN_PROC_BROWSER_TEST_F(InputImeApiTest, CreateWindowTest) { 41 IN_PROC_BROWSER_TEST_F(InputImeApiTest, CreateWindowTest) {
31 // Manipulates the focused text input client because the follow cursor 42 // Manipulates the focused text input client because the follow cursor
32 // window requires the text input focus. 43 // window requires the text input focus.
33 BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser()); 44 BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser());
34 ui::InputMethod* input_method = 45 ui::InputMethod* input_method =
35 browser_view->GetNativeWindow()->GetHost()->GetInputMethod(); 46 browser_view->GetNativeWindow()->GetHost()->GetInputMethod();
36 std::unique_ptr<ui::DummyTextInputClient> client( 47 std::unique_ptr<ui::DummyTextInputClient> client(
37 new ui::DummyTextInputClient(ui::TEXT_INPUT_TYPE_TEXT)); 48 new ui::DummyTextInputClient(ui::TEXT_INPUT_TYPE_TEXT));
38 input_method->SetFocusedTextInputClient(client.get()); 49 input_method->SetFocusedTextInputClient(client.get());
39 ExtensionFunction::ScopedUserGestureForTests scoped_user_gesture; 50 ExtensionFunction::ScopedUserGestureForTests scoped_user_gesture;
40 InputImeActivateFunction::disable_bubble_for_testing_ = true; 51 InputImeActivateFunction::disable_bubble_for_testing_ = true;
52 SetTrackKeyEvents(input_method, true);
41 53
42 ASSERT_TRUE(RunExtensionTest("input_ime_nonchromeos")) << message_; 54 ASSERT_TRUE(RunExtensionTest("input_ime_nonchromeos")) << message_;
43 55
44 // Test the input.ime.sendKeyEvents API. 56 // Test the input.ime.sendKeyEvents API.
45 ASSERT_EQ(client->insert_char_count(), 1); 57 ASSERT_EQ(1, client->insert_char_count());
46 ASSERT_EQ(client->last_insert_char(), L'a'); 58 ASSERT_EQ(L'a', client->last_insert_char());
59
60 std::vector<ui::KeyEvent*> key_events = GetKeyEvents(input_method);
61 ASSERT_EQ(5U, key_events.size());
62 ASSERT_EQ(ui::VKEY_A, key_events[0]->key_code());
63 ASSERT_EQ(ui::VKEY_A, key_events[2]->key_code());
Devlin 2016/06/23 18:43:22 out of curiosity, what about key_events[1] and [3]
Azure Wei 2016/06/24 06:38:19 Added check for all events.
64 ASSERT_EQ(ui::VKEY_TAB, key_events[4]->key_code());
47 65
48 input_method->DetachTextInputClient(client.get()); 66 input_method->DetachTextInputClient(client.get());
49 } 67 }
50 68
69 IN_PROC_BROWSER_TEST_F(InputImeApiTest, SendKeyEventsOnSpecialPages) {
70 // Navigates to special page that sendKeyEvents API has limition with.
71 ui_test_utils::NavigateToURL(browser(), GURL("chrome://flags"));
72
73 BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser());
Devlin 2016/06/23 18:43:22 I don't think you actually need BrowserView here -
Azure Wei 2016/06/24 06:38:19 Done.
74 ui::InputMethod* input_method =
75 browser_view->GetNativeWindow()->GetHost()->GetInputMethod();
76 std::unique_ptr<ui::DummyTextInputClient> client(
77 new ui::DummyTextInputClient(ui::TEXT_INPUT_TYPE_TEXT));
78 input_method->SetFocusedTextInputClient(client.get());
79 ExtensionFunction::ScopedUserGestureForTests scoped_user_gesture;
80 InputImeActivateFunction::disable_bubble_for_testing_ = true;
Devlin 2016/06/23 18:43:22 use a base::AutoReset here.
Azure Wei 2016/06/24 06:38:19 Done.
81 SetTrackKeyEvents(input_method, true);
82
83 ASSERT_TRUE(RunExtensionTest("input_ime_nonchromeos")) << message_;
84
85 std::vector<ui::KeyEvent*> key_events = GetKeyEvents(input_method);
86 ASSERT_EQ(2U, key_events.size());
87 ASSERT_EQ(ui::VKEY_A, key_events[0]->key_code());
Devlin 2016/06/23 18:43:22 what about key_events[1]? Also some of these ASSE
Azure Wei 2016/06/24 06:38:19 Done.
88 }
89
51 } // namespace extensions 90 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698