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

Side by Side Diff: ash/common/system/chromeos/screen_security/screen_tray_item_unittest.cc

Issue 2732813002: chromeos: Move files in //ash/common to //ash, part 1 (Closed)
Patch Set: rebase Created 3 years, 9 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 2013 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/screen_security/screen_tray_item.h"
6
7 #include "ash/common/system/chromeos/screen_security/screen_capture_tray_item.h"
8 #include "ash/common/system/chromeos/screen_security/screen_share_tray_item.h"
9 #include "ash/common/system/tray/system_tray_notifier.h"
10 #include "ash/common/system/tray/tray_item_view.h"
11 #include "ash/common/test/ash_test.h"
12 #include "ash/common/wm_shell.h"
13 #include "base/callback.h"
14 #include "base/memory/ptr_util.h"
15 #include "base/strings/utf_string_conversions.h"
16 #include "ui/events/event.h"
17 #include "ui/events/event_utils.h"
18 #include "ui/gfx/geometry/point.h"
19 #include "ui/message_center/message_center.h"
20 #include "ui/views/view.h"
21
22 namespace ash {
23
24 // Test with unicode strings.
25 const char kTestScreenCaptureAppName[] =
26 "\xE0\xB2\xA0\x5F\xE0\xB2\xA0 (Screen Capture Test)";
27 const char kTestScreenShareHelperName[] =
28 "\xE5\xAE\x8B\xE8\x85\xBE (Screen Share Test)";
29
30 void ClickViewCenter(views::View* view) {
31 gfx::Point click_location_in_local =
32 gfx::Point(view->width() / 2, view->height() / 2);
33 view->OnMousePressed(ui::MouseEvent(
34 ui::ET_MOUSE_PRESSED, click_location_in_local, click_location_in_local,
35 ui::EventTimeForNow(), ui::EF_NONE, ui::EF_NONE));
36 }
37
38 class ScreenTrayItemTest : public AshTest {
39 public:
40 ScreenTrayItemTest() : tray_item_(NULL), stop_callback_hit_count_(0) {}
41 ~ScreenTrayItemTest() override {}
42
43 ScreenTrayItem* tray_item() { return tray_item_; }
44 void set_tray_item(ScreenTrayItem* tray_item) { tray_item_ = tray_item; }
45
46 int stop_callback_hit_count() const { return stop_callback_hit_count_; }
47
48 void SetUp() override {
49 AshTest::SetUp();
50 TrayItemView::DisableAnimationsForTest();
51 }
52
53 void StartSession() {
54 tray_item_->Start(
55 base::Bind(&ScreenTrayItemTest::StopCallback, base::Unretained(this)));
56 }
57
58 void StopSession() { tray_item_->Stop(); }
59
60 void StopCallback() { stop_callback_hit_count_++; }
61
62 private:
63 ScreenTrayItem* tray_item_;
64 int stop_callback_hit_count_;
65
66 DISALLOW_COPY_AND_ASSIGN(ScreenTrayItemTest);
67 };
68
69 class ScreenCaptureTest : public ScreenTrayItemTest {
70 public:
71 ScreenCaptureTest() {}
72 ~ScreenCaptureTest() override {}
73
74 void SetUp() override {
75 ScreenTrayItemTest::SetUp();
76 // This tray item is owned by its parent system tray view and will
77 // be deleted automatically when its parent is destroyed in AshTestBase.
78 ScreenTrayItem* item = new ScreenCaptureTrayItem(GetPrimarySystemTray());
79 GetPrimarySystemTray()->AddTrayItem(base::WrapUnique(item));
80 set_tray_item(item);
81 }
82
83 private:
84 DISALLOW_COPY_AND_ASSIGN(ScreenCaptureTest);
85 };
86
87 class ScreenShareTest : public ScreenTrayItemTest {
88 public:
89 ScreenShareTest() {}
90 ~ScreenShareTest() override {}
91
92 void SetUp() override {
93 ScreenTrayItemTest::SetUp();
94 // This tray item is owned by its parent system tray view and will
95 // be deleted automatically when its parent is destroyed in AshTestBase.
96 ScreenTrayItem* item = new ScreenShareTrayItem(GetPrimarySystemTray());
97 GetPrimarySystemTray()->AddTrayItem(base::WrapUnique(item));
98 set_tray_item(item);
99 }
100
101 DISALLOW_COPY_AND_ASSIGN(ScreenShareTest);
102 };
103
104 void TestStartAndStop(ScreenTrayItemTest* test) {
105 ScreenTrayItem* tray_item = test->tray_item();
106
107 EXPECT_FALSE(tray_item->is_started());
108 EXPECT_EQ(0, test->stop_callback_hit_count());
109
110 test->StartSession();
111 EXPECT_TRUE(tray_item->is_started());
112
113 test->StopSession();
114 EXPECT_FALSE(tray_item->is_started());
115 EXPECT_EQ(1, test->stop_callback_hit_count());
116 }
117
118 TEST_F(ScreenCaptureTest, StartAndStop) {
119 TestStartAndStop(this);
120 }
121
122 TEST_F(ScreenShareTest, StartAndStop) {
123 TestStartAndStop(this);
124 }
125
126 void TestNotificationStartAndStop(ScreenTrayItemTest* test,
127 const base::Closure& start_function,
128 const base::Closure& stop_function) {
129 ScreenTrayItem* tray_item = test->tray_item();
130 EXPECT_FALSE(tray_item->is_started());
131
132 start_function.Run();
133 EXPECT_TRUE(tray_item->is_started());
134
135 // The stop callback shouldn't be called because we stopped
136 // through the notification system.
137 stop_function.Run();
138 EXPECT_FALSE(tray_item->is_started());
139 EXPECT_EQ(0, test->stop_callback_hit_count());
140 }
141
142 TEST_F(ScreenCaptureTest, NotificationStartAndStop) {
143 base::Closure start_function = base::Bind(
144 &SystemTrayNotifier::NotifyScreenCaptureStart,
145 base::Unretained(WmShell::Get()->system_tray_notifier()),
146 base::Bind(&ScreenTrayItemTest::StopCallback, base::Unretained(this)),
147 base::UTF8ToUTF16(kTestScreenCaptureAppName));
148
149 base::Closure stop_function =
150 base::Bind(&SystemTrayNotifier::NotifyScreenCaptureStop,
151 base::Unretained(WmShell::Get()->system_tray_notifier()));
152
153 TestNotificationStartAndStop(this, start_function, stop_function);
154 }
155
156 TEST_F(ScreenShareTest, NotificationStartAndStop) {
157 base::Closure start_func = base::Bind(
158 &SystemTrayNotifier::NotifyScreenShareStart,
159 base::Unretained(WmShell::Get()->system_tray_notifier()),
160 base::Bind(&ScreenTrayItemTest::StopCallback, base::Unretained(this)),
161 base::UTF8ToUTF16(kTestScreenShareHelperName));
162
163 base::Closure stop_func =
164 base::Bind(&SystemTrayNotifier::NotifyScreenShareStop,
165 base::Unretained(WmShell::Get()->system_tray_notifier()));
166
167 TestNotificationStartAndStop(this, start_func, stop_func);
168 }
169
170 void TestNotificationView(ScreenTrayItemTest* test) {
171 ScreenTrayItem* tray_item = test->tray_item();
172
173 test->StartSession();
174 message_center::MessageCenter* message_center =
175 message_center::MessageCenter::Get();
176 EXPECT_TRUE(message_center->FindVisibleNotificationById(
177 tray_item->GetNotificationId()));
178 test->StopSession();
179 }
180
181 TEST_F(ScreenCaptureTest, NotificationView) {
182 TestNotificationView(this);
183 }
184
185 TEST_F(ScreenShareTest, NotificationView) {
186 TestNotificationView(this);
187 }
188
189 void TestSystemTrayInteraction(ScreenTrayItemTest* test) {
190 ScreenTrayItem* tray_item = test->tray_item();
191 EXPECT_FALSE(tray_item->tray_view()->visible());
192
193 std::vector<SystemTrayItem*> tray_items =
194 AshTest::GetPrimarySystemTray()->GetTrayItems();
195 EXPECT_NE(std::find(tray_items.begin(), tray_items.end(), tray_item),
196 tray_items.end());
197
198 test->StartSession();
199 EXPECT_TRUE(tray_item->tray_view()->visible());
200
201 // The default view should be created in a new bubble.
202 AshTest::GetPrimarySystemTray()->ShowDefaultView(BUBBLE_CREATE_NEW);
203 EXPECT_TRUE(tray_item->default_view());
204 AshTest::GetPrimarySystemTray()->CloseSystemBubble();
205 EXPECT_FALSE(tray_item->default_view());
206
207 test->StopSession();
208 EXPECT_FALSE(tray_item->tray_view()->visible());
209
210 // The default view should not be visible because session is stopped.
211 AshTest::GetPrimarySystemTray()->ShowDefaultView(BUBBLE_CREATE_NEW);
212 EXPECT_FALSE(tray_item->default_view()->visible());
213 }
214
215 TEST_F(ScreenCaptureTest, SystemTrayInteraction) {
216 TestSystemTrayInteraction(this);
217 }
218
219 TEST_F(ScreenShareTest, SystemTrayInteraction) {
220 TestSystemTrayInteraction(this);
221 }
222
223 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698