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

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

Issue 16472006: Add unit tests for screen capture and share notification UI. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added test for system tray interaction Created 7 years, 6 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
« no previous file with comments | « ash/system/chromeos/screen_security/screen_tray_item.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/system/chromeos/screen_security/screen_tray_item.h"
6
7 #include "ash/system/chromeos/screen_security/screen_capture_tray_item.h"
8 #include "ash/system/chromeos/screen_security/screen_share_tray_item.h"
9 #include "ash/test/ash_test_base.h"
10 #include "base/callback.h"
11 #include "base/strings/utf_string_conversions.h"
12 #include "ui/base/events/event.h"
13 #include "ui/gfx/point.h"
14 #include "ui/views/view.h"
15
16 namespace ash {
17 namespace internal {
18
19 // Test with unicode strings.
20 const char kTestScreenCaptureAppName[] =
21 "\xE0\xB2\xA0\x5F\xE0\xB2\xA0 (Screen Capture Test)";
22 const char kTestScreenShareHelperName[] =
23 "\xE5\xAE\x8B\xE8\x85\xBE (Screen Share Test)";
24
25 SystemTray* GetSystemTray() {
26 return Shell::GetInstance()->GetPrimarySystemTray();
27 }
28
29 SystemTrayNotifier* GetSystemTrayNotifier() {
30 return Shell::GetInstance()->system_tray_notifier();
31 }
32
33 void ClickViewCenter(views::View* view) {
34 gfx::Point click_location_in_local =
35 gfx::Point(view->width() / 2, view->height() / 2);
36 view->OnMousePressed(ui::MouseEvent(ui::ET_MOUSE_PRESSED,
37 click_location_in_local,
38 click_location_in_local,
39 ui::EF_NONE));
40 }
41
42 class ScreenTrayItemTest : public ash::test::AshTestBase {
43 public:
44 ScreenTrayItemTest()
45 : tray_item_(NULL), stop_callback_hit_count_(0) {}
46 virtual ~ScreenTrayItemTest() {}
47
48 ScreenTrayItem* tray_item() { return tray_item_; }
49 void set_tray_item(ScreenTrayItem* tray_item) { tray_item_ = tray_item; }
50
51 int stop_callback_hit_count() const { return stop_callback_hit_count_; }
52
53 void StartSession() {
54 tray_item_->Start(
55 base::Bind(&ScreenTrayItemTest::StopCallback, base::Unretained(this)));
56 }
57
58 void StopSession() {
59 tray_item_->Stop();
60 }
61
62 void StopCallback() {
63 stop_callback_hit_count_++;
64 }
65
66 private:
67 ScreenTrayItem* tray_item_;
68 int stop_callback_hit_count_;
69
70 DISALLOW_COPY_AND_ASSIGN(ScreenTrayItemTest);
71 };
72
73 class ScreenCaptureTest : public ScreenTrayItemTest {
74 public:
75 ScreenCaptureTest() {}
76 virtual ~ScreenCaptureTest() {}
77
78 virtual void SetUp() OVERRIDE {
79 test::AshTestBase::SetUp();
80 // This tray item is owned by its parent system tray view and will
81 // be deleted automatically when its parent is destroyed in AshTestBase.
82 ScreenTrayItem* tray_item = new ScreenCaptureTrayItem(GetSystemTray());
83 GetSystemTray()->AddTrayItem(tray_item);
84 set_tray_item(tray_item);
85 }
86
87 DISALLOW_COPY_AND_ASSIGN(ScreenCaptureTest);
88 };
89
90 class ScreenShareTest : public ScreenTrayItemTest {
91 public:
92 ScreenShareTest() {}
93 virtual ~ScreenShareTest() {}
94
95 virtual void SetUp() OVERRIDE {
96 test::AshTestBase::SetUp();
97 // This tray item is owned by its parent system tray view and will
98 // be deleted automatically when its parent is destroyed in AshTestBase.
99 ScreenTrayItem* tray_item = new ScreenShareTrayItem(GetSystemTray());
100 GetSystemTray()->AddTrayItem(tray_item);
101 set_tray_item(tray_item);
102 }
103
104 DISALLOW_COPY_AND_ASSIGN(ScreenShareTest);
105 };
106
107 void TestStartAndStop(ScreenTrayItemTest* test) {
108 ScreenTrayItem* tray_item = test->tray_item();
109
110 EXPECT_FALSE(tray_item->is_started());
111 EXPECT_EQ(0, test->stop_callback_hit_count());
112
113 test->StartSession();
114 EXPECT_TRUE(tray_item->is_started());
115
116 test->StopSession();
117 EXPECT_FALSE(tray_item->is_started());
118 EXPECT_EQ(1, test->stop_callback_hit_count());
119 }
120
121 TEST_F(ScreenCaptureTest, StartAndStop) { TestStartAndStop(this); }
122 TEST_F(ScreenShareTest, StartAndStop) { TestStartAndStop(this); }
123
124 void TestNotificationStartAndStop(ScreenTrayItemTest* test,
125 const base::Closure& start_function,
126 const base::Closure& stop_function) {
127 ScreenTrayItem* tray_item = test->tray_item();
128 EXPECT_FALSE(tray_item->is_started());
129
130 start_function.Run();
131 EXPECT_TRUE(tray_item->is_started());
132
133 // The stop callback shouldn't be called because we stopped
134 // through the notification system.
135 stop_function.Run();
136 EXPECT_FALSE(tray_item->is_started());
137 EXPECT_EQ(0, test->stop_callback_hit_count());
138 }
139
140 TEST_F(ScreenCaptureTest, NotificationStartAndStop) {
141 base::Closure start_function =
142 base::Bind(&SystemTrayNotifier::NotifyScreenCaptureStart,
143 base::Unretained(GetSystemTrayNotifier()),
144 base::Bind(&ScreenTrayItemTest::StopCallback,
145 base::Unretained(this)),
146 base::UTF8ToUTF16(kTestScreenCaptureAppName));
147
148 base::Closure stop_function =
149 base::Bind(&SystemTrayNotifier::NotifyScreenCaptureStop,
150 base::Unretained(GetSystemTrayNotifier()));
151
152 TestNotificationStartAndStop(this, start_function, stop_function);
153 }
154
155 TEST_F(ScreenShareTest, NotificationStartAndStop) {
156 base::Closure start_func =
157 base::Bind(&SystemTrayNotifier::NotifyScreenShareStart,
158 base::Unretained(GetSystemTrayNotifier()),
159 base::Bind(&ScreenTrayItemTest::StopCallback,
160 base::Unretained(this)),
161 base::UTF8ToUTF16(kTestScreenShareHelperName));
162
163 base::Closure stop_func =
164 base::Bind(&SystemTrayNotifier::NotifyScreenShareStop,
165 base::Unretained(GetSystemTrayNotifier()));
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 EXPECT_TRUE(tray_item->notification_view()->visible());
175
176 // Clicking on the notification view should dismiss the view
177 ClickViewCenter(tray_item->notification_view());
178 EXPECT_FALSE(tray_item->notification_view());
179
180 test->StopSession();
181 }
182
183 TEST_F(ScreenCaptureTest, NotificationView) { TestNotificationView(this); }
184 TEST_F(ScreenShareTest, NotificationView) { TestNotificationView(this); }
185
186 void TestSystemTrayInteraction(ScreenTrayItemTest* test) {
187 // We can't directly check if a tray item has been added to the system tray,
188 // but we can check the side effects. If the tray item has not been added,
189 // the default view should not be shown.
190 ScreenTrayItem* tray_item = test->tray_item();
191 EXPECT_FALSE(tray_item->tray_view()->visible());
192
193 test->StartSession();
194 EXPECT_TRUE(tray_item->tray_view()->visible());
195
196 // Check interaction between default view and system bubble.
197 GetSystemTray()->ShowDefaultView(BUBBLE_CREATE_NEW);
198 EXPECT_TRUE(tray_item->default_view());
199 GetSystemTray()->CloseSystemBubble();
200 EXPECT_FALSE(tray_item->default_view());
201
202 test->StopSession();
203
204 // When the tray view animates its visibility, so we can't
205 // check it's visibility until the animation finishes.
206 }
207
208 TEST_F(ScreenCaptureTest, SystemTrayInteraction) {
209 TestSystemTrayInteraction(this);
210 }
211 TEST_F(ScreenShareTest, SystemTrayInteraction) {
212 TestSystemTrayInteraction(this);
213 }
214
215 } // namespace internal
216 } // namespace ash
OLDNEW
« no previous file with comments | « ash/system/chromeos/screen_security/screen_tray_item.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698