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
3 // found in the LICENSE file.
5 #include "chrome/browser/ui/ash/caps_lock_delegate_chromeos.h"
7 #include "chrome/test/base/in_process_browser_test.h"
8 #include "chrome/test/base/ui_test_utils.h"
9 #include "chromeos/ime/mock_xkeyboard.h"
13 class CapsLockDelegateTest
: public InProcessBrowserTest
{
15 CapsLockDelegateTest() : initial_caps_lock_state_(false) {
18 virtual void SetUp() OVERRIDE
{
19 delegate_
.reset(new CapsLockDelegate(&xkeyboard_
));
20 // Force CapsLockDelegate::ToggleCapsLock() to toggle the lock state.
21 delegate_
->set_is_running_on_chromeos_for_test(true);
23 virtual void TearDown() OVERRIDE
{
28 const bool initial_caps_lock_state_
;
29 chromeos::input_method::MockXKeyboard xkeyboard_
;
30 scoped_ptr
<CapsLockDelegate
> delegate_
;
32 DISALLOW_COPY_AND_ASSIGN(CapsLockDelegateTest
);
35 // Check if ToggleCapsLock() really changes the lock state.
36 IN_PROC_BROWSER_TEST_F(CapsLockDelegateTest
, TestCapsLock
) {
37 EXPECT_EQ(initial_caps_lock_state_
, delegate_
->caps_lock_is_on_for_test());
38 delegate_
->ToggleCapsLock();
39 EXPECT_EQ(!initial_caps_lock_state_
, xkeyboard_
.CapsLockIsEnabled());
40 delegate_
->OnCapsLockChange(!initial_caps_lock_state_
);
41 EXPECT_EQ(!initial_caps_lock_state_
, delegate_
->caps_lock_is_on_for_test());
42 delegate_
->ToggleCapsLock();
43 delegate_
->OnCapsLockChange(initial_caps_lock_state_
);
44 EXPECT_EQ(initial_caps_lock_state_
, xkeyboard_
.CapsLockIsEnabled());
45 EXPECT_EQ(initial_caps_lock_state_
, delegate_
->caps_lock_is_on_for_test());
47 // Check if SetCapsLockEnabled really changes the lock state.
48 delegate_
->SetCapsLockEnabled(!initial_caps_lock_state_
);
49 EXPECT_EQ(!initial_caps_lock_state_
, delegate_
->caps_lock_is_on_for_test());
50 EXPECT_EQ(!initial_caps_lock_state_
, xkeyboard_
.CapsLockIsEnabled());
51 EXPECT_EQ(!initial_caps_lock_state_
, delegate_
->IsCapsLockEnabled());
52 delegate_
->SetCapsLockEnabled(initial_caps_lock_state_
);
53 EXPECT_EQ(initial_caps_lock_state_
, delegate_
->caps_lock_is_on_for_test());
54 EXPECT_EQ(initial_caps_lock_state_
, xkeyboard_
.CapsLockIsEnabled());
55 EXPECT_EQ(initial_caps_lock_state_
, delegate_
->IsCapsLockEnabled());