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

Side by Side Diff: chrome/browser/notifications/platform_notification_service_browsertest.cc

Issue 1161153003: Convert the WebRtcTestBase to use infobar and bubble autoresponders (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix MANUAL test Created 5 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 <string> 5 #include <string>
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/files/file_path.h" 8 #include "base/files/file_path.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/path_service.h" 10 #include "base/path_service.h"
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 151
152 // ----------------------------------------------------------------------------- 152 // -----------------------------------------------------------------------------
153 153
154 // TODO(peter): Move PlatformNotificationService-related tests over from 154 // TODO(peter): Move PlatformNotificationService-related tests over from
155 // notification_browsertest.cc to this file. 155 // notification_browsertest.cc to this file.
156 156
157 IN_PROC_BROWSER_TEST_F(PlatformNotificationServiceBrowserTest, 157 IN_PROC_BROWSER_TEST_F(PlatformNotificationServiceBrowserTest,
158 DisplayPersistentNotificationWithoutPermission) { 158 DisplayPersistentNotificationWithoutPermission) {
159 std::string script_result; 159 std::string script_result;
160 160
161 InfoBarResponder cancelling_responder(GetInfoBarService(), false); 161 InfoBarResponder cancelling_responder(GetInfoBarService(),
162 InfoBarResponder::DENY);
162 ASSERT_TRUE(RunScript("RequestPermission()", &script_result)); 163 ASSERT_TRUE(RunScript("RequestPermission()", &script_result));
163 EXPECT_EQ("denied", script_result); 164 EXPECT_EQ("denied", script_result);
164 165
165 ASSERT_TRUE(RunScript("DisplayPersistentNotification()", &script_result)); 166 ASSERT_TRUE(RunScript("DisplayPersistentNotification()", &script_result));
166 EXPECT_EQ( 167 EXPECT_EQ(
167 "TypeError: No notification permission has been granted for this origin.", 168 "TypeError: No notification permission has been granted for this origin.",
168 script_result); 169 script_result);
169 170
170 ASSERT_EQ(0u, ui_manager()->GetNotificationCount()); 171 ASSERT_EQ(0u, ui_manager()->GetNotificationCount());
171 } 172 }
172 173
173 IN_PROC_BROWSER_TEST_F(PlatformNotificationServiceBrowserTest, 174 IN_PROC_BROWSER_TEST_F(PlatformNotificationServiceBrowserTest,
174 DisplayPersistentNotificationWithPermission) { 175 DisplayPersistentNotificationWithPermission) {
175 std::string script_result; 176 std::string script_result;
176 177
177 InfoBarResponder accepting_responder(GetInfoBarService(), true); 178 InfoBarResponder accepting_responder(GetInfoBarService(),
179 InfoBarResponder::ACCEPT);
178 ASSERT_TRUE(RunScript("RequestPermission()", &script_result)); 180 ASSERT_TRUE(RunScript("RequestPermission()", &script_result));
179 EXPECT_EQ("granted", script_result); 181 EXPECT_EQ("granted", script_result);
180 182
181 ASSERT_TRUE(RunScript("DisplayPersistentNotification('action_none')", 183 ASSERT_TRUE(RunScript("DisplayPersistentNotification('action_none')",
182 &script_result)); 184 &script_result));
183 EXPECT_EQ("ok", script_result); 185 EXPECT_EQ("ok", script_result);
184 186
185 ASSERT_EQ(1u, ui_manager()->GetNotificationCount()); 187 ASSERT_EQ(1u, ui_manager()->GetNotificationCount());
186 188
187 const Notification& notification = ui_manager()->GetNotificationAt(0); 189 const Notification& notification = ui_manager()->GetNotificationAt(0);
188 notification.delegate()->Click(); 190 notification.delegate()->Click();
189 191
190 ASSERT_TRUE(RunScript("GetMessageFromWorker()", &script_result)); 192 ASSERT_TRUE(RunScript("GetMessageFromWorker()", &script_result));
191 EXPECT_EQ("action_none", script_result); 193 EXPECT_EQ("action_none", script_result);
192 194
193 ASSERT_EQ(1u, ui_manager()->GetNotificationCount()); 195 ASSERT_EQ(1u, ui_manager()->GetNotificationCount());
194 } 196 }
195 197
196 IN_PROC_BROWSER_TEST_F(PlatformNotificationServiceBrowserTest, 198 IN_PROC_BROWSER_TEST_F(PlatformNotificationServiceBrowserTest,
197 WebNotificationOptionsReflection) { 199 WebNotificationOptionsReflection) {
198 std::string script_result; 200 std::string script_result;
199 201
200 // TODO(peter): It doesn't add much value if we use the InfoBarResponder for 202 // TODO(peter): It doesn't add much value if we use the InfoBarResponder for
201 // each test. Rather, we should just toggle the content setting. 203 // each test. Rather, we should just toggle the content setting.
202 InfoBarResponder accepting_responder(GetInfoBarService(), true); 204 InfoBarResponder accepting_responder(GetInfoBarService(),
205 InfoBarResponder::ACCEPT);
203 ASSERT_TRUE(RunScript("RequestPermission()", &script_result)); 206 ASSERT_TRUE(RunScript("RequestPermission()", &script_result));
204 EXPECT_EQ("granted", script_result); 207 EXPECT_EQ("granted", script_result);
205 208
206 ASSERT_TRUE(RunScript("DisplayPersistentAllOptionsNotification()", 209 ASSERT_TRUE(RunScript("DisplayPersistentAllOptionsNotification()",
207 &script_result)); 210 &script_result));
208 EXPECT_EQ("ok", script_result); 211 EXPECT_EQ("ok", script_result);
209 212
210 ASSERT_EQ(1u, ui_manager()->GetNotificationCount()); 213 ASSERT_EQ(1u, ui_manager()->GetNotificationCount());
211 214
212 // We don't use or check the notification's direction and language. 215 // We don't use or check the notification's direction and language.
213 const Notification& notification = ui_manager()->GetNotificationAt(0); 216 const Notification& notification = ui_manager()->GetNotificationAt(0);
214 EXPECT_EQ("Title", base::UTF16ToUTF8(notification.title())); 217 EXPECT_EQ("Title", base::UTF16ToUTF8(notification.title()));
215 EXPECT_EQ("Contents", base::UTF16ToUTF8(notification.message())); 218 EXPECT_EQ("Contents", base::UTF16ToUTF8(notification.message()));
216 EXPECT_EQ("replace-id", notification.tag()); 219 EXPECT_EQ("replace-id", notification.tag());
217 EXPECT_FALSE(notification.icon().IsEmpty()); 220 EXPECT_FALSE(notification.icon().IsEmpty());
218 EXPECT_TRUE(notification.silent()); 221 EXPECT_TRUE(notification.silent());
219 222
220 EXPECT_EQ(kIconWidth, notification.icon().Width()); 223 EXPECT_EQ(kIconWidth, notification.icon().Width());
221 EXPECT_EQ(kIconHeight, notification.icon().Height()); 224 EXPECT_EQ(kIconHeight, notification.icon().Height());
222 } 225 }
223 226
224 IN_PROC_BROWSER_TEST_F(PlatformNotificationServiceBrowserTest, 227 IN_PROC_BROWSER_TEST_F(PlatformNotificationServiceBrowserTest,
225 WebNotificationOptionsVibrationPattern) { 228 WebNotificationOptionsVibrationPattern) {
226 std::string script_result; 229 std::string script_result;
227 230
228 InfoBarResponder accepting_responder(GetInfoBarService(), true); 231 InfoBarResponder accepting_responder(GetInfoBarService(),
232 InfoBarResponder::ACCEPT);
229 ASSERT_TRUE(RunScript("RequestPermission()", &script_result)); 233 ASSERT_TRUE(RunScript("RequestPermission()", &script_result));
230 EXPECT_EQ("granted", script_result); 234 EXPECT_EQ("granted", script_result);
231 235
232 ASSERT_TRUE(RunScript("DisplayPersistentNotificationVibrate()", 236 ASSERT_TRUE(RunScript("DisplayPersistentNotificationVibrate()",
233 &script_result)); 237 &script_result));
234 EXPECT_EQ("ok", script_result); 238 EXPECT_EQ("ok", script_result);
235 239
236 ASSERT_EQ(1u, ui_manager()->GetNotificationCount()); 240 ASSERT_EQ(1u, ui_manager()->GetNotificationCount());
237 241
238 const Notification& notification = ui_manager()->GetNotificationAt(0); 242 const Notification& notification = ui_manager()->GetNotificationAt(0);
239 EXPECT_EQ("Title", base::UTF16ToUTF8(notification.title())); 243 EXPECT_EQ("Title", base::UTF16ToUTF8(notification.title()));
240 EXPECT_EQ("Contents", base::UTF16ToUTF8(notification.message())); 244 EXPECT_EQ("Contents", base::UTF16ToUTF8(notification.message()));
241 245
242 EXPECT_THAT(notification.vibration_pattern(), 246 EXPECT_THAT(notification.vibration_pattern(),
243 testing::ElementsAreArray(kNotificationVibrationPattern)); 247 testing::ElementsAreArray(kNotificationVibrationPattern));
244 } 248 }
245 249
246 IN_PROC_BROWSER_TEST_F(PlatformNotificationServiceBrowserTest, 250 IN_PROC_BROWSER_TEST_F(PlatformNotificationServiceBrowserTest,
247 CloseDisplayedPersistentNotification) { 251 CloseDisplayedPersistentNotification) {
248 std::string script_result; 252 std::string script_result;
249 253
250 InfoBarResponder accepting_responder(GetInfoBarService(), true); 254 InfoBarResponder accepting_responder(GetInfoBarService(),
255 InfoBarResponder::ACCEPT);
251 ASSERT_TRUE(RunScript("RequestPermission()", &script_result)); 256 ASSERT_TRUE(RunScript("RequestPermission()", &script_result));
252 EXPECT_EQ("granted", script_result); 257 EXPECT_EQ("granted", script_result);
253 258
254 ASSERT_TRUE(RunScript("DisplayPersistentNotification('action_close')", 259 ASSERT_TRUE(RunScript("DisplayPersistentNotification('action_close')",
255 &script_result)); 260 &script_result));
256 EXPECT_EQ("ok", script_result); 261 EXPECT_EQ("ok", script_result);
257 262
258 ASSERT_EQ(1u, ui_manager()->GetNotificationCount()); 263 ASSERT_EQ(1u, ui_manager()->GetNotificationCount());
259 264
260 const Notification& notification = ui_manager()->GetNotificationAt(0); 265 const Notification& notification = ui_manager()->GetNotificationAt(0);
261 notification.delegate()->Click(); 266 notification.delegate()->Click();
262 267
263 ASSERT_TRUE(RunScript("GetMessageFromWorker()", &script_result)); 268 ASSERT_TRUE(RunScript("GetMessageFromWorker()", &script_result));
264 EXPECT_EQ("action_close", script_result); 269 EXPECT_EQ("action_close", script_result);
265 270
266 ASSERT_EQ(0u, ui_manager()->GetNotificationCount()); 271 ASSERT_EQ(0u, ui_manager()->GetNotificationCount());
267 } 272 }
268 273
269 IN_PROC_BROWSER_TEST_F(PlatformNotificationServiceBrowserTest, 274 IN_PROC_BROWSER_TEST_F(PlatformNotificationServiceBrowserTest,
270 TestDisplayOriginContextMessage) { 275 TestDisplayOriginContextMessage) {
271 std::string script_result; 276 std::string script_result;
272 277
273 // Creates a simple notification. 278 // Creates a simple notification.
274 InfoBarResponder accepting_responder(GetInfoBarService(), true); 279 InfoBarResponder accepting_responder(GetInfoBarService(),
280 InfoBarResponder::ACCEPT);
275 ASSERT_TRUE(RunScript("RequestPermission()", &script_result)); 281 ASSERT_TRUE(RunScript("RequestPermission()", &script_result));
276 ASSERT_EQ("granted", script_result); 282 ASSERT_EQ("granted", script_result);
277 ASSERT_TRUE(RunScript("DisplayPersistentNotification()", &script_result)); 283 ASSERT_TRUE(RunScript("DisplayPersistentNotification()", &script_result));
278 284
279 net::HostPortPair host_port = ServerHostPort(); 285 net::HostPortPair host_port = ServerHostPort();
280 286
281 const Notification& notification = ui_manager()->GetNotificationAt(0); 287 const Notification& notification = ui_manager()->GetNotificationAt(0);
282 288
283 EXPECT_EQ(base::UTF8ToUTF16(host_port.ToString()), 289 EXPECT_EQ(base::UTF8ToUTF16(host_port.ToString()),
284 notification.context_message()); 290 notification.context_message());
285 } 291 }
286 292
287 IN_PROC_BROWSER_TEST_F(PlatformNotificationServiceBrowserTest, 293 IN_PROC_BROWSER_TEST_F(PlatformNotificationServiceBrowserTest,
288 CheckFilePermissionNotGranted) { 294 CheckFilePermissionNotGranted) {
289 // TODO(dewittj): This test verifies that a bug exists in Chrome; the test 295 // TODO(dewittj): This test verifies that a bug exists in Chrome; the test
290 // will fail if the bug is fixed. The 296 // will fail if the bug is fixed. The
291 // |PlatformNotificationServiceImpl::WebOriginDisplayName| function needs 297 // |PlatformNotificationServiceImpl::WebOriginDisplayName| function needs
292 // to be updated to properly display file:// URL origins. 298 // to be updated to properly display file:// URL origins.
293 // See crbug.com/402191. 299 // See crbug.com/402191.
294 std::string script_result; 300 std::string script_result;
295 301
296 InfoBarResponder accepting_responder_web(GetInfoBarService(), true); 302 InfoBarResponder accepting_responder_web(GetInfoBarService(),
303 InfoBarResponder::ACCEPT);
297 304
298 DesktopNotificationService* notification_service = 305 DesktopNotificationService* notification_service =
299 DesktopNotificationServiceFactory::GetForProfile(browser()->profile()); 306 DesktopNotificationServiceFactory::GetForProfile(browser()->profile());
300 ASSERT_TRUE(notification_service); 307 ASSERT_TRUE(notification_service);
301 message_center::NotifierId web_notifier(TestPageUrl()); 308 message_center::NotifierId web_notifier(TestPageUrl());
302 EXPECT_FALSE(notification_service->IsNotifierEnabled(web_notifier)); 309 EXPECT_FALSE(notification_service->IsNotifierEnabled(web_notifier));
303 ASSERT_TRUE(RunScript("RequestPermission()", &script_result)); 310 ASSERT_TRUE(RunScript("RequestPermission()", &script_result));
304 EXPECT_EQ("granted", script_result); 311 EXPECT_EQ("granted", script_result);
305 312
306 EXPECT_TRUE(notification_service->IsNotifierEnabled(web_notifier)); 313 EXPECT_TRUE(notification_service->IsNotifierEnabled(web_notifier));
307 314
308 base::FilePath dir_source_root; 315 base::FilePath dir_source_root;
309 EXPECT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &dir_source_root)); 316 EXPECT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &dir_source_root));
310 base::FilePath full_file_path = 317 base::FilePath full_file_path =
311 dir_source_root.Append(server_root()).AppendASCII(kTestFileName); 318 dir_source_root.Append(server_root()).AppendASCII(kTestFileName);
312 GURL file_url(net::FilePathToFileURL(full_file_path)); 319 GURL file_url(net::FilePathToFileURL(full_file_path));
313 ui_test_utils::NavigateToURL(browser(), file_url); 320 ui_test_utils::NavigateToURL(browser(), file_url);
314 321
315 message_center::NotifierId file_notifier(file_url); 322 message_center::NotifierId file_notifier(file_url);
316 EXPECT_FALSE(notification_service->IsNotifierEnabled(file_notifier)); 323 EXPECT_FALSE(notification_service->IsNotifierEnabled(file_notifier));
317 324
318 InfoBarResponder accepting_responder_file(GetInfoBarService(), true); 325 InfoBarResponder accepting_responder_file(GetInfoBarService(),
326 InfoBarResponder::ACCEPT);
319 ASSERT_TRUE(RunScript("RequestPermission()", &script_result)); 327 ASSERT_TRUE(RunScript("RequestPermission()", &script_result));
320 EXPECT_EQ("granted", script_result); 328 EXPECT_EQ("granted", script_result);
321 329
322 EXPECT_FALSE(notification_service->IsNotifierEnabled(file_notifier)) 330 EXPECT_FALSE(notification_service->IsNotifierEnabled(file_notifier))
323 << "If this test fails, you may have fixed a bug preventing file origins " 331 << "If this test fails, you may have fixed a bug preventing file origins "
324 << "from sending their origin from Blink; if so you need to update the " 332 << "from sending their origin from Blink; if so you need to update the "
325 << "display function for notification origins to show the file path."; 333 << "display function for notification origins to show the file path.";
326 } 334 }
327 335
328 IN_PROC_BROWSER_TEST_F(PlatformNotificationServiceBrowserTest, 336 IN_PROC_BROWSER_TEST_F(PlatformNotificationServiceBrowserTest,
(...skipping 26 matching lines...) Expand all
355 363
356 ASSERT_EQ(1u, ui_manager()->GetNotificationCount()); 364 ASSERT_EQ(1u, ui_manager()->GetNotificationCount());
357 365
358 const Notification& notification = ui_manager()->GetNotificationAt(0); 366 const Notification& notification = ui_manager()->GetNotificationAt(0);
359 EXPECT_FALSE(notification.icon().IsEmpty()); 367 EXPECT_FALSE(notification.icon().IsEmpty());
360 368
361 EXPECT_EQ("Blob Title", base::UTF16ToUTF8(notification.title())); 369 EXPECT_EQ("Blob Title", base::UTF16ToUTF8(notification.title()));
362 EXPECT_EQ(kIconWidth, notification.icon().Width()); 370 EXPECT_EQ(kIconWidth, notification.icon().Width());
363 EXPECT_EQ(kIconHeight, notification.icon().Height()); 371 EXPECT_EQ(kIconHeight, notification.icon().Height());
364 } 372 }
OLDNEW
« no previous file with comments | « chrome/browser/media/webrtc_browsertest_base.cc ('k') | chrome/browser/push_messaging/push_messaging_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698