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

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

Issue 2098023002: mash: Migrate remaining tray observers and notify functions. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Sync and rebase. 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
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ash/system/chromeos/screen_security/screen_tray_item.h" 5 #include "ash/system/chromeos/screen_security/screen_tray_item.h"
6 6
7 #include "ash/common/system/tray/system_tray_notifier.h"
7 #include "ash/common/system/tray/tray_item_view.h" 8 #include "ash/common/system/tray/tray_item_view.h"
8 #include "ash/shell.h" 9 #include "ash/common/wm_shell.h"
9 #include "ash/system/chromeos/screen_security/screen_capture_tray_item.h" 10 #include "ash/system/chromeos/screen_security/screen_capture_tray_item.h"
10 #include "ash/system/chromeos/screen_security/screen_share_tray_item.h" 11 #include "ash/system/chromeos/screen_security/screen_share_tray_item.h"
11 #include "ash/test/ash_test_base.h" 12 #include "ash/test/ash_test_base.h"
12 #include "base/callback.h" 13 #include "base/callback.h"
13 #include "base/strings/utf_string_conversions.h" 14 #include "base/strings/utf_string_conversions.h"
14 #include "ui/events/event.h" 15 #include "ui/events/event.h"
15 #include "ui/events/event_utils.h" 16 #include "ui/events/event_utils.h"
16 #include "ui/gfx/geometry/point.h" 17 #include "ui/gfx/geometry/point.h"
17 #include "ui/message_center/message_center.h" 18 #include "ui/message_center/message_center.h"
18 #include "ui/views/view.h" 19 #include "ui/views/view.h"
19 20
20 namespace ash { 21 namespace ash {
21 22
22 // Test with unicode strings. 23 // Test with unicode strings.
23 const char kTestScreenCaptureAppName[] = 24 const char kTestScreenCaptureAppName[] =
24 "\xE0\xB2\xA0\x5F\xE0\xB2\xA0 (Screen Capture Test)"; 25 "\xE0\xB2\xA0\x5F\xE0\xB2\xA0 (Screen Capture Test)";
25 const char kTestScreenShareHelperName[] = 26 const char kTestScreenShareHelperName[] =
26 "\xE5\xAE\x8B\xE8\x85\xBE (Screen Share Test)"; 27 "\xE5\xAE\x8B\xE8\x85\xBE (Screen Share Test)";
27 28
28 SystemTray* GetSystemTray() {
29 return Shell::GetInstance()->GetPrimarySystemTray();
30 }
31
32 SystemTrayNotifier* GetSystemTrayNotifier() {
33 return Shell::GetInstance()->system_tray_notifier();
34 }
35
36 void ClickViewCenter(views::View* view) { 29 void ClickViewCenter(views::View* view) {
37 gfx::Point click_location_in_local = 30 gfx::Point click_location_in_local =
38 gfx::Point(view->width() / 2, view->height() / 2); 31 gfx::Point(view->width() / 2, view->height() / 2);
39 view->OnMousePressed(ui::MouseEvent( 32 view->OnMousePressed(ui::MouseEvent(
40 ui::ET_MOUSE_PRESSED, click_location_in_local, click_location_in_local, 33 ui::ET_MOUSE_PRESSED, click_location_in_local, click_location_in_local,
41 ui::EventTimeForNow(), ui::EF_NONE, ui::EF_NONE)); 34 ui::EventTimeForNow(), ui::EF_NONE, ui::EF_NONE));
42 } 35 }
43 36
44 class ScreenTrayItemTest : public ash::test::AshTestBase { 37 class ScreenTrayItemTest : public ash::test::AshTestBase {
45 public: 38 public:
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 72
80 class ScreenCaptureTest : public ScreenTrayItemTest { 73 class ScreenCaptureTest : public ScreenTrayItemTest {
81 public: 74 public:
82 ScreenCaptureTest() {} 75 ScreenCaptureTest() {}
83 ~ScreenCaptureTest() override {} 76 ~ScreenCaptureTest() override {}
84 77
85 void SetUp() override { 78 void SetUp() override {
86 ScreenTrayItemTest::SetUp(); 79 ScreenTrayItemTest::SetUp();
87 // This tray item is owned by its parent system tray view and will 80 // This tray item is owned by its parent system tray view and will
88 // be deleted automatically when its parent is destroyed in AshTestBase. 81 // be deleted automatically when its parent is destroyed in AshTestBase.
89 ScreenTrayItem* tray_item = new ScreenCaptureTrayItem(GetSystemTray()); 82 ScreenTrayItem* item = new ScreenCaptureTrayItem(GetPrimarySystemTray());
90 GetSystemTray()->AddTrayItem(tray_item); 83 GetPrimarySystemTray()->AddTrayItem(item);
91 set_tray_item(tray_item); 84 set_tray_item(item);
92 } 85 }
93 86
94 DISALLOW_COPY_AND_ASSIGN(ScreenCaptureTest); 87 DISALLOW_COPY_AND_ASSIGN(ScreenCaptureTest);
95 }; 88 };
96 89
97 class ScreenShareTest : public ScreenTrayItemTest { 90 class ScreenShareTest : public ScreenTrayItemTest {
98 public: 91 public:
99 ScreenShareTest() {} 92 ScreenShareTest() {}
100 ~ScreenShareTest() override {} 93 ~ScreenShareTest() override {}
101 94
102 void SetUp() override { 95 void SetUp() override {
103 ScreenTrayItemTest::SetUp(); 96 ScreenTrayItemTest::SetUp();
104 // This tray item is owned by its parent system tray view and will 97 // This tray item is owned by its parent system tray view and will
105 // be deleted automatically when its parent is destroyed in AshTestBase. 98 // be deleted automatically when its parent is destroyed in AshTestBase.
106 ScreenTrayItem* tray_item = new ScreenShareTrayItem(GetSystemTray()); 99 ScreenTrayItem* item = new ScreenShareTrayItem(GetPrimarySystemTray());
107 GetSystemTray()->AddTrayItem(tray_item); 100 GetPrimarySystemTray()->AddTrayItem(item);
108 set_tray_item(tray_item); 101 set_tray_item(item);
109 } 102 }
110 103
111 DISALLOW_COPY_AND_ASSIGN(ScreenShareTest); 104 DISALLOW_COPY_AND_ASSIGN(ScreenShareTest);
112 }; 105 };
113 106
114 void TestStartAndStop(ScreenTrayItemTest* test) { 107 void TestStartAndStop(ScreenTrayItemTest* test) {
115 ScreenTrayItem* tray_item = test->tray_item(); 108 ScreenTrayItem* tray_item = test->tray_item();
116 109
117 EXPECT_FALSE(tray_item->is_started()); 110 EXPECT_FALSE(tray_item->is_started());
118 EXPECT_EQ(0, test->stop_callback_hit_count()); 111 EXPECT_EQ(0, test->stop_callback_hit_count());
(...skipping 21 matching lines...) Expand all
140 // The stop callback shouldn't be called because we stopped 133 // The stop callback shouldn't be called because we stopped
141 // through the notification system. 134 // through the notification system.
142 stop_function.Run(); 135 stop_function.Run();
143 EXPECT_FALSE(tray_item->is_started()); 136 EXPECT_FALSE(tray_item->is_started());
144 EXPECT_EQ(0, test->stop_callback_hit_count()); 137 EXPECT_EQ(0, test->stop_callback_hit_count());
145 } 138 }
146 139
147 TEST_F(ScreenCaptureTest, NotificationStartAndStop) { 140 TEST_F(ScreenCaptureTest, NotificationStartAndStop) {
148 base::Closure start_function = 141 base::Closure start_function =
149 base::Bind(&SystemTrayNotifier::NotifyScreenCaptureStart, 142 base::Bind(&SystemTrayNotifier::NotifyScreenCaptureStart,
150 base::Unretained(GetSystemTrayNotifier()), 143 base::Unretained(WmShell::Get()->system_tray_notifier()),
151 base::Bind(&ScreenTrayItemTest::StopCallback, 144 base::Bind(&ScreenTrayItemTest::StopCallback,
152 base::Unretained(this)), 145 base::Unretained(this)),
153 base::UTF8ToUTF16(kTestScreenCaptureAppName)); 146 base::UTF8ToUTF16(kTestScreenCaptureAppName));
154 147
155 base::Closure stop_function = 148 base::Closure stop_function =
156 base::Bind(&SystemTrayNotifier::NotifyScreenCaptureStop, 149 base::Bind(&SystemTrayNotifier::NotifyScreenCaptureStop,
157 base::Unretained(GetSystemTrayNotifier())); 150 base::Unretained(WmShell::Get()->system_tray_notifier()));
158 151
159 TestNotificationStartAndStop(this, start_function, stop_function); 152 TestNotificationStartAndStop(this, start_function, stop_function);
160 } 153 }
161 154
162 TEST_F(ScreenShareTest, NotificationStartAndStop) { 155 TEST_F(ScreenShareTest, NotificationStartAndStop) {
163 base::Closure start_func = 156 base::Closure start_func =
164 base::Bind(&SystemTrayNotifier::NotifyScreenShareStart, 157 base::Bind(&SystemTrayNotifier::NotifyScreenShareStart,
165 base::Unretained(GetSystemTrayNotifier()), 158 base::Unretained(WmShell::Get()->system_tray_notifier()),
166 base::Bind(&ScreenTrayItemTest::StopCallback, 159 base::Bind(&ScreenTrayItemTest::StopCallback,
167 base::Unretained(this)), 160 base::Unretained(this)),
168 base::UTF8ToUTF16(kTestScreenShareHelperName)); 161 base::UTF8ToUTF16(kTestScreenShareHelperName));
169 162
170 base::Closure stop_func = 163 base::Closure stop_func =
171 base::Bind(&SystemTrayNotifier::NotifyScreenShareStop, 164 base::Bind(&SystemTrayNotifier::NotifyScreenShareStop,
172 base::Unretained(GetSystemTrayNotifier())); 165 base::Unretained(WmShell::Get()->system_tray_notifier()));
173 166
174 TestNotificationStartAndStop(this, start_func, stop_func); 167 TestNotificationStartAndStop(this, start_func, stop_func);
175 } 168 }
176 169
177 void TestNotificationView(ScreenTrayItemTest* test) { 170 void TestNotificationView(ScreenTrayItemTest* test) {
178 ScreenTrayItem* tray_item = test->tray_item(); 171 ScreenTrayItem* tray_item = test->tray_item();
179 172
180 test->StartSession(); 173 test->StartSession();
181 message_center::MessageCenter* message_center = 174 message_center::MessageCenter* message_center =
182 message_center::MessageCenter::Get(); 175 message_center::MessageCenter::Get();
183 EXPECT_TRUE(message_center->FindVisibleNotificationById( 176 EXPECT_TRUE(message_center->FindVisibleNotificationById(
184 tray_item->GetNotificationId())); 177 tray_item->GetNotificationId()));
185 test->StopSession(); 178 test->StopSession();
186 } 179 }
187 180
188 TEST_F(ScreenCaptureTest, NotificationView) { TestNotificationView(this); } 181 TEST_F(ScreenCaptureTest, NotificationView) { TestNotificationView(this); }
189 TEST_F(ScreenShareTest, NotificationView) { TestNotificationView(this); } 182 TEST_F(ScreenShareTest, NotificationView) { TestNotificationView(this); }
190 183
191 void TestSystemTrayInteraction(ScreenTrayItemTest* test) { 184 void TestSystemTrayInteraction(ScreenTrayItemTest* test) {
192 ScreenTrayItem* tray_item = test->tray_item(); 185 ScreenTrayItem* tray_item = test->tray_item();
193 EXPECT_FALSE(tray_item->tray_view()->visible()); 186 EXPECT_FALSE(tray_item->tray_view()->visible());
194 187
195 const std::vector<SystemTrayItem*>& tray_items = 188 const std::vector<SystemTrayItem*>& tray_items =
196 GetSystemTray()->GetTrayItems(); 189 test::AshTestBase::GetPrimarySystemTray()->GetTrayItems();
197 EXPECT_NE(std::find(tray_items.begin(), tray_items.end(), tray_item), 190 EXPECT_NE(std::find(tray_items.begin(), tray_items.end(), tray_item),
198 tray_items.end()); 191 tray_items.end());
199 192
200 test->StartSession(); 193 test->StartSession();
201 EXPECT_TRUE(tray_item->tray_view()->visible()); 194 EXPECT_TRUE(tray_item->tray_view()->visible());
202 195
203 // The default view should be created in a new bubble. 196 // The default view should be created in a new bubble.
204 GetSystemTray()->ShowDefaultView(BUBBLE_CREATE_NEW); 197 test::AshTestBase::GetPrimarySystemTray()->ShowDefaultView(BUBBLE_CREATE_NEW);
205 EXPECT_TRUE(tray_item->default_view()); 198 EXPECT_TRUE(tray_item->default_view());
206 GetSystemTray()->CloseSystemBubble(); 199 test::AshTestBase::GetPrimarySystemTray()->CloseSystemBubble();
207 EXPECT_FALSE(tray_item->default_view()); 200 EXPECT_FALSE(tray_item->default_view());
208 201
209 test->StopSession(); 202 test->StopSession();
210 EXPECT_FALSE(tray_item->tray_view()->visible()); 203 EXPECT_FALSE(tray_item->tray_view()->visible());
211 204
212 // The default view should not be visible because session is stopped. 205 // The default view should not be visible because session is stopped.
213 GetSystemTray()->ShowDefaultView(BUBBLE_CREATE_NEW); 206 test::AshTestBase::GetPrimarySystemTray()->ShowDefaultView(BUBBLE_CREATE_NEW);
214 EXPECT_FALSE(tray_item->default_view()->visible()); 207 EXPECT_FALSE(tray_item->default_view()->visible());
215 } 208 }
216 209
217 TEST_F(ScreenCaptureTest, SystemTrayInteraction) { 210 TEST_F(ScreenCaptureTest, SystemTrayInteraction) {
218 TestSystemTrayInteraction(this); 211 TestSystemTrayInteraction(this);
219 } 212 }
220 213
221 TEST_F(ScreenShareTest, SystemTrayInteraction) { 214 TEST_F(ScreenShareTest, SystemTrayInteraction) {
222 TestSystemTrayInteraction(this); 215 TestSystemTrayInteraction(this);
223 } 216 }
224 217
225 } // namespace ash 218 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698