Chromium Code Reviews| Index: ash/common/system/chromeos/ime_menu/ime_menu_tray_unittest.cc |
| diff --git a/ash/common/system/chromeos/ime_menu/ime_menu_tray_unittest.cc b/ash/common/system/chromeos/ime_menu/ime_menu_tray_unittest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..c5535ec9b0298a6dc1fb9f7d431887f1abebed79 |
| --- /dev/null |
| +++ b/ash/common/system/chromeos/ime_menu/ime_menu_tray_unittest.cc |
| @@ -0,0 +1,110 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "ash/common/system/chromeos/ime_menu/ime_menu_tray.h" |
| + |
| +#include "ash/common/system/tray/system_tray_notifier.h" |
| +#include "ash/common/wm_shell.h" |
| +#include "ash/test/ash_test_base.h" |
| +#include "ash/test/test_system_tray_delegate.h" |
| +#include "base/strings/utf_string_conversions.h" |
| +#include "ui/events/event.h" |
| +#include "ui/views/controls/label.h" |
| + |
| +namespace ash { |
| + |
| +class ImeMenuTrayTest : public test::AshTestBase { |
| + public: |
| + ImeMenuTrayTest() {} |
| + ~ImeMenuTrayTest() override {} |
| + |
| + ImeMenuTray* ime_menu_tray() { return ime_menu_tray_.get(); } |
| + |
| + // test::AshTestBase: |
| + void SetUp() override { |
| + test::AshTestBase::SetUp(); |
| + ime_menu_tray_.reset(new ImeMenuTray(GetPrimaryShelf())); |
| + } |
| + |
| + void TearDown() override { |
| + ime_menu_tray_.reset(); |
| + test::AshTestBase::TearDown(); |
| + } |
| + |
| + protected: |
| + // Returns true if the IME menu tray is visible. |
| + bool IsVisible() { return ime_menu_tray_->visible(); } |
| + |
| + // Returns the label text of the tray. |
| + const base::string16& GetTrayText() { return ime_menu_tray_->label_->text(); } |
| + |
| + // Returns true if the background color of the tray is active. |
| + bool IsTrayBackgroundActive() { |
| + return ime_menu_tray_->draw_background_as_active(); |
| + } |
| + |
| + private: |
| + std::unique_ptr<ImeMenuTray> ime_menu_tray_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(ImeMenuTrayTest); |
| +}; |
| + |
| +// Tests that visibility of IME menu tray should be consistent with the |
| +// activation of the IME menu. |
|
James Cook
2016/07/12 17:53:37
Thanks for writing comments about each test. It ma
|
| +TEST_F(ImeMenuTrayTest, ImeMenuTrayVisibility) { |
| + ASSERT_FALSE(IsVisible()); |
| + |
| + WmShell::Get()->system_tray_notifier()->NotifyRefreshIMEMenu(true); |
| + ASSERT_TRUE(IsVisible()); |
|
James Cook
2016/07/12 17:53:37
Use EXPECT_TRUE/EXPECT_FALSE for test expectations
Azure Wei
2016/07/14 02:57:02
Done.
|
| + |
| + WmShell::Get()->system_tray_notifier()->NotifyRefreshIMEMenu(false); |
| + ASSERT_FALSE(IsVisible()); |
| +} |
| + |
| +// Tests that IME menu tray shows the right info of the current IME. |
| +TEST_F(ImeMenuTrayTest, TrayLabelTest) { |
| + WmShell::Get()->system_tray_notifier()->NotifyRefreshIMEMenu(true); |
| + ASSERT_TRUE(IsVisible()); |
| + |
| + // Changes the input method to "ime1". |
| + IMEInfo info1; |
| + info1.id = "ime1"; |
| + info1.name = base::UTF8ToUTF16("English"); |
| + info1.medium_name = base::UTF8ToUTF16("English"); |
| + info1.short_name = base::UTF8ToUTF16("US"); |
| + info1.third_party = false; |
| + info1.selected = true; |
| + GetSystemTrayDelegate()->SetCurrentIME(info1); |
| + WmShell::Get()->system_tray_notifier()->NotifyRefreshIME(); |
| + ASSERT_EQ(info1.short_name, GetTrayText()); |
| + |
| + // Changes the input method to a third-party IME extension. |
| + IMEInfo info2; |
| + info2.id = "ime2"; |
| + info2.name = base::UTF8ToUTF16("English UK"); |
| + info2.medium_name = base::UTF8ToUTF16("English UK"); |
| + info2.short_name = base::UTF8ToUTF16("UK"); |
| + info2.third_party = true; |
| + info2.selected = true; |
| + GetSystemTrayDelegate()->SetCurrentIME(info2); |
| + WmShell::Get()->system_tray_notifier()->NotifyRefreshIME(); |
| + ASSERT_EQ(info2.short_name + base::UTF8ToUTF16("*"), GetTrayText()); |
|
James Cook
2016/07/12 17:53:37
optional nit: It's OK to copy/paste things like st
Azure Wei
2016/07/14 02:57:02
Done. Thanks.
|
| +} |
| + |
|
James Cook
2016/07/12 17:53:37
Can you add a test that checks that the label has
Azure Wei
2016/07/14 02:57:02
Removed the codes of setting the label's border. I
|
| +// Tests that IME menu tray changes background color when tapped/clicked. |
| +TEST_F(ImeMenuTrayTest, PerformAction) { |
| + WmShell::Get()->system_tray_notifier()->NotifyRefreshIMEMenu(true); |
| + ASSERT_TRUE(IsVisible()); |
| + ASSERT_FALSE(IsTrayBackgroundActive()); |
| + |
| + ui::GestureEvent tap(0, 0, 0, base::TimeTicks(), |
| + ui::GestureEventDetails(ui::ET_GESTURE_TAP)); |
| + ime_menu_tray()->PerformAction(tap); |
| + ASSERT_TRUE(IsTrayBackgroundActive()); |
| + |
| + ime_menu_tray()->PerformAction(tap); |
| + ASSERT_FALSE(IsTrayBackgroundActive()); |
| +} |
|
James Cook
2016/07/12 17:53:37
Nice test suite. Easy to read.
|
| + |
| +} // namespace ash |