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

Side by Side Diff: chrome/browser/chromeos/input_method/xkeyboard_unittest.cc

Issue 8497003: Add unit tests for SetAutoRepeatEnabled and SetAutoRepeatRate. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase, review fix Created 9 years, 1 month 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/chromeos/input_method/xkeyboard.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "chrome/browser/chromeos/input_method/xkeyboard.h" 5 #include "chrome/browser/chromeos/input_method/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 24 matching lines...) Expand all
35 namespace { 35 namespace {
36 36
37 class TestableXKeyboard : public XKeyboard { 37 class TestableXKeyboard : public XKeyboard {
38 public: 38 public:
39 explicit TestableXKeyboard(const InputMethodUtil& util) : XKeyboard(util) { 39 explicit TestableXKeyboard(const InputMethodUtil& util) : XKeyboard(util) {
40 } 40 }
41 41
42 // Change access rights. 42 // Change access rights.
43 using XKeyboard::CreateFullXkbLayoutName; 43 using XKeyboard::CreateFullXkbLayoutName;
44 using XKeyboard::ContainsModifierKeyAsReplacement; 44 using XKeyboard::ContainsModifierKeyAsReplacement;
45 using XKeyboard::GetAutoRepeatEnabled;
46 using XKeyboard::GetAutoRepeatRate;
45 }; 47 };
46 48
47 class XKeyboardTest : public testing::Test { 49 class XKeyboardTest : public testing::Test {
48 public: 50 public:
49 XKeyboardTest() 51 XKeyboardTest()
50 : controller_(IBusController::Create()), 52 : controller_(IBusController::Create()),
51 util_(controller_->GetSupportedInputMethods()), 53 util_(controller_->GetSupportedInputMethods()),
52 ui_thread_(BrowserThread::UI, &message_loop_) { 54 ui_thread_(BrowserThread::UI, &message_loop_) {
53 } 55 }
54 56
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 << "layout: " << layout; 250 << "layout: " << layout;
249 // All 4*3*3 layouts should be different. 251 // All 4*3*3 layouts should be different.
250 EXPECT_TRUE(layouts.insert(layout).second) << "layout: " << layout; 252 EXPECT_TRUE(layouts.insert(layout).second) << "layout: " << layout;
251 } 253 }
252 } 254 }
253 } 255 }
254 } 256 }
255 257
256 TEST_F(XKeyboardTest, TestSetCapsLockEnabled) { 258 TEST_F(XKeyboardTest, TestSetCapsLockEnabled) {
257 if (!DisplayAvailable()) { 259 if (!DisplayAvailable()) {
260 // Do not fail the test to allow developers to run unit_tests without an X
261 // server (e.g. via ssh). Note that both try bots and waterfall always have
262 // an X server for running browser_tests.
263 LOG(INFO) << "X server is not available. Skip the test.";
258 return; 264 return;
259 } 265 }
260 const bool initial_lock_state = xkey_->CapsLockIsEnabled(); 266 const bool initial_lock_state = xkey_->CapsLockIsEnabled();
261 xkey_->SetCapsLockEnabled(true); 267 xkey_->SetCapsLockEnabled(true);
262 EXPECT_TRUE(TestableXKeyboard::CapsLockIsEnabled()); 268 EXPECT_TRUE(TestableXKeyboard::CapsLockIsEnabled());
263 xkey_->SetCapsLockEnabled(false); 269 xkey_->SetCapsLockEnabled(false);
264 EXPECT_FALSE(TestableXKeyboard::CapsLockIsEnabled()); 270 EXPECT_FALSE(TestableXKeyboard::CapsLockIsEnabled());
265 xkey_->SetCapsLockEnabled(true); 271 xkey_->SetCapsLockEnabled(true);
266 EXPECT_TRUE(TestableXKeyboard::CapsLockIsEnabled()); 272 EXPECT_TRUE(TestableXKeyboard::CapsLockIsEnabled());
267 xkey_->SetCapsLockEnabled(false); 273 xkey_->SetCapsLockEnabled(false);
268 EXPECT_FALSE(TestableXKeyboard::CapsLockIsEnabled()); 274 EXPECT_FALSE(TestableXKeyboard::CapsLockIsEnabled());
269 xkey_->SetCapsLockEnabled(initial_lock_state); 275 xkey_->SetCapsLockEnabled(initial_lock_state);
270 } 276 }
271 277
272 TEST_F(XKeyboardTest, TestSetNumLockEnabled) { 278 TEST_F(XKeyboardTest, TestSetNumLockEnabled) {
273 if (!DisplayAvailable()) { 279 if (!DisplayAvailable()) {
280 LOG(INFO) << "X server is not available. Skip the test.";
274 return; 281 return;
275 } 282 }
276 const unsigned int num_lock_mask = TestableXKeyboard::GetNumLockMask(); 283 const unsigned int num_lock_mask = TestableXKeyboard::GetNumLockMask();
277 ASSERT_NE(0U, num_lock_mask); 284 ASSERT_NE(0U, num_lock_mask);
278 285
279 const bool initial_lock_state = xkey_->NumLockIsEnabled(num_lock_mask); 286 const bool initial_lock_state = xkey_->NumLockIsEnabled(num_lock_mask);
280 xkey_->SetNumLockEnabled(true); 287 xkey_->SetNumLockEnabled(true);
281 EXPECT_TRUE(TestableXKeyboard::NumLockIsEnabled(num_lock_mask)); 288 EXPECT_TRUE(TestableXKeyboard::NumLockIsEnabled(num_lock_mask));
282 xkey_->SetNumLockEnabled(false); 289 xkey_->SetNumLockEnabled(false);
283 EXPECT_FALSE(TestableXKeyboard::NumLockIsEnabled(num_lock_mask)); 290 EXPECT_FALSE(TestableXKeyboard::NumLockIsEnabled(num_lock_mask));
284 xkey_->SetNumLockEnabled(true); 291 xkey_->SetNumLockEnabled(true);
285 EXPECT_TRUE(TestableXKeyboard::NumLockIsEnabled(num_lock_mask)); 292 EXPECT_TRUE(TestableXKeyboard::NumLockIsEnabled(num_lock_mask));
286 xkey_->SetNumLockEnabled(false); 293 xkey_->SetNumLockEnabled(false);
287 EXPECT_FALSE(TestableXKeyboard::NumLockIsEnabled(num_lock_mask)); 294 EXPECT_FALSE(TestableXKeyboard::NumLockIsEnabled(num_lock_mask));
288 xkey_->SetNumLockEnabled(initial_lock_state); 295 xkey_->SetNumLockEnabled(initial_lock_state);
289 } 296 }
290 297
291 TEST_F(XKeyboardTest, TestSetCapsLockAndNumLockAtTheSameTime) { 298 TEST_F(XKeyboardTest, TestSetCapsLockAndNumLockAtTheSameTime) {
292 if (!DisplayAvailable()) { 299 if (!DisplayAvailable()) {
300 LOG(INFO) << "X server is not available. Skip the test.";
293 return; 301 return;
294 } 302 }
295 const unsigned int num_lock_mask = TestableXKeyboard::GetNumLockMask(); 303 const unsigned int num_lock_mask = TestableXKeyboard::GetNumLockMask();
296 ASSERT_NE(0U, num_lock_mask); 304 ASSERT_NE(0U, num_lock_mask);
297 305
298 const bool initial_caps_lock_state = xkey_->CapsLockIsEnabled(); 306 const bool initial_caps_lock_state = xkey_->CapsLockIsEnabled();
299 const bool initial_num_lock_state = xkey_->NumLockIsEnabled(num_lock_mask); 307 const bool initial_num_lock_state = xkey_->NumLockIsEnabled(num_lock_mask);
300 308
301 // Flip both. 309 // Flip both.
302 xkey_->SetLockedModifiers( 310 xkey_->SetLockedModifiers(
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 EXPECT_TRUE(TestableXKeyboard::ContainsModifierKeyAsReplacement( 354 EXPECT_TRUE(TestableXKeyboard::ContainsModifierKeyAsReplacement(
347 GetMap(kVoidKey, kVoidKey, kCapsLockKey), kCapsLockKey)); 355 GetMap(kVoidKey, kVoidKey, kCapsLockKey), kCapsLockKey));
348 EXPECT_TRUE(TestableXKeyboard::ContainsModifierKeyAsReplacement( 356 EXPECT_TRUE(TestableXKeyboard::ContainsModifierKeyAsReplacement(
349 GetMap(kCapsLockKey, kCapsLockKey, kVoidKey), kCapsLockKey)); 357 GetMap(kCapsLockKey, kCapsLockKey, kVoidKey), kCapsLockKey));
350 EXPECT_TRUE(TestableXKeyboard::ContainsModifierKeyAsReplacement( 358 EXPECT_TRUE(TestableXKeyboard::ContainsModifierKeyAsReplacement(
351 GetMap(kCapsLockKey, kCapsLockKey, kCapsLockKey), kCapsLockKey)); 359 GetMap(kCapsLockKey, kCapsLockKey, kCapsLockKey), kCapsLockKey));
352 EXPECT_TRUE(TestableXKeyboard::ContainsModifierKeyAsReplacement( 360 EXPECT_TRUE(TestableXKeyboard::ContainsModifierKeyAsReplacement(
353 GetMap(kSearchKey, kVoidKey, kVoidKey), kSearchKey)); 361 GetMap(kSearchKey, kVoidKey, kVoidKey), kSearchKey));
354 } 362 }
355 363
364 TEST_F(XKeyboardTest, TestSetAutoRepeatEnabled) {
365 if (!DisplayAvailable()) {
366 LOG(INFO) << "X server is not available. Skip the test.";
367 return;
368 }
369 const bool state = TestableXKeyboard::GetAutoRepeatEnabled();
370 TestableXKeyboard::SetAutoRepeatEnabled(!state);
371 EXPECT_EQ(!state, TestableXKeyboard::GetAutoRepeatEnabled());
372 // Restore the initial state.
373 TestableXKeyboard::SetAutoRepeatEnabled(state);
374 EXPECT_EQ(state, TestableXKeyboard::GetAutoRepeatEnabled());
375 }
376
377 TEST_F(XKeyboardTest, TestSetAutoRepeatRate) {
378 if (!DisplayAvailable()) {
379 LOG(INFO) << "X server is not available. Skip the test.";
380 return;
381 }
382 AutoRepeatRate rate;
383 EXPECT_TRUE(TestableXKeyboard::GetAutoRepeatRate(&rate));
384
385 AutoRepeatRate tmp(rate);
386 ++tmp.initial_delay_in_ms;
387 ++tmp.repeat_interval_in_ms;
388 EXPECT_TRUE(TestableXKeyboard::SetAutoRepeatRate(tmp));
389 EXPECT_TRUE(TestableXKeyboard::GetAutoRepeatRate(&tmp));
390 EXPECT_EQ(rate.initial_delay_in_ms + 1, tmp.initial_delay_in_ms);
391 EXPECT_EQ(rate.repeat_interval_in_ms + 1, tmp.repeat_interval_in_ms);
392
393 // Restore the initial state.
394 EXPECT_TRUE(TestableXKeyboard::SetAutoRepeatRate(rate));
395 EXPECT_TRUE(TestableXKeyboard::GetAutoRepeatRate(&tmp));
396 EXPECT_EQ(rate.initial_delay_in_ms, tmp.initial_delay_in_ms);
397 EXPECT_EQ(rate.repeat_interval_in_ms, tmp.repeat_interval_in_ms);
398 }
399
356 } // namespace input_method 400 } // namespace input_method
357 } // namespace chromeos 401 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/input_method/xkeyboard.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698