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