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

Side by Side Diff: ash/common/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: Addressed comments. 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/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 void SetMenuShelfAlignment(ShelfAlignment alignment) {
50 ime_menu_tray_->SetShelfAlignment(alignment);
51 }
52
53 // Returns true if the label has an empty border.
54 bool IsTrayLabelHasBorder() { return ime_menu_tray_->label_->border(); }
James Cook 2016/07/14 15:47:35 Not used - remove.
Azure Wei 2016/07/15 01:58:12 Done.
55
56 private:
57 std::unique_ptr<ImeMenuTray> ime_menu_tray_;
58
59 DISALLOW_COPY_AND_ASSIGN(ImeMenuTrayTest);
60 };
61
62 // Tests that visibility of IME menu tray should be consistent with the
63 // activation of the IME menu.
64 TEST_F(ImeMenuTrayTest, ImeMenuTrayVisibility) {
65 ASSERT_FALSE(IsVisible());
66
67 WmShell::Get()->system_tray_notifier()->NotifyRefreshIMEMenu(true);
68 EXPECT_TRUE(IsVisible());
69
70 WmShell::Get()->system_tray_notifier()->NotifyRefreshIMEMenu(false);
71 EXPECT_FALSE(IsVisible());
72 }
73
74 // Tests that IME menu tray shows the right info of the current IME.
75 TEST_F(ImeMenuTrayTest, TrayLabelTest) {
76 WmShell::Get()->system_tray_notifier()->NotifyRefreshIMEMenu(true);
77 ASSERT_TRUE(IsVisible());
78
79 // Changes the input method to "ime1".
80 IMEInfo info1;
81 info1.id = "ime1";
82 info1.name = UTF8ToUTF16("English");
83 info1.medium_name = UTF8ToUTF16("English");
84 info1.short_name = UTF8ToUTF16("US");
85 info1.third_party = false;
86 info1.selected = true;
87 GetSystemTrayDelegate()->SetCurrentIME(info1);
88 WmShell::Get()->system_tray_notifier()->NotifyRefreshIME();
89 EXPECT_EQ(UTF8ToUTF16("US"), GetTrayText());
90
91 // Changes the input method to a third-party IME extension.
92 IMEInfo info2;
93 info2.id = "ime2";
94 info2.name = UTF8ToUTF16("English UK");
95 info2.medium_name = UTF8ToUTF16("English UK");
96 info2.short_name = UTF8ToUTF16("UK");
97 info2.third_party = true;
98 info2.selected = true;
99 GetSystemTrayDelegate()->SetCurrentIME(info2);
100 WmShell::Get()->system_tray_notifier()->NotifyRefreshIME();
101 EXPECT_EQ(UTF8ToUTF16("UK*"), GetTrayText());
102 }
103
104 // Tests that IME menu tray changes background color when tapped/clicked. And
105 // tests that the background color becomes 'inactive' when disabling the IME
106 // menu feature.
107 TEST_F(ImeMenuTrayTest, PerformAction) {
108 WmShell::Get()->system_tray_notifier()->NotifyRefreshIMEMenu(true);
109 ASSERT_TRUE(IsVisible());
110 ASSERT_FALSE(IsTrayBackgroundActive());
111
112 ui::GestureEvent tap(0, 0, 0, base::TimeTicks(),
113 ui::GestureEventDetails(ui::ET_GESTURE_TAP));
114 ime_menu_tray()->PerformAction(tap);
115 EXPECT_TRUE(IsTrayBackgroundActive());
116
117 ime_menu_tray()->PerformAction(tap);
118 EXPECT_FALSE(IsTrayBackgroundActive());
119
120 // If disabling the IME menu feature when the menu tray is activated, the tray
121 // element will be deactivated.
122 ime_menu_tray()->PerformAction(tap);
123 EXPECT_TRUE(IsTrayBackgroundActive());
124 WmShell::Get()->system_tray_notifier()->NotifyRefreshIMEMenu(false);
125 EXPECT_FALSE(IsVisible());
126 EXPECT_FALSE(IsTrayBackgroundActive());
James Cook 2016/07/14 15:47:35 Good idea to test this.
127 }
128
129 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698