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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/views/ime/input_ime_apitest_nonchromeos.cc
diff --git a/chrome/browser/ui/views/ime/input_ime_apitest_nonchromeos.cc b/chrome/browser/ui/views/ime/input_ime_apitest_nonchromeos.cc
index 55eadfcb04b16911613f2e486468ddf23fa097d5..88bc20a154a83e91778503180b7780a41c31494c 100644
--- a/chrome/browser/ui/views/ime/input_ime_apitest_nonchromeos.cc
+++ b/chrome/browser/ui/views/ime/input_ime_apitest_nonchromeos.cc
@@ -6,6 +6,7 @@
#include "chrome/browser/extensions/extension_apitest.h"
#include "chrome/browser/ui/views/frame/browser_view.h"
#include "chrome/common/chrome_switches.h"
+#include "chrome/test/base/ui_test_utils.h"
#include "ui/aura/window.h"
#include "ui/aura/window_tree_host.h"
#include "ui/base/ime/dummy_text_input_client.h"
@@ -23,6 +24,16 @@ class InputImeApiTest : public ExtensionApiTest {
command_line->AppendSwitch(switches::kEnableInputImeAPI);
}
+ // Sets the private flag of |track_key_events_for_testing_| in InputMethod.
+ void SetTrackKeyEvents(ui::InputMethod* input_method, bool track) {
+ input_method->track_key_events_for_testing_ = track;
+ }
+
+ // Returns the tracked key events of using input.ime.sendKeyEvents API.
+ std::vector<ui::KeyEvent*> GetKeyEvents(ui::InputMethod* input_method) {
+ return input_method->GetKeyEventsForTesting();
+ }
+
private:
DISALLOW_COPY_AND_ASSIGN(InputImeApiTest);
};
@@ -38,14 +49,42 @@ IN_PROC_BROWSER_TEST_F(InputImeApiTest, CreateWindowTest) {
input_method->SetFocusedTextInputClient(client.get());
ExtensionFunction::ScopedUserGestureForTests scoped_user_gesture;
InputImeActivateFunction::disable_bubble_for_testing_ = true;
+ SetTrackKeyEvents(input_method, true);
ASSERT_TRUE(RunExtensionTest("input_ime_nonchromeos")) << message_;
// Test the input.ime.sendKeyEvents API.
- ASSERT_EQ(client->insert_char_count(), 1);
- ASSERT_EQ(client->last_insert_char(), L'a');
+ ASSERT_EQ(1, client->insert_char_count());
+ ASSERT_EQ(L'a', client->last_insert_char());
+
+ std::vector<ui::KeyEvent*> key_events = GetKeyEvents(input_method);
+ ASSERT_EQ(5U, key_events.size());
+ ASSERT_EQ(ui::VKEY_A, key_events[0]->key_code());
+ 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.
+ ASSERT_EQ(ui::VKEY_TAB, key_events[4]->key_code());
input_method->DetachTextInputClient(client.get());
}
+IN_PROC_BROWSER_TEST_F(InputImeApiTest, SendKeyEventsOnSpecialPages) {
+ // Navigates to special page that sendKeyEvents API has limition with.
+ ui_test_utils::NavigateToURL(browser(), GURL("chrome://flags"));
+
+ 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.
+ ui::InputMethod* input_method =
+ browser_view->GetNativeWindow()->GetHost()->GetInputMethod();
+ std::unique_ptr<ui::DummyTextInputClient> client(
+ new ui::DummyTextInputClient(ui::TEXT_INPUT_TYPE_TEXT));
+ input_method->SetFocusedTextInputClient(client.get());
+ ExtensionFunction::ScopedUserGestureForTests scoped_user_gesture;
+ 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.
+ SetTrackKeyEvents(input_method, true);
+
+ ASSERT_TRUE(RunExtensionTest("input_ime_nonchromeos")) << message_;
+
+ std::vector<ui::KeyEvent*> key_events = GetKeyEvents(input_method);
+ ASSERT_EQ(2U, key_events.size());
+ 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.
+}
+
} // namespace extensions

Powered by Google App Engine
This is Rietveld 408576698