Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 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/common/system/chromeos/ime_menu/ime_menu_tray.h" | |
| 6 | |
| 7 #include "ash/common/system/tray/system_tray_notifier.h" | |
| 8 #include "ash/common/wm_shell.h" | |
| 9 #include "ash/test/ash_test_base.h" | |
| 10 #include "ash/test/test_system_tray_delegate.h" | |
| 11 #include "base/strings/utf_string_conversions.h" | |
| 12 #include "ui/events/event.h" | |
| 13 #include "ui/views/controls/label.h" | |
| 14 | |
| 15 namespace ash { | |
| 16 | |
| 17 class ImeMenuTrayTest : public test::AshTestBase { | |
| 18 public: | |
| 19 ImeMenuTrayTest() {} | |
| 20 ~ImeMenuTrayTest() override {} | |
| 21 | |
| 22 ImeMenuTray* ime_menu_tray() { return ime_menu_tray_.get(); } | |
| 23 | |
| 24 // test::AshTestBase: | |
| 25 void SetUp() override { | |
| 26 test::AshTestBase::SetUp(); | |
| 27 ime_menu_tray_.reset(new ImeMenuTray(GetPrimaryShelf())); | |
| 28 } | |
| 29 | |
| 30 void TearDown() override { | |
| 31 ime_menu_tray_.reset(); | |
| 32 test::AshTestBase::TearDown(); | |
| 33 } | |
| 34 | |
| 35 protected: | |
| 36 // Returns true if the IME menu tray is visible. | |
| 37 bool IsVisible() { return ime_menu_tray_->visible(); } | |
| 38 | |
| 39 // Returns the label text of the tray. | |
| 40 const base::string16& GetTrayText() { return ime_menu_tray_->label_->text(); } | |
| 41 | |
| 42 // Returns true if the background color of the tray is active. | |
| 43 bool IsTrayBackgroundActive() { | |
| 44 return ime_menu_tray_->draw_background_as_active(); | |
| 45 } | |
| 46 | |
| 47 private: | |
| 48 std::unique_ptr<ImeMenuTray> ime_menu_tray_; | |
| 49 | |
| 50 DISALLOW_COPY_AND_ASSIGN(ImeMenuTrayTest); | |
| 51 }; | |
| 52 | |
| 53 // Tests that visibility of IME menu tray should be consistent with the | |
| 54 // activation of the IME menu. | |
|
James Cook
2016/07/12 17:53:37
Thanks for writing comments about each test. It ma
| |
| 55 TEST_F(ImeMenuTrayTest, ImeMenuTrayVisibility) { | |
| 56 ASSERT_FALSE(IsVisible()); | |
| 57 | |
| 58 WmShell::Get()->system_tray_notifier()->NotifyRefreshIMEMenu(true); | |
| 59 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.
| |
| 60 | |
| 61 WmShell::Get()->system_tray_notifier()->NotifyRefreshIMEMenu(false); | |
| 62 ASSERT_FALSE(IsVisible()); | |
| 63 } | |
| 64 | |
| 65 // Tests that IME menu tray shows the right info of the current IME. | |
| 66 TEST_F(ImeMenuTrayTest, TrayLabelTest) { | |
| 67 WmShell::Get()->system_tray_notifier()->NotifyRefreshIMEMenu(true); | |
| 68 ASSERT_TRUE(IsVisible()); | |
| 69 | |
| 70 // Changes the input method to "ime1". | |
| 71 IMEInfo info1; | |
| 72 info1.id = "ime1"; | |
| 73 info1.name = base::UTF8ToUTF16("English"); | |
| 74 info1.medium_name = base::UTF8ToUTF16("English"); | |
| 75 info1.short_name = base::UTF8ToUTF16("US"); | |
| 76 info1.third_party = false; | |
| 77 info1.selected = true; | |
| 78 GetSystemTrayDelegate()->SetCurrentIME(info1); | |
| 79 WmShell::Get()->system_tray_notifier()->NotifyRefreshIME(); | |
| 80 ASSERT_EQ(info1.short_name, GetTrayText()); | |
| 81 | |
| 82 // Changes the input method to a third-party IME extension. | |
| 83 IMEInfo info2; | |
| 84 info2.id = "ime2"; | |
| 85 info2.name = base::UTF8ToUTF16("English UK"); | |
| 86 info2.medium_name = base::UTF8ToUTF16("English UK"); | |
| 87 info2.short_name = base::UTF8ToUTF16("UK"); | |
| 88 info2.third_party = true; | |
| 89 info2.selected = true; | |
| 90 GetSystemTrayDelegate()->SetCurrentIME(info2); | |
| 91 WmShell::Get()->system_tray_notifier()->NotifyRefreshIME(); | |
| 92 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.
| |
| 93 } | |
| 94 | |
|
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
| |
| 95 // Tests that IME menu tray changes background color when tapped/clicked. | |
| 96 TEST_F(ImeMenuTrayTest, PerformAction) { | |
| 97 WmShell::Get()->system_tray_notifier()->NotifyRefreshIMEMenu(true); | |
| 98 ASSERT_TRUE(IsVisible()); | |
| 99 ASSERT_FALSE(IsTrayBackgroundActive()); | |
| 100 | |
| 101 ui::GestureEvent tap(0, 0, 0, base::TimeTicks(), | |
| 102 ui::GestureEventDetails(ui::ET_GESTURE_TAP)); | |
| 103 ime_menu_tray()->PerformAction(tap); | |
| 104 ASSERT_TRUE(IsTrayBackgroundActive()); | |
| 105 | |
| 106 ime_menu_tray()->PerformAction(tap); | |
| 107 ASSERT_FALSE(IsTrayBackgroundActive()); | |
| 108 } | |
|
James Cook
2016/07/12 17:53:37
Nice test suite. Easy to read.
| |
| 109 | |
| 110 } // namespace ash | |
| OLD | NEW |