OLD | NEW |
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 <deque> | 5 #include <deque> |
6 #include <string> | 6 #include <string> |
7 | 7 |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/callback.h" | 9 #include "base/callback.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
385 return false; | 385 return false; |
386 } | 386 } |
387 | 387 |
388 void NotificationsTest::DropOriginPreference(const GURL& origin) { | 388 void NotificationsTest::DropOriginPreference(const GURL& origin) { |
389 DesktopNotificationProfileUtil::ClearSetting(browser()->profile(), | 389 DesktopNotificationProfileUtil::ClearSetting(browser()->profile(), |
390 ContentSettingsPattern::FromURLNoWildcard(origin)); | 390 ContentSettingsPattern::FromURLNoWildcard(origin)); |
391 } | 391 } |
392 | 392 |
393 // Flaky on Windows, Mac, Linux: http://crbug.com/437414. | 393 // Flaky on Windows, Mac, Linux: http://crbug.com/437414. |
394 IN_PROC_BROWSER_TEST_F(NotificationsTest, DISABLED_TestUserGestureInfobar) { | 394 IN_PROC_BROWSER_TEST_F(NotificationsTest, DISABLED_TestUserGestureInfobar) { |
395 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | 395 ASSERT_TRUE(embedded_test_server()->Start()); |
396 | 396 |
397 ui_test_utils::NavigateToURL( | 397 ui_test_utils::NavigateToURL( |
398 browser(), | 398 browser(), |
399 embedded_test_server()->GetURL( | 399 embedded_test_server()->GetURL( |
400 "/notifications/notifications_request_function.html")); | 400 "/notifications/notifications_request_function.html")); |
401 | 401 |
402 // Request permission by calling request() while eval'ing an inline script; | 402 // Request permission by calling request() while eval'ing an inline script; |
403 // That's considered a user gesture to webkit, and should produce an infobar. | 403 // That's considered a user gesture to webkit, and should produce an infobar. |
404 bool result; | 404 bool result; |
405 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( | 405 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( |
406 GetActiveWebContents(browser()), | 406 GetActiveWebContents(browser()), |
407 "window.domAutomationController.send(request());", &result)); | 407 "window.domAutomationController.send(request());", &result)); |
408 EXPECT_TRUE(result); | 408 EXPECT_TRUE(result); |
409 | 409 |
410 InfoBarService* infobar_service = InfoBarService::FromWebContents( | 410 InfoBarService* infobar_service = InfoBarService::FromWebContents( |
411 browser()->tab_strip_model()->GetWebContentsAt(0)); | 411 browser()->tab_strip_model()->GetWebContentsAt(0)); |
412 EXPECT_EQ(1U, infobar_service->infobar_count()); | 412 EXPECT_EQ(1U, infobar_service->infobar_count()); |
413 } | 413 } |
414 | 414 |
415 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestCreateSimpleNotification) { | 415 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestCreateSimpleNotification) { |
416 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | 416 ASSERT_TRUE(embedded_test_server()->Start()); |
417 | 417 |
418 // Creates a simple notification. | 418 // Creates a simple notification. |
419 AllowAllOrigins(); | 419 AllowAllOrigins(); |
420 ui_test_utils::NavigateToURL(browser(), GetTestPageURL()); | 420 ui_test_utils::NavigateToURL(browser(), GetTestPageURL()); |
421 | 421 |
422 std::string result = CreateSimpleNotification(browser(), true); | 422 std::string result = CreateSimpleNotification(browser(), true); |
423 EXPECT_NE("-1", result); | 423 EXPECT_NE("-1", result); |
424 | 424 |
425 GURL EXPECTED_ICON_URL = embedded_test_server()->GetURL(kExpectedIconUrl); | 425 GURL EXPECTED_ICON_URL = embedded_test_server()->GetURL(kExpectedIconUrl); |
426 ASSERT_EQ(1, GetNotificationCount()); | 426 ASSERT_EQ(1, GetNotificationCount()); |
(...skipping 17 matching lines...) Expand all Loading... |
444 std::string result = CreateSimpleNotification(browser(), true); | 444 std::string result = CreateSimpleNotification(browser(), true); |
445 EXPECT_NE("-1", result); | 445 EXPECT_NE("-1", result); |
446 result = CreateSimpleNotification(browser(), true); | 446 result = CreateSimpleNotification(browser(), true); |
447 EXPECT_NE("-1", result); | 447 EXPECT_NE("-1", result); |
448 | 448 |
449 blocker.SetNotificationsEnabled(false); | 449 blocker.SetNotificationsEnabled(false); |
450 EXPECT_EQ(0, GetNotificationPopupCount()); | 450 EXPECT_EQ(0, GetNotificationPopupCount()); |
451 } | 451 } |
452 | 452 |
453 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestCloseNotification) { | 453 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestCloseNotification) { |
454 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | 454 ASSERT_TRUE(embedded_test_server()->Start()); |
455 | 455 |
456 // Creates a notification and closes it. | 456 // Creates a notification and closes it. |
457 AllowAllOrigins(); | 457 AllowAllOrigins(); |
458 ui_test_utils::NavigateToURL(browser(), GetTestPageURL()); | 458 ui_test_utils::NavigateToURL(browser(), GetTestPageURL()); |
459 | 459 |
460 std::string result = CreateSimpleNotification(browser(), true); | 460 std::string result = CreateSimpleNotification(browser(), true); |
461 EXPECT_NE("-1", result); | 461 EXPECT_NE("-1", result); |
462 ASSERT_EQ(1, GetNotificationCount()); | 462 ASSERT_EQ(1, GetNotificationCount()); |
463 | 463 |
464 message_center::NotificationList::Notifications notifications = | 464 message_center::NotificationList::Notifications notifications = |
465 message_center::MessageCenter::Get()->GetVisibleNotifications(); | 465 message_center::MessageCenter::Get()->GetVisibleNotifications(); |
466 message_center::MessageCenter::Get()->RemoveNotification( | 466 message_center::MessageCenter::Get()->RemoveNotification( |
467 (*notifications.rbegin())->id(), | 467 (*notifications.rbegin())->id(), |
468 true); // by_user | 468 true); // by_user |
469 | 469 |
470 ASSERT_EQ(0, GetNotificationCount()); | 470 ASSERT_EQ(0, GetNotificationCount()); |
471 } | 471 } |
472 | 472 |
473 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestCancelNotification) { | 473 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestCancelNotification) { |
474 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | 474 ASSERT_TRUE(embedded_test_server()->Start()); |
475 | 475 |
476 // Creates a notification and cancels it in the origin page. | 476 // Creates a notification and cancels it in the origin page. |
477 AllowAllOrigins(); | 477 AllowAllOrigins(); |
478 ui_test_utils::NavigateToURL(browser(), GetTestPageURL()); | 478 ui_test_utils::NavigateToURL(browser(), GetTestPageURL()); |
479 | 479 |
480 std::string note_id = CreateSimpleNotification(browser(), true); | 480 std::string note_id = CreateSimpleNotification(browser(), true); |
481 EXPECT_NE(note_id, "-1"); | 481 EXPECT_NE(note_id, "-1"); |
482 | 482 |
483 ASSERT_EQ(1, GetNotificationCount()); | 483 ASSERT_EQ(1, GetNotificationCount()); |
484 ASSERT_TRUE(CancelNotification(note_id.c_str(), browser())); | 484 ASSERT_TRUE(CancelNotification(note_id.c_str(), browser())); |
485 ASSERT_EQ(0, GetNotificationCount()); | 485 ASSERT_EQ(0, GetNotificationCount()); |
486 } | 486 } |
487 | 487 |
488 // Requests notification privileges and verifies the prompt appears. | 488 // Requests notification privileges and verifies the prompt appears. |
489 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestPermissionRequestUIAppears) { | 489 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestPermissionRequestUIAppears) { |
490 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | 490 ASSERT_TRUE(embedded_test_server()->Start()); |
491 | 491 |
492 ui_test_utils::NavigateToURL(browser(), GetTestPageURL()); | 492 ui_test_utils::NavigateToURL(browser(), GetTestPageURL()); |
493 EXPECT_TRUE(RequestPermissionAndWait(browser())); | 493 EXPECT_TRUE(RequestPermissionAndWait(browser())); |
494 ASSERT_EQ(0, GetNotificationCount()); | 494 ASSERT_EQ(0, GetNotificationCount()); |
495 } | 495 } |
496 | 496 |
497 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestAllowOnPermissionRequestUI) { | 497 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestAllowOnPermissionRequestUI) { |
498 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | 498 ASSERT_TRUE(embedded_test_server()->Start()); |
499 | 499 |
500 // Tries to create a notification & clicks 'allow' on the prompt. | 500 // Tries to create a notification & clicks 'allow' on the prompt. |
501 ui_test_utils::NavigateToURL(browser(), GetTestPageURL()); | 501 ui_test_utils::NavigateToURL(browser(), GetTestPageURL()); |
502 // This notification should not be shown because we do not have permission. | 502 // This notification should not be shown because we do not have permission. |
503 CreateSimpleNotification(browser(), false); | 503 CreateSimpleNotification(browser(), false); |
504 ASSERT_EQ(0, GetNotificationCount()); | 504 ASSERT_EQ(0, GetNotificationCount()); |
505 | 505 |
506 ASSERT_TRUE(RequestAndAcceptPermission(browser())); | 506 ASSERT_TRUE(RequestAndAcceptPermission(browser())); |
507 | 507 |
508 CreateSimpleNotification(browser(), true); | 508 CreateSimpleNotification(browser(), true); |
509 EXPECT_EQ(1, GetNotificationCount()); | 509 EXPECT_EQ(1, GetNotificationCount()); |
510 } | 510 } |
511 | 511 |
512 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestDenyOnPermissionRequestUI) { | 512 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestDenyOnPermissionRequestUI) { |
513 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | 513 ASSERT_TRUE(embedded_test_server()->Start()); |
514 | 514 |
515 // Test that no notification is created when Deny is chosen from prompt. | 515 // Test that no notification is created when Deny is chosen from prompt. |
516 ui_test_utils::NavigateToURL(browser(), GetTestPageURL()); | 516 ui_test_utils::NavigateToURL(browser(), GetTestPageURL()); |
517 ASSERT_TRUE(RequestAndDenyPermission(browser())); | 517 ASSERT_TRUE(RequestAndDenyPermission(browser())); |
518 CreateSimpleNotification(browser(), false); | 518 CreateSimpleNotification(browser(), false); |
519 ASSERT_EQ(0, GetNotificationCount()); | 519 ASSERT_EQ(0, GetNotificationCount()); |
520 ContentSettingsForOneType settings; | 520 ContentSettingsForOneType settings; |
521 GetPrefsByContentSetting(CONTENT_SETTING_BLOCK, &settings); | 521 GetPrefsByContentSetting(CONTENT_SETTING_BLOCK, &settings); |
522 EXPECT_TRUE(CheckOriginInSetting(settings, GetTestPageURL())); | 522 EXPECT_TRUE(CheckOriginInSetting(settings, GetTestPageURL())); |
523 } | 523 } |
524 | 524 |
525 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestClosePermissionRequestUI) { | 525 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestClosePermissionRequestUI) { |
526 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | 526 ASSERT_TRUE(embedded_test_server()->Start()); |
527 | 527 |
528 // Test that no notification is created when prompt is dismissed. | 528 // Test that no notification is created when prompt is dismissed. |
529 ui_test_utils::NavigateToURL(browser(), GetTestPageURL()); | 529 ui_test_utils::NavigateToURL(browser(), GetTestPageURL()); |
530 ASSERT_TRUE(RequestAndDismissPermission(browser())); | 530 ASSERT_TRUE(RequestAndDismissPermission(browser())); |
531 CreateSimpleNotification(browser(), false); | 531 CreateSimpleNotification(browser(), false); |
532 ASSERT_EQ(0, GetNotificationCount()); | 532 ASSERT_EQ(0, GetNotificationCount()); |
533 ContentSettingsForOneType settings; | 533 ContentSettingsForOneType settings; |
534 GetPrefsByContentSetting(CONTENT_SETTING_BLOCK, &settings); | 534 GetPrefsByContentSetting(CONTENT_SETTING_BLOCK, &settings); |
535 EXPECT_EQ(0U, settings.size()); | 535 EXPECT_EQ(0U, settings.size()); |
536 } | 536 } |
537 | 537 |
538 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestAllowNotificationsFromAllSites) { | 538 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestAllowNotificationsFromAllSites) { |
539 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | 539 ASSERT_TRUE(embedded_test_server()->Start()); |
540 | 540 |
541 // Verify that all domains can be allowed to show notifications. | 541 // Verify that all domains can be allowed to show notifications. |
542 SetDefaultContentSetting(CONTENT_SETTING_ALLOW); | 542 SetDefaultContentSetting(CONTENT_SETTING_ALLOW); |
543 ui_test_utils::NavigateToURL(browser(), GetTestPageURL()); | 543 ui_test_utils::NavigateToURL(browser(), GetTestPageURL()); |
544 | 544 |
545 std::string result = CreateSimpleNotification(browser(), true); | 545 std::string result = CreateSimpleNotification(browser(), true); |
546 EXPECT_NE("-1", result); | 546 EXPECT_NE("-1", result); |
547 | 547 |
548 ASSERT_EQ(1, GetNotificationCount()); | 548 ASSERT_EQ(1, GetNotificationCount()); |
549 } | 549 } |
550 | 550 |
551 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestDenyNotificationsFromAllSites) { | 551 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestDenyNotificationsFromAllSites) { |
552 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | 552 ASSERT_TRUE(embedded_test_server()->Start()); |
553 | 553 |
554 // Verify that no domain can show notifications. | 554 // Verify that no domain can show notifications. |
555 SetDefaultContentSetting(CONTENT_SETTING_BLOCK); | 555 SetDefaultContentSetting(CONTENT_SETTING_BLOCK); |
556 ui_test_utils::NavigateToURL(browser(), GetTestPageURL()); | 556 ui_test_utils::NavigateToURL(browser(), GetTestPageURL()); |
557 | 557 |
558 std::string result = CreateSimpleNotification(browser(), false); | 558 std::string result = CreateSimpleNotification(browser(), false); |
559 EXPECT_EQ("-1", result); | 559 EXPECT_EQ("-1", result); |
560 | 560 |
561 ASSERT_EQ(0, GetNotificationCount()); | 561 ASSERT_EQ(0, GetNotificationCount()); |
562 } | 562 } |
563 | 563 |
564 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestDenyDomainAndAllowAll) { | 564 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestDenyDomainAndAllowAll) { |
565 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | 565 ASSERT_TRUE(embedded_test_server()->Start()); |
566 | 566 |
567 // Verify that denying a domain and allowing all shouldn't show | 567 // Verify that denying a domain and allowing all shouldn't show |
568 // notifications from the denied domain. | 568 // notifications from the denied domain. |
569 DenyOrigin(GetTestPageURL().GetOrigin()); | 569 DenyOrigin(GetTestPageURL().GetOrigin()); |
570 SetDefaultContentSetting(CONTENT_SETTING_ALLOW); | 570 SetDefaultContentSetting(CONTENT_SETTING_ALLOW); |
571 | 571 |
572 ui_test_utils::NavigateToURL(browser(), GetTestPageURL()); | 572 ui_test_utils::NavigateToURL(browser(), GetTestPageURL()); |
573 | 573 |
574 std::string result = CreateSimpleNotification(browser(), false); | 574 std::string result = CreateSimpleNotification(browser(), false); |
575 EXPECT_EQ("-1", result); | 575 EXPECT_EQ("-1", result); |
576 | 576 |
577 ASSERT_EQ(0, GetNotificationCount()); | 577 ASSERT_EQ(0, GetNotificationCount()); |
578 } | 578 } |
579 | 579 |
580 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestAllowDomainAndDenyAll) { | 580 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestAllowDomainAndDenyAll) { |
581 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | 581 ASSERT_TRUE(embedded_test_server()->Start()); |
582 | 582 |
583 // Verify that allowing a domain and denying all others should show | 583 // Verify that allowing a domain and denying all others should show |
584 // notifications from the allowed domain. | 584 // notifications from the allowed domain. |
585 AllowOrigin(GetTestPageURL().GetOrigin()); | 585 AllowOrigin(GetTestPageURL().GetOrigin()); |
586 SetDefaultContentSetting(CONTENT_SETTING_BLOCK); | 586 SetDefaultContentSetting(CONTENT_SETTING_BLOCK); |
587 | 587 |
588 ui_test_utils::NavigateToURL(browser(), GetTestPageURL()); | 588 ui_test_utils::NavigateToURL(browser(), GetTestPageURL()); |
589 | 589 |
590 std::string result = CreateSimpleNotification(browser(), true); | 590 std::string result = CreateSimpleNotification(browser(), true); |
591 EXPECT_NE("-1", result); | 591 EXPECT_NE("-1", result); |
592 | 592 |
593 ASSERT_EQ(1, GetNotificationCount()); | 593 ASSERT_EQ(1, GetNotificationCount()); |
594 } | 594 } |
595 | 595 |
596 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestDenyAndThenAllowDomain) { | 596 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestDenyAndThenAllowDomain) { |
597 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | 597 ASSERT_TRUE(embedded_test_server()->Start()); |
598 | 598 |
599 // Verify that denying and again allowing should show notifications. | 599 // Verify that denying and again allowing should show notifications. |
600 DenyOrigin(GetTestPageURL().GetOrigin()); | 600 DenyOrigin(GetTestPageURL().GetOrigin()); |
601 | 601 |
602 ui_test_utils::NavigateToURL(browser(), GetTestPageURL()); | 602 ui_test_utils::NavigateToURL(browser(), GetTestPageURL()); |
603 | 603 |
604 std::string result = CreateSimpleNotification(browser(), false); | 604 std::string result = CreateSimpleNotification(browser(), false); |
605 EXPECT_EQ("-1", result); | 605 EXPECT_EQ("-1", result); |
606 | 606 |
607 ASSERT_EQ(0, GetNotificationCount()); | 607 ASSERT_EQ(0, GetNotificationCount()); |
608 | 608 |
609 AllowOrigin(GetTestPageURL().GetOrigin()); | 609 AllowOrigin(GetTestPageURL().GetOrigin()); |
610 result = CreateSimpleNotification(browser(), true); | 610 result = CreateSimpleNotification(browser(), true); |
611 EXPECT_NE("-1", result); | 611 EXPECT_NE("-1", result); |
612 | 612 |
613 ASSERT_EQ(1, GetNotificationCount()); | 613 ASSERT_EQ(1, GetNotificationCount()); |
614 } | 614 } |
615 | 615 |
616 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestCreateDenyCloseNotifications) { | 616 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestCreateDenyCloseNotifications) { |
617 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | 617 ASSERT_TRUE(embedded_test_server()->Start()); |
618 | 618 |
619 // Verify able to create, deny, and close the notification. | 619 // Verify able to create, deny, and close the notification. |
620 AllowAllOrigins(); | 620 AllowAllOrigins(); |
621 ui_test_utils::NavigateToURL(browser(), GetTestPageURL()); | 621 ui_test_utils::NavigateToURL(browser(), GetTestPageURL()); |
622 CreateSimpleNotification(browser(), true); | 622 CreateSimpleNotification(browser(), true); |
623 ASSERT_EQ(1, GetNotificationCount()); | 623 ASSERT_EQ(1, GetNotificationCount()); |
624 | 624 |
625 DenyOrigin(GetTestPageURL().GetOrigin()); | 625 DenyOrigin(GetTestPageURL().GetOrigin()); |
626 ContentSettingsForOneType settings; | 626 ContentSettingsForOneType settings; |
627 GetPrefsByContentSetting(CONTENT_SETTING_BLOCK, &settings); | 627 GetPrefsByContentSetting(CONTENT_SETTING_BLOCK, &settings); |
628 ASSERT_TRUE(CheckOriginInSetting(settings, GetTestPageURL().GetOrigin())); | 628 ASSERT_TRUE(CheckOriginInSetting(settings, GetTestPageURL().GetOrigin())); |
629 | 629 |
630 EXPECT_EQ(1, GetNotificationCount()); | 630 EXPECT_EQ(1, GetNotificationCount()); |
631 message_center::NotificationList::Notifications notifications = | 631 message_center::NotificationList::Notifications notifications = |
632 message_center::MessageCenter::Get()->GetVisibleNotifications(); | 632 message_center::MessageCenter::Get()->GetVisibleNotifications(); |
633 message_center::MessageCenter::Get()->RemoveNotification( | 633 message_center::MessageCenter::Get()->RemoveNotification( |
634 (*notifications.rbegin())->id(), | 634 (*notifications.rbegin())->id(), |
635 true); // by_user | 635 true); // by_user |
636 ASSERT_EQ(0, GetNotificationCount()); | 636 ASSERT_EQ(0, GetNotificationCount()); |
637 } | 637 } |
638 | 638 |
639 // Crashes on Linux/Win. See http://crbug.com/160657. | 639 // Crashes on Linux/Win. See http://crbug.com/160657. |
640 IN_PROC_BROWSER_TEST_F( | 640 IN_PROC_BROWSER_TEST_F( |
641 NotificationsTest, | 641 NotificationsTest, |
642 DISABLED_TestOriginPrefsNotSavedInIncognito) { | 642 DISABLED_TestOriginPrefsNotSavedInIncognito) { |
643 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | 643 ASSERT_TRUE(embedded_test_server()->Start()); |
644 | 644 |
645 // Verify that allow/deny origin preferences are not saved in incognito. | 645 // Verify that allow/deny origin preferences are not saved in incognito. |
646 Browser* incognito = CreateIncognitoBrowser(); | 646 Browser* incognito = CreateIncognitoBrowser(); |
647 ui_test_utils::NavigateToURL(incognito, GetTestPageURL()); | 647 ui_test_utils::NavigateToURL(incognito, GetTestPageURL()); |
648 ASSERT_TRUE(RequestAndDenyPermission(incognito)); | 648 ASSERT_TRUE(RequestAndDenyPermission(incognito)); |
649 CloseBrowserWindow(incognito); | 649 CloseBrowserWindow(incognito); |
650 | 650 |
651 incognito = CreateIncognitoBrowser(); | 651 incognito = CreateIncognitoBrowser(); |
652 ui_test_utils::NavigateToURL(incognito, GetTestPageURL()); | 652 ui_test_utils::NavigateToURL(incognito, GetTestPageURL()); |
653 ASSERT_TRUE(RequestAndAcceptPermission(incognito)); | 653 ASSERT_TRUE(RequestAndAcceptPermission(incognito)); |
654 CreateSimpleNotification(incognito, true); | 654 CreateSimpleNotification(incognito, true); |
655 ASSERT_EQ(1, GetNotificationCount()); | 655 ASSERT_EQ(1, GetNotificationCount()); |
656 CloseBrowserWindow(incognito); | 656 CloseBrowserWindow(incognito); |
657 | 657 |
658 incognito = CreateIncognitoBrowser(); | 658 incognito = CreateIncognitoBrowser(); |
659 ui_test_utils::NavigateToURL(incognito, GetTestPageURL()); | 659 ui_test_utils::NavigateToURL(incognito, GetTestPageURL()); |
660 ASSERT_TRUE(RequestPermissionAndWait(incognito)); | 660 ASSERT_TRUE(RequestPermissionAndWait(incognito)); |
661 | 661 |
662 ContentSettingsForOneType settings; | 662 ContentSettingsForOneType settings; |
663 GetPrefsByContentSetting(CONTENT_SETTING_BLOCK, &settings); | 663 GetPrefsByContentSetting(CONTENT_SETTING_BLOCK, &settings); |
664 EXPECT_EQ(0U, settings.size()); | 664 EXPECT_EQ(0U, settings.size()); |
665 GetPrefsByContentSetting(CONTENT_SETTING_ALLOW, &settings); | 665 GetPrefsByContentSetting(CONTENT_SETTING_ALLOW, &settings); |
666 EXPECT_EQ(0U, settings.size()); | 666 EXPECT_EQ(0U, settings.size()); |
667 } | 667 } |
668 | 668 |
669 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestIncognitoNotification) { | 669 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestIncognitoNotification) { |
670 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | 670 ASSERT_TRUE(embedded_test_server()->Start()); |
671 | 671 |
672 // Test notifications in incognito window. | 672 // Test notifications in incognito window. |
673 Browser* browser = CreateIncognitoBrowser(); | 673 Browser* browser = CreateIncognitoBrowser(); |
674 ui_test_utils::NavigateToURL(browser, GetTestPageURL()); | 674 ui_test_utils::NavigateToURL(browser, GetTestPageURL()); |
675 browser->tab_strip_model()->ActivateTabAt(0, true); | 675 browser->tab_strip_model()->ActivateTabAt(0, true); |
676 ASSERT_TRUE(RequestAndAcceptPermission(browser)); | 676 ASSERT_TRUE(RequestAndAcceptPermission(browser)); |
677 CreateSimpleNotification(browser, true); | 677 CreateSimpleNotification(browser, true); |
678 ASSERT_EQ(1, GetNotificationCount()); | 678 ASSERT_EQ(1, GetNotificationCount()); |
679 } | 679 } |
680 | 680 |
681 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestCloseTabWithPermissionRequestUI) { | 681 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestCloseTabWithPermissionRequestUI) { |
682 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | 682 ASSERT_TRUE(embedded_test_server()->Start()); |
683 | 683 |
684 // Test that user can close tab when bubble present. | 684 // Test that user can close tab when bubble present. |
685 ui_test_utils::NavigateToURL(browser(), GetTestPageURL()); | 685 ui_test_utils::NavigateToURL(browser(), GetTestPageURL()); |
686 EXPECT_TRUE(RequestPermissionAndWait(browser())); | 686 EXPECT_TRUE(RequestPermissionAndWait(browser())); |
687 content::WebContentsDestroyedWatcher destroyed_watcher( | 687 content::WebContentsDestroyedWatcher destroyed_watcher( |
688 browser()->tab_strip_model()->GetWebContentsAt(0)); | 688 browser()->tab_strip_model()->GetWebContentsAt(0)); |
689 browser()->tab_strip_model()->CloseWebContentsAt(0, | 689 browser()->tab_strip_model()->CloseWebContentsAt(0, |
690 TabStripModel::CLOSE_NONE); | 690 TabStripModel::CLOSE_NONE); |
691 destroyed_watcher.Wait(); | 691 destroyed_watcher.Wait(); |
692 } | 692 } |
693 | 693 |
694 // See crbug.com/248470 | 694 // See crbug.com/248470 |
695 #if defined(OS_LINUX) | 695 #if defined(OS_LINUX) |
696 #define MAYBE_TestCrashRendererNotificationRemain \ | 696 #define MAYBE_TestCrashRendererNotificationRemain \ |
697 DISABLED_TestCrashRendererNotificationRemain | 697 DISABLED_TestCrashRendererNotificationRemain |
698 #else | 698 #else |
699 #define MAYBE_TestCrashRendererNotificationRemain \ | 699 #define MAYBE_TestCrashRendererNotificationRemain \ |
700 TestCrashRendererNotificationRemain | 700 TestCrashRendererNotificationRemain |
701 #endif | 701 #endif |
702 | 702 |
703 IN_PROC_BROWSER_TEST_F(NotificationsTest, | 703 IN_PROC_BROWSER_TEST_F(NotificationsTest, |
704 MAYBE_TestCrashRendererNotificationRemain) { | 704 MAYBE_TestCrashRendererNotificationRemain) { |
705 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | 705 ASSERT_TRUE(embedded_test_server()->Start()); |
706 | 706 |
707 // Test crashing renderer does not close or crash notification. | 707 // Test crashing renderer does not close or crash notification. |
708 AllowAllOrigins(); | 708 AllowAllOrigins(); |
709 ui_test_utils::NavigateToURLWithDisposition( | 709 ui_test_utils::NavigateToURLWithDisposition( |
710 browser(), | 710 browser(), |
711 GURL("about:blank"), | 711 GURL("about:blank"), |
712 NEW_BACKGROUND_TAB, | 712 NEW_BACKGROUND_TAB, |
713 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); | 713 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); |
714 browser()->tab_strip_model()->ActivateTabAt(0, true); | 714 browser()->tab_strip_model()->ActivateTabAt(0, true); |
715 ui_test_utils::NavigateToURL(browser(), GetTestPageURL()); | 715 ui_test_utils::NavigateToURL(browser(), GetTestPageURL()); |
716 CreateSimpleNotification(browser(), true); | 716 CreateSimpleNotification(browser(), true); |
717 ASSERT_EQ(1, GetNotificationCount()); | 717 ASSERT_EQ(1, GetNotificationCount()); |
718 CrashTab(browser(), 0); | 718 CrashTab(browser(), 0); |
719 ASSERT_EQ(1, GetNotificationCount()); | 719 ASSERT_EQ(1, GetNotificationCount()); |
720 } | 720 } |
721 | 721 |
722 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestNotificationReplacement) { | 722 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestNotificationReplacement) { |
723 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | 723 ASSERT_TRUE(embedded_test_server()->Start()); |
724 | 724 |
725 // Test that we can replace a notification using the replaceId. | 725 // Test that we can replace a notification using the replaceId. |
726 AllowAllOrigins(); | 726 AllowAllOrigins(); |
727 | 727 |
728 ui_test_utils::NavigateToURL(browser(), GetTestPageURL()); | 728 ui_test_utils::NavigateToURL(browser(), GetTestPageURL()); |
729 | 729 |
730 std::string result = CreateNotification( | 730 std::string result = CreateNotification( |
731 browser(), true, "abc.png", "Title1", "Body1", "chat"); | 731 browser(), true, "abc.png", "Title1", "Body1", "chat"); |
732 EXPECT_NE("-1", result); | 732 EXPECT_NE("-1", result); |
733 | 733 |
734 ASSERT_EQ(1, GetNotificationCount()); | 734 ASSERT_EQ(1, GetNotificationCount()); |
735 | 735 |
736 result = CreateNotification( | 736 result = CreateNotification( |
737 browser(), false, "no_such_file.png", "Title2", "Body2", "chat"); | 737 browser(), false, "no_such_file.png", "Title2", "Body2", "chat"); |
738 EXPECT_NE("-1", result); | 738 EXPECT_NE("-1", result); |
739 | 739 |
740 ASSERT_EQ(1, GetNotificationCount()); | 740 ASSERT_EQ(1, GetNotificationCount()); |
741 message_center::NotificationList::Notifications notifications = | 741 message_center::NotificationList::Notifications notifications = |
742 message_center::MessageCenter::Get()->GetVisibleNotifications(); | 742 message_center::MessageCenter::Get()->GetVisibleNotifications(); |
743 EXPECT_EQ(base::ASCIIToUTF16("Title2"), (*notifications.rbegin())->title()); | 743 EXPECT_EQ(base::ASCIIToUTF16("Title2"), (*notifications.rbegin())->title()); |
744 EXPECT_EQ(base::ASCIIToUTF16("Body2"), | 744 EXPECT_EQ(base::ASCIIToUTF16("Body2"), |
745 (*notifications.rbegin())->message()); | 745 (*notifications.rbegin())->message()); |
746 } | 746 } |
747 | 747 |
748 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestLastUsage) { | 748 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestLastUsage) { |
749 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | 749 ASSERT_TRUE(embedded_test_server()->Start()); |
750 | 750 |
751 HostContentSettingsMap* settings_map = | 751 HostContentSettingsMap* settings_map = |
752 HostContentSettingsMapFactory::GetForProfile(browser()->profile()); | 752 HostContentSettingsMapFactory::GetForProfile(browser()->profile()); |
753 base::SimpleTestClock* clock = new base::SimpleTestClock(); | 753 base::SimpleTestClock* clock = new base::SimpleTestClock(); |
754 settings_map->SetPrefClockForTesting(scoped_ptr<base::Clock>(clock)); | 754 settings_map->SetPrefClockForTesting(scoped_ptr<base::Clock>(clock)); |
755 clock->SetNow(base::Time::UnixEpoch() + base::TimeDelta::FromSeconds(10)); | 755 clock->SetNow(base::Time::UnixEpoch() + base::TimeDelta::FromSeconds(10)); |
756 | 756 |
757 // Creates a simple notification. | 757 // Creates a simple notification. |
758 AllowAllOrigins(); | 758 AllowAllOrigins(); |
759 ui_test_utils::NavigateToURL(browser(), GetTestPageURL()); | 759 ui_test_utils::NavigateToURL(browser(), GetTestPageURL()); |
(...skipping 14 matching lines...) Expand all Loading... |
774 | 774 |
775 EXPECT_EQ(settings_map->GetLastUsage(GetTestPageURL().GetOrigin(), | 775 EXPECT_EQ(settings_map->GetLastUsage(GetTestPageURL().GetOrigin(), |
776 GetTestPageURL().GetOrigin(), | 776 GetTestPageURL().GetOrigin(), |
777 CONTENT_SETTINGS_TYPE_NOTIFICATIONS) | 777 CONTENT_SETTINGS_TYPE_NOTIFICATIONS) |
778 .ToDoubleT(), | 778 .ToDoubleT(), |
779 13); | 779 13); |
780 } | 780 } |
781 | 781 |
782 IN_PROC_BROWSER_TEST_F(NotificationsTest, | 782 IN_PROC_BROWSER_TEST_F(NotificationsTest, |
783 TestNotificationReplacementReappearance) { | 783 TestNotificationReplacementReappearance) { |
784 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | 784 ASSERT_TRUE(embedded_test_server()->Start()); |
785 | 785 |
786 // Test that we can replace a notification using the tag, and that it will | 786 // Test that we can replace a notification using the tag, and that it will |
787 // cause the notification to reappear as a popup again. | 787 // cause the notification to reappear as a popup again. |
788 AllowAllOrigins(); | 788 AllowAllOrigins(); |
789 | 789 |
790 ui_test_utils::NavigateToURL(browser(), GetTestPageURL()); | 790 ui_test_utils::NavigateToURL(browser(), GetTestPageURL()); |
791 | 791 |
792 ASSERT_EQ(0, GetNotificationPopupCount()); | 792 ASSERT_EQ(0, GetNotificationPopupCount()); |
793 | 793 |
794 std::string result = CreateNotification( | 794 std::string result = CreateNotification( |
(...skipping 14 matching lines...) Expand all Loading... |
809 #endif | 809 #endif |
810 | 810 |
811 result = CreateNotification( | 811 result = CreateNotification( |
812 browser(), true, "abc.png", "Title2", "Body2", "chat"); | 812 browser(), true, "abc.png", "Title2", "Body2", "chat"); |
813 EXPECT_NE("-1", result); | 813 EXPECT_NE("-1", result); |
814 | 814 |
815 ASSERT_EQ(1, GetNotificationPopupCount()); | 815 ASSERT_EQ(1, GetNotificationPopupCount()); |
816 } | 816 } |
817 | 817 |
818 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestNotificationValidIcon) { | 818 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestNotificationValidIcon) { |
819 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | 819 ASSERT_TRUE(embedded_test_server()->Start()); |
820 AllowAllOrigins(); | 820 AllowAllOrigins(); |
821 | 821 |
822 ui_test_utils::NavigateToURL(browser(), GetTestPageURL()); | 822 ui_test_utils::NavigateToURL(browser(), GetTestPageURL()); |
823 ASSERT_EQ(0, GetNotificationPopupCount()); | 823 ASSERT_EQ(0, GetNotificationPopupCount()); |
824 | 824 |
825 std::string result = CreateNotification( | 825 std::string result = CreateNotification( |
826 browser(), true, "icon.png", "Title1", "Body1", "chat"); | 826 browser(), true, "icon.png", "Title1", "Body1", "chat"); |
827 EXPECT_NE("-1", result); | 827 EXPECT_NE("-1", result); |
828 | 828 |
829 message_center::NotificationList::PopupNotifications notifications = | 829 message_center::NotificationList::PopupNotifications notifications = |
830 message_center::MessageCenter::Get()->GetPopupNotifications(); | 830 message_center::MessageCenter::Get()->GetPopupNotifications(); |
831 ASSERT_EQ(1u, notifications.size()); | 831 ASSERT_EQ(1u, notifications.size()); |
832 | 832 |
833 auto* notification = *notifications.rbegin(); | 833 auto* notification = *notifications.rbegin(); |
834 | 834 |
835 EXPECT_EQ(100, notification->icon().Width()); | 835 EXPECT_EQ(100, notification->icon().Width()); |
836 EXPECT_EQ(100, notification->icon().Height()); | 836 EXPECT_EQ(100, notification->icon().Height()); |
837 } | 837 } |
838 | 838 |
839 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestNotificationInvalidIcon) { | 839 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestNotificationInvalidIcon) { |
840 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | 840 ASSERT_TRUE(embedded_test_server()->Start()); |
841 AllowAllOrigins(); | 841 AllowAllOrigins(); |
842 | 842 |
843 ui_test_utils::NavigateToURL(browser(), GetTestPageURL()); | 843 ui_test_utils::NavigateToURL(browser(), GetTestPageURL()); |
844 ASSERT_EQ(0, GetNotificationPopupCount()); | 844 ASSERT_EQ(0, GetNotificationPopupCount()); |
845 | 845 |
846 // Not supplying an icon URL. | 846 // Not supplying an icon URL. |
847 std::string result = CreateNotification( | 847 std::string result = CreateNotification( |
848 browser(), true, "", "Title1", "Body1", "chat"); | 848 browser(), true, "", "Title1", "Body1", "chat"); |
849 EXPECT_NE("-1", result); | 849 EXPECT_NE("-1", result); |
850 | 850 |
(...skipping 10 matching lines...) Expand all Loading... |
861 EXPECT_NE("-1", result); | 861 EXPECT_NE("-1", result); |
862 | 862 |
863 notifications = message_center::MessageCenter::Get()->GetPopupNotifications(); | 863 notifications = message_center::MessageCenter::Get()->GetPopupNotifications(); |
864 ASSERT_EQ(1u, notifications.size()); | 864 ASSERT_EQ(1u, notifications.size()); |
865 | 865 |
866 notification = *notifications.rbegin(); | 866 notification = *notifications.rbegin(); |
867 EXPECT_TRUE(notification->icon().IsEmpty()); | 867 EXPECT_TRUE(notification->icon().IsEmpty()); |
868 } | 868 } |
869 | 869 |
870 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestNotificationDoubleClose) { | 870 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestNotificationDoubleClose) { |
871 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | 871 ASSERT_TRUE(embedded_test_server()->Start()); |
872 AllowAllOrigins(); | 872 AllowAllOrigins(); |
873 | 873 |
874 ui_test_utils::NavigateToURL( | 874 ui_test_utils::NavigateToURL( |
875 browser(), GetTestPageURLForFile("notification-double-close.html")); | 875 browser(), GetTestPageURLForFile("notification-double-close.html")); |
876 ASSERT_EQ(0, GetNotificationPopupCount()); | 876 ASSERT_EQ(0, GetNotificationPopupCount()); |
877 | 877 |
878 std::string result = CreateNotification( | 878 std::string result = CreateNotification( |
879 browser(), true, "", "Title1", "Body1", "chat"); | 879 browser(), true, "", "Title1", "Body1", "chat"); |
880 EXPECT_NE("-1", result); | 880 EXPECT_NE("-1", result); |
881 | 881 |
882 ASSERT_EQ(1, GetNotificationCount()); | 882 ASSERT_EQ(1, GetNotificationCount()); |
883 message_center::NotificationList::Notifications notifications = | 883 message_center::NotificationList::Notifications notifications = |
884 message_center::MessageCenter::Get()->GetVisibleNotifications(); | 884 message_center::MessageCenter::Get()->GetVisibleNotifications(); |
885 message_center::MessageCenter::Get()->RemoveNotification( | 885 message_center::MessageCenter::Get()->RemoveNotification( |
886 (*notifications.rbegin())->id(), | 886 (*notifications.rbegin())->id(), |
887 true); // by_user | 887 true); // by_user |
888 | 888 |
889 ASSERT_EQ(0, GetNotificationCount()); | 889 ASSERT_EQ(0, GetNotificationCount()); |
890 | 890 |
891 // Calling WebContents::IsCrashed() will return FALSE here, even if the WC did | 891 // Calling WebContents::IsCrashed() will return FALSE here, even if the WC did |
892 // crash. Work around this timing issue by creating another notification, | 892 // crash. Work around this timing issue by creating another notification, |
893 // which requires interaction with the renderer process. | 893 // which requires interaction with the renderer process. |
894 result = CreateNotification(browser(), true, "", "Title1", "Body1", "chat"); | 894 result = CreateNotification(browser(), true, "", "Title1", "Body1", "chat"); |
895 EXPECT_NE("-1", result); | 895 EXPECT_NE("-1", result); |
896 } | 896 } |
OLD | NEW |