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

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

Issue 211273007: Split InfoBarService core code into InfoBarManager (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix android compilation Created 6 years, 8 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 | Annotate | Revision Log
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 <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 281 matching lines...) Expand 10 before | Expand all | Expand 10 after
311 312
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));
322 InfoBarManager& infobar_manager = infobar_service->infobar_manager();
321 323
322 ASSERT_EQ(1U, infobar_service->infobar_count()); 324 ASSERT_EQ(1U, infobar_manager.infobar_count());
323 ConfirmInfoBarDelegate* confirm_infobar = 325 ConfirmInfoBarDelegate* confirm_infobar =
324 infobar_service->infobar_at(0)->delegate()->AsConfirmInfoBarDelegate(); 326 infobar_manager.infobar_at(0)->delegate()->AsConfirmInfoBarDelegate();
325 ASSERT_TRUE(confirm_infobar); 327 ASSERT_TRUE(confirm_infobar);
326 int buttons = confirm_infobar->GetButtons(); 328 int buttons = confirm_infobar->GetButtons();
327 EXPECT_TRUE(buttons & ConfirmInfoBarDelegate::BUTTON_OK); 329 EXPECT_TRUE(buttons & ConfirmInfoBarDelegate::BUTTON_OK);
328 EXPECT_TRUE(buttons & ConfirmInfoBarDelegate::BUTTON_CANCEL); 330 EXPECT_TRUE(buttons & ConfirmInfoBarDelegate::BUTTON_CANCEL);
329 } 331 }
330 332
331 std::string NotificationsTest::CreateNotification( 333 std::string NotificationsTest::CreateNotification(
332 Browser* browser, 334 Browser* browser,
333 bool wait_for_new_balloon, 335 bool wait_for_new_balloon,
334 const char* icon, 336 const char* icon,
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
395 return observer->Wait(); 397 return observer->Wait();
396 } 398 }
397 399
398 bool NotificationsTest::PerformActionOnInfoBar( 400 bool NotificationsTest::PerformActionOnInfoBar(
399 Browser* browser, 401 Browser* browser,
400 InfobarAction action, 402 InfobarAction action,
401 size_t infobar_index, 403 size_t infobar_index,
402 int tab_index) { 404 int tab_index) {
403 InfoBarService* infobar_service = InfoBarService::FromWebContents( 405 InfoBarService* infobar_service = InfoBarService::FromWebContents(
404 browser->tab_strip_model()->GetWebContentsAt(tab_index)); 406 browser->tab_strip_model()->GetWebContentsAt(tab_index));
405 if (infobar_index >= infobar_service->infobar_count()) { 407 InfoBarManager& infobar_manager = infobar_service->infobar_manager();
408 if (infobar_index >= infobar_manager.infobar_count()) {
406 ADD_FAILURE(); 409 ADD_FAILURE();
407 return false; 410 return false;
408 } 411 }
409 412
410 InfoBar* infobar = infobar_service->infobar_at(infobar_index); 413 InfoBar* infobar = infobar_manager.infobar_at(infobar_index);
411 InfoBarDelegate* infobar_delegate = infobar->delegate(); 414 InfoBarDelegate* infobar_delegate = infobar->delegate();
412 switch (action) { 415 switch (action) {
413 case DISMISS: 416 case DISMISS:
414 infobar_delegate->InfoBarDismissed(); 417 infobar_delegate->InfoBarDismissed();
415 infobar_service->RemoveInfoBar(infobar); 418 infobar_manager.RemoveInfoBar(infobar);
416 return true; 419 return true;
417 420
418 case ALLOW: { 421 case ALLOW: {
419 ConfirmInfoBarDelegate* confirm_infobar_delegate = 422 ConfirmInfoBarDelegate* confirm_infobar_delegate =
420 infobar_delegate->AsConfirmInfoBarDelegate(); 423 infobar_delegate->AsConfirmInfoBarDelegate();
421 if (!confirm_infobar_delegate) { 424 if (!confirm_infobar_delegate) {
422 ADD_FAILURE(); 425 ADD_FAILURE();
423 } else if (confirm_infobar_delegate->Accept()) { 426 } else if (confirm_infobar_delegate->Accept()) {
424 infobar_service->RemoveInfoBar(infobar); 427 infobar_manager.RemoveInfoBar(infobar);
425 return true; 428 return true;
426 } 429 }
427 } 430 }
428 431
429 case DENY: { 432 case DENY: {
430 ConfirmInfoBarDelegate* confirm_infobar_delegate = 433 ConfirmInfoBarDelegate* confirm_infobar_delegate =
431 infobar_delegate->AsConfirmInfoBarDelegate(); 434 infobar_delegate->AsConfirmInfoBarDelegate();
432 if (!confirm_infobar_delegate) { 435 if (!confirm_infobar_delegate) {
433 ADD_FAILURE(); 436 ADD_FAILURE();
434 } else if (confirm_infobar_delegate->Cancel()) { 437 } else if (confirm_infobar_delegate->Cancel()) {
435 infobar_service->RemoveInfoBar(infobar); 438 infobar_manager.RemoveInfoBar(infobar);
436 return true; 439 return true;
437 } 440 }
438 } 441 }
439 } 442 }
440 443
441 return false; 444 return false;
442 } 445 }
443 446
444 void NotificationsTest::GetPrefsByContentSetting( 447 void NotificationsTest::GetPrefsByContentSetting(
445 ContentSetting setting, 448 ContentSetting setting,
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
489 492
490 // Request permission by calling request() while eval'ing an inline script; 493 // 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. 494 // That's considered a user gesture to webkit, and should produce an infobar.
492 bool result; 495 bool result;
493 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( 496 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
494 browser()->tab_strip_model()->GetActiveWebContents(), 497 browser()->tab_strip_model()->GetActiveWebContents(),
495 "window.domAutomationController.send(request());", 498 "window.domAutomationController.send(request());",
496 &result)); 499 &result));
497 EXPECT_TRUE(result); 500 EXPECT_TRUE(result);
498 501
499 EXPECT_EQ(1U, InfoBarService::FromWebContents( 502 EXPECT_EQ(1U,
500 browser()->tab_strip_model()->GetWebContentsAt(0))->infobar_count()); 503 InfoBarService::FromWebContents(
504 browser()->tab_strip_model()->GetWebContentsAt(0))
505 ->infobar_manager()
506 .infobar_count());
blundell 2014/03/27 09:40:30 This indentation seems odd (and below)
501 } 507 }
502 508
503 // If this flakes, use http://crbug.com/62311. 509 // If this flakes, use http://crbug.com/62311.
504 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestNoUserGestureInfobar) { 510 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestNoUserGestureInfobar) {
505 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); 511 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
506 512
507 // Load a page which just does a request; no user gesture should result 513 // Load a page which just does a request; no user gesture should result
508 // in no infobar. 514 // in no infobar.
509 ui_test_utils::NavigateToURL( 515 ui_test_utils::NavigateToURL(
510 browser(), 516 browser(),
511 embedded_test_server()->GetURL( 517 embedded_test_server()->GetURL(
512 "/notifications/notifications_request_inline.html")); 518 "/notifications/notifications_request_inline.html"));
513 519
514 EXPECT_EQ(0U, InfoBarService::FromWebContents( 520 EXPECT_EQ(0U,
515 browser()->tab_strip_model()->GetWebContentsAt(0))->infobar_count()); 521 InfoBarService::FromWebContents(
522 browser()->tab_strip_model()->GetWebContentsAt(0))
523 ->infobar_manager()
524 .infobar_count());
516 } 525 }
517 526
518 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestCreateSimpleNotification) { 527 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestCreateSimpleNotification) {
519 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); 528 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
520 529
521 // Creates a simple notification. 530 // Creates a simple notification.
522 AllowAllOrigins(); 531 AllowAllOrigins();
523 ui_test_utils::NavigateToURL(browser(), GetTestPageURL()); 532 ui_test_utils::NavigateToURL(browser(), GetTestPageURL());
524 533
525 std::string result = CreateSimpleNotification(browser(), true); 534 std::string result = CreateSimpleNotification(browser(), true);
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
645 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); 654 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
646 655
647 // Verify that all domains can be allowed to show notifications. 656 // Verify that all domains can be allowed to show notifications.
648 SetDefaultPermissionSetting(CONTENT_SETTING_ALLOW); 657 SetDefaultPermissionSetting(CONTENT_SETTING_ALLOW);
649 ui_test_utils::NavigateToURL(browser(), GetTestPageURL()); 658 ui_test_utils::NavigateToURL(browser(), GetTestPageURL());
650 659
651 std::string result = CreateSimpleNotification(browser(), true); 660 std::string result = CreateSimpleNotification(browser(), true);
652 EXPECT_NE("-1", result); 661 EXPECT_NE("-1", result);
653 662
654 ASSERT_EQ(1, GetNotificationCount()); 663 ASSERT_EQ(1, GetNotificationCount());
655 EXPECT_EQ(0U, InfoBarService::FromWebContents( 664 InfoBarService* infobar_service = InfoBarService::FromWebContents(
656 browser()->tab_strip_model()->GetWebContentsAt(0))->infobar_count()); 665 browser()->tab_strip_model()->GetWebContentsAt(0));
666 EXPECT_EQ(0U, infobar_service->infobar_manager().infobar_count());
657 } 667 }
658 668
659 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestDenyNotificationsFromAllSites) { 669 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestDenyNotificationsFromAllSites) {
660 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); 670 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
661 671
662 // Verify that no domain can show notifications. 672 // Verify that no domain can show notifications.
663 SetDefaultPermissionSetting(CONTENT_SETTING_BLOCK); 673 SetDefaultPermissionSetting(CONTENT_SETTING_BLOCK);
664 ui_test_utils::NavigateToURL(browser(), GetTestPageURL()); 674 ui_test_utils::NavigateToURL(browser(), GetTestPageURL());
665 675
666 std::string result = CreateSimpleNotification(browser(), false); 676 std::string result = CreateSimpleNotification(browser(), false);
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
712 std::string result = CreateSimpleNotification(browser(), false); 722 std::string result = CreateSimpleNotification(browser(), false);
713 EXPECT_EQ("-1", result); 723 EXPECT_EQ("-1", result);
714 724
715 ASSERT_EQ(0, GetNotificationCount()); 725 ASSERT_EQ(0, GetNotificationCount());
716 726
717 AllowOrigin(GetTestPageURL().GetOrigin()); 727 AllowOrigin(GetTestPageURL().GetOrigin());
718 result = CreateSimpleNotification(browser(), true); 728 result = CreateSimpleNotification(browser(), true);
719 EXPECT_NE("-1", result); 729 EXPECT_NE("-1", result);
720 730
721 ASSERT_EQ(1, GetNotificationCount()); 731 ASSERT_EQ(1, GetNotificationCount());
722 EXPECT_EQ(0U, InfoBarService::FromWebContents( 732 InfoBarService* infobar_service = InfoBarService::FromWebContents(
723 browser()->tab_strip_model()->GetWebContentsAt(0))->infobar_count()); 733 browser()->tab_strip_model()->GetWebContentsAt(0));
734 EXPECT_EQ(0U, infobar_service->infobar_manager().infobar_count());
724 } 735 }
725 736
726 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestCreateDenyCloseNotifications) { 737 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestCreateDenyCloseNotifications) {
727 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); 738 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
728 739
729 // Verify able to create, deny, and close the notification. 740 // Verify able to create, deny, and close the notification.
730 AllowAllOrigins(); 741 AllowAllOrigins();
731 ui_test_utils::NavigateToURL(browser(), GetTestPageURL()); 742 ui_test_utils::NavigateToURL(browser(), GetTestPageURL());
732 CreateSimpleNotification(browser(), true); 743 CreateSimpleNotification(browser(), true);
733 ASSERT_EQ(1, GetNotificationCount()); 744 ASSERT_EQ(1, GetNotificationCount());
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
945 const std::deque<Balloon*>& balloons = GetActiveBalloons(); 956 const std::deque<Balloon*>& balloons = GetActiveBalloons();
946 ASSERT_EQ(1U, balloons.size()); 957 ASSERT_EQ(1U, balloons.size());
947 Balloon* balloon = balloons[0]; 958 Balloon* balloon = balloons[0];
948 const Notification& notification = balloon->notification(); 959 const Notification& notification = balloon->notification();
949 GURL EXPECTED_ICON_URL = embedded_test_server()->GetURL(kExpectedIconUrl); 960 GURL EXPECTED_ICON_URL = embedded_test_server()->GetURL(kExpectedIconUrl);
950 EXPECT_EQ(EXPECTED_ICON_URL, notification.icon_url()); 961 EXPECT_EQ(EXPECTED_ICON_URL, notification.icon_url());
951 EXPECT_EQ(base::ASCIIToUTF16("Title2"), notification.title()); 962 EXPECT_EQ(base::ASCIIToUTF16("Title2"), notification.title());
952 EXPECT_EQ(base::ASCIIToUTF16("Body2"), notification.message()); 963 EXPECT_EQ(base::ASCIIToUTF16("Body2"), notification.message());
953 } 964 }
954 } 965 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698