| 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_service.h" | 20 #include "chrome/browser/infobars/infobar_service.h" |
| 20 #include "chrome/browser/notifications/balloon.h" | 21 #include "chrome/browser/notifications/balloon.h" |
| 21 #include "chrome/browser/notifications/balloon_collection.h" | 22 #include "chrome/browser/notifications/balloon_collection.h" |
| 22 #include "chrome/browser/notifications/balloon_host.h" | 23 #include "chrome/browser/notifications/balloon_host.h" |
| 23 #include "chrome/browser/notifications/balloon_notification_ui_manager.h" | 24 #include "chrome/browser/notifications/balloon_notification_ui_manager.h" |
| 24 #include "chrome/browser/notifications/desktop_notification_service.h" | 25 #include "chrome/browser/notifications/desktop_notification_service.h" |
| 25 #include "chrome/browser/notifications/desktop_notification_service_factory.h" | 26 #include "chrome/browser/notifications/desktop_notification_service_factory.h" |
| 26 #include "chrome/browser/notifications/notification.h" | 27 #include "chrome/browser/notifications/notification.h" |
| 27 #include "chrome/browser/profiles/profile.h" | 28 #include "chrome/browser/profiles/profile.h" |
| 28 #include "chrome/browser/ui/browser.h" | 29 #include "chrome/browser/ui/browser.h" |
| (...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 313 GetDesktopNotificationService()->SetDefaultContentSetting( | 314 GetDesktopNotificationService()->SetDefaultContentSetting( |
| 314 CONTENT_SETTING_ALLOW); | 315 CONTENT_SETTING_ALLOW); |
| 315 } | 316 } |
| 316 | 317 |
| 317 void NotificationsTest::VerifyInfoBar(const Browser* browser, int index) { | 318 void NotificationsTest::VerifyInfoBar(const Browser* browser, int index) { |
| 318 InfoBarService* infobar_service = InfoBarService::FromWebContents( | 319 InfoBarService* infobar_service = InfoBarService::FromWebContents( |
| 319 browser->tab_strip_model()->GetWebContentsAt(index)); | 320 browser->tab_strip_model()->GetWebContentsAt(index)); |
| 320 | 321 |
| 321 ASSERT_EQ(1U, infobar_service->infobar_count()); | 322 ASSERT_EQ(1U, infobar_service->infobar_count()); |
| 322 ConfirmInfoBarDelegate* confirm_infobar = | 323 ConfirmInfoBarDelegate* confirm_infobar = |
| 323 infobar_service->infobar_at(0)->AsConfirmInfoBarDelegate(); | 324 infobar_service->infobar_at(0)->delegate()->AsConfirmInfoBarDelegate(); |
| 324 ASSERT_TRUE(confirm_infobar); | 325 ASSERT_TRUE(confirm_infobar); |
| 325 int buttons = confirm_infobar->GetButtons(); | 326 int buttons = confirm_infobar->GetButtons(); |
| 326 EXPECT_TRUE(buttons & ConfirmInfoBarDelegate::BUTTON_OK); | 327 EXPECT_TRUE(buttons & ConfirmInfoBarDelegate::BUTTON_OK); |
| 327 EXPECT_TRUE(buttons & ConfirmInfoBarDelegate::BUTTON_CANCEL); | 328 EXPECT_TRUE(buttons & ConfirmInfoBarDelegate::BUTTON_CANCEL); |
| 328 } | 329 } |
| 329 | 330 |
| 330 std::string NotificationsTest::CreateNotification( | 331 std::string NotificationsTest::CreateNotification( |
| 331 Browser* browser, | 332 Browser* browser, |
| 332 bool wait_for_new_balloon, | 333 bool wait_for_new_balloon, |
| 333 const char* icon, | 334 const char* icon, |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 399 InfobarAction action, | 400 InfobarAction action, |
| 400 size_t infobar_index, | 401 size_t infobar_index, |
| 401 int tab_index) { | 402 int tab_index) { |
| 402 InfoBarService* infobar_service = InfoBarService::FromWebContents( | 403 InfoBarService* infobar_service = InfoBarService::FromWebContents( |
| 403 browser->tab_strip_model()->GetWebContentsAt(tab_index)); | 404 browser->tab_strip_model()->GetWebContentsAt(tab_index)); |
| 404 if (infobar_index >= infobar_service->infobar_count()) { | 405 if (infobar_index >= infobar_service->infobar_count()) { |
| 405 ADD_FAILURE(); | 406 ADD_FAILURE(); |
| 406 return false; | 407 return false; |
| 407 } | 408 } |
| 408 | 409 |
| 409 InfoBarDelegate* infobar_delegate = | 410 InfoBar* infobar = infobar_service->infobar_at(infobar_index); |
| 410 infobar_service->infobar_at(infobar_index); | 411 InfoBarDelegate* infobar_delegate = infobar->delegate(); |
| 411 switch (action) { | 412 switch (action) { |
| 412 case DISMISS: | 413 case DISMISS: |
| 413 infobar_delegate->InfoBarDismissed(); | 414 infobar_delegate->InfoBarDismissed(); |
| 414 infobar_service->RemoveInfoBar(infobar_delegate); | 415 infobar_service->RemoveInfoBar(infobar); |
| 415 return true; | 416 return true; |
| 416 | 417 |
| 417 case ALLOW: { | 418 case ALLOW: { |
| 418 ConfirmInfoBarDelegate* confirm_infobar_delegate = | 419 ConfirmInfoBarDelegate* confirm_infobar_delegate = |
| 419 infobar_delegate->AsConfirmInfoBarDelegate(); | 420 infobar_delegate->AsConfirmInfoBarDelegate(); |
| 420 if (!confirm_infobar_delegate) { | 421 if (!confirm_infobar_delegate) { |
| 421 ADD_FAILURE(); | 422 ADD_FAILURE(); |
| 422 } else if (confirm_infobar_delegate->Accept()) { | 423 } else if (confirm_infobar_delegate->Accept()) { |
| 423 infobar_service->RemoveInfoBar(infobar_delegate); | 424 infobar_service->RemoveInfoBar(infobar); |
| 424 return true; | 425 return true; |
| 425 } | 426 } |
| 426 } | 427 } |
| 427 | 428 |
| 428 case DENY: { | 429 case DENY: { |
| 429 ConfirmInfoBarDelegate* confirm_infobar_delegate = | 430 ConfirmInfoBarDelegate* confirm_infobar_delegate = |
| 430 infobar_delegate->AsConfirmInfoBarDelegate(); | 431 infobar_delegate->AsConfirmInfoBarDelegate(); |
| 431 if (!confirm_infobar_delegate) { | 432 if (!confirm_infobar_delegate) { |
| 432 ADD_FAILURE(); | 433 ADD_FAILURE(); |
| 433 } else if (confirm_infobar_delegate->Cancel()) { | 434 } else if (confirm_infobar_delegate->Cancel()) { |
| 434 infobar_service->RemoveInfoBar(infobar_delegate); | 435 infobar_service->RemoveInfoBar(infobar); |
| 435 return true; | 436 return true; |
| 436 } | 437 } |
| 437 } | 438 } |
| 438 } | 439 } |
| 439 | 440 |
| 440 return false; | 441 return false; |
| 441 } | 442 } |
| 442 | 443 |
| 443 void NotificationsTest::GetPrefsByContentSetting( | 444 void NotificationsTest::GetPrefsByContentSetting( |
| 444 ContentSetting setting, | 445 ContentSetting setting, |
| (...skipping 496 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 941 const std::deque<Balloon*>& balloons = GetActiveBalloons(); | 942 const std::deque<Balloon*>& balloons = GetActiveBalloons(); |
| 942 ASSERT_EQ(1U, balloons.size()); | 943 ASSERT_EQ(1U, balloons.size()); |
| 943 Balloon* balloon = balloons[0]; | 944 Balloon* balloon = balloons[0]; |
| 944 const Notification& notification = balloon->notification(); | 945 const Notification& notification = balloon->notification(); |
| 945 GURL EXPECTED_ICON_URL = embedded_test_server()->GetURL(kExpectedIconUrl); | 946 GURL EXPECTED_ICON_URL = embedded_test_server()->GetURL(kExpectedIconUrl); |
| 946 EXPECT_EQ(EXPECTED_ICON_URL, notification.icon_url()); | 947 EXPECT_EQ(EXPECTED_ICON_URL, notification.icon_url()); |
| 947 EXPECT_EQ(ASCIIToUTF16("Title2"), notification.title()); | 948 EXPECT_EQ(ASCIIToUTF16("Title2"), notification.title()); |
| 948 EXPECT_EQ(ASCIIToUTF16("Body2"), notification.message()); | 949 EXPECT_EQ(ASCIIToUTF16("Body2"), notification.message()); |
| 949 } | 950 } |
| 950 } | 951 } |
| OLD | NEW |