| 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 "ui/base/ime/chromeos/ime_keyboard.h" | 5 #include "ui/base/ime/chromeos/ime_keyboard.h" |
| 6 | 6 |
| 7 #include <X11/Xlib.h> | 7 #include <X11/Xlib.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <memory> | 10 #include <memory> |
| 11 #include <set> | 11 #include <set> |
| 12 #include <string> | 12 #include <string> |
| 13 | 13 |
| 14 #include "base/logging.h" | 14 #include "base/logging.h" |
| 15 #include "base/message_loop/message_loop.h" | 15 #include "base/test/scoped_task_environment.h" |
| 16 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 17 #include "ui/gfx/x/x11_types.h" | 17 #include "ui/gfx/x/x11_types.h" |
| 18 | 18 |
| 19 namespace chromeos { | 19 namespace chromeos { |
| 20 namespace input_method { | 20 namespace input_method { |
| 21 | 21 |
| 22 namespace { | 22 namespace { |
| 23 | 23 |
| 24 class ImeKeyboardTest : public testing::Test, | 24 class ImeKeyboardTest : public testing::Test, |
| 25 public ImeKeyboard::Observer { | 25 public ImeKeyboard::Observer { |
| 26 public: | 26 public: |
| 27 ImeKeyboardTest() { | 27 ImeKeyboardTest() |
| 28 } | 28 : scoped_task_environment_( |
| 29 base::test::ScopedTaskEnvironment::MainThreadType::UI) {} |
| 29 | 30 |
| 30 void SetUp() override { | 31 void SetUp() override { |
| 31 xkey_.reset(ImeKeyboard::Create()); | 32 xkey_.reset(ImeKeyboard::Create()); |
| 32 xkey_->AddObserver(this); | 33 xkey_->AddObserver(this); |
| 33 caps_changed_ = false; | 34 caps_changed_ = false; |
| 34 } | 35 } |
| 35 | 36 |
| 36 void TearDown() override { | 37 void TearDown() override { |
| 37 xkey_->RemoveObserver(this); | 38 xkey_->RemoveObserver(this); |
| 38 xkey_.reset(); | 39 xkey_.reset(); |
| 39 } | 40 } |
| 40 | 41 |
| 41 void OnCapsLockChanged(bool enabled) override { | 42 void OnCapsLockChanged(bool enabled) override { |
| 42 caps_changed_ = true; | 43 caps_changed_ = true; |
| 43 } | 44 } |
| 44 | 45 |
| 45 void VerifyCapsLockChanged(bool changed) { | 46 void VerifyCapsLockChanged(bool changed) { |
| 46 EXPECT_EQ(changed, caps_changed_); | 47 EXPECT_EQ(changed, caps_changed_); |
| 47 caps_changed_ = false; | 48 caps_changed_ = false; |
| 48 } | 49 } |
| 49 | 50 |
| 50 std::unique_ptr<ImeKeyboard> xkey_; | 51 std::unique_ptr<ImeKeyboard> xkey_; |
| 51 base::MessageLoopForUI message_loop_; | 52 base::test::ScopedTaskEnvironment scoped_task_environment_; |
| 52 bool caps_changed_; | 53 bool caps_changed_; |
| 53 }; | 54 }; |
| 54 | 55 |
| 55 // Returns true if X display is available. | 56 // Returns true if X display is available. |
| 56 bool DisplayAvailable() { | 57 bool DisplayAvailable() { |
| 57 return gfx::GetXDisplay() != NULL; | 58 return gfx::GetXDisplay() != NULL; |
| 58 } | 59 } |
| 59 | 60 |
| 60 } // namespace | 61 } // namespace |
| 61 | 62 |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 | 148 |
| 148 // Restore the initial state. | 149 // Restore the initial state. |
| 149 EXPECT_TRUE(xkey_->SetAutoRepeatRate(rate)); | 150 EXPECT_TRUE(xkey_->SetAutoRepeatRate(rate)); |
| 150 EXPECT_TRUE(ImeKeyboard::GetAutoRepeatRateForTesting(&tmp)); | 151 EXPECT_TRUE(ImeKeyboard::GetAutoRepeatRateForTesting(&tmp)); |
| 151 EXPECT_EQ(rate.initial_delay_in_ms, tmp.initial_delay_in_ms); | 152 EXPECT_EQ(rate.initial_delay_in_ms, tmp.initial_delay_in_ms); |
| 152 EXPECT_EQ(rate.repeat_interval_in_ms, tmp.repeat_interval_in_ms); | 153 EXPECT_EQ(rate.repeat_interval_in_ms, tmp.repeat_interval_in_ms); |
| 153 } | 154 } |
| 154 | 155 |
| 155 } // namespace input_method | 156 } // namespace input_method |
| 156 } // namespace chromeos | 157 } // namespace chromeos |
| OLD | NEW |