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
3 // found in the LICENSE file.
5 #include "ash/ime/input_method_menu_manager.h"
7 #include "base/logging.h"
8 #include "base/memory/scoped_ptr.h"
9 #include "testing/gtest/include/gtest/gtest.h"
14 TEST(InputMethodMenuManagerTest
, TestGetSingleton
) {
15 EXPECT_TRUE(InputMethodMenuManager::GetInstance());
18 class MockObserver
: public InputMethodMenuManager::Observer
{
20 MockObserver() : input_method_menu_item_changed_count_(0) {}
21 virtual ~MockObserver() {}
23 // Called when the list of menu items is changed.
24 virtual void InputMethodMenuItemChanged(
25 InputMethodMenuManager
* manager
) OVERRIDE
{
26 input_method_menu_item_changed_count_
++;
28 int input_method_menu_item_changed_count_
;
31 class InputMethodMenuManagerStatefulTest
: public testing::Test
{
33 InputMethodMenuManagerStatefulTest()
34 : observer_(new MockObserver()) {}
35 virtual ~InputMethodMenuManagerStatefulTest() {}
36 virtual void SetUp() OVERRIDE
{
37 menu_manager_
= InputMethodMenuManager::GetInstance();
38 menu_manager_
->AddObserver(observer_
.get());
41 virtual void TearDown() OVERRIDE
{
42 menu_manager_
->RemoveObserver(observer_
.get());
45 InputMethodMenuManager
* menu_manager_
;
46 scoped_ptr
<MockObserver
> observer_
;
49 TEST_F(InputMethodMenuManagerStatefulTest
, AddAndObserve
) {
50 EXPECT_EQ(observer_
->input_method_menu_item_changed_count_
, 0);
51 menu_manager_
->SetCurrentInputMethodMenuItemList(InputMethodMenuItemList());
52 EXPECT_EQ(observer_
->input_method_menu_item_changed_count_
, 1);
55 TEST_F(InputMethodMenuManagerStatefulTest
, AddAndCheckExists
) {
56 InputMethodMenuItemList list
;
57 list
.push_back(InputMethodMenuItem("key1", "label1", false, false));
58 list
.push_back(InputMethodMenuItem("key2", "label2", false, false));
59 menu_manager_
->SetCurrentInputMethodMenuItemList(list
);
60 EXPECT_EQ(menu_manager_
->GetCurrentInputMethodMenuItemList().size(), 2U);
62 menu_manager_
->GetCurrentInputMethodMenuItemList().at(0).ToString(),
63 "key=key1, label=label1, "
64 "is_selection_item=0, is_selection_item_checked=0");
66 menu_manager_
->GetCurrentInputMethodMenuItemList().at(1).ToString(),
67 "key=key2, label=label2, "
68 "is_selection_item=0, is_selection_item_checked=0");
70 EXPECT_TRUE(menu_manager_
->HasInputMethodMenuItemForKey("key1"));
71 EXPECT_TRUE(menu_manager_
->HasInputMethodMenuItemForKey("key2"));
72 EXPECT_FALSE(menu_manager_
->HasInputMethodMenuItemForKey("key-not-exist"));