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

Side by Side Diff: ash/system/ime_menu/ime_menu_tray_unittest.cc

Issue 2953033002: Hide handwriting and voice buttons when keyboard is in restricted state (Closed)
Patch Set: Add FEATURE_ALL Created 3 years, 5 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 "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
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
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->GetImeMenuFeatureEnabled(
327 InputMethodManager::FEATURE_EMOJI));
328 EXPECT_TRUE(input_method_manager->GetImeMenuFeatureEnabled(
329 InputMethodManager::FEATURE_HANDWRITING));
330 EXPECT_TRUE(input_method_manager->GetImeMenuFeatureEnabled(
331 InputMethodManager::FEATURE_VOICE));
332 EXPECT_TRUE(GetTray()->ShouldShowBottomButtons());
333 EXPECT_TRUE(IsEmojiEnabled());
334 EXPECT_TRUE(IsHandwritingEnabled());
335 EXPECT_TRUE(IsVoiceEnabled());
315 336
316 FocusInInputContext(ui::TEXT_INPUT_TYPE_PASSWORD); 337 FocusInInputContext(ui::TEXT_INPUT_TYPE_PASSWORD);
317 EXPECT_FALSE(GetTray()->ShouldShowEmojiHandwritingVoiceButtons()); 338 EXPECT_FALSE(GetTray()->ShouldShowBottomButtons());
339 EXPECT_FALSE(IsEmojiEnabled());
340 EXPECT_FALSE(IsHandwritingEnabled());
341 EXPECT_FALSE(IsVoiceEnabled());
342 }
343
344 TEST_F(ImeMenuTrayTest, ShouldShowBottomButtonsSeperate) {
345 FocusInInputContext(ui::TEXT_INPUT_TYPE_TEXT);
346 InputMethodManager* input_method_manager = InputMethodManager::Get();
347 InputMethodManager::Initialize(new MockInputMethodManager);
348 input_method_manager = InputMethodManager::Get();
349 EXPECT_TRUE(input_method_manager &&
350 input_method_manager->IsEmojiHandwritingVoiceOnImeMenuEnabled());
351
352 // Sets emoji disabled.
353 input_method_manager->SetImeMenuFeatureEnabled(
354 InputMethodManager::FEATURE_EMOJI, false);
355 EXPECT_FALSE(input_method_manager->GetImeMenuFeatureEnabled(
356 InputMethodManager::FEATURE_EMOJI));
357 EXPECT_TRUE(GetTray()->ShouldShowBottomButtons());
358 EXPECT_FALSE(IsEmojiEnabled());
359 EXPECT_TRUE(IsHandwritingEnabled());
360 EXPECT_TRUE(IsVoiceEnabled());
361
362 // Sets emoji enabled, but voice and handwriting disabled.
363 input_method_manager->SetImeMenuFeatureEnabled(
364 InputMethodManager::FEATURE_EMOJI, true);
365 input_method_manager->SetImeMenuFeatureEnabled(
366 InputMethodManager::FEATURE_VOICE, false);
367 input_method_manager->SetImeMenuFeatureEnabled(
368 InputMethodManager::FEATURE_HANDWRITING, false);
369 EXPECT_TRUE(input_method_manager->GetImeMenuFeatureEnabled(
370 InputMethodManager::FEATURE_EMOJI));
371 EXPECT_FALSE(input_method_manager->GetImeMenuFeatureEnabled(
372 InputMethodManager::FEATURE_VOICE));
373 EXPECT_FALSE(input_method_manager->GetImeMenuFeatureEnabled(
374 InputMethodManager::FEATURE_HANDWRITING));
375 EXPECT_TRUE(GetTray()->ShouldShowBottomButtons());
376 EXPECT_TRUE(IsEmojiEnabled());
377 EXPECT_FALSE(IsHandwritingEnabled());
378 EXPECT_FALSE(IsVoiceEnabled());
318 } 379 }
319 380
320 } // namespace ash 381 } // namespace ash
OLDNEW
« no previous file with comments | « ash/system/ime_menu/ime_menu_tray.cc ('k') | chrome/browser/chromeos/input_method/input_method_manager_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698