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

Side by Side Diff: chrome/browser/extensions/api/notifications/notifications_apitest.cc

Issue 2875673002: Minimize the delegate dependencies for native extension notifications. (Closed)
Patch Set: disable non applicable tests Created 3 years, 7 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "base/strings/string_number_conversions.h" 5 #include "base/strings/string_number_conversions.h"
6 #include "base/strings/stringprintf.h" 6 #include "base/strings/stringprintf.h"
7 #include "base/strings/utf_string_conversions.h" 7 #include "base/strings/utf_string_conversions.h"
8 #include "base/test/scoped_feature_list.h" 8 #include "base/test/scoped_feature_list.h"
9 #include "build/build_config.h" 9 #include "build/build_config.h"
10 #include "chrome/browser/apps/app_browsertest_util.h" 10 #include "chrome/browser/apps/app_browsertest_util.h"
(...skipping 21 matching lines...) Expand all
32 #include "extensions/browser/app_window/native_app_window.h" 32 #include "extensions/browser/app_window/native_app_window.h"
33 #include "extensions/browser/notification_types.h" 33 #include "extensions/browser/notification_types.h"
34 #include "extensions/common/features/feature.h" 34 #include "extensions/common/features/feature.h"
35 #include "extensions/common/test_util.h" 35 #include "extensions/common/test_util.h"
36 #include "extensions/test/extension_test_message_listener.h" 36 #include "extensions/test/extension_test_message_listener.h"
37 #include "extensions/test/result_catcher.h" 37 #include "extensions/test/result_catcher.h"
38 #include "ui/message_center/notifier_settings.h" 38 #include "ui/message_center/notifier_settings.h"
39 39
40 #if defined(OS_MACOSX) 40 #if defined(OS_MACOSX)
41 #include "base/mac/mac_util.h" 41 #include "base/mac/mac_util.h"
42 #include "ui/base/test/scoped_fake_nswindow_fullscreen.h"
43 #endif 42 #endif
44 43
45 using extensions::AppWindow; 44 using extensions::AppWindow;
46 using extensions::AppWindowRegistry; 45 using extensions::AppWindowRegistry;
47 using extensions::Extension; 46 using extensions::Extension;
48 using extensions::ExtensionNotificationDisplayHelper; 47 using extensions::ExtensionNotificationDisplayHelper;
49 using extensions::ExtensionNotificationDisplayHelperFactory; 48 using extensions::ExtensionNotificationDisplayHelperFactory;
50 using extensions::ResultCatcher; 49 using extensions::ResultCatcher;
51 50
52 namespace utils = extension_function_test_utils; 51 namespace utils = extension_function_test_utils;
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 } 236 }
238 237
239 IN_PROC_BROWSER_TEST_F(NotificationsApiTest, TestEvents) { 238 IN_PROC_BROWSER_TEST_F(NotificationsApiTest, TestEvents) {
240 ASSERT_TRUE(RunExtensionTest("notifications/api/events")) << message_; 239 ASSERT_TRUE(RunExtensionTest("notifications/api/events")) << message_;
241 } 240 }
242 241
243 IN_PROC_BROWSER_TEST_F(NotificationsApiTest, TestCSP) { 242 IN_PROC_BROWSER_TEST_F(NotificationsApiTest, TestCSP) {
244 ASSERT_TRUE(RunExtensionTest("notifications/api/csp")) << message_; 243 ASSERT_TRUE(RunExtensionTest("notifications/api/csp")) << message_;
245 } 244 }
246 245
246 // Native notifications don't support (nor use) observers.
247 #if !defined(OS_MACOSX)
247 IN_PROC_BROWSER_TEST_F(NotificationsApiTest, TestByUser) { 248 IN_PROC_BROWSER_TEST_F(NotificationsApiTest, TestByUser) {
248 const extensions::Extension* extension = 249 const extensions::Extension* extension =
249 LoadExtensionAndWait("notifications/api/by_user"); 250 LoadExtensionAndWait("notifications/api/by_user");
250 ASSERT_TRUE(extension) << message_; 251 ASSERT_TRUE(extension) << message_;
251 252
252 { 253 {
253 ResultCatcher catcher; 254 ResultCatcher catcher;
254 const std::string notification_id = 255 const std::string notification_id =
255 GetNotificationIdFromDelegateId(extension->id() + "-FOO"); 256 GetNotificationIdFromDelegateId(extension->id() + "-FOO");
256 GetDisplayService()->RemoveNotification( 257 GetDisplayService()->RemoveNotification(
(...skipping 16 matching lines...) Expand all
273 false /* by_user */); 274 false /* by_user */);
274 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); 275 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
275 } 276 }
276 { 277 {
277 ResultCatcher catcher; 278 ResultCatcher catcher;
278 GetDisplayService()->RemoveAllNotifications(NotificationCommon::EXTENSION, 279 GetDisplayService()->RemoveAllNotifications(NotificationCommon::EXTENSION,
279 true /* by_user */); 280 true /* by_user */);
280 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); 281 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
281 } 282 }
282 } 283 }
284 #endif // !defined(OS_MACOSX)
283 285
284 IN_PROC_BROWSER_TEST_F(NotificationsApiTest, TestPartialUpdate) { 286 IN_PROC_BROWSER_TEST_F(NotificationsApiTest, TestPartialUpdate) {
285 ASSERT_TRUE(RunExtensionTest("notifications/api/partial_update")) << message_; 287 ASSERT_TRUE(RunExtensionTest("notifications/api/partial_update")) << message_;
286 const extensions::Extension* extension = GetSingleLoadedExtension(); 288 const extensions::Extension* extension = GetSingleLoadedExtension();
287 ASSERT_TRUE(extension) << message_; 289 ASSERT_TRUE(extension) << message_;
288 290
289 const char kNewTitle[] = "Changed!"; 291 const char kNewTitle[] = "Changed!";
290 const char kNewMessage[] = "Too late! The show ended yesterday"; 292 const char kNewMessage[] = "Too late! The show ended yesterday";
291 int kNewPriority = 2; 293 int kNewPriority = 2;
292 const char kButtonTitle[] = "NewButton"; 294 const char kButtonTitle[] = "NewButton";
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
372 374
373 message_center::NotifierId notifier_id( 375 message_center::NotifierId notifier_id(
374 message_center::NotifierId::APPLICATION, 376 message_center::NotifierId::APPLICATION,
375 extension->id()); 377 extension->id());
376 GetNotifierStateTracker()->SetNotifierEnabled(notifier_id, true); 378 GetNotifierStateTracker()->SetNotifierEnabled(notifier_id, true);
377 379
378 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); 380 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
379 } 381 }
380 } 382 }
381 383
384 // Native notifications don't support (nor use) observers.
385 #if !defined(OS_MACOSX)
382 IN_PROC_BROWSER_TEST_F(NotificationsApiTest, TestUserGesture) { 386 IN_PROC_BROWSER_TEST_F(NotificationsApiTest, TestUserGesture) {
383 const extensions::Extension* extension = 387 const extensions::Extension* extension =
384 LoadExtensionAndWait("notifications/api/user_gesture"); 388 LoadExtensionAndWait("notifications/api/user_gesture");
385 ASSERT_TRUE(extension) << message_; 389 ASSERT_TRUE(extension) << message_;
386 390
387 Notification* notification = GetNotificationForExtension(extension); 391 Notification* notification = GetNotificationForExtension(extension);
388 ASSERT_TRUE(notification); 392 ASSERT_TRUE(notification);
389 393
390 { 394 {
391 UserGestureCatcher catcher; 395 UserGestureCatcher catcher;
392 notification->ButtonClick(0); 396 notification->ButtonClick(0);
393 EXPECT_TRUE(catcher.GetNextResult()); 397 EXPECT_TRUE(catcher.GetNextResult());
394 notification->Click(); 398 notification->Click();
395 EXPECT_TRUE(catcher.GetNextResult()); 399 EXPECT_TRUE(catcher.GetNextResult());
396 notification->Close(true /* by_user */); 400 notification->Close(true /* by_user */);
397 EXPECT_TRUE(catcher.GetNextResult()); 401 EXPECT_TRUE(catcher.GetNextResult());
398 402
399 // Note that |notification| no longer points to valid memory. 403 // Note that |notification| no longer points to valid memory.
400 } 404 }
401 405
402 ASSERT_FALSE(GetNotificationForExtension(extension)); 406 ASSERT_FALSE(GetNotificationForExtension(extension));
403 } 407 }
408 #endif // !defined(OS_MACOSX)
404 409
405 IN_PROC_BROWSER_TEST_F(NotificationsApiTest, TestRequireInteraction) { 410 IN_PROC_BROWSER_TEST_F(NotificationsApiTest, TestRequireInteraction) {
406 const extensions::Extension* extension = 411 const extensions::Extension* extension =
407 LoadExtensionAndWait("notifications/api/require_interaction"); 412 LoadExtensionAndWait("notifications/api/require_interaction");
408 ASSERT_TRUE(extension) << message_; 413 ASSERT_TRUE(extension) << message_;
409 414
410 Notification* notification = GetNotificationForExtension(extension); 415 Notification* notification = GetNotificationForExtension(extension);
411 ASSERT_TRUE(notification); 416 ASSERT_TRUE(notification);
412 417
413 EXPECT_TRUE(notification->never_timeout()); 418 EXPECT_TRUE(notification->never_timeout());
(...skipping 12 matching lines...) Expand all
426 GetFirstAppWindow(extension->id())->GetNativeWindow())); 431 GetFirstAppWindow(extension->id())->GetNativeWindow()));
427 432
428 Notification* notification = GetNotificationForExtension(extension); 433 Notification* notification = GetNotificationForExtension(extension);
429 ASSERT_TRUE(notification); 434 ASSERT_TRUE(notification);
430 435
431 // If the app hasn't created a fullscreen window, then its notifications 436 // If the app hasn't created a fullscreen window, then its notifications
432 // shouldn't be displayed when a window is fullscreen. 437 // shouldn't be displayed when a window is fullscreen.
433 ASSERT_FALSE(notification->delegate()->ShouldDisplayOverFullscreen()); 438 ASSERT_FALSE(notification->delegate()->ShouldDisplayOverFullscreen());
434 } 439 }
435 440
441 // Full screen related tests don't run on Mac as native notifications full
442 // screen decisions are done by the OS directly.
443 #if !defined(OS_MACOSX)
436 IN_PROC_BROWSER_TEST_F(NotificationsApiTest, TestShouldDisplayFullscreen) { 444 IN_PROC_BROWSER_TEST_F(NotificationsApiTest, TestShouldDisplayFullscreen) {
437 #if defined(OS_MACOSX)
438 ui::test::ScopedFakeNSWindowFullscreen fake_fullscreen;
439 #endif
440 EnableFullscreenNotifications(); 445 EnableFullscreenNotifications();
441 ExtensionTestMessageListener notification_created_listener("created", false); 446 ExtensionTestMessageListener notification_created_listener("created", false);
442 const Extension* extension = LoadAppWithWindowState( 447 const Extension* extension = LoadAppWithWindowState(
443 "notifications/api/basic_app", WindowState::FULLSCREEN); 448 "notifications/api/basic_app", WindowState::FULLSCREEN);
444 ASSERT_TRUE(extension) << message_; 449 ASSERT_TRUE(extension) << message_;
445 ASSERT_TRUE(notification_created_listener.WaitUntilSatisfied()); 450 ASSERT_TRUE(notification_created_listener.WaitUntilSatisfied());
446 451
447 // We start by making sure the window is actually focused. 452 // We start by making sure the window is actually focused.
448 ASSERT_TRUE(ui_test_utils::ShowAndFocusNativeWindow( 453 ASSERT_TRUE(ui_test_utils::ShowAndFocusNativeWindow(
449 GetFirstAppWindow(extension->id())->GetNativeWindow())); 454 GetFirstAppWindow(extension->id())->GetNativeWindow()));
450 455
451 ASSERT_TRUE(GetFirstAppWindow(extension->id())->IsFullscreen()) 456 ASSERT_TRUE(GetFirstAppWindow(extension->id())->IsFullscreen())
452 << "Not Fullscreen"; 457 << "Not Fullscreen";
453 ASSERT_TRUE(GetFirstAppWindow(extension->id())->GetBaseWindow()->IsActive()) 458 ASSERT_TRUE(GetFirstAppWindow(extension->id())->GetBaseWindow()->IsActive())
454 << "Not Active"; 459 << "Not Active";
455 460
456 Notification* notification = GetNotificationForExtension(extension); 461 Notification* notification = GetNotificationForExtension(extension);
457 ASSERT_TRUE(notification); 462 ASSERT_TRUE(notification);
458 463
459 // If the app has created a fullscreen window, then its notifications should 464 // If the app has created a fullscreen window, then its notifications should
460 // be displayed when a window is fullscreen. 465 // be displayed when a window is fullscreen.
461 ASSERT_TRUE(notification->delegate()->ShouldDisplayOverFullscreen()); 466 ASSERT_TRUE(notification->delegate()->ShouldDisplayOverFullscreen());
462 } 467 }
463 468
464 IN_PROC_BROWSER_TEST_F(NotificationsApiTest, TestShouldDisplayFullscreenOff) { 469 IN_PROC_BROWSER_TEST_F(NotificationsApiTest, TestShouldDisplayFullscreenOff) {
465 #if defined(OS_MACOSX)
466 ui::test::ScopedFakeNSWindowFullscreen fake_fullscreen;
467 #endif
468 DisableFullscreenNotifications(); 470 DisableFullscreenNotifications();
469 ExtensionTestMessageListener notification_created_listener("created", false); 471 ExtensionTestMessageListener notification_created_listener("created", false);
470 const Extension* extension = LoadAppWithWindowState( 472 const Extension* extension = LoadAppWithWindowState(
471 "notifications/api/basic_app", WindowState::FULLSCREEN); 473 "notifications/api/basic_app", WindowState::FULLSCREEN);
472 ASSERT_TRUE(extension) << message_; 474 ASSERT_TRUE(extension) << message_;
473 ASSERT_TRUE(notification_created_listener.WaitUntilSatisfied()); 475 ASSERT_TRUE(notification_created_listener.WaitUntilSatisfied());
474 476
475 // We start by making sure the window is actually focused. 477 // We start by making sure the window is actually focused.
476 ASSERT_TRUE(ui_test_utils::ShowAndFocusNativeWindow( 478 ASSERT_TRUE(ui_test_utils::ShowAndFocusNativeWindow(
477 GetFirstAppWindow(extension->id())->GetNativeWindow())); 479 GetFirstAppWindow(extension->id())->GetNativeWindow()));
478 480
479 ASSERT_TRUE(GetFirstAppWindow(extension->id())->IsFullscreen()) 481 ASSERT_TRUE(GetFirstAppWindow(extension->id())->IsFullscreen())
480 << "Not Fullscreen"; 482 << "Not Fullscreen";
481 ASSERT_TRUE(GetFirstAppWindow(extension->id())->GetBaseWindow()->IsActive()) 483 ASSERT_TRUE(GetFirstAppWindow(extension->id())->GetBaseWindow()->IsActive())
482 << "Not Active"; 484 << "Not Active";
483 485
484 Notification* notification = GetNotificationForExtension(extension); 486 Notification* notification = GetNotificationForExtension(extension);
485 ASSERT_TRUE(notification); 487 ASSERT_TRUE(notification);
486 488
487 // When the experiment flag is off, then ShouldDisplayOverFullscreen should 489 // When the experiment flag is off, then ShouldDisplayOverFullscreen should
488 // return false. 490 // return false.
489 ASSERT_FALSE(notification->delegate()->ShouldDisplayOverFullscreen()); 491 ASSERT_FALSE(notification->delegate()->ShouldDisplayOverFullscreen());
490 } 492 }
491 493
492 // The Fake OSX fullscreen window doesn't like drawing a second fullscreen 494 // The Fake OSX fullscreen window doesn't like drawing a second fullscreen
493 // window when another is visible. 495 // window when another is visible.
494 #if !defined(OS_MACOSX)
495 IN_PROC_BROWSER_TEST_F(NotificationsApiTest, TestShouldDisplayMultiFullscreen) { 496 IN_PROC_BROWSER_TEST_F(NotificationsApiTest, TestShouldDisplayMultiFullscreen) {
496 // Start a fullscreen app, and then start another fullscreen app on top of the 497 // Start a fullscreen app, and then start another fullscreen app on top of the
497 // first. Notifications from the first should not be displayed because it is 498 // first. Notifications from the first should not be displayed because it is
498 // not the app actually displaying on the screen. 499 // not the app actually displaying on the screen.
499 EnableFullscreenNotifications(); 500 EnableFullscreenNotifications();
500 ExtensionTestMessageListener notification_created_listener("created", false); 501 ExtensionTestMessageListener notification_created_listener("created", false);
501 const Extension* extension1 = LoadAppWithWindowState( 502 const Extension* extension1 = LoadAppWithWindowState(
502 "notifications/api/basic_app", WindowState::FULLSCREEN); 503 "notifications/api/basic_app", WindowState::FULLSCREEN);
503 ASSERT_TRUE(extension1) << message_; 504 ASSERT_TRUE(extension1) << message_;
504 505
505 ExtensionTestMessageListener window_visible_listener("visible", false); 506 ExtensionTestMessageListener window_visible_listener("visible", false);
506 const Extension* extension2 = LoadAppWithWindowState( 507 const Extension* extension2 = LoadAppWithWindowState(
507 "notifications/api/other_app", WindowState::FULLSCREEN); 508 "notifications/api/other_app", WindowState::FULLSCREEN);
508 ASSERT_TRUE(extension2) << message_; 509 ASSERT_TRUE(extension2) << message_;
509 510
510 ASSERT_TRUE(notification_created_listener.WaitUntilSatisfied()); 511 ASSERT_TRUE(notification_created_listener.WaitUntilSatisfied());
511 ASSERT_TRUE(window_visible_listener.WaitUntilSatisfied()); 512 ASSERT_TRUE(window_visible_listener.WaitUntilSatisfied());
512 513
513 // We start by making sure the window is actually focused. 514 // We start by making sure the window is actually focused.
514 ASSERT_TRUE(ui_test_utils::ShowAndFocusNativeWindow( 515 ASSERT_TRUE(ui_test_utils::ShowAndFocusNativeWindow(
515 GetFirstAppWindow(extension2->id())->GetNativeWindow())); 516 GetFirstAppWindow(extension2->id())->GetNativeWindow()));
516 517
517 Notification* notification = GetNotificationForExtension(extension1); 518 Notification* notification = GetNotificationForExtension(extension1);
518 ASSERT_TRUE(notification); 519 ASSERT_TRUE(notification);
519 520
520 // The first app window is superseded by the second window, so its 521 // The first app window is superseded by the second window, so its
521 // notification shouldn't be displayed. 522 // notification shouldn't be displayed.
522 ASSERT_FALSE(notification->delegate()->ShouldDisplayOverFullscreen()); 523 ASSERT_FALSE(notification->delegate()->ShouldDisplayOverFullscreen());
523 } 524 }
524 #endif
525 525
526 // Verify that a notification is actually displayed when the app window that 526 // Verify that a notification is actually displayed when the app window that
527 // creates it is fullscreen with the fullscreen notification flag turned on. 527 // creates it is fullscreen with the fullscreen notification flag turned on.
528 IN_PROC_BROWSER_TEST_F(NotificationsApiTest, 528 IN_PROC_BROWSER_TEST_F(NotificationsApiTest,
529 TestShouldDisplayPopupNotification) { 529 TestShouldDisplayPopupNotification) {
530 #if defined(OS_MACOSX)
531 ui::test::ScopedFakeNSWindowFullscreen fake_fullscreen;
532 #endif
533 EnableFullscreenNotifications(); 530 EnableFullscreenNotifications();
534 ExtensionTestMessageListener notification_created_listener("created", false); 531 ExtensionTestMessageListener notification_created_listener("created", false);
535 const Extension* extension = LoadAppWithWindowState( 532 const Extension* extension = LoadAppWithWindowState(
536 "notifications/api/basic_app", WindowState::FULLSCREEN); 533 "notifications/api/basic_app", WindowState::FULLSCREEN);
537 ASSERT_TRUE(extension) << message_; 534 ASSERT_TRUE(extension) << message_;
538 ASSERT_TRUE(notification_created_listener.WaitUntilSatisfied()); 535 ASSERT_TRUE(notification_created_listener.WaitUntilSatisfied());
539 536
540 // We start by making sure the window is actually focused. 537 // We start by making sure the window is actually focused.
541 ASSERT_TRUE(ui_test_utils::ShowAndFocusNativeWindow( 538 ASSERT_TRUE(ui_test_utils::ShowAndFocusNativeWindow(
542 GetFirstAppWindow(extension->id())->GetNativeWindow())); 539 GetFirstAppWindow(extension->id())->GetNativeWindow()));
543 540
544 ASSERT_TRUE(GetFirstAppWindow(extension->id())->IsFullscreen()) 541 ASSERT_TRUE(GetFirstAppWindow(extension->id())->IsFullscreen())
545 << "Not Fullscreen"; 542 << "Not Fullscreen";
546 ASSERT_TRUE(GetFirstAppWindow(extension->id())->GetBaseWindow()->IsActive()) 543 ASSERT_TRUE(GetFirstAppWindow(extension->id())->GetBaseWindow()->IsActive())
547 << "Not Active"; 544 << "Not Active";
548 545
549 Notification* notification = GetNotificationForExtension(extension); 546 Notification* notification = GetNotificationForExtension(extension);
550 ASSERT_TRUE(notification); 547 ASSERT_TRUE(notification);
551 548
552 // The extension's window is being shown and focused, so its expected that 549 // The extension's window is being shown and focused, so its expected that
553 // the notification displays on top of it. 550 // the notification displays on top of it.
554 ASSERT_TRUE(notification->delegate()->ShouldDisplayOverFullscreen()); 551 ASSERT_TRUE(notification->delegate()->ShouldDisplayOverFullscreen());
555 } 552 }
553 #endif // !defined(OS_MACOSX)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698