1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647
|
// Copyright 2016 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ash/system/ime_menu/ime_menu_tray.h"
#include <string_view>
#include "ash/accelerators/accelerator_controller_impl.h"
#include "ash/accessibility/a11y_feature_type.h"
#include "ash/accessibility/accessibility_controller.h"
#include "ash/ime/ime_controller_impl.h"
#include "ash/ime/test_ime_controller_client.h"
#include "ash/public/cpp/ash_view_ids.h"
#include "ash/public/cpp/ime_info.h"
#include "ash/session/session_controller_impl.h"
#include "ash/shell.h"
#include "ash/strings/grit/ash_strings.h"
#include "ash/system/ime_menu/ime_list_view.h"
#include "ash/system/status_area_widget.h"
#include "ash/system/status_area_widget_test_helper.h"
#include "ash/test/ash_test_base.h"
#include "base/containers/contains.h"
#include "base/run_loop.h"
#include "base/strings/utf_string_conversions.h"
#include "base/test/bind.h"
#include "base/test/scoped_feature_list.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/accessibility/ax_enums.mojom.h"
#include "ui/accessibility/ax_node_data.h"
#include "ui/base/emoji/emoji_panel_helper.h"
#include "ui/base/ime/ash/ime_bridge.h"
#include "ui/base/ime/text_input_flags.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/display/test/display_manager_test_api.h"
#include "ui/events/devices/device_data_manager_test_api.h"
#include "ui/events/devices/input_device.h"
#include "ui/events/devices/keyboard_device.h"
#include "ui/events/devices/touchscreen_device.h"
#include "ui/events/event.h"
#include "ui/views/accessibility/view_accessibility.h"
#include "ui/views/controls/label.h"
#include "ui/views/view_class_properties.h"
namespace ash {
namespace {
const int kEmojiButtonId = 1;
const int kSettingsButtonId = 2;
const int kVoiceButtonId = 3;
ImeMenuTray* GetTray() {
return StatusAreaWidgetTestHelper::GetStatusAreaWidget()->ime_menu_tray();
}
void SetCurrentIme(const std::string& current_ime_id,
const std::vector<ImeInfo>& available_imes) {
std::vector<ImeInfo> available_ime_ptrs;
for (const auto& ime : available_imes) {
available_ime_ptrs.push_back(ime);
}
Shell::Get()->ime_controller()->RefreshIme(current_ime_id,
std::move(available_ime_ptrs),
std::vector<ImeMenuItem>());
}
} // namespace
class ImeMenuTrayTest : public AshTestBase {
public:
ImeMenuTrayTest() = default;
ImeMenuTrayTest(const ImeMenuTrayTest&) = delete;
ImeMenuTrayTest& operator=(const ImeMenuTrayTest&) = delete;
~ImeMenuTrayTest() override = default;
protected:
// Returns true if the IME menu tray is visible.
bool IsVisible() { return GetTray()->GetVisible(); }
// Returns the label text of the tray.
std::u16string_view GetTrayText() { return GetTray()->label_->GetText(); }
// Returns true if the background color of the tray is active.
bool IsTrayBackgroundActive() { return GetTray()->is_active(); }
// Returns true if the IME menu bubble has been shown.
bool IsBubbleShown() { return GetTray()->GetBubbleView() != nullptr; }
// Returns true if emoji palatte is enabled for the current keyboard.
bool IsEmojiEnabled() { return GetTray()->is_emoji_enabled_; }
// Returns true if handwirting input is enabled for the current keyboard.
bool IsHandwritingEnabled() { return GetTray()->is_handwriting_enabled_; }
// Returns true if voice input is enabled for the current keyboard.
bool IsVoiceEnabled() { return GetTray()->is_voice_enabled_; }
views::Button* GetEmojiButton() const {
return static_cast<views::Button*>(
GetTray()->bubble_->bubble_view()->GetViewByID(kEmojiButtonId));
}
views::View* GetSettingsButton() const {
return static_cast<views::View*>(
GetTray()->bubble_->bubble_view()->GetViewByID(kSettingsButtonId));
}
views::View* GetVoiceButton() const {
return static_cast<views::View*>(
GetTray()->bubble_->bubble_view()->GetViewByID(kVoiceButtonId));
}
void SetUpKioskSession() {
SessionInfo info;
info.is_running_in_app_mode = true;
Shell::Get()->session_controller()->SetSessionInfo(info);
}
// Verifies the IME menu list has been updated with the right IME list.
void ExpectValidImeList(const std::vector<ImeInfo>& expected_imes,
const ImeInfo& expected_current_ime) {
const std::map<views::View*, std::string>& ime_map =
ImeListViewTestApi(GetTray()->ime_list_view_).ime_map();
EXPECT_EQ(expected_imes.size(), ime_map.size());
std::vector<std::string> expected_ime_ids;
for (const auto& ime : expected_imes) {
expected_ime_ids.push_back(ime.id);
}
for (const auto& ime : ime_map) {
// Tests that all the IMEs on the view is in the list of selected IMEs.
EXPECT_TRUE(base::Contains(expected_ime_ids, ime.second));
// Tests that the checked IME is the current IME.
ui::AXNodeData node_data;
ime.first->GetViewAccessibility().GetAccessibleNodeData(&node_data);
const auto checked_state = static_cast<ax::mojom::CheckedState>(
node_data.GetIntAttribute(ax::mojom::IntAttribute::kCheckedState));
if (checked_state == ax::mojom::CheckedState::kTrue) {
EXPECT_EQ(expected_current_ime.id, ime.second);
}
}
}
// Focuses in the given type of input context.
void FocusInInputContext(ui::TextInputType input_type) {
IMEBridge::Get()->SetCurrentInputContext(
TextInputMethod::InputContext(input_type));
}
bool MenuHasOnScreenKeyboardToggle() const {
if (!GetTray()->ime_list_view_) {
return false;
}
return ImeListViewTestApi(GetTray()->ime_list_view_).GetToggleView();
}
};
// Tests that visibility of IME menu tray should be consistent with the
// activation of the IME menu.
TEST_F(ImeMenuTrayTest, ImeMenuTrayVisibility) {
ASSERT_FALSE(IsVisible());
Shell::Get()->ime_controller()->ShowImeMenuOnShelf(true);
EXPECT_TRUE(IsVisible());
Shell::Get()->ime_controller()->ShowImeMenuOnShelf(false);
EXPECT_FALSE(IsVisible());
}
// Tests that IME menu tray shows the right info of the current IME.
TEST_F(ImeMenuTrayTest, TrayLabelTest) {
Shell::Get()->ime_controller()->ShowImeMenuOnShelf(true);
ASSERT_TRUE(IsVisible());
ImeInfo info1;
info1.id = "ime1";
info1.name = u"English";
info1.short_name = u"US";
info1.third_party = false;
ImeInfo info2;
info2.id = "ime2";
info2.name = u"English UK";
info2.short_name = u"UK";
info2.third_party = true;
// Changes the input method to "ime1".
SetCurrentIme("ime1", {info1, info2});
EXPECT_EQ(u"US", GetTrayText());
// Changes the input method to a third-party IME extension.
SetCurrentIme("ime2", {info1, info2});
EXPECT_EQ(u"UK*", GetTrayText());
}
TEST_F(ImeMenuTrayTest, TrayLabelExludesDictation) {
Shell::Get()->ime_controller()->ShowImeMenuOnShelf(true);
ASSERT_TRUE(IsVisible());
ImeInfo info1;
info1.id = "ime1";
info1.name = u"English";
info1.short_name = u"US";
info1.third_party = false;
ImeInfo info2;
info2.id = "ime2";
info2.name = u"English UK";
info2.short_name = u"UK";
info2.third_party = true;
ImeInfo dictation;
dictation.id = "_ext_ime_egfdjlfmgnehecnclamagfafdccgfndpdictation";
dictation.name = u"Dictation";
// Changes the input method to "ime1".
SetCurrentIme("ime1", {info1, dictation, info2});
EXPECT_EQ(u"US", GetTrayText());
// Changes the input method to a third-party IME extension.
SetCurrentIme("ime2", {info1, dictation, info2});
EXPECT_EQ(u"UK*", GetTrayText());
// Sets to "dictation", which shouldn't be shown.
SetCurrentIme(dictation.id, {info1, dictation, info2});
EXPECT_EQ(u"", GetTrayText());
}
// Tests that the IME menu tray changes background color when tapped, and
// tests that the background color becomes 'inactive' when disabling the IME
// menu feature. Also makes sure that the shelf won't autohide as long as the
// IME menu is open.
TEST_F(ImeMenuTrayTest, PerformActionGestureTap) {
Shell::Get()->ime_controller()->ShowImeMenuOnShelf(true);
ASSERT_TRUE(IsVisible());
ASSERT_FALSE(IsTrayBackgroundActive());
StatusAreaWidget* status = StatusAreaWidgetTestHelper::GetStatusAreaWidget();
EXPECT_FALSE(status->ShouldShowShelf());
GestureTapOn(GetTray());
EXPECT_TRUE(IsTrayBackgroundActive());
EXPECT_TRUE(IsBubbleShown());
// Auto-hidden shelf would be forced to be visible as long as the bubble is
// open.
EXPECT_TRUE(status->ShouldShowShelf());
GestureTapOn(GetTray());
EXPECT_FALSE(IsTrayBackgroundActive());
EXPECT_FALSE(IsBubbleShown());
// If disabling the IME menu feature when the menu tray is activated, the tray
// element will be deactivated.
GestureTapOn(GetTray());
EXPECT_TRUE(IsTrayBackgroundActive());
Shell::Get()->ime_controller()->ShowImeMenuOnShelf(false);
EXPECT_FALSE(IsVisible());
EXPECT_FALSE(IsBubbleShown());
EXPECT_FALSE(IsTrayBackgroundActive());
EXPECT_FALSE(status->ShouldShowShelf());
}
// Tests that the IME menu reacts to left click.
TEST_F(ImeMenuTrayTest, PerformActionLeftClick) {
Shell::Get()->ime_controller()->ShowImeMenuOnShelf(true);
ASSERT_TRUE(IsVisible());
ASSERT_FALSE(IsTrayBackgroundActive());
LeftClickOn(GetTray());
EXPECT_TRUE(IsTrayBackgroundActive());
EXPECT_TRUE(IsBubbleShown());
LeftClickOn(GetTray());
EXPECT_FALSE(IsTrayBackgroundActive());
EXPECT_FALSE(IsBubbleShown());
}
// Tests that IME menu list updates when changing the current IME. This should
// only happen by using shortcuts (Ctrl + Space / Ctrl + Shift + Space) to
// switch IMEs.
TEST_F(ImeMenuTrayTest, RefreshImeWithListViewCreated) {
GetTray()->SetVisiblePreferred(true);
GestureTapOn(GetTray());
EXPECT_TRUE(IsTrayBackgroundActive());
EXPECT_TRUE(IsBubbleShown());
ImeInfo info1, info2, info3;
info1.id = "ime1";
info1.name = u"English";
info1.short_name = u"US";
info1.third_party = false;
info2.id = "ime2";
info2.name = u"English UK";
info2.short_name = u"UK";
info2.third_party = true;
info3.id = "ime3";
info3.name = u"Pinyin";
info3.short_name = u"拼";
info3.third_party = false;
std::vector<ImeInfo> ime_info_list{info1, info2, info3};
// Switch to ime1.
SetCurrentIme("ime1", ime_info_list);
EXPECT_EQ(u"US", GetTrayText());
ExpectValidImeList(ime_info_list, info1);
// Switch to ime3.
SetCurrentIme("ime3", ime_info_list);
EXPECT_EQ(u"拼", GetTrayText());
ExpectValidImeList(ime_info_list, info3);
// Closes the menu before quitting.
GestureTapOn(GetTray());
EXPECT_FALSE(IsTrayBackgroundActive());
EXPECT_FALSE(IsBubbleShown());
}
// Tests that quits Chrome with IME menu openned will not crash.
TEST_F(ImeMenuTrayTest, QuitChromeWithMenuOpen) {
Shell::Get()->ime_controller()->ShowImeMenuOnShelf(true);
ASSERT_TRUE(IsVisible());
ASSERT_FALSE(IsTrayBackgroundActive());
GestureTapOn(GetTray());
EXPECT_TRUE(IsTrayBackgroundActive());
EXPECT_TRUE(IsBubbleShown());
}
// Tests using 'Alt+Shift+K' to open the menu.
TEST_F(ImeMenuTrayTest, TestAccelerator) {
Shell::Get()->ime_controller()->ShowImeMenuOnShelf(true);
ASSERT_TRUE(IsVisible());
ASSERT_FALSE(IsTrayBackgroundActive());
Shell::Get()->accelerator_controller()->PerformActionIfEnabled(
AcceleratorAction::kToggleImeMenuBubble, {});
EXPECT_TRUE(IsTrayBackgroundActive());
EXPECT_TRUE(IsBubbleShown());
GestureTapOn(GetTray());
EXPECT_FALSE(IsTrayBackgroundActive());
EXPECT_FALSE(IsBubbleShown());
}
TEST_F(ImeMenuTrayTest, ShowingEmojiKeysetHidesBubble) {
// Setup the callback required by ui::ShowEmojiPanel() to a dummy one.
// The ui::ShowEmojiPanel() call in ShowKeyboardWithKeyset will fail
// without this callback.
ui::SetShowEmojiKeyboardCallback(base::DoNothing());
Shell::Get()->ime_controller()->ShowImeMenuOnShelf(true);
ASSERT_TRUE(IsVisible());
ASSERT_FALSE(IsTrayBackgroundActive());
GestureTapOn(GetTray());
EXPECT_TRUE(IsTrayBackgroundActive());
EXPECT_TRUE(IsBubbleShown());
TestImeControllerClient client;
Shell::Get()->ime_controller()->SetClient(&client);
GetTray()->ShowKeyboardWithKeyset(input_method::ImeKeyset::kEmoji);
// The menu should be hidden.
EXPECT_FALSE(IsBubbleShown());
}
// Tests that the IME menu accelerator toggles the bubble on and off.
TEST_F(ImeMenuTrayTest, ImeBubbleAccelerator) {
Shell::Get()->ime_controller()->ShowImeMenuOnShelf(true);
ASSERT_TRUE(IsVisible());
EXPECT_FALSE(IsBubbleShown());
PressAndReleaseKey(ui::VKEY_K, ui::EF_SHIFT_DOWN | ui::EF_COMMAND_DOWN);
base::RunLoop().RunUntilIdle();
EXPECT_TRUE(IsBubbleShown());
PressAndReleaseKey(ui::VKEY_K, ui::EF_SHIFT_DOWN | ui::EF_COMMAND_DOWN);
base::RunLoop().RunUntilIdle();
EXPECT_FALSE(IsBubbleShown());
}
// Tests that tapping the emoji button does not crash. http://crbug.com/739630
TEST_F(ImeMenuTrayTest, TapEmojiButton) {
int call_count = 0;
ui::SetShowEmojiKeyboardCallback(base::BindLambdaForTesting(
[&](ui::EmojiPickerCategory unused, ui::EmojiPickerFocusBehavior,
const std::string&) { ++call_count; }));
Shell::Get()->ime_controller()->ShowImeMenuOnShelf(true);
Shell::Get()->ime_controller()->SetExtraInputOptionsEnabledState(
true /* ui enabled */, true /* emoji input enabled */,
true /* hanwriting input enabled */, true /* voice input enabled */);
// Open the menu.
GestureTapOn(GetTray());
// Tap the emoji button.
views::Button* emoji_button = GetEmojiButton();
ASSERT_TRUE(emoji_button);
GestureTapOn(emoji_button);
// The menu should be hidden.
EXPECT_FALSE(IsBubbleShown());
// The callback should have been called.
EXPECT_EQ(call_count, 1);
}
TEST_F(ImeMenuTrayTest, ShouldShowBottomButtons) {
Shell::Get()->ime_controller()->SetExtraInputOptionsEnabledState(
true /* ui enabled */, true /* emoji input enabled */,
true /* hanwriting input enabled */, true /* voice input enabled */);
FocusInInputContext(ui::TEXT_INPUT_TYPE_TEXT);
GetTray()->ShowBubble();
base::RunLoop().RunUntilIdle();
EXPECT_TRUE(GetTray()->AnyBottomButtonShownForTest());
EXPECT_TRUE(IsEmojiEnabled());
EXPECT_TRUE(IsHandwritingEnabled());
EXPECT_TRUE(IsVoiceEnabled());
FocusInInputContext(ui::TEXT_INPUT_TYPE_PASSWORD);
GetTray()->CloseBubble();
GetTray()->ShowBubble();
base::RunLoop().RunUntilIdle();
EXPECT_FALSE(GetTray()->AnyBottomButtonShownForTest());
EXPECT_FALSE(IsEmojiEnabled());
EXPECT_FALSE(IsHandwritingEnabled());
EXPECT_FALSE(IsVoiceEnabled());
}
TEST_F(ImeMenuTrayTest, ShouldShowBottomButtonsSeperate) {
FocusInInputContext(ui::TEXT_INPUT_TYPE_TEXT);
// Sets emoji disabled.
Shell::Get()->ime_controller()->SetExtraInputOptionsEnabledState(
true /* ui enabled */, false /* emoji input disabled */,
true /* hanwriting input enabled */, true /* voice input enabled */);
GetTray()->ShowBubble();
base::RunLoop().RunUntilIdle();
EXPECT_TRUE(GetTray()->AnyBottomButtonShownForTest());
EXPECT_FALSE(IsEmojiEnabled());
EXPECT_TRUE(IsHandwritingEnabled());
EXPECT_TRUE(IsVoiceEnabled());
// Sets emoji enabled, but voice and handwriting disabled.
Shell::Get()->ime_controller()->SetExtraInputOptionsEnabledState(
true /* ui enabled */, true /* emoji input enabled */,
false /* hanwriting input disabled */, false /* voice input disabled */);
GetTray()->CloseBubble();
GetTray()->ShowBubble();
base::RunLoop().RunUntilIdle();
EXPECT_TRUE(GetTray()->AnyBottomButtonShownForTest());
EXPECT_TRUE(IsEmojiEnabled());
EXPECT_FALSE(IsHandwritingEnabled());
EXPECT_FALSE(IsVoiceEnabled());
}
TEST_F(ImeMenuTrayTest, KioskImeTraySettingsButton) {
SetUpKioskSession();
Shell::Get()->ime_controller()->ShowImeMenuOnShelf(true);
ASSERT_TRUE(IsVisible());
// Open the menu.
GestureTapOn(GetTray());
views::View* settings_button = GetSettingsButton();
EXPECT_FALSE(settings_button);
}
TEST_F(ImeMenuTrayTest, UserSessionImeTraySettingsButton) {
Shell::Get()->ime_controller()->ShowImeMenuOnShelf(true);
ASSERT_TRUE(IsVisible());
// Open the menu.
GestureTapOn(GetTray());
views::View* settings_button = GetSettingsButton();
EXPECT_TRUE(settings_button);
}
TEST_F(ImeMenuTrayTest, ShowOnScreenKeyboardToggle) {
Shell::Get()->ime_controller()->ShowImeMenuOnShelf(true);
ASSERT_TRUE(IsVisible());
ASSERT_FALSE(IsTrayBackgroundActive());
GestureTapOn(GetTray());
EXPECT_TRUE(IsTrayBackgroundActive());
EXPECT_TRUE(IsBubbleShown());
EXPECT_FALSE(MenuHasOnScreenKeyboardToggle());
// The on-screen keyboard toggle should show if the device has a touch
// screen, and does not have an internal keyboard.
std::vector<ui::TouchscreenDevice> screens;
screens.push_back(
ui::TouchscreenDevice(1, ui::InputDeviceType::INPUT_DEVICE_INTERNAL,
"Touchscreen", gfx::Size(1024, 768), 0));
ui::DeviceDataManagerTestApi().SetTouchscreenDevices(screens);
std::vector<ui::KeyboardDevice> keyboard_devices;
keyboard_devices.push_back(ui::KeyboardDevice(
1, ui::InputDeviceType::INPUT_DEVICE_USB, "external keyboard"));
ui::DeviceDataManagerTestApi().SetKeyboardDevices(keyboard_devices);
// Bubble gets closed when the keyboard suppression state changes.
EXPECT_FALSE(IsBubbleShown());
GestureTapOn(GetTray());
EXPECT_TRUE(IsBubbleShown());
EXPECT_TRUE(MenuHasOnScreenKeyboardToggle());
// The toggle should not be removed on IME device refresh.
ImeInfo info;
info.id = "ime";
info.name = u"English UK";
info.short_name = u"UK";
info.third_party = true;
SetCurrentIme("ime", {info});
EXPECT_TRUE(MenuHasOnScreenKeyboardToggle());
// The toggle should be hidden with internal keyboard.
keyboard_devices.push_back(ui::KeyboardDevice(
1, ui::InputDeviceType::INPUT_DEVICE_USB, "external keyboard"));
keyboard_devices.push_back(ui::KeyboardDevice(
1, ui::InputDeviceType::INPUT_DEVICE_INTERNAL, "internal keyboard"));
ui::DeviceDataManagerTestApi().SetKeyboardDevices(keyboard_devices);
// Bubble gets closed when the keyboard suppression state changes.
EXPECT_FALSE(IsBubbleShown());
GestureTapOn(GetTray());
EXPECT_TRUE(IsBubbleShown());
EXPECT_FALSE(MenuHasOnScreenKeyboardToggle());
}
TEST_F(ImeMenuTrayTest, ShowVoiceButtonWhenDictationDisabled) {
// Enable all extra input options.
Shell::Get()->ime_controller()->SetExtraInputOptionsEnabledState(
/*is_extra_input_options_enabled=*/true,
/*is_emoji_enabled=*/true,
/*is_handwriting_enabled=*/true, /*is_voice_enabled=*/true);
// Disable accessibility dictation.
Shell::Get()
->accessibility_controller()
->GetFeature(A11yFeatureType::kDictation)
.SetEnabled(false);
// Show IME tray bubble.
GetTray()->ShowBubble();
// Voice button should be shown.
views::View* voice_button = GetVoiceButton();
EXPECT_TRUE(voice_button);
}
TEST_F(ImeMenuTrayTest, HideVoiceButtonWhenDictationEnabled) {
// Enable all extra input options.
Shell::Get()->ime_controller()->SetExtraInputOptionsEnabledState(
/*is_extra_input_options_enabled=*/true,
/*is_emoji_enabled=*/true,
/*is_handwriting_enabled=*/true, /*is_voice_enabled=*/true);
// Enable accessibility dictation.
Shell::Get()
->accessibility_controller()
->GetFeature(A11yFeatureType::kDictation)
.SetEnabled(true);
// Show IME tray bubble.
GetTray()->ShowBubble();
// Voice button should be hidden.
views::View* voice_button = GetVoiceButton();
EXPECT_FALSE(voice_button);
}
TEST_F(ImeMenuTrayTest, ImeMenuHasBottomInsetsOnLockScreen) {
Shell::Get()->ime_controller()->SetExtraInputOptionsEnabledState(
true /* ui enabled */, true /* emoji input enabled */,
true /* hanwriting input enabled */, true /* voice input enabled */);
// SHow IME tray bubble.
GetTray()->ShowBubble();
// Make sure there is no margin when the screen is unlocked.
gfx::Insets* container_margins =
GetTray()
->GetBubbleView()
->GetViewByID(VIEW_ID_IME_LIST_VIEW_SCROLLER)
->GetProperty(views::kMarginsKey);
EXPECT_EQ(container_margins->bottom(), 0);
BlockUserSession(BLOCKED_BY_LOCK_SCREEN);
// Make sure the margin is updated when the screen is locked.
GetTray()->ShowBubble();
container_margins = GetTray()
->GetBubbleView()
->GetViewByID(VIEW_ID_IME_LIST_VIEW_SCROLLER)
->GetProperty(views::kMarginsKey);
EXPECT_GT(container_margins->bottom(), 0);
}
TEST_F(ImeMenuTrayTest, AccessibleNames) {
Shell::Get()->ime_controller()->SetExtraInputOptionsEnabledState(
/*is_extra_input_options_enabled=*/true, /*is_emoji_enabled=*/true,
/*is_handwriting_enabled=*/true, /*is_voice_enabled=*/true);
{
ui::AXNodeData node_data;
GetTray()->GetViewAccessibility().GetAccessibleNodeData(&node_data);
EXPECT_EQ(node_data.GetString16Attribute(ax::mojom::StringAttribute::kName),
l10n_util::GetStringUTF16(IDS_ASH_IME_MENU_ACCESSIBLE_NAME));
}
// Show IME tray bubble.
GetTray()->ShowBubble();
TrayBubbleView* bubble_view = GetTray()->GetBubbleView();
{
ui::AXNodeData node_data;
bubble_view->GetViewAccessibility().GetAccessibleNodeData(&node_data);
EXPECT_EQ(node_data.GetString16Attribute(ax::mojom::StringAttribute::kName),
GetTray()->GetAccessibleNameForBubble());
}
}
} // namespace ash
|