diff options
author | yusukes@chromium.org <yusukes@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-11-14 04:02:26 +0000 |
---|---|---|
committer | yusukes@chromium.org <yusukes@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-11-14 04:02:26 +0000 |
commit | 94e334dcb4d70f9ec917e0303128b04bfa3d3f1f (patch) | |
tree | 218047314dc9056128e389db76ad0c9b450e3a14 /chrome/browser/chromeos | |
parent | 5408788fa1c445defb7b56f5ed8a14cb217c5b27 (diff) | |
download | chromium_src-94e334dcb4d70f9ec917e0303128b04bfa3d3f1f.zip chromium_src-94e334dcb4d70f9ec917e0303128b04bfa3d3f1f.tar.gz chromium_src-94e334dcb4d70f9ec917e0303128b04bfa3d3f1f.tar.bz2 |
Add unit tests for SetAutoRepeatEnabled and SetAutoRepeatRate.
BUG=None
TEST=ran try
Review URL: http://codereview.chromium.org/8497003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@109844 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/chromeos')
-rw-r--r-- | chrome/browser/chromeos/input_method/xkeyboard.cc | 15 | ||||
-rw-r--r-- | chrome/browser/chromeos/input_method/xkeyboard.h | 10 | ||||
-rw-r--r-- | chrome/browser/chromeos/input_method/xkeyboard_unittest.cc | 44 |
3 files changed, 68 insertions, 1 deletions
diff --git a/chrome/browser/chromeos/input_method/xkeyboard.cc b/chrome/browser/chromeos/input_method/xkeyboard.cc index a810f30..0050a51 100644 --- a/chrome/browser/chromeos/input_method/xkeyboard.cc +++ b/chrome/browser/chromeos/input_method/xkeyboard.cc @@ -355,7 +355,6 @@ bool XKeyboard::SetAutoRepeatEnabled(bool enabled) { // static bool XKeyboard::SetAutoRepeatRate(const AutoRepeatRate& rate) { - // TODO(yusukes): write auto tests for the function. CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); DLOG(INFO) << "Set auto-repeat rate to: " << rate.initial_delay_in_ms << " ms delay, " @@ -369,6 +368,20 @@ bool XKeyboard::SetAutoRepeatRate(const AutoRepeatRate& rate) { return true; } +// static +bool XKeyboard::GetAutoRepeatEnabled() { + XKeyboardState state = {}; + XGetKeyboardControl(ui::GetXDisplay(), &state); + return state.global_auto_repeat != AutoRepeatModeOff; +} + +// static +bool XKeyboard::GetAutoRepeatRate(AutoRepeatRate* out_rate) { + return XkbGetAutoRepeatRate(ui::GetXDisplay(), XkbUseCoreKbd, + &(out_rate->initial_delay_in_ms), + &(out_rate->repeat_interval_in_ms)) == True; +} + void XKeyboard::SetLockedModifiers(ModifierLockStatus new_caps_lock_status, ModifierLockStatus new_num_lock_status) { CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); diff --git a/chrome/browser/chromeos/input_method/xkeyboard.h b/chrome/browser/chromeos/input_method/xkeyboard.h index cbe9852..15d1b82 100644 --- a/chrome/browser/chromeos/input_method/xkeyboard.h +++ b/chrome/browser/chromeos/input_method/xkeyboard.h @@ -141,6 +141,16 @@ class XKeyboard { static bool ContainsModifierKeyAsReplacement(const ModifierMap& modifier_map, ModifierKey key); + // THIS FUNCTION IS ONLY FOR UNIT TESTS. + // Returns true if auto repeat is enabled. This function is protected: for + // testability. + static bool GetAutoRepeatEnabled(); + + // THIS FUNCTION IS ONLY FOR UNIT TESTS. + // On success, set current auto repeat rate on |out_rate| and returns true. + // Returns false otherwise. This function is protected: for testability. + static bool GetAutoRepeatRate(AutoRepeatRate* out_rate); + private: // This function is used by SetLayout() and RemapModifierKeys(). Calls // setxkbmap command if needed, and updates the last_full_layout_name_ cache. diff --git a/chrome/browser/chromeos/input_method/xkeyboard_unittest.cc b/chrome/browser/chromeos/input_method/xkeyboard_unittest.cc index 901c27b..e0eccaf 100644 --- a/chrome/browser/chromeos/input_method/xkeyboard_unittest.cc +++ b/chrome/browser/chromeos/input_method/xkeyboard_unittest.cc @@ -42,6 +42,8 @@ class TestableXKeyboard : public XKeyboard { // Change access rights. using XKeyboard::CreateFullXkbLayoutName; using XKeyboard::ContainsModifierKeyAsReplacement; + using XKeyboard::GetAutoRepeatEnabled; + using XKeyboard::GetAutoRepeatRate; }; class XKeyboardTest : public testing::Test { @@ -255,6 +257,10 @@ TEST_F(XKeyboardTest, TestCreateFullXkbLayoutNameModifierKeys) { TEST_F(XKeyboardTest, TestSetCapsLockEnabled) { if (!DisplayAvailable()) { + // Do not fail the test to allow developers to run unit_tests without an X + // server (e.g. via ssh). Note that both try bots and waterfall always have + // an X server for running browser_tests. + LOG(INFO) << "X server is not available. Skip the test."; return; } const bool initial_lock_state = xkey_->CapsLockIsEnabled(); @@ -271,6 +277,7 @@ TEST_F(XKeyboardTest, TestSetCapsLockEnabled) { TEST_F(XKeyboardTest, TestSetNumLockEnabled) { if (!DisplayAvailable()) { + LOG(INFO) << "X server is not available. Skip the test."; return; } const unsigned int num_lock_mask = TestableXKeyboard::GetNumLockMask(); @@ -290,6 +297,7 @@ TEST_F(XKeyboardTest, TestSetNumLockEnabled) { TEST_F(XKeyboardTest, TestSetCapsLockAndNumLockAtTheSameTime) { if (!DisplayAvailable()) { + LOG(INFO) << "X server is not available. Skip the test."; return; } const unsigned int num_lock_mask = TestableXKeyboard::GetNumLockMask(); @@ -353,5 +361,41 @@ TEST_F(XKeyboardTest, TestContainsModifierKeyAsReplacement) { GetMap(kSearchKey, kVoidKey, kVoidKey), kSearchKey)); } +TEST_F(XKeyboardTest, TestSetAutoRepeatEnabled) { + if (!DisplayAvailable()) { + LOG(INFO) << "X server is not available. Skip the test."; + return; + } + const bool state = TestableXKeyboard::GetAutoRepeatEnabled(); + TestableXKeyboard::SetAutoRepeatEnabled(!state); + EXPECT_EQ(!state, TestableXKeyboard::GetAutoRepeatEnabled()); + // Restore the initial state. + TestableXKeyboard::SetAutoRepeatEnabled(state); + EXPECT_EQ(state, TestableXKeyboard::GetAutoRepeatEnabled()); +} + +TEST_F(XKeyboardTest, TestSetAutoRepeatRate) { + if (!DisplayAvailable()) { + LOG(INFO) << "X server is not available. Skip the test."; + return; + } + AutoRepeatRate rate; + EXPECT_TRUE(TestableXKeyboard::GetAutoRepeatRate(&rate)); + + AutoRepeatRate tmp(rate); + ++tmp.initial_delay_in_ms; + ++tmp.repeat_interval_in_ms; + EXPECT_TRUE(TestableXKeyboard::SetAutoRepeatRate(tmp)); + EXPECT_TRUE(TestableXKeyboard::GetAutoRepeatRate(&tmp)); + EXPECT_EQ(rate.initial_delay_in_ms + 1, tmp.initial_delay_in_ms); + EXPECT_EQ(rate.repeat_interval_in_ms + 1, tmp.repeat_interval_in_ms); + + // Restore the initial state. + EXPECT_TRUE(TestableXKeyboard::SetAutoRepeatRate(rate)); + EXPECT_TRUE(TestableXKeyboard::GetAutoRepeatRate(&tmp)); + EXPECT_EQ(rate.initial_delay_in_ms, tmp.initial_delay_in_ms); + EXPECT_EQ(rate.repeat_interval_in_ms, tmp.repeat_interval_in_ms); +} + } // namespace input_method } // namespace chromeos |