Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(94)

Side by Side Diff: ash/system/chromeos/ime_menu/ime_menu_tray_unittest.cc

Issue 1996563002: Add ImeMenuTray element. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Activates window when clicked. Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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/window_state.h"
9 #include "ash/common/wm_shell.h"
10 #include "ash/system/status_area_widget.h"
11 #include "ash/system/tray/system_tray.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/aura/window.h"
19 #include "ui/events/event.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 base::string16 GetTrayText() { return GetTray()->GetLabelTextForTesting(); }
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 wm::WindowState* window_state = wm::GetWindowState(window.get());
66 GetTray()->SetWindowState(window_state);
67
68 // Changes the input method to "ime1".
69 IMEInfo info1;
70 info1.id = "ime1";
71 info1.name = base::UTF8ToUTF16("English");
72 info1.medium_name = base::UTF8ToUTF16("English");
73 info1.short_name = base::UTF8ToUTF16("US");
74 info1.third_party = false;
75 info1.selected = true;
76 GetSystemTrayDelegate()->SetCurrentIME(info1);
77 WmShell::Get()->system_tray_notifier()->NotifyRefreshIME();
78 ASSERT_EQ(info1.short_name, GetTrayText());
79
80 // Changes the input method to a third-party IME extension.
81 IMEInfo info2;
82 info2.id = "ime2";
83 info2.name = base::UTF8ToUTF16("English UK");
84 info2.medium_name = base::UTF8ToUTF16("English UK");
85 info2.short_name = base::UTF8ToUTF16("UK");
86 info2.third_party = true;
87 info2.selected = true;
88 GetSystemTrayDelegate()->SetCurrentIME(info2);
89 WmShell::Get()->system_tray_notifier()->NotifyRefreshIME();
90 ASSERT_EQ(info2.short_name + base::UTF8ToUTF16("*"), GetTrayText());
91
92 GetTray()->SetWindowState(nullptr);
93 }
94
95 TEST_F(ImeMenuTrayTest, PerformAction) {
96 ASSERT_TRUE(GetTray());
97 ASSERT_TRUE(GetSystemTrayDelegate());
98
99 std::unique_ptr<aura::Window> window(CreateTestWindowInShellWithId(0));
100 wm::WindowState* window_state = wm::GetWindowState(window.get());
101 window_state->Minimize();
102 ASSERT_TRUE(window_state->IsMinimized());
103 ASSERT_FALSE(window_state->IsActive());
104
105 GetTray()->SetWindowState(window_state);
106 WmShell::Get()->system_tray_notifier()->NotifyRefreshIMEMenu(true);
107 ASSERT_TRUE(GetTray()->visible());
108
109 // Tabs on the tray when the window is minimized.
110 ui::GestureEvent tap(0, 0, 0, base::TimeTicks(),
111 ui::GestureEventDetails(ui::ET_GESTURE_TAP));
112 GetTray()->PerformAction(tap);
113 ASSERT_TRUE(window_state->IsActive());
114 ASSERT_TRUE(IsTrayBackgroundActive());
115
116 // Tabs on the tray when the window is unminimized.
117 GetTray()->PerformAction(tap);
118 ASSERT_FALSE(window_state->IsActive());
119 ASSERT_FALSE(IsTrayBackgroundActive());
120
121 GetTray()->SetWindowState(nullptr);
122 }
123
124 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698