| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/message_loop.h" | 13 #include "base/message_loop.h" |
| 14 #include "chrome/browser/chromeos/input_method/input_method_util.h" | 14 #include "chrome/browser/chromeos/input_method/input_method_util.h" |
| 15 #include "chrome/browser/chromeos/input_method/input_method_whitelist.h" | 15 #include "chrome/browser/chromeos/input_method/input_method_whitelist.h" |
| 16 #include "chrome/browser/chromeos/input_method/mock_input_method_delegate.h" | 16 #include "chrome/browser/chromeos/input_method/mock_input_method_delegate.h" |
| 17 #include "content/public/test/test_browser_thread.h" | 17 #include "chrome/browser/chromeos/input_method/mock_sequenced_task_runner.h" |
| 18 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
| 19 #include "ui/base/x/x11_util.h" | 19 #include "ui/base/x/x11_util.h" |
| 20 | 20 |
| 21 #include <X11/Xlib.h> | 21 #include <X11/Xlib.h> |
| 22 | 22 |
| 23 using content::BrowserThread; | |
| 24 | |
| 25 namespace chromeos { | 23 namespace chromeos { |
| 26 namespace input_method { | 24 namespace input_method { |
| 27 | 25 |
| 28 namespace { | 26 namespace { |
| 29 | 27 |
| 30 class XKeyboardTest : public testing::Test { | 28 class XKeyboardTest : public testing::Test { |
| 31 public: | 29 public: |
| 32 XKeyboardTest() | 30 XKeyboardTest() |
| 33 : util_(&delegate_, whitelist_.GetSupportedInputMethods()), | 31 : util_(&delegate_, whitelist_.GetSupportedInputMethods()), |
| 34 ui_thread_(BrowserThread::UI, &message_loop_) { | 32 mock_task_runner_(new MockSequencedTaskRunner) { |
| 35 } | 33 } |
| 36 | 34 |
| 37 virtual void SetUp() { | 35 virtual void SetUp() { |
| 38 xkey_.reset(XKeyboard::Create(util_)); | 36 xkey_.reset(XKeyboard::Create(util_, mock_task_runner_)); |
| 39 } | 37 } |
| 40 | 38 |
| 41 virtual void TearDown() { | 39 virtual void TearDown() { |
| 42 xkey_.reset(); | 40 xkey_.reset(); |
| 43 } | 41 } |
| 44 | 42 |
| 45 MockInputMethodDelegate delegate_; | 43 MockInputMethodDelegate delegate_; |
| 46 InputMethodWhitelist whitelist_; | 44 InputMethodWhitelist whitelist_; |
| 47 InputMethodUtil util_; | 45 InputMethodUtil util_; |
| 46 scoped_refptr<MockSequencedTaskRunner> mock_task_runner_; |
| 48 scoped_ptr<XKeyboard> xkey_; | 47 scoped_ptr<XKeyboard> xkey_; |
| 49 | |
| 50 MessageLoopForUI message_loop_; | |
| 51 content::TestBrowserThread ui_thread_; | |
| 52 }; | 48 }; |
| 53 | 49 |
| 54 // Returns true if X display is available. | 50 // Returns true if X display is available. |
| 55 bool DisplayAvailable() { | 51 bool DisplayAvailable() { |
| 56 return ui::GetXDisplay() ? true : false; | 52 return ui::GetXDisplay() ? true : false; |
| 57 } | 53 } |
| 58 | 54 |
| 59 } // namespace | 55 } // namespace |
| 60 | 56 |
| 61 // Tests CheckLayoutName() function. | 57 // Tests CheckLayoutName() function. |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 // No-op GetLockedModifiers call. Confirm it does not crash. | 178 // No-op GetLockedModifiers call. Confirm it does not crash. |
| 183 xkey_->GetLockedModifiers(NULL, NULL); | 179 xkey_->GetLockedModifiers(NULL, NULL); |
| 184 } | 180 } |
| 185 | 181 |
| 186 TEST_F(XKeyboardTest, TestSetAutoRepeatEnabled) { | 182 TEST_F(XKeyboardTest, TestSetAutoRepeatEnabled) { |
| 187 if (!DisplayAvailable()) { | 183 if (!DisplayAvailable()) { |
| 188 DVLOG(1) << "X server is not available. Skip the test."; | 184 DVLOG(1) << "X server is not available. Skip the test."; |
| 189 return; | 185 return; |
| 190 } | 186 } |
| 191 const bool state = XKeyboard::GetAutoRepeatEnabledForTesting(); | 187 const bool state = XKeyboard::GetAutoRepeatEnabledForTesting(); |
| 192 XKeyboard::SetAutoRepeatEnabled(!state); | 188 xkey_->SetAutoRepeatEnabled(!state); |
| 193 EXPECT_EQ(!state, XKeyboard::GetAutoRepeatEnabledForTesting()); | 189 EXPECT_EQ(!state, XKeyboard::GetAutoRepeatEnabledForTesting()); |
| 194 // Restore the initial state. | 190 // Restore the initial state. |
| 195 XKeyboard::SetAutoRepeatEnabled(state); | 191 xkey_->SetAutoRepeatEnabled(state); |
| 196 EXPECT_EQ(state, XKeyboard::GetAutoRepeatEnabledForTesting()); | 192 EXPECT_EQ(state, XKeyboard::GetAutoRepeatEnabledForTesting()); |
| 197 } | 193 } |
| 198 | 194 |
| 199 TEST_F(XKeyboardTest, TestSetAutoRepeatRate) { | 195 TEST_F(XKeyboardTest, TestSetAutoRepeatRate) { |
| 200 if (!DisplayAvailable()) { | 196 if (!DisplayAvailable()) { |
| 201 DVLOG(1) << "X server is not available. Skip the test."; | 197 DVLOG(1) << "X server is not available. Skip the test."; |
| 202 return; | 198 return; |
| 203 } | 199 } |
| 204 AutoRepeatRate rate; | 200 AutoRepeatRate rate; |
| 205 EXPECT_TRUE(XKeyboard::GetAutoRepeatRateForTesting(&rate)); | 201 EXPECT_TRUE(XKeyboard::GetAutoRepeatRateForTesting(&rate)); |
| 206 | 202 |
| 207 AutoRepeatRate tmp(rate); | 203 AutoRepeatRate tmp(rate); |
| 208 ++tmp.initial_delay_in_ms; | 204 ++tmp.initial_delay_in_ms; |
| 209 ++tmp.repeat_interval_in_ms; | 205 ++tmp.repeat_interval_in_ms; |
| 210 EXPECT_TRUE(XKeyboard::SetAutoRepeatRate(tmp)); | 206 EXPECT_TRUE(xkey_->SetAutoRepeatRate(tmp)); |
| 211 EXPECT_TRUE(XKeyboard::GetAutoRepeatRateForTesting(&tmp)); | 207 EXPECT_TRUE(XKeyboard::GetAutoRepeatRateForTesting(&tmp)); |
| 212 EXPECT_EQ(rate.initial_delay_in_ms + 1, tmp.initial_delay_in_ms); | 208 EXPECT_EQ(rate.initial_delay_in_ms + 1, tmp.initial_delay_in_ms); |
| 213 EXPECT_EQ(rate.repeat_interval_in_ms + 1, tmp.repeat_interval_in_ms); | 209 EXPECT_EQ(rate.repeat_interval_in_ms + 1, tmp.repeat_interval_in_ms); |
| 214 | 210 |
| 215 // Restore the initial state. | 211 // Restore the initial state. |
| 216 EXPECT_TRUE(XKeyboard::SetAutoRepeatRate(rate)); | 212 EXPECT_TRUE(xkey_->SetAutoRepeatRate(rate)); |
| 217 EXPECT_TRUE(XKeyboard::GetAutoRepeatRateForTesting(&tmp)); | 213 EXPECT_TRUE(XKeyboard::GetAutoRepeatRateForTesting(&tmp)); |
| 218 EXPECT_EQ(rate.initial_delay_in_ms, tmp.initial_delay_in_ms); | 214 EXPECT_EQ(rate.initial_delay_in_ms, tmp.initial_delay_in_ms); |
| 219 EXPECT_EQ(rate.repeat_interval_in_ms, tmp.repeat_interval_in_ms); | 215 EXPECT_EQ(rate.repeat_interval_in_ms, tmp.repeat_interval_in_ms); |
| 220 } | 216 } |
| 221 | 217 |
| 222 } // namespace input_method | 218 } // namespace input_method |
| 223 } // namespace chromeos | 219 } // namespace chromeos |
| OLD | NEW |