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.
4
5 #include "ash/ime/input_method_menu_manager.h"
6
7 #include "base/logging.h"
8 #include "base/memory/scoped_ptr.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10
11 namespace ash {
12 namespace ime {
13
TEST(InputMethodMenuManagerTest,TestGetSingleton)14 TEST(InputMethodMenuManagerTest, TestGetSingleton) {
15 EXPECT_TRUE(InputMethodMenuManager::GetInstance());
16 }
17
18 class MockObserver : public InputMethodMenuManager::Observer {
19 public:
MockObserver()20 MockObserver() : input_method_menu_item_changed_count_(0) {}
~MockObserver()21 virtual ~MockObserver() {}
22
23 // Called when the list of menu items is changed.
InputMethodMenuItemChanged(InputMethodMenuManager * manager)24 virtual void InputMethodMenuItemChanged(
25 InputMethodMenuManager* manager) OVERRIDE {
26 input_method_menu_item_changed_count_++;
27 }
28 int input_method_menu_item_changed_count_;
29 };
30
31 class InputMethodMenuManagerStatefulTest : public testing::Test{
32 public:
InputMethodMenuManagerStatefulTest()33 InputMethodMenuManagerStatefulTest()
34 : observer_(new MockObserver()) {}
~InputMethodMenuManagerStatefulTest()35 virtual ~InputMethodMenuManagerStatefulTest() {}
SetUp()36 virtual void SetUp() OVERRIDE {
37 menu_manager_ = InputMethodMenuManager::GetInstance();
38 menu_manager_->AddObserver(observer_.get());
39 }
40
TearDown()41 virtual void TearDown() OVERRIDE {
42 menu_manager_->RemoveObserver(observer_.get());
43 }
44
45 InputMethodMenuManager* menu_manager_;
46 scoped_ptr<MockObserver> observer_;
47 };
48
TEST_F(InputMethodMenuManagerStatefulTest,AddAndObserve)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);
53 }
54
TEST_F(InputMethodMenuManagerStatefulTest,AddAndCheckExists)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);
61 EXPECT_EQ(
62 menu_manager_->GetCurrentInputMethodMenuItemList().at(0).ToString(),
63 "key=key1, label=label1, "
64 "is_selection_item=0, is_selection_item_checked=0");
65 EXPECT_EQ(
66 menu_manager_->GetCurrentInputMethodMenuItemList().at(1).ToString(),
67 "key=key2, label=label2, "
68 "is_selection_item=0, is_selection_item_checked=0");
69
70 EXPECT_TRUE(menu_manager_->HasInputMethodMenuItemForKey("key1"));
71 EXPECT_TRUE(menu_manager_->HasInputMethodMenuItemForKey("key2"));
72 EXPECT_FALSE(menu_manager_->HasInputMethodMenuItemForKey("key-not-exist"));
73 }
74
75 } // namespace ime
76 } // namespace ash
77