OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/chromeos/virtual_keyboard/tray_keyboard_lock.h" | 5 #include "ash/system/ime/tray_ime_chromeos.h" |
6 | 6 |
7 #include "ash/accessibility_delegate.h" | 7 #include "ash/accessibility_delegate.h" |
8 #include "ash/shell.h" | 8 #include "ash/shell.h" |
9 #include "ash/system/status_area_widget.h" | 9 #include "ash/system/status_area_widget.h" |
10 #include "ash/system/tray/system_tray_notifier.h" | |
10 #include "ash/test/ash_test_base.h" | 11 #include "ash/test/ash_test_base.h" |
11 #include "ash/test/status_area_widget_test_helper.h" | 12 #include "ash/test/status_area_widget_test_helper.h" |
12 #include "ash/test/virtual_keyboard_test_helper.h" | 13 #include "ash/test/virtual_keyboard_test_helper.h" |
13 #include "base/command_line.h" | 14 #include "base/command_line.h" |
14 #include "ui/keyboard/keyboard_switches.h" | 15 #include "ui/keyboard/keyboard_switches.h" |
15 #include "ui/keyboard/keyboard_util.h" | 16 #include "ui/keyboard/keyboard_util.h" |
16 | 17 |
17 namespace ash { | 18 namespace ash { |
18 | 19 |
19 class TrayKeyboardLockTest : public test::AshTestBase { | 20 class TrayIMETest : public test::AshTestBase { |
20 public: | 21 public: |
21 TrayKeyboardLockTest() {} | 22 TrayIMETest() {} |
22 virtual ~TrayKeyboardLockTest() {} | 23 virtual ~TrayIMETest() {} |
23 | 24 |
24 TrayKeyboardLock* tray() { return tray_.get(); } | 25 TrayIME* tray() { return tray_.get(); } |
25 | 26 |
26 views::View* default_view() { return default_view_.get(); } | 27 views::View* default_view() { return default_view_.get(); } |
27 | 28 |
28 // Sets up a TrayKeyboardLock and its default view. | 29 views::View* detailed_view() { return detailed_view_.get(); } |
30 | |
31 // Sets up a TrayIME and its default view. | |
29 void SetUpForStatusAreaWidget(StatusAreaWidget* status_area_widget); | 32 void SetUpForStatusAreaWidget(StatusAreaWidget* status_area_widget); |
30 | 33 |
31 // Mocks enabling the a11y virtual keyboard since the actual a11y manager | 34 // Mocks enabling the a11y virtual keyboard since the actual a11y manager |
32 // is not created in ash tests. | 35 // is not created in ash tests. |
33 void SetAccessibilityKeyboardEnabled(bool enabled); | 36 void SetAccessibilityKeyboardEnabled(bool enabled); |
34 | 37 |
35 // Resets |tray_| and |default_view_| so that all components of | 38 // Resets |tray_| and |default_view_| so that all components of |
36 // TrayKeyboardLock have been cleared. Tests may then call | 39 // TrayIME have been cleared. Tests may then call |
37 // SetUpForStatusAreaWidget in order to initialize the components. | 40 // SetUpForStatusAreaWidget in order to initialize the components. |
38 void TearDownViews(); | 41 void TearDownViews(); |
39 | 42 |
43 // Sets the current number of active IMEs. | |
44 void SetIMELength(int length); | |
45 | |
46 // Returns the view in the detailed views scroll content at the provided | |
47 // index. | |
48 views::View* GetScrollChildView(int index); | |
49 | |
40 // test::AshTestBase: | 50 // test::AshTestBase: |
41 virtual void SetUp() override; | 51 virtual void SetUp() override; |
42 virtual void TearDown() override; | 52 virtual void TearDown() override; |
43 | 53 |
44 private: | 54 private: |
45 scoped_ptr<TrayKeyboardLock> tray_; | 55 scoped_ptr<TrayIME> tray_; |
46 scoped_ptr<views::View> default_view_; | 56 scoped_ptr<views::View> default_view_; |
57 scoped_ptr<views::View> detailed_view_; | |
47 }; | 58 }; |
48 | 59 |
49 void TrayKeyboardLockTest::SetUpForStatusAreaWidget( | 60 void TrayIMETest::SetUpForStatusAreaWidget( |
50 StatusAreaWidget* status_area_widget) { | 61 StatusAreaWidget* status_area_widget) { |
51 tray_.reset(new TrayKeyboardLock(status_area_widget->system_tray())); | 62 tray_.reset(new TrayIME(status_area_widget->system_tray())); |
52 default_view_.reset(tray_->CreateDefaultView( | 63 default_view_.reset(tray_->CreateDefaultView( |
53 StatusAreaWidgetTestHelper::GetUserLoginStatus())); | 64 StatusAreaWidgetTestHelper::GetUserLoginStatus())); |
65 detailed_view_.reset(tray_->CreateDetailedView( | |
66 StatusAreaWidgetTestHelper::GetUserLoginStatus())); | |
54 } | 67 } |
55 | 68 |
56 void TrayKeyboardLockTest::SetAccessibilityKeyboardEnabled(bool enabled) { | 69 void TrayIMETest::SetAccessibilityKeyboardEnabled(bool enabled) { |
57 Shell::GetInstance()->accessibility_delegate()->SetVirtualKeyboardEnabled( | 70 Shell::GetInstance()->accessibility_delegate()->SetVirtualKeyboardEnabled( |
58 enabled); | 71 enabled); |
59 keyboard::SetAccessibilityKeyboardEnabled(enabled); | 72 keyboard::SetAccessibilityKeyboardEnabled(enabled); |
60 ui::AccessibilityNotificationVisibility notification = | 73 ui::AccessibilityNotificationVisibility notification = |
61 enabled ? ui::AccessibilityNotificationVisibility::A11Y_NOTIFICATION_SHOW | 74 enabled ? ui::AccessibilityNotificationVisibility::A11Y_NOTIFICATION_SHOW |
62 : ui::AccessibilityNotificationVisibility::A11Y_NOTIFICATION_NONE; | 75 : ui::AccessibilityNotificationVisibility::A11Y_NOTIFICATION_NONE; |
63 Shell::GetInstance()->system_tray_notifier()->NotifyAccessibilityModeChanged( | 76 Shell::GetInstance()->system_tray_notifier()->NotifyAccessibilityModeChanged( |
64 notification); | 77 notification); |
65 } | 78 } |
66 | 79 |
67 void TrayKeyboardLockTest::TearDownViews() { | 80 void TrayIMETest::TearDownViews() { |
81 tray_.reset(); | |
68 default_view_.reset(); | 82 default_view_.reset(); |
69 tray_.reset(); | 83 detailed_view_.reset(); |
70 } | 84 } |
71 | 85 |
72 void TrayKeyboardLockTest::SetUp() { | 86 void TrayIMETest::SetIMELength(int length) { |
87 tray_->ime_list_.clear(); | |
88 IMEInfo ime; | |
89 for (int i = 0; i < length; i++) { | |
90 tray_->ime_list_.push_back(ime); | |
91 } | |
92 tray_->Update(); | |
93 } | |
94 | |
95 views::View* TrayIMETest::GetScrollChildView(int index) { | |
96 TrayDetailsView* details = static_cast<TrayDetailsView*>(detailed_view()); | |
97 views::View* content = details->scroll_content(); | |
98 EXPECT_TRUE(content); | |
99 EXPECT_GT(content->child_count(), index); | |
100 return content->child_at(index); | |
101 } | |
102 | |
103 void TrayIMETest::SetUp() { | |
73 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 104 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
74 keyboard::switches::kEnableAutoVirtualKeyboard); | 105 keyboard::switches::kEnableAutoVirtualKeyboard); |
75 test::AshTestBase::SetUp(); | 106 test::AshTestBase::SetUp(); |
76 SetUpForStatusAreaWidget(StatusAreaWidgetTestHelper::GetStatusAreaWidget()); | 107 SetUpForStatusAreaWidget(StatusAreaWidgetTestHelper::GetStatusAreaWidget()); |
77 } | 108 } |
78 | 109 |
79 void TrayKeyboardLockTest::TearDown() { | 110 void TrayIMETest::TearDown() { |
80 SetAccessibilityKeyboardEnabled(false); | 111 SetAccessibilityKeyboardEnabled(false); |
81 TearDownViews(); | 112 TearDownViews(); |
82 test::AshTestBase::TearDown(); | 113 test::AshTestBase::TearDown(); |
83 } | 114 } |
84 | 115 |
85 // Tests that when the tray is initially created that the default view is | 116 // Tests that if the keyboard is not suppressed the default view is hidden |
86 // hidden. | 117 // if less than 2 IMEs are present. |
87 TEST_F(TrayKeyboardLockTest, HiddenOnCreation) { | 118 TEST_F(TrayIMETest, HiddenWithNoIMEs) { |
119 SetIMELength(0); | |
88 EXPECT_FALSE(default_view()->visible()); | 120 EXPECT_FALSE(default_view()->visible()); |
121 SetIMELength(1); | |
122 EXPECT_FALSE(default_view()->visible()); | |
123 SetIMELength(2); | |
124 EXPECT_TRUE(default_view()->visible()); | |
89 } | 125 } |
90 | 126 |
91 // Tests that the default view and tray are hidden when a11y is enabled. | 127 // Tests that if no IMEs are present the default view is hidden when a11y is |
92 TEST_F(TrayKeyboardLockTest, HidesOnA11yEnabled) { | 128 // enabled. |
129 TEST_F(TrayIMETest, HidesOnA11yEnabled) { | |
130 SetIMELength(0); | |
93 test::VirtualKeyboardTestHelper::SuppressKeyboard(); | 131 test::VirtualKeyboardTestHelper::SuppressKeyboard(); |
94 EXPECT_TRUE(default_view()->visible()); | 132 EXPECT_TRUE(default_view()->visible()); |
95 // Enable a11y keyboard. | 133 // Enable a11y keyboard. |
96 SetAccessibilityKeyboardEnabled(true); | 134 SetAccessibilityKeyboardEnabled(true); |
97 EXPECT_FALSE(default_view()->visible()); | 135 EXPECT_FALSE(default_view()->visible()); |
98 // Disable the a11y keyboard. | 136 // Disable the a11y keyboard. |
99 SetAccessibilityKeyboardEnabled(false); | 137 SetAccessibilityKeyboardEnabled(false); |
100 EXPECT_TRUE(default_view()->visible()); | 138 EXPECT_TRUE(default_view()->visible()); |
101 } | 139 } |
102 | 140 |
103 TEST_F(TrayKeyboardLockTest, PerformActionOnDefaultView) { | 141 // Tests that clicking on the keyboard toggle causes the virtual keyboard |
142 // to toggle between enabled and disabled. | |
143 TEST_F(TrayIMETest, PerformActionOnDetailedView) { | |
144 SetIMELength(0); | |
104 test::VirtualKeyboardTestHelper::SuppressKeyboard(); | 145 test::VirtualKeyboardTestHelper::SuppressKeyboard(); |
105 EXPECT_FALSE(keyboard::IsKeyboardEnabled()); | 146 EXPECT_FALSE(keyboard::IsKeyboardEnabled()); |
106 EXPECT_TRUE(default_view()->visible()); | 147 views::View* toggle = GetScrollChildView(0); |
107 | 148 ui::GestureEvent tap(0, 0, 0, base::TimeDelta(), |
108 ui::GestureEvent tap( | 149 ui::GestureEventDetails(ui::ET_GESTURE_TAP)); |
109 0, 0, 0, base::TimeDelta(), ui::GestureEventDetails(ui::ET_GESTURE_TAP)); | 150 // Enable the keyboard. |
110 default_view()->OnGestureEvent(&tap); | 151 toggle->OnGestureEvent(&tap); |
111 EXPECT_TRUE(keyboard::IsKeyboardEnabled()); | 152 EXPECT_TRUE(keyboard::IsKeyboardEnabled()); |
112 EXPECT_TRUE(default_view()->visible()); | 153 // With no IMEs the toggle should be the first child. |
113 | 154 toggle = GetScrollChildView(0); |
114 tap = ui::GestureEvent( | 155 // Clicking again should disable the keyboard. |
115 0, 0, 0, base::TimeDelta(), ui::GestureEventDetails(ui::ET_GESTURE_TAP)); | 156 tap = ui::GestureEvent(0, 0, 0, base::TimeDelta(), |
116 default_view()->OnGestureEvent(&tap); | 157 ui::GestureEventDetails(ui::ET_GESTURE_TAP)); |
158 toggle->OnGestureEvent(&tap); | |
117 EXPECT_FALSE(keyboard::IsKeyboardEnabled()); | 159 EXPECT_FALSE(keyboard::IsKeyboardEnabled()); |
Mr4D (OOO till 08-26)
2015/01/12 22:35:37
If the opposite is now true (!visible) - chouldn't
rsadam
2015/01/13 00:05:34
I'm not sure I follow - the keyboard is disabled,
Mr4D (OOO till 08-26)
2015/01/13 15:04:05
Oh - I have meant the test which you have removed
| |
118 EXPECT_TRUE(default_view()->visible()); | |
119 } | 160 } |
120 | 161 |
121 } // namespace ash | 162 } // namespace ash |
OLD | NEW |