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" |
11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
13 #include "base/run_loop.h" | 13 #include "base/run_loop.h" |
14 #include "base/strings/stringprintf.h" | 14 #include "base/strings/stringprintf.h" |
15 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
16 #include "chrome/browser/browser_process.h" | 16 #include "chrome/browser/browser_process.h" |
17 #include "chrome/browser/chrome_notification_types.h" | 17 #include "chrome/browser/chrome_notification_types.h" |
18 #include "chrome/browser/infobars/confirm_infobar_delegate.h" | 18 #include "chrome/browser/infobars/confirm_infobar_delegate.h" |
19 #include "chrome/browser/infobars/infobar.h" | 19 #include "chrome/browser/infobars/infobar.h" |
| 20 #include "chrome/browser/infobars/infobar_manager.h" |
20 #include "chrome/browser/infobars/infobar_service.h" | 21 #include "chrome/browser/infobars/infobar_service.h" |
21 #include "chrome/browser/notifications/balloon.h" | 22 #include "chrome/browser/notifications/balloon.h" |
22 #include "chrome/browser/notifications/balloon_collection.h" | 23 #include "chrome/browser/notifications/balloon_collection.h" |
23 #include "chrome/browser/notifications/balloon_host.h" | 24 #include "chrome/browser/notifications/balloon_host.h" |
24 #include "chrome/browser/notifications/balloon_notification_ui_manager.h" | 25 #include "chrome/browser/notifications/balloon_notification_ui_manager.h" |
25 #include "chrome/browser/notifications/desktop_notification_service.h" | 26 #include "chrome/browser/notifications/desktop_notification_service.h" |
26 #include "chrome/browser/notifications/desktop_notification_service_factory.h" | 27 #include "chrome/browser/notifications/desktop_notification_service_factory.h" |
27 #include "chrome/browser/notifications/notification.h" | 28 #include "chrome/browser/notifications/notification.h" |
28 #include "chrome/browser/profiles/profile.h" | 29 #include "chrome/browser/profiles/profile.h" |
29 #include "chrome/browser/ui/browser.h" | 30 #include "chrome/browser/ui/browser.h" |
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
312 void NotificationsTest::AllowAllOrigins() { | 313 void NotificationsTest::AllowAllOrigins() { |
313 GetDesktopNotificationService()->ResetAllOrigins(); | 314 GetDesktopNotificationService()->ResetAllOrigins(); |
314 GetDesktopNotificationService()->SetDefaultContentSetting( | 315 GetDesktopNotificationService()->SetDefaultContentSetting( |
315 CONTENT_SETTING_ALLOW); | 316 CONTENT_SETTING_ALLOW); |
316 } | 317 } |
317 | 318 |
318 void NotificationsTest::VerifyInfoBar(const Browser* browser, int index) { | 319 void NotificationsTest::VerifyInfoBar(const Browser* browser, int index) { |
319 InfoBarService* infobar_service = InfoBarService::FromWebContents( | 320 InfoBarService* infobar_service = InfoBarService::FromWebContents( |
320 browser->tab_strip_model()->GetWebContentsAt(index)); | 321 browser->tab_strip_model()->GetWebContentsAt(index)); |
321 | 322 |
322 ASSERT_EQ(1U, infobar_service->infobar_count()); | 323 ASSERT_EQ(1U, infobar_service->infobar_manager().infobar_count()); |
323 ConfirmInfoBarDelegate* confirm_infobar = | 324 ConfirmInfoBarDelegate* confirm_infobar = infobar_service->infobar_manager() |
324 infobar_service->infobar_at(0)->delegate()->AsConfirmInfoBarDelegate(); | 325 .infobar_at(0) |
| 326 ->delegate() |
| 327 ->AsConfirmInfoBarDelegate(); |
325 ASSERT_TRUE(confirm_infobar); | 328 ASSERT_TRUE(confirm_infobar); |
326 int buttons = confirm_infobar->GetButtons(); | 329 int buttons = confirm_infobar->GetButtons(); |
327 EXPECT_TRUE(buttons & ConfirmInfoBarDelegate::BUTTON_OK); | 330 EXPECT_TRUE(buttons & ConfirmInfoBarDelegate::BUTTON_OK); |
328 EXPECT_TRUE(buttons & ConfirmInfoBarDelegate::BUTTON_CANCEL); | 331 EXPECT_TRUE(buttons & ConfirmInfoBarDelegate::BUTTON_CANCEL); |
329 } | 332 } |
330 | 333 |
331 std::string NotificationsTest::CreateNotification( | 334 std::string NotificationsTest::CreateNotification( |
332 Browser* browser, | 335 Browser* browser, |
333 bool wait_for_new_balloon, | 336 bool wait_for_new_balloon, |
334 const char* icon, | 337 const char* icon, |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
395 return observer->Wait(); | 398 return observer->Wait(); |
396 } | 399 } |
397 | 400 |
398 bool NotificationsTest::PerformActionOnInfoBar( | 401 bool NotificationsTest::PerformActionOnInfoBar( |
399 Browser* browser, | 402 Browser* browser, |
400 InfobarAction action, | 403 InfobarAction action, |
401 size_t infobar_index, | 404 size_t infobar_index, |
402 int tab_index) { | 405 int tab_index) { |
403 InfoBarService* infobar_service = InfoBarService::FromWebContents( | 406 InfoBarService* infobar_service = InfoBarService::FromWebContents( |
404 browser->tab_strip_model()->GetWebContentsAt(tab_index)); | 407 browser->tab_strip_model()->GetWebContentsAt(tab_index)); |
405 if (infobar_index >= infobar_service->infobar_count()) { | 408 InfoBarManager& infobar_manager = infobar_service->infobar_manager(); |
| 409 if (infobar_index >= infobar_manager.infobar_count()) { |
406 ADD_FAILURE(); | 410 ADD_FAILURE(); |
407 return false; | 411 return false; |
408 } | 412 } |
409 | 413 |
410 InfoBar* infobar = infobar_service->infobar_at(infobar_index); | 414 InfoBar* infobar = infobar_manager.infobar_at(infobar_index); |
411 InfoBarDelegate* infobar_delegate = infobar->delegate(); | 415 InfoBarDelegate* infobar_delegate = infobar->delegate(); |
412 switch (action) { | 416 switch (action) { |
413 case DISMISS: | 417 case DISMISS: |
414 infobar_delegate->InfoBarDismissed(); | 418 infobar_delegate->InfoBarDismissed(); |
415 infobar_service->RemoveInfoBar(infobar); | 419 infobar_manager.RemoveInfoBar(infobar); |
416 return true; | 420 return true; |
417 | 421 |
418 case ALLOW: { | 422 case ALLOW: { |
419 ConfirmInfoBarDelegate* confirm_infobar_delegate = | 423 ConfirmInfoBarDelegate* confirm_infobar_delegate = |
420 infobar_delegate->AsConfirmInfoBarDelegate(); | 424 infobar_delegate->AsConfirmInfoBarDelegate(); |
421 if (!confirm_infobar_delegate) { | 425 if (!confirm_infobar_delegate) { |
422 ADD_FAILURE(); | 426 ADD_FAILURE(); |
423 } else if (confirm_infobar_delegate->Accept()) { | 427 } else if (confirm_infobar_delegate->Accept()) { |
424 infobar_service->RemoveInfoBar(infobar); | 428 infobar_manager.RemoveInfoBar(infobar); |
425 return true; | 429 return true; |
426 } | 430 } |
427 } | 431 } |
428 | 432 |
429 case DENY: { | 433 case DENY: { |
430 ConfirmInfoBarDelegate* confirm_infobar_delegate = | 434 ConfirmInfoBarDelegate* confirm_infobar_delegate = |
431 infobar_delegate->AsConfirmInfoBarDelegate(); | 435 infobar_delegate->AsConfirmInfoBarDelegate(); |
432 if (!confirm_infobar_delegate) { | 436 if (!confirm_infobar_delegate) { |
433 ADD_FAILURE(); | 437 ADD_FAILURE(); |
434 } else if (confirm_infobar_delegate->Cancel()) { | 438 } else if (confirm_infobar_delegate->Cancel()) { |
435 infobar_service->RemoveInfoBar(infobar); | 439 infobar_manager.RemoveInfoBar(infobar); |
436 return true; | 440 return true; |
437 } | 441 } |
438 } | 442 } |
439 } | 443 } |
440 | 444 |
441 return false; | 445 return false; |
442 } | 446 } |
443 | 447 |
444 void NotificationsTest::GetPrefsByContentSetting( | 448 void NotificationsTest::GetPrefsByContentSetting( |
445 ContentSetting setting, | 449 ContentSetting setting, |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
489 | 493 |
490 // Request permission by calling request() while eval'ing an inline script; | 494 // Request permission by calling request() while eval'ing an inline script; |
491 // That's considered a user gesture to webkit, and should produce an infobar. | 495 // That's considered a user gesture to webkit, and should produce an infobar. |
492 bool result; | 496 bool result; |
493 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( | 497 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( |
494 browser()->tab_strip_model()->GetActiveWebContents(), | 498 browser()->tab_strip_model()->GetActiveWebContents(), |
495 "window.domAutomationController.send(request());", | 499 "window.domAutomationController.send(request());", |
496 &result)); | 500 &result)); |
497 EXPECT_TRUE(result); | 501 EXPECT_TRUE(result); |
498 | 502 |
499 EXPECT_EQ(1U, InfoBarService::FromWebContents( | 503 EXPECT_EQ(1U, |
500 browser()->tab_strip_model()->GetWebContentsAt(0))->infobar_count()); | 504 InfoBarService::FromWebContents( |
| 505 browser()->tab_strip_model()->GetWebContentsAt(0)) |
| 506 ->infobar_manager() |
| 507 .infobar_count()); |
501 } | 508 } |
502 | 509 |
503 // If this flakes, use http://crbug.com/62311. | 510 // If this flakes, use http://crbug.com/62311. |
504 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestNoUserGestureInfobar) { | 511 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestNoUserGestureInfobar) { |
505 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | 512 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
506 | 513 |
507 // Load a page which just does a request; no user gesture should result | 514 // Load a page which just does a request; no user gesture should result |
508 // in no infobar. | 515 // in no infobar. |
509 ui_test_utils::NavigateToURL( | 516 ui_test_utils::NavigateToURL( |
510 browser(), | 517 browser(), |
511 embedded_test_server()->GetURL( | 518 embedded_test_server()->GetURL( |
512 "/notifications/notifications_request_inline.html")); | 519 "/notifications/notifications_request_inline.html")); |
513 | 520 |
514 EXPECT_EQ(0U, InfoBarService::FromWebContents( | 521 EXPECT_EQ(0U, |
515 browser()->tab_strip_model()->GetWebContentsAt(0))->infobar_count()); | 522 InfoBarService::FromWebContents( |
| 523 browser()->tab_strip_model()->GetWebContentsAt(0)) |
| 524 ->infobar_manager() |
| 525 .infobar_count()); |
516 } | 526 } |
517 | 527 |
518 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestCreateSimpleNotification) { | 528 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestCreateSimpleNotification) { |
519 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | 529 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
520 | 530 |
521 // Creates a simple notification. | 531 // Creates a simple notification. |
522 AllowAllOrigins(); | 532 AllowAllOrigins(); |
523 ui_test_utils::NavigateToURL(browser(), GetTestPageURL()); | 533 ui_test_utils::NavigateToURL(browser(), GetTestPageURL()); |
524 | 534 |
525 std::string result = CreateSimpleNotification(browser(), true); | 535 std::string result = CreateSimpleNotification(browser(), true); |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
645 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | 655 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
646 | 656 |
647 // Verify that all domains can be allowed to show notifications. | 657 // Verify that all domains can be allowed to show notifications. |
648 SetDefaultPermissionSetting(CONTENT_SETTING_ALLOW); | 658 SetDefaultPermissionSetting(CONTENT_SETTING_ALLOW); |
649 ui_test_utils::NavigateToURL(browser(), GetTestPageURL()); | 659 ui_test_utils::NavigateToURL(browser(), GetTestPageURL()); |
650 | 660 |
651 std::string result = CreateSimpleNotification(browser(), true); | 661 std::string result = CreateSimpleNotification(browser(), true); |
652 EXPECT_NE("-1", result); | 662 EXPECT_NE("-1", result); |
653 | 663 |
654 ASSERT_EQ(1, GetNotificationCount()); | 664 ASSERT_EQ(1, GetNotificationCount()); |
655 EXPECT_EQ(0U, InfoBarService::FromWebContents( | 665 EXPECT_EQ(0U, |
656 browser()->tab_strip_model()->GetWebContentsAt(0))->infobar_count()); | 666 InfoBarService::FromWebContents( |
| 667 browser()->tab_strip_model()->GetWebContentsAt(0)) |
| 668 ->infobar_manager() |
| 669 .infobar_count()); |
657 } | 670 } |
658 | 671 |
659 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestDenyNotificationsFromAllSites) { | 672 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestDenyNotificationsFromAllSites) { |
660 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | 673 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
661 | 674 |
662 // Verify that no domain can show notifications. | 675 // Verify that no domain can show notifications. |
663 SetDefaultPermissionSetting(CONTENT_SETTING_BLOCK); | 676 SetDefaultPermissionSetting(CONTENT_SETTING_BLOCK); |
664 ui_test_utils::NavigateToURL(browser(), GetTestPageURL()); | 677 ui_test_utils::NavigateToURL(browser(), GetTestPageURL()); |
665 | 678 |
666 std::string result = CreateSimpleNotification(browser(), false); | 679 std::string result = CreateSimpleNotification(browser(), false); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
712 std::string result = CreateSimpleNotification(browser(), false); | 725 std::string result = CreateSimpleNotification(browser(), false); |
713 EXPECT_EQ("-1", result); | 726 EXPECT_EQ("-1", result); |
714 | 727 |
715 ASSERT_EQ(0, GetNotificationCount()); | 728 ASSERT_EQ(0, GetNotificationCount()); |
716 | 729 |
717 AllowOrigin(GetTestPageURL().GetOrigin()); | 730 AllowOrigin(GetTestPageURL().GetOrigin()); |
718 result = CreateSimpleNotification(browser(), true); | 731 result = CreateSimpleNotification(browser(), true); |
719 EXPECT_NE("-1", result); | 732 EXPECT_NE("-1", result); |
720 | 733 |
721 ASSERT_EQ(1, GetNotificationCount()); | 734 ASSERT_EQ(1, GetNotificationCount()); |
722 EXPECT_EQ(0U, InfoBarService::FromWebContents( | 735 EXPECT_EQ(0U, |
723 browser()->tab_strip_model()->GetWebContentsAt(0))->infobar_count()); | 736 InfoBarService::FromWebContents( |
| 737 browser()->tab_strip_model()->GetWebContentsAt(0)) |
| 738 ->infobar_manager() |
| 739 .infobar_count()); |
724 } | 740 } |
725 | 741 |
726 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestCreateDenyCloseNotifications) { | 742 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestCreateDenyCloseNotifications) { |
727 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | 743 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
728 | 744 |
729 // Verify able to create, deny, and close the notification. | 745 // Verify able to create, deny, and close the notification. |
730 AllowAllOrigins(); | 746 AllowAllOrigins(); |
731 ui_test_utils::NavigateToURL(browser(), GetTestPageURL()); | 747 ui_test_utils::NavigateToURL(browser(), GetTestPageURL()); |
732 CreateSimpleNotification(browser(), true); | 748 CreateSimpleNotification(browser(), true); |
733 ASSERT_EQ(1, GetNotificationCount()); | 749 ASSERT_EQ(1, GetNotificationCount()); |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
945 const std::deque<Balloon*>& balloons = GetActiveBalloons(); | 961 const std::deque<Balloon*>& balloons = GetActiveBalloons(); |
946 ASSERT_EQ(1U, balloons.size()); | 962 ASSERT_EQ(1U, balloons.size()); |
947 Balloon* balloon = balloons[0]; | 963 Balloon* balloon = balloons[0]; |
948 const Notification& notification = balloon->notification(); | 964 const Notification& notification = balloon->notification(); |
949 GURL EXPECTED_ICON_URL = embedded_test_server()->GetURL(kExpectedIconUrl); | 965 GURL EXPECTED_ICON_URL = embedded_test_server()->GetURL(kExpectedIconUrl); |
950 EXPECT_EQ(EXPECTED_ICON_URL, notification.icon_url()); | 966 EXPECT_EQ(EXPECTED_ICON_URL, notification.icon_url()); |
951 EXPECT_EQ(base::ASCIIToUTF16("Title2"), notification.title()); | 967 EXPECT_EQ(base::ASCIIToUTF16("Title2"), notification.title()); |
952 EXPECT_EQ(base::ASCIIToUTF16("Body2"), notification.message()); | 968 EXPECT_EQ(base::ASCIIToUTF16("Body2"), notification.message()); |
953 } | 969 } |
954 } | 970 } |
OLD | NEW |