Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / ui / chromeos / ime / input_method_menu_manager_unittest.cc
blobb6bf5efa387b54e74411446fc21e82d340f1fc86
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 "ui/chromeos/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"
11 namespace ui {
12 namespace ime {
14 TEST(InputMethodMenuManagerTest, TestGetSingleton) {
15 EXPECT_TRUE(InputMethodMenuManager::GetInstance());
18 class MockObserver : public InputMethodMenuManager::Observer {
19 public:
20 MockObserver() : input_method_menu_item_changed_count_(0) {}
21 ~MockObserver() override {}
23 // Called when the list of menu items is changed.
24 void InputMethodMenuItemChanged(InputMethodMenuManager* manager) override {
25 input_method_menu_item_changed_count_++;
27 int input_method_menu_item_changed_count_;
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());
40 void TearDown() override { menu_manager_->RemoveObserver(observer_.get()); }
42 InputMethodMenuManager* menu_manager_;
43 scoped_ptr<MockObserver> observer_;
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);
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");
67 EXPECT_TRUE(menu_manager_->HasInputMethodMenuItemForKey("key1"));
68 EXPECT_TRUE(menu_manager_->HasInputMethodMenuItemForKey("key2"));
69 EXPECT_FALSE(menu_manager_->HasInputMethodMenuItemForKey("key-not-exist"));
72 } // namespace ime
73 } // namespace ui