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

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: Addressed Devlin's comments. 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..83c941f17be2e752ce252664c13f396749658df0 100644
--- a/chrome/browser/ui/views/ime/input_ime_apitest_nonchromeos.cc
+++ b/chrome/browser/ui/views/ime/input_ime_apitest_nonchromeos.cc
@@ -2,10 +2,12 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "base/auto_reset.h"
#include "chrome/browser/extensions/api/input_ime/input_ime_api_nonchromeos.h"
#include "chrome/browser/extensions/extension_apitest.h"
-#include "chrome/browser/ui/views/frame/browser_view.h"
+#include "chrome/browser/ui/browser_window.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,28 +25,104 @@ 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 true if the key events get from input method equals to the expected
+ // key events.
+ bool CompareKeyEvents(const ScopedVector<ui::KeyEvent>& expected_key_events,
+ ui::InputMethod* input_method) {
+ if (expected_key_events.size() != GetKeyEvents(input_method).size())
+ return false;
+ for (size_t i = 0; i < expected_key_events.size(); i++) {
+ if (!CompareKeyEvent(expected_key_events[i],
+ GetKeyEvents(input_method)[i]))
+ return false;
+ }
+ return true;
+ }
+
private:
+ // Returns the tracked key events of using input.ime.sendKeyEvents API.
+ const ScopedVector<ui::KeyEvent>& GetKeyEvents(
+ ui::InputMethod* input_method) {
+ return input_method->GetKeyEventsForTesting();
+ }
+
+ // Returns true if the two events have the same type, key code and flag.
+ bool CompareKeyEvent(ui::KeyEvent* event1, ui::KeyEvent* event2) {
+ return event1->type() == event2->type() &&
+ event1->key_code() == event2->key_code() &&
+ event1->flags() == event2->flags();
+ }
+
DISALLOW_COPY_AND_ASSIGN(InputImeApiTest);
};
IN_PROC_BROWSER_TEST_F(InputImeApiTest, CreateWindowTest) {
// Manipulates the focused text input client because the follow cursor
// window requires the text input focus.
- BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser());
ui::InputMethod* input_method =
- browser_view->GetNativeWindow()->GetHost()->GetInputMethod();
+ browser()->window()->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;
+ base::AutoReset<bool> auto_reset_disable_bubble(
+ &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());
+ EXPECT_EQ(L'a', client->last_insert_char());
+
+ ScopedVector<ui::KeyEvent> key_events;
Devlin 2016/06/28 20:56:44 ScopedVector is deprecated. Use std::vector<std::
Azure Wei 2016/06/29 02:53:46 Done.
+ key_events.push_back(
+ new ui::KeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_A, ui::EF_NONE));
+ key_events.push_back(
+ new ui::KeyEvent(ui::ET_KEY_RELEASED, ui::VKEY_A, ui::EF_NONE));
+ key_events.push_back(
+ new ui::KeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_A, ui::EF_CONTROL_DOWN));
+ key_events.push_back(
+ new ui::KeyEvent(ui::ET_KEY_RELEASED, ui::VKEY_A, ui::EF_CONTROL_DOWN));
+ key_events.push_back(
+ new ui::KeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_TAB, ui::EF_NONE));
+
+ EXPECT_TRUE(CompareKeyEvents(key_events, input_method));
+
+ 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"));
+
+ ui::InputMethod* input_method =
+ browser()->window()->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;
+ base::AutoReset<bool> auto_reset_disable_bubble(
+ &InputImeActivateFunction::disable_bubble_for_testing_, true);
+ SetTrackKeyEvents(input_method, true);
+
+ ASSERT_TRUE(RunExtensionTest("input_ime_nonchromeos")) << message_;
+
+ ASSERT_EQ(1, client->insert_char_count());
+ EXPECT_EQ(L'a', client->last_insert_char());
+
+ ScopedVector<ui::KeyEvent> key_events;
+ key_events.push_back(
+ new ui::KeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_A, ui::EF_NONE));
+ key_events.push_back(
+ new ui::KeyEvent(ui::ET_KEY_RELEASED, ui::VKEY_A, ui::EF_NONE));
+ EXPECT_TRUE(CompareKeyEvents(key_events, input_method));
input_method->DetachTextInputClient(client.get());
}

Powered by Google App Engine
This is Rietveld 408576698