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

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

Issue 228293004: InfoBarService inherits from InfoBarManager (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: review comments 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"
21 #include "chrome/browser/infobars/infobar_service.h" 20 #include "chrome/browser/infobars/infobar_service.h"
22 #include "chrome/browser/notifications/balloon.h" 21 #include "chrome/browser/notifications/balloon.h"
23 #include "chrome/browser/notifications/balloon_collection.h" 22 #include "chrome/browser/notifications/balloon_collection.h"
24 #include "chrome/browser/notifications/balloon_host.h" 23 #include "chrome/browser/notifications/balloon_host.h"
25 #include "chrome/browser/notifications/balloon_notification_ui_manager.h" 24 #include "chrome/browser/notifications/balloon_notification_ui_manager.h"
26 #include "chrome/browser/notifications/desktop_notification_service.h" 25 #include "chrome/browser/notifications/desktop_notification_service.h"
27 #include "chrome/browser/notifications/desktop_notification_service_factory.h" 26 #include "chrome/browser/notifications/desktop_notification_service_factory.h"
28 #include "chrome/browser/notifications/notification.h" 27 #include "chrome/browser/notifications/notification.h"
29 #include "chrome/browser/profiles/profile.h" 28 #include "chrome/browser/profiles/profile.h"
30 #include "chrome/browser/ui/browser.h" 29 #include "chrome/browser/ui/browser.h"
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 311
313 void NotificationsTest::AllowAllOrigins() { 312 void NotificationsTest::AllowAllOrigins() {
314 GetDesktopNotificationService()->ResetAllOrigins(); 313 GetDesktopNotificationService()->ResetAllOrigins();
315 GetDesktopNotificationService()->SetDefaultContentSetting( 314 GetDesktopNotificationService()->SetDefaultContentSetting(
316 CONTENT_SETTING_ALLOW); 315 CONTENT_SETTING_ALLOW);
317 } 316 }
318 317
319 void NotificationsTest::VerifyInfoBar(const Browser* browser, int index) { 318 void NotificationsTest::VerifyInfoBar(const Browser* browser, int index) {
320 InfoBarService* infobar_service = InfoBarService::FromWebContents( 319 InfoBarService* infobar_service = InfoBarService::FromWebContents(
321 browser->tab_strip_model()->GetWebContentsAt(index)); 320 browser->tab_strip_model()->GetWebContentsAt(index));
322 InfoBarManager* infobar_manager = infobar_service->infobar_manager();
323 321
324 ASSERT_EQ(1U, infobar_manager->infobar_count()); 322 ASSERT_EQ(1U, infobar_service->infobar_count());
325 ConfirmInfoBarDelegate* confirm_infobar = 323 ConfirmInfoBarDelegate* confirm_infobar =
326 infobar_manager->infobar_at(0)->delegate()->AsConfirmInfoBarDelegate(); 324 infobar_service->infobar_at(0)->delegate()->AsConfirmInfoBarDelegate();
327 ASSERT_TRUE(confirm_infobar); 325 ASSERT_TRUE(confirm_infobar);
328 int buttons = confirm_infobar->GetButtons(); 326 int buttons = confirm_infobar->GetButtons();
329 EXPECT_TRUE(buttons & ConfirmInfoBarDelegate::BUTTON_OK); 327 EXPECT_TRUE(buttons & ConfirmInfoBarDelegate::BUTTON_OK);
330 EXPECT_TRUE(buttons & ConfirmInfoBarDelegate::BUTTON_CANCEL); 328 EXPECT_TRUE(buttons & ConfirmInfoBarDelegate::BUTTON_CANCEL);
331 } 329 }
332 330
333 std::string NotificationsTest::CreateNotification( 331 std::string NotificationsTest::CreateNotification(
334 Browser* browser, 332 Browser* browser,
335 bool wait_for_new_balloon, 333 bool wait_for_new_balloon,
336 const char* icon, 334 const char* icon,
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
397 return observer->Wait(); 395 return observer->Wait();
398 } 396 }
399 397
400 bool NotificationsTest::PerformActionOnInfoBar( 398 bool NotificationsTest::PerformActionOnInfoBar(
401 Browser* browser, 399 Browser* browser,
402 InfobarAction action, 400 InfobarAction action,
403 size_t infobar_index, 401 size_t infobar_index,
404 int tab_index) { 402 int tab_index) {
405 InfoBarService* infobar_service = InfoBarService::FromWebContents( 403 InfoBarService* infobar_service = InfoBarService::FromWebContents(
406 browser->tab_strip_model()->GetWebContentsAt(tab_index)); 404 browser->tab_strip_model()->GetWebContentsAt(tab_index));
407 InfoBarManager* infobar_manager = infobar_service->infobar_manager(); 405 if (infobar_index >= infobar_service->infobar_count()) {
408 if (infobar_index >= infobar_manager->infobar_count()) {
409 ADD_FAILURE(); 406 ADD_FAILURE();
410 return false; 407 return false;
411 } 408 }
412 409
413 InfoBar* infobar = infobar_manager->infobar_at(infobar_index); 410 InfoBar* infobar = infobar_service->infobar_at(infobar_index);
414 InfoBarDelegate* infobar_delegate = infobar->delegate(); 411 InfoBarDelegate* infobar_delegate = infobar->delegate();
415 switch (action) { 412 switch (action) {
416 case DISMISS: 413 case DISMISS:
417 infobar_delegate->InfoBarDismissed(); 414 infobar_delegate->InfoBarDismissed();
418 infobar_manager->RemoveInfoBar(infobar); 415 infobar_service->RemoveInfoBar(infobar);
419 return true; 416 return true;
420 417
421 case ALLOW: { 418 case ALLOW: {
422 ConfirmInfoBarDelegate* confirm_infobar_delegate = 419 ConfirmInfoBarDelegate* confirm_infobar_delegate =
423 infobar_delegate->AsConfirmInfoBarDelegate(); 420 infobar_delegate->AsConfirmInfoBarDelegate();
424 if (!confirm_infobar_delegate) { 421 if (!confirm_infobar_delegate) {
425 ADD_FAILURE(); 422 ADD_FAILURE();
426 } else if (confirm_infobar_delegate->Accept()) { 423 } else if (confirm_infobar_delegate->Accept()) {
427 infobar_manager->RemoveInfoBar(infobar); 424 infobar_service->RemoveInfoBar(infobar);
428 return true; 425 return true;
429 } 426 }
430 } 427 }
431 428
432 case DENY: { 429 case DENY: {
433 ConfirmInfoBarDelegate* confirm_infobar_delegate = 430 ConfirmInfoBarDelegate* confirm_infobar_delegate =
434 infobar_delegate->AsConfirmInfoBarDelegate(); 431 infobar_delegate->AsConfirmInfoBarDelegate();
435 if (!confirm_infobar_delegate) { 432 if (!confirm_infobar_delegate) {
436 ADD_FAILURE(); 433 ADD_FAILURE();
437 } else if (confirm_infobar_delegate->Cancel()) { 434 } else if (confirm_infobar_delegate->Cancel()) {
438 infobar_manager->RemoveInfoBar(infobar); 435 infobar_service->RemoveInfoBar(infobar);
439 return true; 436 return true;
440 } 437 }
441 } 438 }
442 } 439 }
443 440
444 return false; 441 return false;
445 } 442 }
446 443
447 void NotificationsTest::GetPrefsByContentSetting( 444 void NotificationsTest::GetPrefsByContentSetting(
448 ContentSetting setting, 445 ContentSetting setting,
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
494 // That's considered a user gesture to webkit, and should produce an infobar. 491 // That's considered a user gesture to webkit, and should produce an infobar.
495 bool result; 492 bool result;
496 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( 493 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
497 browser()->tab_strip_model()->GetActiveWebContents(), 494 browser()->tab_strip_model()->GetActiveWebContents(),
498 "window.domAutomationController.send(request());", 495 "window.domAutomationController.send(request());",
499 &result)); 496 &result));
500 EXPECT_TRUE(result); 497 EXPECT_TRUE(result);
501 498
502 InfoBarService* infobar_service = InfoBarService::FromWebContents( 499 InfoBarService* infobar_service = InfoBarService::FromWebContents(
503 browser()->tab_strip_model()->GetWebContentsAt(0)); 500 browser()->tab_strip_model()->GetWebContentsAt(0));
504 EXPECT_EQ(1U, infobar_service->infobar_manager()->infobar_count()); 501 EXPECT_EQ(1U, infobar_service->infobar_count());
505 } 502 }
506 503
507 // If this flakes, use http://crbug.com/62311. 504 // If this flakes, use http://crbug.com/62311.
508 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestNoUserGestureInfobar) { 505 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestNoUserGestureInfobar) {
509 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); 506 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
510 507
511 // Load a page which just does a request; no user gesture should result 508 // Load a page which just does a request; no user gesture should result
512 // in no infobar. 509 // in no infobar.
513 ui_test_utils::NavigateToURL( 510 ui_test_utils::NavigateToURL(
514 browser(), 511 browser(),
515 embedded_test_server()->GetURL( 512 embedded_test_server()->GetURL(
516 "/notifications/notifications_request_inline.html")); 513 "/notifications/notifications_request_inline.html"));
517 514
518 InfoBarService* infobar_service = InfoBarService::FromWebContents( 515 InfoBarService* infobar_service = InfoBarService::FromWebContents(
519 browser()->tab_strip_model()->GetWebContentsAt(0)); 516 browser()->tab_strip_model()->GetWebContentsAt(0));
520 EXPECT_EQ(0U, infobar_service->infobar_manager()->infobar_count()); 517 EXPECT_EQ(0U, infobar_service->infobar_count());
521 } 518 }
522 519
523 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestCreateSimpleNotification) { 520 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestCreateSimpleNotification) {
524 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); 521 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
525 522
526 // Creates a simple notification. 523 // Creates a simple notification.
527 AllowAllOrigins(); 524 AllowAllOrigins();
528 ui_test_utils::NavigateToURL(browser(), GetTestPageURL()); 525 ui_test_utils::NavigateToURL(browser(), GetTestPageURL());
529 526
530 std::string result = CreateSimpleNotification(browser(), true); 527 std::string result = CreateSimpleNotification(browser(), true);
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
652 // Verify that all domains can be allowed to show notifications. 649 // Verify that all domains can be allowed to show notifications.
653 SetDefaultPermissionSetting(CONTENT_SETTING_ALLOW); 650 SetDefaultPermissionSetting(CONTENT_SETTING_ALLOW);
654 ui_test_utils::NavigateToURL(browser(), GetTestPageURL()); 651 ui_test_utils::NavigateToURL(browser(), GetTestPageURL());
655 652
656 std::string result = CreateSimpleNotification(browser(), true); 653 std::string result = CreateSimpleNotification(browser(), true);
657 EXPECT_NE("-1", result); 654 EXPECT_NE("-1", result);
658 655
659 ASSERT_EQ(1, GetNotificationCount()); 656 ASSERT_EQ(1, GetNotificationCount());
660 InfoBarService* infobar_service = InfoBarService::FromWebContents( 657 InfoBarService* infobar_service = InfoBarService::FromWebContents(
661 browser()->tab_strip_model()->GetWebContentsAt(0)); 658 browser()->tab_strip_model()->GetWebContentsAt(0));
662 EXPECT_EQ(0U, infobar_service->infobar_manager()->infobar_count()); 659 EXPECT_EQ(0U, infobar_service->infobar_count());
663 } 660 }
664 661
665 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestDenyNotificationsFromAllSites) { 662 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestDenyNotificationsFromAllSites) {
666 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); 663 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
667 664
668 // Verify that no domain can show notifications. 665 // Verify that no domain can show notifications.
669 SetDefaultPermissionSetting(CONTENT_SETTING_BLOCK); 666 SetDefaultPermissionSetting(CONTENT_SETTING_BLOCK);
670 ui_test_utils::NavigateToURL(browser(), GetTestPageURL()); 667 ui_test_utils::NavigateToURL(browser(), GetTestPageURL());
671 668
672 std::string result = CreateSimpleNotification(browser(), false); 669 std::string result = CreateSimpleNotification(browser(), false);
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
720 717
721 ASSERT_EQ(0, GetNotificationCount()); 718 ASSERT_EQ(0, GetNotificationCount());
722 719
723 AllowOrigin(GetTestPageURL().GetOrigin()); 720 AllowOrigin(GetTestPageURL().GetOrigin());
724 result = CreateSimpleNotification(browser(), true); 721 result = CreateSimpleNotification(browser(), true);
725 EXPECT_NE("-1", result); 722 EXPECT_NE("-1", result);
726 723
727 ASSERT_EQ(1, GetNotificationCount()); 724 ASSERT_EQ(1, GetNotificationCount());
728 InfoBarService* infobar_service = InfoBarService::FromWebContents( 725 InfoBarService* infobar_service = InfoBarService::FromWebContents(
729 browser()->tab_strip_model()->GetWebContentsAt(0)); 726 browser()->tab_strip_model()->GetWebContentsAt(0));
730 EXPECT_EQ(0U, infobar_service->infobar_manager()->infobar_count()); 727 EXPECT_EQ(0U, infobar_service->infobar_count());
731 } 728 }
732 729
733 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestCreateDenyCloseNotifications) { 730 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestCreateDenyCloseNotifications) {
734 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); 731 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
735 732
736 // Verify able to create, deny, and close the notification. 733 // Verify able to create, deny, and close the notification.
737 AllowAllOrigins(); 734 AllowAllOrigins();
738 ui_test_utils::NavigateToURL(browser(), GetTestPageURL()); 735 ui_test_utils::NavigateToURL(browser(), GetTestPageURL());
739 CreateSimpleNotification(browser(), true); 736 CreateSimpleNotification(browser(), true);
740 ASSERT_EQ(1, GetNotificationCount()); 737 ASSERT_EQ(1, GetNotificationCount());
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
952 const std::deque<Balloon*>& balloons = GetActiveBalloons(); 949 const std::deque<Balloon*>& balloons = GetActiveBalloons();
953 ASSERT_EQ(1U, balloons.size()); 950 ASSERT_EQ(1U, balloons.size());
954 Balloon* balloon = balloons[0]; 951 Balloon* balloon = balloons[0];
955 const Notification& notification = balloon->notification(); 952 const Notification& notification = balloon->notification();
956 GURL EXPECTED_ICON_URL = embedded_test_server()->GetURL(kExpectedIconUrl); 953 GURL EXPECTED_ICON_URL = embedded_test_server()->GetURL(kExpectedIconUrl);
957 EXPECT_EQ(EXPECTED_ICON_URL, notification.icon_url()); 954 EXPECT_EQ(EXPECTED_ICON_URL, notification.icon_url());
958 EXPECT_EQ(base::ASCIIToUTF16("Title2"), notification.title()); 955 EXPECT_EQ(base::ASCIIToUTF16("Title2"), notification.title());
959 EXPECT_EQ(base::ASCIIToUTF16("Body2"), notification.message()); 956 EXPECT_EQ(base::ASCIIToUTF16("Body2"), notification.message());
960 } 957 }
961 } 958 }
OLDNEW
« no previous file with comments | « chrome/browser/media/webrtc_browsertest_base.cc ('k') | chrome/browser/password_manager/password_manager_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698