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

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

Powered by Google App Engine
This is Rietveld 408576698