| 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 using base::UTF8ToUTF16; |
| 16 |
| 17 namespace ash { |
| 18 |
| 19 class ImeMenuTrayTest : public test::AshTestBase { |
| 20 public: |
| 21 ImeMenuTrayTest() {} |
| 22 ~ImeMenuTrayTest() override {} |
| 23 |
| 24 ImeMenuTray* ime_menu_tray() { return ime_menu_tray_.get(); } |
| 25 |
| 26 // test::AshTestBase: |
| 27 void SetUp() override { |
| 28 test::AshTestBase::SetUp(); |
| 29 ime_menu_tray_.reset(new ImeMenuTray(GetPrimaryShelf())); |
| 30 } |
| 31 |
| 32 void TearDown() override { |
| 33 ime_menu_tray_.reset(); |
| 34 test::AshTestBase::TearDown(); |
| 35 } |
| 36 |
| 37 protected: |
| 38 // Returns true if the IME menu tray is visible. |
| 39 bool IsVisible() { return ime_menu_tray_->visible(); } |
| 40 |
| 41 // Returns the label text of the tray. |
| 42 const base::string16& GetTrayText() { return ime_menu_tray_->label_->text(); } |
| 43 |
| 44 // Returns true if the background color of the tray is active. |
| 45 bool IsTrayBackgroundActive() { |
| 46 return ime_menu_tray_->draw_background_as_active(); |
| 47 } |
| 48 |
| 49 private: |
| 50 std::unique_ptr<ImeMenuTray> ime_menu_tray_; |
| 51 |
| 52 DISALLOW_COPY_AND_ASSIGN(ImeMenuTrayTest); |
| 53 }; |
| 54 |
| 55 // Tests that visibility of IME menu tray should be consistent with the |
| 56 // activation of the IME menu. |
| 57 TEST_F(ImeMenuTrayTest, ImeMenuTrayVisibility) { |
| 58 ASSERT_FALSE(IsVisible()); |
| 59 |
| 60 WmShell::Get()->system_tray_notifier()->NotifyRefreshIMEMenu(true); |
| 61 EXPECT_TRUE(IsVisible()); |
| 62 |
| 63 WmShell::Get()->system_tray_notifier()->NotifyRefreshIMEMenu(false); |
| 64 EXPECT_FALSE(IsVisible()); |
| 65 } |
| 66 |
| 67 // Tests that IME menu tray shows the right info of the current IME. |
| 68 TEST_F(ImeMenuTrayTest, TrayLabelTest) { |
| 69 WmShell::Get()->system_tray_notifier()->NotifyRefreshIMEMenu(true); |
| 70 ASSERT_TRUE(IsVisible()); |
| 71 |
| 72 // Changes the input method to "ime1". |
| 73 IMEInfo info1; |
| 74 info1.id = "ime1"; |
| 75 info1.name = UTF8ToUTF16("English"); |
| 76 info1.medium_name = UTF8ToUTF16("English"); |
| 77 info1.short_name = UTF8ToUTF16("US"); |
| 78 info1.third_party = false; |
| 79 info1.selected = true; |
| 80 GetSystemTrayDelegate()->SetCurrentIME(info1); |
| 81 WmShell::Get()->system_tray_notifier()->NotifyRefreshIME(); |
| 82 EXPECT_EQ(UTF8ToUTF16("US"), GetTrayText()); |
| 83 |
| 84 // Changes the input method to a third-party IME extension. |
| 85 IMEInfo info2; |
| 86 info2.id = "ime2"; |
| 87 info2.name = UTF8ToUTF16("English UK"); |
| 88 info2.medium_name = UTF8ToUTF16("English UK"); |
| 89 info2.short_name = UTF8ToUTF16("UK"); |
| 90 info2.third_party = true; |
| 91 info2.selected = true; |
| 92 GetSystemTrayDelegate()->SetCurrentIME(info2); |
| 93 WmShell::Get()->system_tray_notifier()->NotifyRefreshIME(); |
| 94 EXPECT_EQ(UTF8ToUTF16("UK*"), GetTrayText()); |
| 95 } |
| 96 |
| 97 // Tests that IME menu tray changes background color when tapped/clicked. And |
| 98 // tests that the background color becomes 'inactive' when disabling the IME |
| 99 // menu feature. |
| 100 TEST_F(ImeMenuTrayTest, PerformAction) { |
| 101 WmShell::Get()->system_tray_notifier()->NotifyRefreshIMEMenu(true); |
| 102 ASSERT_TRUE(IsVisible()); |
| 103 ASSERT_FALSE(IsTrayBackgroundActive()); |
| 104 |
| 105 ui::GestureEvent tap(0, 0, 0, base::TimeTicks(), |
| 106 ui::GestureEventDetails(ui::ET_GESTURE_TAP)); |
| 107 ime_menu_tray()->PerformAction(tap); |
| 108 EXPECT_TRUE(IsTrayBackgroundActive()); |
| 109 |
| 110 ime_menu_tray()->PerformAction(tap); |
| 111 EXPECT_FALSE(IsTrayBackgroundActive()); |
| 112 |
| 113 // If disabling the IME menu feature when the menu tray is activated, the tray |
| 114 // element will be deactivated. |
| 115 ime_menu_tray()->PerformAction(tap); |
| 116 EXPECT_TRUE(IsTrayBackgroundActive()); |
| 117 WmShell::Get()->system_tray_notifier()->NotifyRefreshIMEMenu(false); |
| 118 EXPECT_FALSE(IsVisible()); |
| 119 EXPECT_FALSE(IsTrayBackgroundActive()); |
| 120 } |
| 121 |
| 122 } // namespace ash |
| OLD | NEW |