1// Copyright 2013 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 "chrome/browser/ui/libgtk2ui/x11_input_method_context_impl_gtk2.h"
6
7#include "base/strings/utf_string_conversions.h"
8#include "testing/gtest/include/gtest/gtest.h"
9
10namespace libgtk2ui {
11
12class X11InputMethodContextImplGtk2FriendTest : public testing::Test {
13};
14
15TEST_F(X11InputMethodContextImplGtk2FriendTest, GtkCommitSignalTrap) {
16  libgtk2ui::X11InputMethodContextImplGtk2::GtkCommitSignalTrap trap;
17
18  // Test the initial state.
19  EXPECT_FALSE(trap.IsSignalCaught());
20  EXPECT_FALSE(trap.Trap(base::string16()));
21  EXPECT_FALSE(trap.IsSignalCaught());
22
23  // Cases which don't match the target keyval.
24  trap.StartTrap('t');
25  EXPECT_FALSE(trap.Trap(base::UTF8ToUTF16("T")));
26  EXPECT_FALSE(trap.IsSignalCaught());
27  EXPECT_FALSE(trap.Trap(base::UTF8ToUTF16("true")));
28  EXPECT_FALSE(trap.IsSignalCaught());
29
30  // Do not catch when the trap is not activated.
31  trap.StopTrap();
32  EXPECT_FALSE(trap.Trap(base::UTF8ToUTF16("t")));
33  EXPECT_FALSE(trap.IsSignalCaught());
34
35  // Successive calls don't break anything.
36  trap.StopTrap();
37  trap.StopTrap();
38  EXPECT_FALSE(trap.Trap(base::UTF8ToUTF16("t")));
39  EXPECT_FALSE(trap.IsSignalCaught());
40  trap.StartTrap('f');
41  trap.StartTrap('t');
42  EXPECT_TRUE(trap.Trap(base::UTF8ToUTF16("t")));
43  EXPECT_TRUE(trap.IsSignalCaught());
44
45  // StartTrap() resets the state.
46  trap.StartTrap('t');
47  EXPECT_FALSE(trap.IsSignalCaught());
48  // Many times calls to Trap() are okay.
49  EXPECT_FALSE(trap.Trap(base::UTF8ToUTF16("f")));
50  EXPECT_FALSE(trap.IsSignalCaught());
51  EXPECT_TRUE(trap.Trap(base::UTF8ToUTF16("t")));
52  EXPECT_TRUE(trap.IsSignalCaught());
53}
54
55}  // namespace libgtk2ui
56