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