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/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/system/status_area_widget.h" |
| 10 #include "ash/system/tray/system_tray.h" |
| 11 #include "ash/test/ash_test_base.h" |
| 12 #include "ash/test/status_area_widget_test_helper.h" |
| 13 #include "ash/test/test_system_tray_delegate.h" |
| 14 #include "base/strings/utf_string_conversions.h" |
| 15 #include "base/time/time.h" |
| 16 #include "ui/aura/window.h" |
| 17 #include "ui/events/event.h" |
| 18 #include "ui/views/controls/label.h" |
| 19 #include "ui/wm/core/window_util.h" |
| 20 |
| 21 namespace ash { |
| 22 |
| 23 namespace { |
| 24 |
| 25 ImeMenuTray* GetTray() { |
| 26 return StatusAreaWidgetTestHelper::GetStatusAreaWidget()->ime_menu_tray(); |
| 27 } |
| 28 |
| 29 } // namespace |
| 30 |
| 31 class ImeMenuTrayTest : public test::AshTestBase { |
| 32 public: |
| 33 ImeMenuTrayTest() {} |
| 34 ~ImeMenuTrayTest() override {} |
| 35 |
| 36 protected: |
| 37 // Returns the label text of the tray. |
| 38 const base::string16& GetTrayText() { return GetTray()->label_->text(); } |
| 39 |
| 40 // Returns true if the background color of the tray is active. |
| 41 bool IsTrayBackgroundActive() { |
| 42 return GetTray()->draw_background_as_active(); |
| 43 } |
| 44 |
| 45 private: |
| 46 DISALLOW_COPY_AND_ASSIGN(ImeMenuTrayTest); |
| 47 }; |
| 48 |
| 49 TEST_F(ImeMenuTrayTest, ImeMenuTrayVisibility) { |
| 50 ASSERT_TRUE(GetTray()); |
| 51 ASSERT_FALSE(GetTray()->visible()); |
| 52 |
| 53 WmShell::Get()->system_tray_notifier()->NotifyRefreshIMEMenu(true); |
| 54 ASSERT_TRUE(GetTray()->visible()); |
| 55 |
| 56 WmShell::Get()->system_tray_notifier()->NotifyRefreshIMEMenu(false); |
| 57 ASSERT_FALSE(GetTray()->visible()); |
| 58 } |
| 59 |
| 60 TEST_F(ImeMenuTrayTest, TrayLabelTest) { |
| 61 ASSERT_TRUE(GetTray()); |
| 62 ASSERT_TRUE(GetSystemTrayDelegate()); |
| 63 |
| 64 std::unique_ptr<aura::Window> window(CreateTestWindowInShellWithId(0)); |
| 65 GetTray()->SetImeWindow(window.get()); |
| 66 |
| 67 // Changes the input method to "ime1". |
| 68 IMEInfo info1; |
| 69 info1.id = "ime1"; |
| 70 info1.name = base::UTF8ToUTF16("English"); |
| 71 info1.medium_name = base::UTF8ToUTF16("English"); |
| 72 info1.short_name = base::UTF8ToUTF16("US"); |
| 73 info1.third_party = false; |
| 74 info1.selected = true; |
| 75 GetSystemTrayDelegate()->SetCurrentIME(info1); |
| 76 WmShell::Get()->system_tray_notifier()->NotifyRefreshIME(); |
| 77 ASSERT_EQ(info1.short_name, GetTrayText()); |
| 78 |
| 79 // Changes the input method to a third-party IME extension. |
| 80 IMEInfo info2; |
| 81 info2.id = "ime2"; |
| 82 info2.name = base::UTF8ToUTF16("English UK"); |
| 83 info2.medium_name = base::UTF8ToUTF16("English UK"); |
| 84 info2.short_name = base::UTF8ToUTF16("UK"); |
| 85 info2.third_party = true; |
| 86 info2.selected = true; |
| 87 GetSystemTrayDelegate()->SetCurrentIME(info2); |
| 88 WmShell::Get()->system_tray_notifier()->NotifyRefreshIME(); |
| 89 ASSERT_EQ(info2.short_name + base::UTF8ToUTF16("*"), GetTrayText()); |
| 90 } |
| 91 |
| 92 TEST_F(ImeMenuTrayTest, PerformAction) { |
| 93 ASSERT_TRUE(GetTray()); |
| 94 ASSERT_TRUE(GetSystemTrayDelegate()); |
| 95 |
| 96 std::unique_ptr<aura::Window> window(CreateTestWindowInShellWithId(0)); |
| 97 ::wm::ActivateWindow(window.get()); |
| 98 ASSERT_TRUE(::wm::IsActiveWindow(window.get())); |
| 99 |
| 100 GetTray()->SetImeWindow(window.get()); |
| 101 WmShell::Get()->system_tray_notifier()->NotifyRefreshIMEMenu(true); |
| 102 ASSERT_TRUE(GetTray()->visible()); |
| 103 ASSERT_TRUE(IsTrayBackgroundActive()); |
| 104 |
| 105 // Tabs on the tray when the window is minimized. |
| 106 ui::GestureEvent tap(0, 0, 0, base::TimeTicks(), |
| 107 ui::GestureEventDetails(ui::ET_GESTURE_TAP)); |
| 108 GetTray()->PerformAction(tap); |
| 109 ASSERT_FALSE(::wm::IsActiveWindow(window.get())); |
| 110 ASSERT_FALSE(IsTrayBackgroundActive()); |
| 111 |
| 112 // Tabs on the tray when the window is unminimized. |
| 113 GetTray()->PerformAction(tap); |
| 114 ASSERT_TRUE(::wm::IsActiveWindow(window.get())); |
| 115 ASSERT_TRUE(IsTrayBackgroundActive()); |
| 116 } |
| 117 |
| 118 } // namespace ash |
OLD | NEW |