OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "chromeos/ime/xkeyboard.h" | 5 #include "chromeos/ime/xkeyboard.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <set> | 8 #include <set> |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 EXPECT_TRUE(xkey_->CapsLockIsEnabled()); | 84 EXPECT_TRUE(xkey_->CapsLockIsEnabled()); |
85 xkey_->SetCapsLockEnabled(false); | 85 xkey_->SetCapsLockEnabled(false); |
86 EXPECT_FALSE(xkey_->CapsLockIsEnabled()); | 86 EXPECT_FALSE(xkey_->CapsLockIsEnabled()); |
87 xkey_->SetCapsLockEnabled(true); | 87 xkey_->SetCapsLockEnabled(true); |
88 EXPECT_TRUE(xkey_->CapsLockIsEnabled()); | 88 EXPECT_TRUE(xkey_->CapsLockIsEnabled()); |
89 xkey_->SetCapsLockEnabled(false); | 89 xkey_->SetCapsLockEnabled(false); |
90 EXPECT_FALSE(xkey_->CapsLockIsEnabled()); | 90 EXPECT_FALSE(xkey_->CapsLockIsEnabled()); |
91 xkey_->SetCapsLockEnabled(initial_lock_state); | 91 xkey_->SetCapsLockEnabled(initial_lock_state); |
92 } | 92 } |
93 | 93 |
94 TEST_F(XKeyboardTest, TestSetNumLockEnabled) { | |
95 if (!DisplayAvailable()) { | |
96 DVLOG(1) << "X server is not available. Skip the test."; | |
97 return; | |
98 } | |
99 const unsigned int num_lock_mask = xkey_->GetNumLockMask(); | |
100 ASSERT_NE(0U, num_lock_mask); | |
101 | |
102 const bool initial_lock_state = xkey_->NumLockIsEnabled(); | |
103 xkey_->SetNumLockEnabled(true); | |
104 EXPECT_TRUE(xkey_->NumLockIsEnabled()); | |
105 xkey_->SetNumLockEnabled(false); | |
106 EXPECT_FALSE(xkey_->NumLockIsEnabled()); | |
107 xkey_->SetNumLockEnabled(true); | |
108 EXPECT_TRUE(xkey_->NumLockIsEnabled()); | |
109 xkey_->SetNumLockEnabled(false); | |
110 EXPECT_FALSE(xkey_->NumLockIsEnabled()); | |
111 xkey_->SetNumLockEnabled(initial_lock_state); | |
112 } | |
113 | |
114 TEST_F(XKeyboardTest, TestSetCapsLockAndNumLockAtTheSameTime) { | |
115 if (!DisplayAvailable()) { | |
116 DVLOG(1) << "X server is not available. Skip the test."; | |
117 return; | |
118 } | |
119 const unsigned int num_lock_mask = xkey_->GetNumLockMask(); | |
120 ASSERT_NE(0U, num_lock_mask); | |
121 | |
122 const bool initial_caps_lock_state = xkey_->CapsLockIsEnabled(); | |
123 const bool initial_num_lock_state = xkey_->NumLockIsEnabled(); | |
124 | |
125 // Flip both. | |
126 xkey_->SetLockedModifiers( | |
127 initial_caps_lock_state ? kDisableLock : kEnableLock, | |
128 initial_num_lock_state ? kDisableLock : kEnableLock); | |
129 EXPECT_EQ(!initial_caps_lock_state, xkey_->CapsLockIsEnabled()); | |
130 EXPECT_EQ(!initial_num_lock_state, xkey_->NumLockIsEnabled()); | |
131 | |
132 // Flip Caps Lock. | |
133 xkey_->SetLockedModifiers( | |
134 initial_caps_lock_state ? kEnableLock : kDisableLock, | |
135 kDontChange); | |
136 // Use GetLockedModifiers() for verifying the result. | |
137 bool c, n; | |
138 xkey_->GetLockedModifiers(&c, &n); | |
139 EXPECT_EQ(initial_caps_lock_state, c); | |
140 EXPECT_EQ(!initial_num_lock_state, n); | |
141 | |
142 // Flip both. | |
143 xkey_->SetLockedModifiers( | |
144 initial_caps_lock_state ? kDisableLock : kEnableLock, | |
145 initial_num_lock_state ? kEnableLock : kDisableLock); | |
146 EXPECT_EQ(!initial_caps_lock_state, xkey_->CapsLockIsEnabled()); | |
147 EXPECT_EQ(initial_num_lock_state, xkey_->NumLockIsEnabled()); | |
148 | |
149 // Flip Num Lock. | |
150 xkey_->SetLockedModifiers( | |
151 kDontChange, | |
152 initial_num_lock_state ? kDisableLock : kEnableLock); | |
153 xkey_->GetLockedModifiers(&c, &n); | |
154 EXPECT_EQ(!initial_caps_lock_state, c); | |
155 EXPECT_EQ(!initial_num_lock_state, n); | |
156 | |
157 // Flip both to restore the initial state. | |
158 xkey_->SetLockedModifiers( | |
159 initial_caps_lock_state ? kEnableLock : kDisableLock, | |
160 initial_num_lock_state ? kEnableLock : kDisableLock); | |
161 EXPECT_EQ(initial_caps_lock_state, xkey_->CapsLockIsEnabled()); | |
162 EXPECT_EQ(initial_num_lock_state, xkey_->NumLockIsEnabled()); | |
163 | |
164 // No-op SetLockedModifiers call. | |
165 xkey_->SetLockedModifiers(kDontChange, kDontChange); | |
166 EXPECT_EQ(initial_caps_lock_state, xkey_->CapsLockIsEnabled()); | |
167 EXPECT_EQ(initial_num_lock_state, xkey_->NumLockIsEnabled()); | |
168 | |
169 // No-op GetLockedModifiers call. Confirm it does not crash. | |
170 xkey_->GetLockedModifiers(NULL, NULL); | |
171 } | |
172 | |
173 TEST_F(XKeyboardTest, TestSetAutoRepeatEnabled) { | 94 TEST_F(XKeyboardTest, TestSetAutoRepeatEnabled) { |
174 if (!DisplayAvailable()) { | 95 if (!DisplayAvailable()) { |
175 DVLOG(1) << "X server is not available. Skip the test."; | 96 DVLOG(1) << "X server is not available. Skip the test."; |
176 return; | 97 return; |
177 } | 98 } |
178 const bool state = XKeyboard::GetAutoRepeatEnabledForTesting(); | 99 const bool state = XKeyboard::GetAutoRepeatEnabledForTesting(); |
179 xkey_->SetAutoRepeatEnabled(!state); | 100 xkey_->SetAutoRepeatEnabled(!state); |
180 EXPECT_EQ(!state, XKeyboard::GetAutoRepeatEnabledForTesting()); | 101 EXPECT_EQ(!state, XKeyboard::GetAutoRepeatEnabledForTesting()); |
181 // Restore the initial state. | 102 // Restore the initial state. |
182 xkey_->SetAutoRepeatEnabled(state); | 103 xkey_->SetAutoRepeatEnabled(state); |
(...skipping 18 matching lines...) Expand all Loading... |
201 | 122 |
202 // Restore the initial state. | 123 // Restore the initial state. |
203 EXPECT_TRUE(xkey_->SetAutoRepeatRate(rate)); | 124 EXPECT_TRUE(xkey_->SetAutoRepeatRate(rate)); |
204 EXPECT_TRUE(XKeyboard::GetAutoRepeatRateForTesting(&tmp)); | 125 EXPECT_TRUE(XKeyboard::GetAutoRepeatRateForTesting(&tmp)); |
205 EXPECT_EQ(rate.initial_delay_in_ms, tmp.initial_delay_in_ms); | 126 EXPECT_EQ(rate.initial_delay_in_ms, tmp.initial_delay_in_ms); |
206 EXPECT_EQ(rate.repeat_interval_in_ms, tmp.repeat_interval_in_ms); | 127 EXPECT_EQ(rate.repeat_interval_in_ms, tmp.repeat_interval_in_ms); |
207 } | 128 } |
208 | 129 |
209 } // namespace input_method | 130 } // namespace input_method |
210 } // namespace chromeos | 131 } // namespace chromeos |
OLD | NEW |