| 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 "base/strings/stringprintf.h" | 5 #include "base/strings/stringprintf.h" |
| 6 #import "chrome/browser/ui/cocoa/browser_window_utils.h" | 6 #import "chrome/browser/ui/cocoa/browser_window_utils.h" |
| 7 #include "content/public/browser/native_web_keyboard_event.h" | 7 #include "content/public/browser/native_web_keyboard_event.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 #include "ui/events/keycodes/keyboard_codes.h" | 9 #include "ui/events/keycodes/keyboard_codes.h" |
| 10 | 10 |
| 11 using blink::WebInputEvent; | 11 using blink::WebInputEvent; |
| 12 | 12 |
| 13 const struct { | 13 const struct { |
| 14 ui::KeyboardCode key_code; | 14 ui::KeyboardCode key_code; |
| 15 int modifiers; | 15 int modifiers; |
| 16 bool is_text_editing_event; | 16 bool is_text_editing_event; |
| 17 } kTextEditingEventTestCases[] = { | 17 } kTextEditingEventTestCases[] = { |
| 18 {ui::VKEY_A, WebInputEvent::MetaKey, true}, | 18 {ui::VKEY_A, WebInputEvent::MetaKey, true}, |
| 19 {ui::VKEY_V, WebInputEvent::MetaKey, true}, | 19 {ui::VKEY_V, WebInputEvent::MetaKey, true}, |
| 20 {ui::VKEY_C, WebInputEvent::MetaKey, true}, | 20 {ui::VKEY_C, WebInputEvent::MetaKey, true}, |
| 21 {ui::VKEY_X, WebInputEvent::MetaKey, true}, | 21 {ui::VKEY_X, WebInputEvent::MetaKey, true}, |
| 22 {ui::VKEY_Z, WebInputEvent::MetaKey, true}, | 22 {ui::VKEY_Z, WebInputEvent::MetaKey, true}, |
| 23 | 23 |
| 24 {ui::VKEY_A, WebInputEvent::ShiftKey, false}, | 24 {ui::VKEY_A, WebInputEvent::ShiftKey, false}, |
| 25 {ui::VKEY_G, WebInputEvent::MetaKey, false}, | 25 {ui::VKEY_G, WebInputEvent::MetaKey, false}, |
| 26 }; | 26 }; |
| 27 | 27 |
| 28 TEST(BrowserWindowUtilsTest, TestIsTextEditingEvent) { | 28 TEST(BrowserWindowUtilsTest, TestIsTextEditingEvent) { |
| 29 content::NativeWebKeyboardEvent event; | 29 content::NativeWebKeyboardEvent event(WebInputEvent::Char, |
| 30 WebInputEvent::NoModifiers, |
| 31 WebInputEvent::TimeStampForTesting); |
| 30 EXPECT_FALSE([BrowserWindowUtils isTextEditingEvent:event]); | 32 EXPECT_FALSE([BrowserWindowUtils isTextEditingEvent:event]); |
| 31 | 33 |
| 32 for (const auto& test : kTextEditingEventTestCases) { | 34 for (const auto& test : kTextEditingEventTestCases) { |
| 33 SCOPED_TRACE(base::StringPrintf("key = %c, modifiers = %d", | 35 SCOPED_TRACE(base::StringPrintf("key = %c, modifiers = %d", |
| 34 test.key_code, test.modifiers)); | 36 test.key_code, test.modifiers)); |
| 35 content::NativeWebKeyboardEvent event; | 37 content::NativeWebKeyboardEvent event(WebInputEvent::Char, test.modifiers, |
| 38 WebInputEvent::TimeStampForTesting); |
| 36 event.windowsKeyCode = test.key_code; | 39 event.windowsKeyCode = test.key_code; |
| 37 event.modifiers = test.modifiers; | |
| 38 EXPECT_EQ(test.is_text_editing_event, | 40 EXPECT_EQ(test.is_text_editing_event, |
| 39 [BrowserWindowUtils isTextEditingEvent:event]); | 41 [BrowserWindowUtils isTextEditingEvent:event]); |
| 40 } | 42 } |
| 41 } | 43 } |
| OLD | NEW |