| 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/wm/window_state.h" |
| 8 #include "ash/shell.h" |
| 9 #include "ash/system/status_area_widget.h" |
| 10 #include "ash/system/tray/system_tray.h" |
| 11 #include "ash/system/tray/system_tray_notifier.h" |
| 12 #include "ash/test/ash_test_base.h" |
| 13 #include "ash/test/status_area_widget_test_helper.h" |
| 14 #include "ash/test/test_system_tray_delegate.h" |
| 15 #include "ash/wm/window_state_aura.h" |
| 16 #include "base/strings/utf_string_conversions.h" |
| 17 #include "base/time/time.h" |
| 18 #include "ui/events/event.h" |
| 19 |
| 20 namespace ash { |
| 21 |
| 22 namespace { |
| 23 |
| 24 ImeMenuTray* GetTray() { |
| 25 return StatusAreaWidgetTestHelper::GetStatusAreaWidget()->ime_menu_tray(); |
| 26 } |
| 27 |
| 28 } // namespace |
| 29 |
| 30 class ImeMenuTrayTest : public test::AshTestBase { |
| 31 public: |
| 32 ImeMenuTrayTest() {} |
| 33 ~ImeMenuTrayTest() override {} |
| 34 |
| 35 protected: |
| 36 // Returns the label text of the tray. |
| 37 base::string16 GetTrayText() { return GetTray()->GetLabelTextForTesting(); } |
| 38 |
| 39 // Returns true if the background color of the tray is active. |
| 40 bool IsTrayBackgroundActive() { |
| 41 return GetTray()->draw_background_as_active(); |
| 42 } |
| 43 |
| 44 private: |
| 45 DISALLOW_COPY_AND_ASSIGN(ImeMenuTrayTest); |
| 46 }; |
| 47 |
| 48 TEST_F(ImeMenuTrayTest, ImeMenuTrayVisibility) { |
| 49 ASSERT_TRUE(GetTray()); |
| 50 ASSERT_FALSE(GetTray()->visible()); |
| 51 |
| 52 Shell::GetInstance()->system_tray_notifier()->NotifyRefreshIMEMenu(true); |
| 53 ASSERT_TRUE(GetTray()->visible()); |
| 54 |
| 55 Shell::GetInstance()->system_tray_notifier()->NotifyRefreshIMEMenu(false); |
| 56 ASSERT_FALSE(GetTray()->visible()); |
| 57 } |
| 58 |
| 59 TEST_F(ImeMenuTrayTest, TrayLabelTest) { |
| 60 ASSERT_TRUE(GetTray()); |
| 61 ASSERT_TRUE(GetSystemTrayDelegate()); |
| 62 |
| 63 std::unique_ptr<aura::Window> window(CreateTestWindowInShellWithId(0)); |
| 64 wm::WindowState* window_state = wm::GetWindowState(window.get()); |
| 65 GetTray()->SetWindowState(window_state); |
| 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 Shell::GetInstance()->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 Shell::GetInstance()->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::WindowState* window_state = wm::GetWindowState(window.get()); |
| 98 window_state->Minimize(); |
| 99 ASSERT_TRUE(window_state->IsMinimized()); |
| 100 |
| 101 GetTray()->SetWindowState(window_state); |
| 102 Shell::GetInstance()->system_tray_notifier()->NotifyRefreshIMEMenu(true); |
| 103 ASSERT_TRUE(GetTray()->visible()); |
| 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(window_state->IsMinimized()); |
| 110 ASSERT_TRUE(IsTrayBackgroundActive()); |
| 111 |
| 112 // Tabs on the tray when the window is unminimized. |
| 113 GetTray()->PerformAction(tap); |
| 114 ASSERT_TRUE(window_state->IsMinimized()); |
| 115 ASSERT_FALSE(IsTrayBackgroundActive()); |
| 116 } |
| 117 |
| 118 } // namespace ash |
| OLD | NEW |