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

Side by Side Diff: content/browser/renderer_host/input/web_input_event_builders_android_unittest.cc

Issue 1811553002: [Android] Synthetic composition event should have DomKey 'Unidentified' (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Filter synthetic key event by checking |android_key_event| not null Created 4 years, 9 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 "content/browser/renderer_host/input/web_input_event_builders_android.h " 5 #include "content/browser/renderer_host/input/web_input_event_builders_android.h "
6 6
7 #include <android/input.h> 7 #include <android/input.h>
8 #include <android/keycodes.h> 8 #include <android/keycodes.h>
9 9
10 #include "base/android/jni_android.h" 10 #include "base/android/jni_android.h"
11 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
12 #include "third_party/WebKit/public/web/WebInputEvent.h" 12 #include "third_party/WebKit/public/web/WebInputEvent.h"
13 #include "ui/events/android/key_event_utils.h" 13 #include "ui/events/android/key_event_utils.h"
14 #include "ui/events/gesture_detection/motion_event.h" 14 #include "ui/events/gesture_detection/motion_event.h"
15 #include "ui/events/keycodes/dom/dom_code.h"
15 #include "ui/events/keycodes/dom/dom_key.h" 16 #include "ui/events/keycodes/dom/dom_key.h"
16 #include "ui/events/keycodes/dom/keycode_converter.h" 17 #include "ui/events/keycodes/dom/keycode_converter.h"
18 #include "ui/events/keycodes/keyboard_codes_posix.h"
17 19
18 using base::android::AttachCurrentThread; 20 using base::android::AttachCurrentThread;
19 using base::android::ScopedJavaLocalRef; 21 using base::android::ScopedJavaLocalRef;
20 using blink::WebKeyboardEvent; 22 using blink::WebKeyboardEvent;
21 23
22 namespace { 24 namespace {
23 25
24 const int kCombiningAccent = 0x80000000; 26 const int kCombiningAccent = 0x80000000;
25 const int kCombiningAccentMask = 0x7fffffff; 27 const int kCombiningAccentMask = 0x7fffffff;
28 const int kCompositionKeyCode = 229;
26 29
27 WebKeyboardEvent CreateFakeWebKeyboardEvent(JNIEnv* env, 30 WebKeyboardEvent CreateFakeWebKeyboardEvent(JNIEnv* env,
28 int key_code, 31 int key_code,
29 int web_modifier, 32 int web_modifier,
30 int unicode_character) { 33 int unicode_character) {
31 ScopedJavaLocalRef<jobject> keydown_event = 34 ScopedJavaLocalRef<jobject> keydown_event =
32 ui::events::android::CreateKeyEvent(env, ui::MotionEvent::ACTION_DOWN, 35 ui::events::android::CreateKeyEvent(env, ui::MotionEvent::ACTION_DOWN,
33 key_code); 36 key_code);
34 37
35 WebKeyboardEvent web_event = content::WebKeyboardEventBuilder::Build( 38 WebKeyboardEvent web_event = content::WebKeyboardEventBuilder::Build(
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 << ui::KeycodeConverter::DomKeyToKeyString(web_event.domKey); 135 << ui::KeycodeConverter::DomKeyToKeyString(web_event.domKey);
133 136
134 // Tests DomKey with Ctrl and Alt. 137 // Tests DomKey with Ctrl and Alt.
135 web_event = CreateFakeWebKeyboardEvent( 138 web_event = CreateFakeWebKeyboardEvent(
136 env, entry.key_code, 139 env, entry.key_code,
137 WebKeyboardEvent::ControlKey | WebKeyboardEvent::AltKey, 0); 140 WebKeyboardEvent::ControlKey | WebKeyboardEvent::AltKey, 0);
138 EXPECT_EQ(ui::DomKey::FromCharacter(entry.character), web_event.domKey) 141 EXPECT_EQ(ui::DomKey::FromCharacter(entry.character), web_event.domKey)
139 << ui::KeycodeConverter::DomKeyToKeyString(web_event.domKey); 142 << ui::KeycodeConverter::DomKeyToKeyString(web_event.domKey);
140 } 143 }
141 } 144 }
145
146 // Testing AKEYCODE_LAST_CHANNEL because it's overlapping with
147 // COMPOSITION_KEY_CODE (both 229).
148 TEST(WebInputEventBuilderAndroidTest, LastChannelKey) {
149 JNIEnv* env = AttachCurrentThread();
150
151 // AKEYCODE_LAST_CHANNEL (229) is not defined in minimum NDK.
152 WebKeyboardEvent web_event =
153 CreateFakeWebKeyboardEvent(env, 229, 0, 0);
154 EXPECT_EQ(229, web_event.nativeKeyCode);
155 EXPECT_EQ(ui::KeyboardCode::VKEY_UNKNOWN, web_event.windowsKeyCode);
156 EXPECT_EQ(static_cast<int>(ui::DomCode::NONE), web_event.domCode);
157 EXPECT_EQ(ui::DomKey::MEDIA_LAST, web_event.domKey);
158 }
159
160 // Synthetic key event should produce DomKey::UNIDENTIFIED.
161 TEST(WebInputEventBuilderAndroidTest, DomKeySyntheticEvent) {
162 WebKeyboardEvent web_event = content::WebKeyboardEventBuilder::Build(
163 nullptr, nullptr, WebKeyboardEvent::KeyDown, 0, 0, kCompositionKeyCode, 0,
164 0, false);
165 EXPECT_EQ(kCompositionKeyCode, web_event.nativeKeyCode);
166 EXPECT_EQ(ui::KeyboardCode::VKEY_UNKNOWN, web_event.windowsKeyCode);
167 EXPECT_EQ(static_cast<int>(ui::DomCode::NONE), web_event.domCode);
168 EXPECT_EQ(ui::DomKey::UNIDENTIFIED, web_event.domKey);
169 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698