Commit 5e89e2ef authored by Meilin Wang's avatar Meilin Wang Committed by Commit Bot

Add unit tests for Assistant key remapping.

This change expands the unit tests to cover the Assistant key remapping
feature.

Misc: fix typo and lint errors.

Bug: None.
Test: Local compile and run tests changed in this CL.
Change-Id: I21a559a4d2cec07f581bcc3573034520c6c79c3e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1570806
Commit-Queue: Meilin Wang <meilinw@chromium.org>
Reviewed-by: default avatarTao Wu <wutao@chromium.org>
Reviewed-by: default avatarSteven Bennetts <stevenjb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#652482}
parent 263e7db8
......@@ -5,6 +5,9 @@
#include "chrome/browser/ui/webui/settings/chromeos/device_keyboard_handler.h"
#include <memory>
#include <string>
#include <utility>
#include <vector>
#include "base/command_line.h"
#include "base/logging.h"
......@@ -51,7 +54,8 @@ class KeyboardHandlerTest : public testing::Test {
bool GetLastShowKeysChangedMessage(bool* has_caps_lock_out,
bool* has_external_meta_key_out,
bool* has_apple_command_key_out,
bool* has_internal_search_out)
bool* has_internal_search_out,
bool* has_assistant_key_out)
WARN_UNUSED_RESULT {
for (auto it = web_ui_.call_data().rbegin();
it != web_ui_.call_data().rend(); ++it) {
......@@ -74,6 +78,7 @@ class KeyboardHandlerTest : public testing::Test {
{"showExternalMetaKey", has_external_meta_key_out},
{"showAppleCommandKey", has_apple_command_key_out},
{"hasInternalKeyboard", has_internal_search_out},
{"hasAssistantKey", has_assistant_key_out},
};
for (const auto& pair : path_to_out_param) {
......@@ -96,7 +101,7 @@ class KeyboardHandlerTest : public testing::Test {
bool has_caps_lock = false;
bool ignored = false;
if (!GetLastShowKeysChangedMessage(&has_caps_lock, &ignored, &ignored,
&ignored)) {
&ignored, &ignored)) {
ADD_FAILURE() << "Didn't get " << KeyboardHandler::kShowKeysChangedName;
return false;
}
......@@ -110,7 +115,7 @@ class KeyboardHandlerTest : public testing::Test {
bool has_external_meta = false;
bool ignored = false;
if (!GetLastShowKeysChangedMessage(&ignored, &has_external_meta, &ignored,
&ignored)) {
&ignored, &ignored)) {
ADD_FAILURE() << "Didn't get " << KeyboardHandler::kShowKeysChangedName;
return false;
}
......@@ -123,8 +128,8 @@ class KeyboardHandlerTest : public testing::Test {
bool HasAppleCommandKey() {
bool has_apple_command_key = false;
bool ignored = false;
if (!GetLastShowKeysChangedMessage(&ignored, &ignored,
&has_apple_command_key, &ignored)) {
if (!GetLastShowKeysChangedMessage(
&ignored, &ignored, &has_apple_command_key, &ignored, &ignored)) {
ADD_FAILURE() << "Didn't get " << KeyboardHandler::kShowKeysChangedName;
return false;
}
......@@ -138,13 +143,27 @@ class KeyboardHandlerTest : public testing::Test {
bool has_internal_search_key = false;
bool ignored = false;
if (!GetLastShowKeysChangedMessage(&ignored, &ignored, &ignored,
&has_internal_search_key)) {
&has_internal_search_key, &ignored)) {
ADD_FAILURE() << "Didn't get " << KeyboardHandler::kShowKeysChangedName;
return false;
}
return has_internal_search_key;
}
// Returns true if the last keys-changed message reported that the device has
// an assistant key on its keyboard and otherwise false. A failure is added
// if a message wasn't found.
bool HasAssistantKey() {
bool has_assistant_key = false;
bool ignored = false;
if (!GetLastShowKeysChangedMessage(&ignored, &ignored, &ignored, &ignored,
&has_assistant_key)) {
ADD_FAILURE() << "Didn't get " << KeyboardHandler::kShowKeysChangedName;
return false;
}
return has_assistant_key;
}
std::unique_ptr<ui::InputDeviceManager> input_device_manager_;
ws::InputDeviceClientTestApi input_device_client_test_api_;
content::TestWebUI web_ui_;
......@@ -163,6 +182,7 @@ TEST_F(KeyboardHandlerTest, DefaultKeys) {
EXPECT_FALSE(HasCapsLock());
EXPECT_FALSE(HasExternalMetaKey());
EXPECT_FALSE(HasAppleCommandKey());
EXPECT_FALSE(HasAssistantKey());
}
TEST_F(KeyboardHandlerTest, NonChromeOSKeyboard) {
......@@ -173,6 +193,7 @@ TEST_F(KeyboardHandlerTest, NonChromeOSKeyboard) {
EXPECT_TRUE(HasCapsLock());
EXPECT_FALSE(HasExternalMetaKey());
EXPECT_FALSE(HasAppleCommandKey());
EXPECT_FALSE(HasAssistantKey());
}
TEST_F(KeyboardHandlerTest, ExternalKeyboard) {
......@@ -186,6 +207,7 @@ TEST_F(KeyboardHandlerTest, ExternalKeyboard) {
EXPECT_FALSE(HasCapsLock());
EXPECT_FALSE(HasExternalMetaKey());
EXPECT_FALSE(HasAppleCommandKey());
EXPECT_FALSE(HasAssistantKey());
// Simulate an external keyboard being connected. We should assume there's a
// Caps Lock and Meta keys now.
......@@ -196,6 +218,7 @@ TEST_F(KeyboardHandlerTest, ExternalKeyboard) {
EXPECT_TRUE(HasCapsLock());
EXPECT_TRUE(HasExternalMetaKey());
EXPECT_FALSE(HasAppleCommandKey());
EXPECT_FALSE(HasAssistantKey());
// Simulate an external Apple keyboard being connected. Now users can remap
// the command key.
......@@ -206,6 +229,7 @@ TEST_F(KeyboardHandlerTest, ExternalKeyboard) {
EXPECT_TRUE(HasCapsLock());
EXPECT_FALSE(HasExternalMetaKey());
EXPECT_TRUE(HasAppleCommandKey());
EXPECT_FALSE(HasAssistantKey());
// Simulate two external keyboards (Apple and non-Apple) are connected at the
// same time.
......@@ -216,9 +240,10 @@ TEST_F(KeyboardHandlerTest, ExternalKeyboard) {
EXPECT_TRUE(HasCapsLock());
EXPECT_TRUE(HasExternalMetaKey());
EXPECT_TRUE(HasAppleCommandKey());
EXPECT_FALSE(HasAssistantKey());
// Some keyboard devices don't report the string "keyboard" as part of their
// device names. Those should also be detcted as external keyboards, and
// device names. Those should also be detected as external keyboards, and
// should show the capslock and external meta remapping.
// https://crbug.com/834594.
input_device_client_test_api_.SetKeyboardDevices(std::vector<ui::InputDevice>{
......@@ -227,6 +252,7 @@ TEST_F(KeyboardHandlerTest, ExternalKeyboard) {
EXPECT_TRUE(HasCapsLock());
EXPECT_TRUE(HasExternalMetaKey());
EXPECT_FALSE(HasAppleCommandKey());
EXPECT_FALSE(HasAssistantKey());
// Disconnect the external keyboard and check that the key goes away.
input_device_client_test_api_.SetKeyboardDevices({});
......@@ -234,6 +260,7 @@ TEST_F(KeyboardHandlerTest, ExternalKeyboard) {
EXPECT_FALSE(HasCapsLock());
EXPECT_FALSE(HasExternalMetaKey());
EXPECT_FALSE(HasAppleCommandKey());
EXPECT_FALSE(HasAssistantKey());
}
} // namespace settings
......
......@@ -604,6 +604,7 @@ cr.define('device_page_tests', function() {
'showExternalMetaKey': false,
'showAppleCommandKey': false,
'hasInternalKeyboard': false,
'hasAssistantKey': false,
};
cr.webUIListenerCallback('show-keys-changed', keyboardParams);
Polymer.dom.flush();
......@@ -611,6 +612,7 @@ cr.define('device_page_tests', function() {
expectFalse(!!keyboardPage.$$('#capsLockKey'));
expectFalse(!!keyboardPage.$$('#externalMetaKey'));
expectFalse(!!keyboardPage.$$('#externalCommandKey'));
expectFalse(!!keyboardPage.$$('#assistantKey'));
// Pretend a Caps Lock key is now available.
keyboardParams['showCapsLock'] = true;
......@@ -620,6 +622,7 @@ cr.define('device_page_tests', function() {
expectTrue(!!keyboardPage.$$('#capsLockKey'));
expectFalse(!!keyboardPage.$$('#externalMetaKey'));
expectFalse(!!keyboardPage.$$('#externalCommandKey'));
expectFalse(!!keyboardPage.$$('#assistantKey'));
// Add a non-Apple external keyboard.
keyboardParams['showExternalMetaKey'] = true;
......@@ -629,6 +632,7 @@ cr.define('device_page_tests', function() {
expectTrue(!!keyboardPage.$$('#capsLockKey'));
expectTrue(!!keyboardPage.$$('#externalMetaKey'));
expectFalse(!!keyboardPage.$$('#externalCommandKey'));
expectFalse(!!keyboardPage.$$('#assistantKey'));
// Add an Apple keyboard.
keyboardParams['showAppleCommandKey'] = true;
......@@ -638,6 +642,7 @@ cr.define('device_page_tests', function() {
expectTrue(!!keyboardPage.$$('#capsLockKey'));
expectTrue(!!keyboardPage.$$('#externalMetaKey'));
expectTrue(!!keyboardPage.$$('#externalCommandKey'));
expectFalse(!!keyboardPage.$$('#assistantKey'));
// Add an internal keyboard.
keyboardParams['hasInternalKeyboard'] = true;
......@@ -647,6 +652,17 @@ cr.define('device_page_tests', function() {
expectTrue(!!keyboardPage.$$('#capsLockKey'));
expectTrue(!!keyboardPage.$$('#externalMetaKey'));
expectTrue(!!keyboardPage.$$('#externalCommandKey'));
expectFalse(!!keyboardPage.$$('#assistantKey'));
// Pretend an Assistant key is now available.
keyboardParams['hasAssistantKey'] = true;
cr.webUIListenerCallback('show-keys-changed', keyboardParams);
Polymer.dom.flush();
expectTrue(!!keyboardPage.$$('#internalSearchKey'));
expectTrue(!!keyboardPage.$$('#capsLockKey'));
expectTrue(!!keyboardPage.$$('#externalMetaKey'));
expectTrue(!!keyboardPage.$$('#externalCommandKey'));
expectTrue(!!keyboardPage.$$('#assistantKey'));
collapse = keyboardPage.$$('iron-collapse');
assertTrue(!!collapse);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment