| 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_service.h" | 20 #include "chrome/browser/infobars/infobar_service.h" |
| 21 #include "chrome/browser/notifications/balloon.h" | |
| 22 #include "chrome/browser/notifications/balloon_collection.h" | |
| 23 #include "chrome/browser/notifications/balloon_host.h" | |
| 24 #include "chrome/browser/notifications/balloon_notification_ui_manager.h" | |
| 25 #include "chrome/browser/notifications/desktop_notification_service.h" | 21 #include "chrome/browser/notifications/desktop_notification_service.h" |
| 26 #include "chrome/browser/notifications/desktop_notification_service_factory.h" | 22 #include "chrome/browser/notifications/desktop_notification_service_factory.h" |
| 27 #include "chrome/browser/notifications/notification.h" | 23 #include "chrome/browser/notifications/notification.h" |
| 28 #include "chrome/browser/profiles/profile.h" | 24 #include "chrome/browser/profiles/profile.h" |
| 29 #include "chrome/browser/ui/browser.h" | 25 #include "chrome/browser/ui/browser.h" |
| 30 #include "chrome/browser/ui/browser_tabstrip.h" | 26 #include "chrome/browser/ui/browser_tabstrip.h" |
| 31 #include "chrome/browser/ui/browser_window.h" | 27 #include "chrome/browser/ui/browser_window.h" |
| 32 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 28 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 33 #include "chrome/common/content_settings.h" | 29 #include "chrome/common/content_settings.h" |
| 34 #include "chrome/common/content_settings_pattern.h" | 30 #include "chrome/common/content_settings_pattern.h" |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 if (message_loop_runner_.get()) | 107 if (message_loop_runner_.get()) |
| 112 message_loop_runner_->Quit(); | 108 message_loop_runner_->Quit(); |
| 113 } | 109 } |
| 114 | 110 |
| 115 bool notification_received_; | 111 bool notification_received_; |
| 116 scoped_refptr<content::MessageLoopRunner> message_loop_runner_; | 112 scoped_refptr<content::MessageLoopRunner> message_loop_runner_; |
| 117 | 113 |
| 118 DISALLOW_COPY_AND_ASSIGN(MessageCenterChangeObserver); | 114 DISALLOW_COPY_AND_ASSIGN(MessageCenterChangeObserver); |
| 119 }; | 115 }; |
| 120 | 116 |
| 121 class NotificationBalloonChangeObserver | |
| 122 : public content::NotificationObserver, | |
| 123 public NotificationChangeObserver { | |
| 124 public: | |
| 125 NotificationBalloonChangeObserver() | |
| 126 : collection_(BalloonNotificationUIManager::GetInstanceForTesting()-> | |
| 127 balloon_collection()), | |
| 128 collection_changed_(false), | |
| 129 notification_received_(false), | |
| 130 running_(false), | |
| 131 done_(false) { | |
| 132 registrar_.Add(this, chrome::NOTIFICATION_NOTIFY_BALLOON_CONNECTED, | |
| 133 content::NotificationService::AllSources()); | |
| 134 registrar_.Add(this, chrome::NOTIFICATION_NOTIFY_BALLOON_DISCONNECTED, | |
| 135 content::NotificationService::AllSources()); | |
| 136 collection_->set_on_collection_changed_callback( | |
| 137 base::Bind(&NotificationBalloonChangeObserver::OnCollectionChanged, | |
| 138 base::Unretained(this))); | |
| 139 } | |
| 140 | |
| 141 virtual ~NotificationBalloonChangeObserver() { | |
| 142 collection_->set_on_collection_changed_callback(base::Closure()); | |
| 143 } | |
| 144 | |
| 145 // NotificationChangeObserver: | |
| 146 virtual bool Wait() OVERRIDE { | |
| 147 if (!Check()) { | |
| 148 running_ = true; | |
| 149 message_loop_runner_ = new content::MessageLoopRunner; | |
| 150 message_loop_runner_->Run(); | |
| 151 EXPECT_TRUE(done_); | |
| 152 } | |
| 153 return done_; | |
| 154 } | |
| 155 | |
| 156 bool Check() { | |
| 157 if (done_) | |
| 158 return true; | |
| 159 | |
| 160 if (collection_changed_ && notification_received_) { | |
| 161 done_ = true; | |
| 162 if (running_) { | |
| 163 message_loop_runner_->Quit(); | |
| 164 running_ = false; | |
| 165 } | |
| 166 } | |
| 167 return done_; | |
| 168 } | |
| 169 | |
| 170 void OnCollectionChanged() { | |
| 171 collection_changed_ = true; | |
| 172 Check(); | |
| 173 } | |
| 174 | |
| 175 // content::NotificationObserver: | |
| 176 virtual void Observe(int type, | |
| 177 const content::NotificationSource& source, | |
| 178 const content::NotificationDetails& details) OVERRIDE { | |
| 179 DCHECK(type == chrome::NOTIFICATION_NOTIFY_BALLOON_DISCONNECTED || | |
| 180 type == chrome::NOTIFICATION_NOTIFY_BALLOON_CONNECTED); | |
| 181 notification_received_ = true; | |
| 182 Check(); | |
| 183 } | |
| 184 | |
| 185 private: | |
| 186 content::NotificationRegistrar registrar_; | |
| 187 BalloonCollection* collection_; | |
| 188 | |
| 189 bool collection_changed_; | |
| 190 bool notification_received_; | |
| 191 bool running_; | |
| 192 bool done_; | |
| 193 scoped_refptr<content::MessageLoopRunner> message_loop_runner_; | |
| 194 | |
| 195 DISALLOW_COPY_AND_ASSIGN(NotificationBalloonChangeObserver); | |
| 196 }; | |
| 197 | |
| 198 } // namespace | 117 } // namespace |
| 199 | 118 |
| 200 class NotificationsTest : public InProcessBrowserTest { | 119 class NotificationsTest : public InProcessBrowserTest { |
| 201 public: | 120 public: |
| 202 NotificationsTest() {} | 121 NotificationsTest() {} |
| 203 | 122 |
| 204 protected: | 123 protected: |
| 205 int GetNotificationCount(); | 124 int GetNotificationCount(); |
| 206 | 125 |
| 207 NotificationChangeObserver* CreateObserver(); | |
| 208 | |
| 209 void CloseBrowserWindow(Browser* browser); | 126 void CloseBrowserWindow(Browser* browser); |
| 210 void CrashTab(Browser* browser, int index); | 127 void CrashTab(Browser* browser, int index); |
| 211 const std::deque<Balloon*>& GetActiveBalloons(); | |
| 212 void CrashNotification(Balloon* balloon); | |
| 213 bool CloseNotificationAndWait(const Notification& notification); | |
| 214 | 128 |
| 215 void SetDefaultPermissionSetting(ContentSetting setting); | 129 void SetDefaultPermissionSetting(ContentSetting setting); |
| 216 void DenyOrigin(const GURL& origin); | 130 void DenyOrigin(const GURL& origin); |
| 217 void AllowOrigin(const GURL& origin); | 131 void AllowOrigin(const GURL& origin); |
| 218 void AllowAllOrigins(); | 132 void AllowAllOrigins(); |
| 219 | 133 |
| 220 void VerifyInfoBar(const Browser* browser, int index); | 134 void VerifyInfoBar(const Browser* browser, int index); |
| 221 std::string CreateNotification(Browser* browser, | 135 std::string CreateNotification(Browser* browser, |
| 222 bool wait_for_new_balloon, | 136 bool wait_for_new_balloon, |
| 223 const char* icon, | 137 const char* icon, |
| (...skipping 17 matching lines...) Expand all Loading... |
| 241 return embedded_test_server()->GetURL( | 155 return embedded_test_server()->GetURL( |
| 242 "/notifications/notification_tester.html"); | 156 "/notifications/notification_tester.html"); |
| 243 } | 157 } |
| 244 | 158 |
| 245 private: | 159 private: |
| 246 void DropOriginPreference(const GURL& origin); | 160 void DropOriginPreference(const GURL& origin); |
| 247 DesktopNotificationService* GetDesktopNotificationService(); | 161 DesktopNotificationService* GetDesktopNotificationService(); |
| 248 }; | 162 }; |
| 249 | 163 |
| 250 int NotificationsTest::GetNotificationCount() { | 164 int NotificationsTest::GetNotificationCount() { |
| 251 if (message_center::IsRichNotificationEnabled()) { | 165 return message_center::MessageCenter::Get()->NotificationCount(); |
| 252 return message_center::MessageCenter::Get()->NotificationCount(); | |
| 253 } else { | |
| 254 return BalloonNotificationUIManager::GetInstanceForTesting()-> | |
| 255 balloon_collection()->GetActiveBalloons().size(); | |
| 256 } | |
| 257 } | |
| 258 | |
| 259 NotificationChangeObserver* NotificationsTest::CreateObserver() { | |
| 260 if (message_center::IsRichNotificationEnabled()) | |
| 261 return new MessageCenterChangeObserver(); | |
| 262 else | |
| 263 return new NotificationBalloonChangeObserver(); | |
| 264 } | 166 } |
| 265 | 167 |
| 266 void NotificationsTest::CloseBrowserWindow(Browser* browser) { | 168 void NotificationsTest::CloseBrowserWindow(Browser* browser) { |
| 267 content::WindowedNotificationObserver observer( | 169 content::WindowedNotificationObserver observer( |
| 268 chrome::NOTIFICATION_BROWSER_CLOSED, | 170 chrome::NOTIFICATION_BROWSER_CLOSED, |
| 269 content::Source<Browser>(browser)); | 171 content::Source<Browser>(browser)); |
| 270 browser->window()->Close(); | 172 browser->window()->Close(); |
| 271 observer.Wait(); | 173 observer.Wait(); |
| 272 } | 174 } |
| 273 | 175 |
| 274 void NotificationsTest::CrashTab(Browser* browser, int index) { | 176 void NotificationsTest::CrashTab(Browser* browser, int index) { |
| 275 content::CrashTab(browser->tab_strip_model()->GetWebContentsAt(index)); | 177 content::CrashTab(browser->tab_strip_model()->GetWebContentsAt(index)); |
| 276 } | 178 } |
| 277 | 179 |
| 278 const std::deque<Balloon*>& NotificationsTest::GetActiveBalloons() { | |
| 279 return BalloonNotificationUIManager::GetInstanceForTesting()-> | |
| 280 balloon_collection()->GetActiveBalloons(); | |
| 281 } | |
| 282 | |
| 283 void NotificationsTest::CrashNotification(Balloon* balloon) { | |
| 284 content::CrashTab(balloon->balloon_view()->GetHost()->web_contents()); | |
| 285 } | |
| 286 | |
| 287 bool NotificationsTest::CloseNotificationAndWait( | |
| 288 const Notification& notification) { | |
| 289 scoped_ptr<NotificationChangeObserver> observer(CreateObserver()); | |
| 290 bool success = g_browser_process->notification_ui_manager()-> | |
| 291 CancelById(notification.notification_id()); | |
| 292 if (success) | |
| 293 return observer->Wait(); | |
| 294 return false; | |
| 295 } | |
| 296 | |
| 297 void NotificationsTest::SetDefaultPermissionSetting(ContentSetting setting) { | 180 void NotificationsTest::SetDefaultPermissionSetting(ContentSetting setting) { |
| 298 DesktopNotificationService* service = GetDesktopNotificationService(); | 181 DesktopNotificationService* service = GetDesktopNotificationService(); |
| 299 service->SetDefaultContentSetting(setting); | 182 service->SetDefaultContentSetting(setting); |
| 300 } | 183 } |
| 301 | 184 |
| 302 void NotificationsTest::DenyOrigin(const GURL& origin) { | 185 void NotificationsTest::DenyOrigin(const GURL& origin) { |
| 303 DropOriginPreference(origin); | 186 DropOriginPreference(origin); |
| 304 GetDesktopNotificationService()->DenyPermission(origin); | 187 GetDesktopNotificationService()->DenyPermission(origin); |
| 305 } | 188 } |
| 306 | 189 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 332 Browser* browser, | 215 Browser* browser, |
| 333 bool wait_for_new_balloon, | 216 bool wait_for_new_balloon, |
| 334 const char* icon, | 217 const char* icon, |
| 335 const char* title, | 218 const char* title, |
| 336 const char* body, | 219 const char* body, |
| 337 const char* replace_id) { | 220 const char* replace_id) { |
| 338 std::string script = base::StringPrintf( | 221 std::string script = base::StringPrintf( |
| 339 "createNotification('%s', '%s', '%s', '%s');", | 222 "createNotification('%s', '%s', '%s', '%s');", |
| 340 icon, title, body, replace_id); | 223 icon, title, body, replace_id); |
| 341 | 224 |
| 342 scoped_ptr<NotificationChangeObserver> observer(CreateObserver()); | 225 MessageCenterChangeObserver observer; |
| 343 std::string result; | 226 std::string result; |
| 344 bool success = content::ExecuteScriptAndExtractString( | 227 bool success = content::ExecuteScriptAndExtractString( |
| 345 browser->tab_strip_model()->GetActiveWebContents(), | 228 browser->tab_strip_model()->GetActiveWebContents(), |
| 346 script, | 229 script, |
| 347 &result); | 230 &result); |
| 348 if (success && result != "-1" && wait_for_new_balloon) | 231 if (success && result != "-1" && wait_for_new_balloon) |
| 349 success = observer->Wait(); | 232 success = observer.Wait(); |
| 350 EXPECT_TRUE(success); | 233 EXPECT_TRUE(success); |
| 351 | 234 |
| 352 return result; | 235 return result; |
| 353 } | 236 } |
| 354 | 237 |
| 355 std::string NotificationsTest::CreateSimpleNotification( | 238 std::string NotificationsTest::CreateSimpleNotification( |
| 356 Browser* browser, | 239 Browser* browser, |
| 357 bool wait_for_new_balloon) { | 240 bool wait_for_new_balloon) { |
| 358 return CreateNotification( | 241 return CreateNotification( |
| 359 browser, wait_for_new_balloon, | 242 browser, wait_for_new_balloon, |
| (...skipping 17 matching lines...) Expand all Loading... |
| 377 return true; | 260 return true; |
| 378 } | 261 } |
| 379 | 262 |
| 380 bool NotificationsTest::CancelNotification( | 263 bool NotificationsTest::CancelNotification( |
| 381 const char* notification_id, | 264 const char* notification_id, |
| 382 Browser* browser) { | 265 Browser* browser) { |
| 383 std::string script = base::StringPrintf( | 266 std::string script = base::StringPrintf( |
| 384 "cancelNotification('%s');", | 267 "cancelNotification('%s');", |
| 385 notification_id); | 268 notification_id); |
| 386 | 269 |
| 387 scoped_ptr<NotificationChangeObserver> observer(CreateObserver()); | 270 MessageCenterChangeObserver observer; |
| 388 std::string result; | 271 std::string result; |
| 389 bool success = content::ExecuteScriptAndExtractString( | 272 bool success = content::ExecuteScriptAndExtractString( |
| 390 browser->tab_strip_model()->GetActiveWebContents(), | 273 browser->tab_strip_model()->GetActiveWebContents(), |
| 391 script, | 274 script, |
| 392 &result); | 275 &result); |
| 393 if (!success || result != "1") | 276 if (!success || result != "1") |
| 394 return false; | 277 return false; |
| 395 return observer->Wait(); | 278 return observer.Wait(); |
| 396 } | 279 } |
| 397 | 280 |
| 398 bool NotificationsTest::PerformActionOnInfoBar( | 281 bool NotificationsTest::PerformActionOnInfoBar( |
| 399 Browser* browser, | 282 Browser* browser, |
| 400 InfobarAction action, | 283 InfobarAction action, |
| 401 size_t infobar_index, | 284 size_t infobar_index, |
| 402 int tab_index) { | 285 int tab_index) { |
| 403 InfoBarService* infobar_service = InfoBarService::FromWebContents( | 286 InfoBarService* infobar_service = InfoBarService::FromWebContents( |
| 404 browser->tab_strip_model()->GetWebContentsAt(tab_index)); | 287 browser->tab_strip_model()->GetWebContentsAt(tab_index)); |
| 405 if (infobar_index >= infobar_service->infobar_count()) { | 288 if (infobar_index >= infobar_service->infobar_count()) { |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 522 | 405 |
| 523 // Creates a simple notification. | 406 // Creates a simple notification. |
| 524 AllowAllOrigins(); | 407 AllowAllOrigins(); |
| 525 ui_test_utils::NavigateToURL(browser(), GetTestPageURL()); | 408 ui_test_utils::NavigateToURL(browser(), GetTestPageURL()); |
| 526 | 409 |
| 527 std::string result = CreateSimpleNotification(browser(), true); | 410 std::string result = CreateSimpleNotification(browser(), true); |
| 528 EXPECT_NE("-1", result); | 411 EXPECT_NE("-1", result); |
| 529 | 412 |
| 530 GURL EXPECTED_ICON_URL = embedded_test_server()->GetURL(kExpectedIconUrl); | 413 GURL EXPECTED_ICON_URL = embedded_test_server()->GetURL(kExpectedIconUrl); |
| 531 ASSERT_EQ(1, GetNotificationCount()); | 414 ASSERT_EQ(1, GetNotificationCount()); |
| 532 if (message_center::IsRichNotificationEnabled()) { | 415 message_center::NotificationList::Notifications notifications = |
| 533 message_center::NotificationList::Notifications notifications = | 416 message_center::MessageCenter::Get()->GetVisibleNotifications(); |
| 534 message_center::MessageCenter::Get()->GetVisibleNotifications(); | 417 EXPECT_EQ(base::ASCIIToUTF16("My Title"), |
| 535 EXPECT_EQ(base::ASCIIToUTF16("My Title"), | 418 (*notifications.rbegin())->title()); |
| 536 (*notifications.rbegin())->title()); | 419 EXPECT_EQ(base::ASCIIToUTF16("My Body"), |
| 537 EXPECT_EQ(base::ASCIIToUTF16("My Body"), | 420 (*notifications.rbegin())->message()); |
| 538 (*notifications.rbegin())->message()); | |
| 539 } else { | |
| 540 const std::deque<Balloon*>& balloons = GetActiveBalloons(); | |
| 541 ASSERT_EQ(1U, balloons.size()); | |
| 542 Balloon* balloon = balloons[0]; | |
| 543 const Notification& notification = balloon->notification(); | |
| 544 EXPECT_EQ(EXPECTED_ICON_URL, notification.icon_url()); | |
| 545 EXPECT_EQ(base::ASCIIToUTF16("My Title"), notification.title()); | |
| 546 EXPECT_EQ(base::ASCIIToUTF16("My Body"), notification.message()); | |
| 547 } | |
| 548 } | 421 } |
| 549 | 422 |
| 550 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestCloseNotification) { | 423 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestCloseNotification) { |
| 551 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | 424 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 552 | 425 |
| 553 // Creates a notification and closes it. | 426 // Creates a notification and closes it. |
| 554 AllowAllOrigins(); | 427 AllowAllOrigins(); |
| 555 ui_test_utils::NavigateToURL(browser(), GetTestPageURL()); | 428 ui_test_utils::NavigateToURL(browser(), GetTestPageURL()); |
| 556 | 429 |
| 557 std::string result = CreateSimpleNotification(browser(), true); | 430 std::string result = CreateSimpleNotification(browser(), true); |
| 558 EXPECT_NE("-1", result); | 431 EXPECT_NE("-1", result); |
| 559 ASSERT_EQ(1, GetNotificationCount()); | 432 ASSERT_EQ(1, GetNotificationCount()); |
| 560 | 433 |
| 561 if (message_center::IsRichNotificationEnabled()) { | 434 message_center::NotificationList::Notifications notifications = |
| 562 message_center::NotificationList::Notifications notifications = | 435 message_center::MessageCenter::Get()->GetVisibleNotifications(); |
| 563 message_center::MessageCenter::Get()->GetVisibleNotifications(); | 436 message_center::MessageCenter::Get()->RemoveNotification( |
| 564 message_center::MessageCenter::Get()->RemoveNotification( | 437 (*notifications.rbegin())->id(), |
| 565 (*notifications.rbegin())->id(), | 438 true); // by_user |
| 566 true); // by_user | |
| 567 } else { | |
| 568 const std::deque<Balloon*>& balloons = GetActiveBalloons(); | |
| 569 EXPECT_TRUE(CloseNotificationAndWait(balloons[0]->notification())); | |
| 570 } | |
| 571 | 439 |
| 572 ASSERT_EQ(0, GetNotificationCount()); | 440 ASSERT_EQ(0, GetNotificationCount()); |
| 573 } | 441 } |
| 574 | 442 |
| 575 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestCancelNotification) { | 443 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestCancelNotification) { |
| 576 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | 444 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 577 | 445 |
| 578 // Creates a notification and cancels it in the origin page. | 446 // Creates a notification and cancels it in the origin page. |
| 579 AllowAllOrigins(); | 447 AllowAllOrigins(); |
| 580 ui_test_utils::NavigateToURL(browser(), GetTestPageURL()); | 448 ui_test_utils::NavigateToURL(browser(), GetTestPageURL()); |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 735 ui_test_utils::NavigateToURL(browser(), GetTestPageURL()); | 603 ui_test_utils::NavigateToURL(browser(), GetTestPageURL()); |
| 736 CreateSimpleNotification(browser(), true); | 604 CreateSimpleNotification(browser(), true); |
| 737 ASSERT_EQ(1, GetNotificationCount()); | 605 ASSERT_EQ(1, GetNotificationCount()); |
| 738 | 606 |
| 739 DenyOrigin(GetTestPageURL().GetOrigin()); | 607 DenyOrigin(GetTestPageURL().GetOrigin()); |
| 740 ContentSettingsForOneType settings; | 608 ContentSettingsForOneType settings; |
| 741 GetPrefsByContentSetting(CONTENT_SETTING_BLOCK, &settings); | 609 GetPrefsByContentSetting(CONTENT_SETTING_BLOCK, &settings); |
| 742 ASSERT_TRUE(CheckOriginInSetting(settings, GetTestPageURL().GetOrigin())); | 610 ASSERT_TRUE(CheckOriginInSetting(settings, GetTestPageURL().GetOrigin())); |
| 743 | 611 |
| 744 EXPECT_EQ(1, GetNotificationCount()); | 612 EXPECT_EQ(1, GetNotificationCount()); |
| 745 if (message_center::IsRichNotificationEnabled()) { | 613 message_center::NotificationList::Notifications notifications = |
| 746 message_center::NotificationList::Notifications notifications = | 614 message_center::MessageCenter::Get()->GetVisibleNotifications(); |
| 747 message_center::MessageCenter::Get()->GetVisibleNotifications(); | 615 message_center::MessageCenter::Get()->RemoveNotification( |
| 748 message_center::MessageCenter::Get()->RemoveNotification( | 616 (*notifications.rbegin())->id(), |
| 749 (*notifications.rbegin())->id(), | 617 true); // by_user |
| 750 true); // by_user | |
| 751 } else { | |
| 752 const std::deque<Balloon*>& balloons = GetActiveBalloons(); | |
| 753 ASSERT_TRUE(CloseNotificationAndWait(balloons[0]->notification())); | |
| 754 } | |
| 755 ASSERT_EQ(0, GetNotificationCount()); | 618 ASSERT_EQ(0, GetNotificationCount()); |
| 756 } | 619 } |
| 757 | 620 |
| 758 // Crashes on Linux/Win. See http://crbug.com/160657. | 621 // Crashes on Linux/Win. See http://crbug.com/160657. |
| 759 IN_PROC_BROWSER_TEST_F( | 622 IN_PROC_BROWSER_TEST_F( |
| 760 NotificationsTest, | 623 NotificationsTest, |
| 761 DISABLED_TestOriginPrefsNotSavedInIncognito) { | 624 DISABLED_TestOriginPrefsNotSavedInIncognito) { |
| 762 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | 625 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 763 | 626 |
| 764 // Verify that allow/deny origin preferences are not saved in incognito. | 627 // Verify that allow/deny origin preferences are not saved in incognito. |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 812 browser(), | 675 browser(), |
| 813 embedded_test_server()->GetURL("/empty.html"), | 676 embedded_test_server()->GetURL("/empty.html"), |
| 814 NEW_BACKGROUND_TAB, | 677 NEW_BACKGROUND_TAB, |
| 815 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); | 678 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); |
| 816 browser()->tab_strip_model()->ActivateTabAt(0, true); | 679 browser()->tab_strip_model()->ActivateTabAt(0, true); |
| 817 ui_test_utils::NavigateToURL(browser(), GetTestPageURL()); | 680 ui_test_utils::NavigateToURL(browser(), GetTestPageURL()); |
| 818 ASSERT_TRUE(RequestPermissionAndWait(browser())); | 681 ASSERT_TRUE(RequestPermissionAndWait(browser())); |
| 819 CrashTab(browser(), 0); | 682 CrashTab(browser(), 0); |
| 820 } | 683 } |
| 821 | 684 |
| 822 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestKillNotificationProcess) { | |
| 823 // Notifications don't have their own process with the message center. | |
| 824 if (message_center::IsRichNotificationEnabled()) | |
| 825 return; | |
| 826 | |
| 827 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | |
| 828 | |
| 829 // Test killing a notification doesn't crash Chrome. | |
| 830 AllowAllOrigins(); | |
| 831 ui_test_utils::NavigateToURL(browser(), GetTestPageURL()); | |
| 832 CreateSimpleNotification(browser(), true); | |
| 833 ASSERT_EQ(1, GetNotificationCount()); | |
| 834 | |
| 835 const std::deque<Balloon*>& balloons = GetActiveBalloons(); | |
| 836 ASSERT_EQ(1U, balloons.size()); | |
| 837 CrashNotification(balloons[0]); | |
| 838 ASSERT_EQ(0, GetNotificationCount()); | |
| 839 } | |
| 840 | |
| 841 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestIncognitoNotification) { | 685 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestIncognitoNotification) { |
| 842 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | 686 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 843 | 687 |
| 844 // Test notifications in incognito window. | 688 // Test notifications in incognito window. |
| 845 Browser* browser = CreateIncognitoBrowser(); | 689 Browser* browser = CreateIncognitoBrowser(); |
| 846 ui_test_utils::NavigateToURL(browser, GetTestPageURL()); | 690 ui_test_utils::NavigateToURL(browser, GetTestPageURL()); |
| 847 browser->tab_strip_model()->ActivateTabAt(0, true); | 691 browser->tab_strip_model()->ActivateTabAt(0, true); |
| 848 ASSERT_TRUE(RequestPermissionAndWait(browser)); | 692 ASSERT_TRUE(RequestPermissionAndWait(browser)); |
| 849 PerformActionOnInfoBar(browser, ALLOW, 0, 0); | 693 PerformActionOnInfoBar(browser, ALLOW, 0, 0); |
| 850 CreateSimpleNotification(browser, true); | 694 CreateSimpleNotification(browser, true); |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 931 std::string result = CreateNotification( | 775 std::string result = CreateNotification( |
| 932 browser(), true, "abc.png", "Title1", "Body1", "chat"); | 776 browser(), true, "abc.png", "Title1", "Body1", "chat"); |
| 933 EXPECT_NE("-1", result); | 777 EXPECT_NE("-1", result); |
| 934 | 778 |
| 935 ASSERT_EQ(1, GetNotificationCount()); | 779 ASSERT_EQ(1, GetNotificationCount()); |
| 936 | 780 |
| 937 result = CreateNotification( | 781 result = CreateNotification( |
| 938 browser(), false, "no_such_file.png", "Title2", "Body2", "chat"); | 782 browser(), false, "no_such_file.png", "Title2", "Body2", "chat"); |
| 939 EXPECT_NE("-1", result); | 783 EXPECT_NE("-1", result); |
| 940 | 784 |
| 941 if (message_center::IsRichNotificationEnabled()) { | 785 ASSERT_EQ(1, GetNotificationCount()); |
| 942 ASSERT_EQ(1, GetNotificationCount()); | 786 message_center::NotificationList::Notifications notifications = |
| 943 message_center::NotificationList::Notifications notifications = | 787 message_center::MessageCenter::Get()->GetVisibleNotifications(); |
| 944 message_center::MessageCenter::Get()->GetVisibleNotifications(); | 788 EXPECT_EQ(base::ASCIIToUTF16("Title2"), (*notifications.rbegin())->title()); |
| 945 EXPECT_EQ(base::ASCIIToUTF16("Title2"), (*notifications.rbegin())->title()); | 789 EXPECT_EQ(base::ASCIIToUTF16("Body2"), |
| 946 EXPECT_EQ(base::ASCIIToUTF16("Body2"), | 790 (*notifications.rbegin())->message()); |
| 947 (*notifications.rbegin())->message()); | |
| 948 } else { | |
| 949 const std::deque<Balloon*>& balloons = GetActiveBalloons(); | |
| 950 ASSERT_EQ(1U, balloons.size()); | |
| 951 Balloon* balloon = balloons[0]; | |
| 952 const Notification& notification = balloon->notification(); | |
| 953 GURL EXPECTED_ICON_URL = embedded_test_server()->GetURL(kExpectedIconUrl); | |
| 954 EXPECT_EQ(EXPECTED_ICON_URL, notification.icon_url()); | |
| 955 EXPECT_EQ(base::ASCIIToUTF16("Title2"), notification.title()); | |
| 956 EXPECT_EQ(base::ASCIIToUTF16("Body2"), notification.message()); | |
| 957 } | |
| 958 } | 791 } |
| OLD | NEW |