OLD | NEW |
| (Empty) |
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 | |
14 TEST(InputMethodMenuManagerTest, TestGetSingleton) { | |
15 EXPECT_TRUE(InputMethodMenuManager::GetInstance()); | |
16 } | |
17 | |
18 class MockObserver : public InputMethodMenuManager::Observer { | |
19 public: | |
20 MockObserver() : input_method_menu_item_changed_count_(0) {} | |
21 ~MockObserver() override {} | |
22 | |
23 // Called when the list of menu items is changed. | |
24 void InputMethodMenuItemChanged(InputMethodMenuManager* manager) override { | |
25 input_method_menu_item_changed_count_++; | |
26 } | |
27 int input_method_menu_item_changed_count_; | |
28 }; | |
29 | |
30 class InputMethodMenuManagerStatefulTest : public testing::Test{ | |
31 public: | |
32 InputMethodMenuManagerStatefulTest() | |
33 : observer_(new MockObserver()) {} | |
34 ~InputMethodMenuManagerStatefulTest() override {} | |
35 void SetUp() override { | |
36 menu_manager_ = InputMethodMenuManager::GetInstance(); | |
37 menu_manager_->AddObserver(observer_.get()); | |
38 } | |
39 | |
40 void TearDown() override { menu_manager_->RemoveObserver(observer_.get()); } | |
41 | |
42 InputMethodMenuManager* menu_manager_; | |
43 scoped_ptr<MockObserver> observer_; | |
44 }; | |
45 | |
46 TEST_F(InputMethodMenuManagerStatefulTest, AddAndObserve) { | |
47 EXPECT_EQ(observer_->input_method_menu_item_changed_count_, 0); | |
48 menu_manager_->SetCurrentInputMethodMenuItemList(InputMethodMenuItemList()); | |
49 EXPECT_EQ(observer_->input_method_menu_item_changed_count_, 1); | |
50 } | |
51 | |
52 TEST_F(InputMethodMenuManagerStatefulTest, AddAndCheckExists) { | |
53 InputMethodMenuItemList list; | |
54 list.push_back(InputMethodMenuItem("key1", "label1", false, false)); | |
55 list.push_back(InputMethodMenuItem("key2", "label2", false, false)); | |
56 menu_manager_->SetCurrentInputMethodMenuItemList(list); | |
57 EXPECT_EQ(menu_manager_->GetCurrentInputMethodMenuItemList().size(), 2U); | |
58 EXPECT_EQ( | |
59 menu_manager_->GetCurrentInputMethodMenuItemList().at(0).ToString(), | |
60 "key=key1, label=label1, " | |
61 "is_selection_item=0, is_selection_item_checked=0"); | |
62 EXPECT_EQ( | |
63 menu_manager_->GetCurrentInputMethodMenuItemList().at(1).ToString(), | |
64 "key=key2, label=label2, " | |
65 "is_selection_item=0, is_selection_item_checked=0"); | |
66 | |
67 EXPECT_TRUE(menu_manager_->HasInputMethodMenuItemForKey("key1")); | |
68 EXPECT_TRUE(menu_manager_->HasInputMethodMenuItemForKey("key2")); | |
69 EXPECT_FALSE(menu_manager_->HasInputMethodMenuItemForKey("key-not-exist")); | |
70 } | |
71 | |
72 } // namespace ime | |
73 } // namespace ash | |
OLD | NEW |