OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "base/logging.h" |
| 6 #include "testing/gtest/include/gtest/gtest.h" |
| 7 #include "ui/base/ime/chromeos/fake_ime_keyboard.h" |
| 8 #include "ui/base/ime/chromeos/ime_keyboard.h" |
| 9 |
| 10 namespace chromeos { |
| 11 namespace input_method { |
| 12 |
| 13 namespace { |
| 14 |
| 15 class ImeKeyboardTest : public testing::Test, |
| 16 public ImeKeyboard::Observer { |
| 17 public: |
| 18 void SetUp() override { |
| 19 xkey_.reset(new FakeImeKeyboard()); |
| 20 xkey_->AddObserver(this); |
| 21 caps_changed_ = false; |
| 22 } |
| 23 void TearDown() override { |
| 24 xkey_->RemoveObserver(this); |
| 25 xkey_.reset(); |
| 26 } |
| 27 void OnCapsLockChanged(bool enabled) override { |
| 28 caps_changed_ = true; |
| 29 } |
| 30 void OnLayoutChanging(const std::string& layout_name) override { |
| 31 layout_changed_ = true; |
| 32 } |
| 33 void VerifyCapsLockChanged(bool changed) { |
| 34 EXPECT_EQ(changed, caps_changed_); |
| 35 caps_changed_ = false; |
| 36 } |
| 37 void VerifyLayoutChanged(bool changed) { |
| 38 EXPECT_EQ(changed, layout_changed_); |
| 39 layout_changed_ = false; |
| 40 } |
| 41 std::unique_ptr<ImeKeyboard> xkey_; |
| 42 bool caps_changed_; |
| 43 bool layout_changed_; |
| 44 }; |
| 45 |
| 46 // Tests CheckLayoutName() function. |
| 47 TEST_F(ImeKeyboardTest, TestObserver) { |
| 48 xkey_->SetCapsLockEnabled(true); |
| 49 VerifyCapsLockChanged(true); |
| 50 xkey_->SetCurrentKeyboardLayoutByName("foo"); |
| 51 VerifyLayoutChanged(true); |
| 52 } |
| 53 |
| 54 } // namespace |
| 55 |
| 56 } // namespace input_method |
| 57 } // namespace chromeos |
OLD | NEW |