Chromium Code Reviews| 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 "ash/system/ime_menu/ime_menu_tray.h" | 5 #include "ash/system/ime_menu/ime_menu_tray.h" |
| 6 | 6 |
| 7 #include "ash/accelerators/accelerator_controller.h" | 7 #include "ash/accelerators/accelerator_controller.h" |
| 8 #include "ash/accessibility_delegate.h" | 8 #include "ash/accessibility_delegate.h" |
| 9 #include "ash/ime/ime_controller.h" | 9 #include "ash/ime/ime_controller.h" |
| 10 #include "ash/public/interfaces/ime_info.mojom.h" | 10 #include "ash/public/interfaces/ime_info.mojom.h" |
| 11 #include "ash/shell.h" | 11 #include "ash/shell.h" |
| 12 #include "ash/system/ime_menu/ime_list_view.h" | 12 #include "ash/system/ime_menu/ime_list_view.h" |
| 13 #include "ash/system/status_area_widget.h" | 13 #include "ash/system/status_area_widget.h" |
| 14 #include "ash/test/ash_test_base.h" | 14 #include "ash/test/ash_test_base.h" |
| 15 #include "ash/test/status_area_widget_test_helper.h" | 15 #include "ash/test/status_area_widget_test_helper.h" |
| 16 #include "base/run_loop.h" | 16 #include "base/run_loop.h" |
| 17 #include "base/strings/utf_string_conversions.h" | 17 #include "base/strings/utf_string_conversions.h" |
| 18 #include "ui/accessibility/ax_node_data.h" | 18 #include "ui/accessibility/ax_node_data.h" |
| 19 #include "ui/base/ime/chromeos/input_method_manager.h" | 19 #include "ui/base/ime/chromeos/input_method_manager.h" |
| 20 #include "ui/base/ime/chromeos/mock_input_method_manager.h" | 20 #include "ui/base/ime/chromeos/mock_input_method_manager.h" |
| 21 #include "ui/base/ime/ime_bridge.h" | 21 #include "ui/base/ime/ime_bridge.h" |
| 22 #include "ui/base/ime/text_input_flags.h" | 22 #include "ui/base/ime/text_input_flags.h" |
| 23 #include "ui/events/event.h" | 23 #include "ui/events/event.h" |
| 24 #include "ui/views/controls/label.h" | 24 #include "ui/views/controls/label.h" |
| 25 | 25 |
| 26 using base::UTF8ToUTF16; | 26 using base::UTF8ToUTF16; |
| 27 using chromeos::input_method::InputMethodManager; | |
| 28 using chromeos::input_method::MockInputMethodManager; | |
| 27 | 29 |
| 28 namespace ash { | 30 namespace ash { |
| 29 namespace { | 31 namespace { |
| 30 | 32 |
| 31 ImeMenuTray* GetTray() { | 33 ImeMenuTray* GetTray() { |
| 32 return StatusAreaWidgetTestHelper::GetStatusAreaWidget()->ime_menu_tray(); | 34 return StatusAreaWidgetTestHelper::GetStatusAreaWidget()->ime_menu_tray(); |
| 33 } | 35 } |
| 34 | 36 |
| 35 void SetCurrentIme(const std::string& current_ime_id, | 37 void SetCurrentIme(const std::string& current_ime_id, |
| 36 const std::vector<mojom::ImeInfo>& available_imes) { | 38 const std::vector<mojom::ImeInfo>& available_imes) { |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 55 | 57 |
| 56 // Returns the label text of the tray. | 58 // Returns the label text of the tray. |
| 57 const base::string16& GetTrayText() { return GetTray()->label_->text(); } | 59 const base::string16& GetTrayText() { return GetTray()->label_->text(); } |
| 58 | 60 |
| 59 // Returns true if the background color of the tray is active. | 61 // Returns true if the background color of the tray is active. |
| 60 bool IsTrayBackgroundActive() { return GetTray()->is_active(); } | 62 bool IsTrayBackgroundActive() { return GetTray()->is_active(); } |
| 61 | 63 |
| 62 // Returns true if the IME menu bubble has been shown. | 64 // Returns true if the IME menu bubble has been shown. |
| 63 bool IsBubbleShown() { return GetTray()->IsImeMenuBubbleShown(); } | 65 bool IsBubbleShown() { return GetTray()->IsImeMenuBubbleShown(); } |
| 64 | 66 |
| 67 // Returns true if emoji palatte is enabled for the current keyboard. | |
| 68 bool IsEmojiEnabled() { return GetTray()->emoji_enabled_; } | |
| 69 | |
| 70 // Returns true if handwirting input is enabled for the current keyboard. | |
| 71 bool IsHandwritingEnabled() { return GetTray()->handwriting_enabled_; } | |
| 72 | |
| 73 // Returns true if voice input is enabled for the current keyboard. | |
| 74 bool IsVoiceEnabled() { return GetTray()->voice_enabled_; } | |
| 75 | |
| 65 // Verifies the IME menu list has been updated with the right IME list. | 76 // Verifies the IME menu list has been updated with the right IME list. |
| 66 void ExpectValidImeList(const std::vector<mojom::ImeInfo>& expected_imes, | 77 void ExpectValidImeList(const std::vector<mojom::ImeInfo>& expected_imes, |
| 67 const mojom::ImeInfo& expected_current_ime) { | 78 const mojom::ImeInfo& expected_current_ime) { |
| 68 const std::map<views::View*, std::string>& ime_map = | 79 const std::map<views::View*, std::string>& ime_map = |
| 69 ImeListViewTestApi(GetTray()->ime_list_view_).ime_map(); | 80 ImeListViewTestApi(GetTray()->ime_list_view_).ime_map(); |
| 70 EXPECT_EQ(expected_imes.size(), ime_map.size()); | 81 EXPECT_EQ(expected_imes.size(), ime_map.size()); |
| 71 | 82 |
| 72 std::vector<std::string> expected_ime_ids; | 83 std::vector<std::string> expected_ime_ids; |
| 73 for (const auto& ime : expected_imes) { | 84 for (const auto& ime : expected_imes) { |
| 74 expected_ime_ids.push_back(ime.id); | 85 expected_ime_ids.push_back(ime.id); |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 292 // The virtual keyboard should be enabled. | 303 // The virtual keyboard should be enabled. |
| 293 EXPECT_TRUE(accessibility_delegate->IsVirtualKeyboardEnabled()); | 304 EXPECT_TRUE(accessibility_delegate->IsVirtualKeyboardEnabled()); |
| 294 | 305 |
| 295 // Hides the keyboard. | 306 // Hides the keyboard. |
| 296 GetTray()->OnKeyboardHidden(); | 307 GetTray()->OnKeyboardHidden(); |
| 297 // The keyboard should still be disabled, which is a posted task. | 308 // The keyboard should still be disabled, which is a posted task. |
| 298 base::RunLoop().RunUntilIdle(); | 309 base::RunLoop().RunUntilIdle(); |
| 299 EXPECT_FALSE(accessibility_delegate->IsVirtualKeyboardEnabled()); | 310 EXPECT_FALSE(accessibility_delegate->IsVirtualKeyboardEnabled()); |
| 300 } | 311 } |
| 301 | 312 |
| 302 TEST_F(ImeMenuTrayTest, ShowEmojiHandwritingVoiceButtons) { | 313 TEST_F(ImeMenuTrayTest, ShouldShowBottomButtons) { |
| 303 FocusInInputContext(ui::TEXT_INPUT_TYPE_TEXT); | 314 FocusInInputContext(ui::TEXT_INPUT_TYPE_TEXT); |
| 304 EXPECT_FALSE(GetTray()->ShouldShowEmojiHandwritingVoiceButtons()); | 315 EXPECT_FALSE(GetTray()->ShouldShowBottomButtons()); |
| 316 EXPECT_FALSE(IsEmojiEnabled()); | |
| 317 EXPECT_FALSE(IsHandwritingEnabled()); | |
| 318 EXPECT_FALSE(IsVoiceEnabled()); | |
| 305 | 319 |
| 306 chromeos::input_method::InputMethodManager* input_method_manager = | 320 InputMethodManager* input_method_manager = InputMethodManager::Get(); |
| 307 chromeos::input_method::InputMethodManager::Get(); | |
| 308 EXPECT_FALSE(input_method_manager); | 321 EXPECT_FALSE(input_method_manager); |
| 309 chromeos::input_method::InputMethodManager::Initialize( | 322 InputMethodManager::Initialize(new MockInputMethodManager); |
| 310 new chromeos::input_method::MockInputMethodManager); | 323 input_method_manager = InputMethodManager::Get(); |
| 311 input_method_manager = chromeos::input_method::InputMethodManager::Get(); | |
| 312 EXPECT_TRUE(input_method_manager && | 324 EXPECT_TRUE(input_method_manager && |
| 313 input_method_manager->IsEmojiHandwritingVoiceOnImeMenuEnabled()); | 325 input_method_manager->IsEmojiHandwritingVoiceOnImeMenuEnabled()); |
| 314 EXPECT_TRUE(GetTray()->ShouldShowEmojiHandwritingVoiceButtons()); | 326 EXPECT_TRUE(input_method_manager->GetFeaturesRestricted( |
| 327 InputMethodManager::FeaturesRestricted::NONE)); | |
|
James Cook
2017/06/27 16:31:11
nit: No "::FeaturesRestricted::" for plain enums.
Azure Wei
2017/06/29 16:37:02
Done.
| |
| 328 EXPECT_TRUE(GetTray()->ShouldShowBottomButtons()); | |
| 329 EXPECT_TRUE(IsEmojiEnabled()); | |
| 330 EXPECT_TRUE(IsHandwritingEnabled()); | |
| 331 EXPECT_TRUE(IsVoiceEnabled()); | |
| 315 | 332 |
| 316 FocusInInputContext(ui::TEXT_INPUT_TYPE_PASSWORD); | 333 FocusInInputContext(ui::TEXT_INPUT_TYPE_PASSWORD); |
| 317 EXPECT_FALSE(GetTray()->ShouldShowEmojiHandwritingVoiceButtons()); | 334 EXPECT_FALSE(GetTray()->ShouldShowBottomButtons()); |
| 335 EXPECT_FALSE(IsEmojiEnabled()); | |
| 336 EXPECT_FALSE(IsHandwritingEnabled()); | |
| 337 EXPECT_FALSE(IsVoiceEnabled()); | |
| 338 } | |
| 339 | |
| 340 TEST_F(ImeMenuTrayTest, ShouldShowBottomButtonsSeperate) { | |
| 341 FocusInInputContext(ui::TEXT_INPUT_TYPE_TEXT); | |
| 342 InputMethodManager* input_method_manager = InputMethodManager::Get(); | |
| 343 InputMethodManager::Initialize(new MockInputMethodManager); | |
| 344 input_method_manager = InputMethodManager::Get(); | |
| 345 EXPECT_TRUE(input_method_manager && | |
| 346 input_method_manager->IsEmojiHandwritingVoiceOnImeMenuEnabled()); | |
| 347 | |
| 348 // Sets emoji restricted. | |
| 349 input_method_manager->SetFeaturesRestricted( | |
| 350 InputMethodManager::FeaturesRestricted::EMOJI, true); | |
| 351 EXPECT_TRUE(input_method_manager->GetFeaturesRestricted( | |
| 352 InputMethodManager::FeaturesRestricted::EMOJI)); | |
| 353 EXPECT_TRUE(GetTray()->ShouldShowBottomButtons()); | |
| 354 EXPECT_FALSE(IsEmojiEnabled()); | |
| 355 EXPECT_TRUE(IsHandwritingEnabled()); | |
| 356 EXPECT_TRUE(IsVoiceEnabled()); | |
| 357 | |
| 358 // Sets emoji not restriected, but voice and handwriting restricted. | |
| 359 input_method_manager->SetFeaturesRestricted( | |
| 360 InputMethodManager::FeaturesRestricted::EMOJI, false); | |
| 361 input_method_manager->SetFeaturesRestricted( | |
| 362 InputMethodManager::FeaturesRestricted::VOICE, true); | |
| 363 input_method_manager->SetFeaturesRestricted( | |
| 364 InputMethodManager::FeaturesRestricted::HANDWRITING, true); | |
| 365 EXPECT_FALSE(input_method_manager->GetFeaturesRestricted( | |
| 366 InputMethodManager::FeaturesRestricted::EMOJI)); | |
| 367 EXPECT_TRUE(input_method_manager->GetFeaturesRestricted( | |
| 368 InputMethodManager::FeaturesRestricted::VOICE)); | |
| 369 EXPECT_TRUE(input_method_manager->GetFeaturesRestricted( | |
| 370 InputMethodManager::FeaturesRestricted::HANDWRITING)); | |
| 371 EXPECT_TRUE(GetTray()->ShouldShowBottomButtons()); | |
| 372 EXPECT_TRUE(IsEmojiEnabled()); | |
| 373 EXPECT_FALSE(IsHandwritingEnabled()); | |
| 374 EXPECT_FALSE(IsVoiceEnabled()); | |
| 318 } | 375 } |
| 319 | 376 |
| 320 } // namespace ash | 377 } // namespace ash |
| OLD | NEW |