| 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" |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 #include "chrome/test/base/ui_test_utils.h" | 35 #include "chrome/test/base/ui_test_utils.h" |
| 36 #include "content/public/browser/notification_service.h" | 36 #include "content/public/browser/notification_service.h" |
| 37 #include "content/public/browser/notification_source.h" | 37 #include "content/public/browser/notification_source.h" |
| 38 #include "content/public/browser/notification_types.h" | 38 #include "content/public/browser/notification_types.h" |
| 39 #include "content/public/browser/render_view_host.h" | 39 #include "content/public/browser/render_view_host.h" |
| 40 #include "content/public/browser/web_contents.h" | 40 #include "content/public/browser/web_contents.h" |
| 41 #include "content/public/test/browser_test_utils.h" | 41 #include "content/public/test/browser_test_utils.h" |
| 42 #include "content/public/test/test_utils.h" | 42 #include "content/public/test/test_utils.h" |
| 43 #include "googleurl/src/gurl.h" | 43 #include "googleurl/src/gurl.h" |
| 44 #include "net/base/net_util.h" | 44 #include "net/base/net_util.h" |
| 45 #include "net/test/spawned_test_server/spawned_test_server.h" | 45 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 46 #include "testing/gtest/include/gtest/gtest.h" | 46 #include "testing/gtest/include/gtest/gtest.h" |
| 47 #include "ui/base/window_open_disposition.h" | 47 #include "ui/base/window_open_disposition.h" |
| 48 #include "ui/message_center/message_center.h" | 48 #include "ui/message_center/message_center.h" |
| 49 #include "ui/message_center/message_center_observer.h" | 49 #include "ui/message_center/message_center_observer.h" |
| 50 #include "ui/message_center/message_center_switches.h" | 50 #include "ui/message_center/message_center_switches.h" |
| 51 #include "ui/message_center/message_center_util.h" | 51 #include "ui/message_center/message_center_util.h" |
| 52 | 52 |
| 53 // TODO(kbr): remove: http://crbug.com/222296 | 53 // TODO(kbr): remove: http://crbug.com/222296 |
| 54 #if defined(OS_MACOSX) | 54 #if defined(OS_MACOSX) |
| 55 #import "base/mac/mac_util.h" | 55 #import "base/mac/mac_util.h" |
| 56 #endif | 56 #endif |
| 57 | 57 |
| 58 namespace { | 58 namespace { |
| 59 | 59 |
| 60 const char kExpectedIconUrl[] = "files/notifications/no_such_file.png"; | 60 const char kExpectedIconUrl[] = "/notifications/no_such_file.png"; |
| 61 | 61 |
| 62 enum InfobarAction { | 62 enum InfobarAction { |
| 63 DISMISS = 0, | 63 DISMISS = 0, |
| 64 ALLOW, | 64 ALLOW, |
| 65 DENY, | 65 DENY, |
| 66 }; | 66 }; |
| 67 | 67 |
| 68 class NotificationChangeObserver { | 68 class NotificationChangeObserver { |
| 69 public: | 69 public: |
| 70 virtual ~NotificationChangeObserver() {} | 70 virtual ~NotificationChangeObserver() {} |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 DISALLOW_COPY_AND_ASSIGN(NotificationBalloonChangeObserver); | 199 DISALLOW_COPY_AND_ASSIGN(NotificationBalloonChangeObserver); |
| 200 }; | 200 }; |
| 201 | 201 |
| 202 } // namespace | 202 } // namespace |
| 203 | 203 |
| 204 class NotificationsTest : public InProcessBrowserTest { | 204 class NotificationsTest : public InProcessBrowserTest { |
| 205 public: | 205 public: |
| 206 NotificationsTest() {} | 206 NotificationsTest() {} |
| 207 | 207 |
| 208 protected: | 208 protected: |
| 209 // Overriden from InProcessBrowserTest: | |
| 210 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE; | |
| 211 | |
| 212 int GetNotificationCount(); | 209 int GetNotificationCount(); |
| 213 | 210 |
| 214 NotificationChangeObserver* CreateObserver(); | 211 NotificationChangeObserver* CreateObserver(); |
| 215 | 212 |
| 216 void CloseBrowserWindow(Browser* browser); | 213 void CloseBrowserWindow(Browser* browser); |
| 217 void CrashTab(Browser* browser, int index); | 214 void CrashTab(Browser* browser, int index); |
| 218 const std::deque<Balloon*>& GetActiveBalloons(); | 215 const std::deque<Balloon*>& GetActiveBalloons(); |
| 219 void CrashNotification(Balloon* balloon); | 216 void CrashNotification(Balloon* balloon); |
| 220 bool CloseNotificationAndWait(const Notification& notification); | 217 bool CloseNotificationAndWait(const Notification& notification); |
| 221 | 218 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 237 bool CancelNotification(const char* notification_id, Browser* browser); | 234 bool CancelNotification(const char* notification_id, Browser* browser); |
| 238 bool PerformActionOnInfobar(Browser* browser, | 235 bool PerformActionOnInfobar(Browser* browser, |
| 239 InfobarAction action, | 236 InfobarAction action, |
| 240 int infobar_index, | 237 int infobar_index, |
| 241 int tab_index); | 238 int tab_index); |
| 242 void GetPrefsByContentSetting(ContentSetting setting, | 239 void GetPrefsByContentSetting(ContentSetting setting, |
| 243 ContentSettingsForOneType* settings); | 240 ContentSettingsForOneType* settings); |
| 244 bool CheckOriginInSetting(const ContentSettingsForOneType& settings, | 241 bool CheckOriginInSetting(const ContentSettingsForOneType& settings, |
| 245 const GURL& origin); | 242 const GURL& origin); |
| 246 | 243 |
| 247 GURL empty_page_url_; | 244 GURL GetTestPageURL() const { |
| 248 GURL test_page_url_; | 245 return embedded_test_server()->GetURL( |
| 246 "/notifications/notification_tester.html"); |
| 247 } |
| 249 | 248 |
| 250 private: | 249 private: |
| 251 void DropOriginPreference(const GURL& origin); | 250 void DropOriginPreference(const GURL& origin); |
| 252 DesktopNotificationService* GetDesktopNotificationService(); | 251 DesktopNotificationService* GetDesktopNotificationService(); |
| 253 }; | 252 }; |
| 254 | 253 |
| 255 void NotificationsTest::SetUpInProcessBrowserTestFixture() { | |
| 256 InProcessBrowserTest::SetUpInProcessBrowserTestFixture(); | |
| 257 | |
| 258 ASSERT_TRUE(test_server()->Start()); | |
| 259 empty_page_url_ = test_server()->GetURL("files/empty.html"); | |
| 260 test_page_url_ = test_server()->GetURL( | |
| 261 "files/notifications/notification_tester.html"); | |
| 262 } | |
| 263 | |
| 264 int NotificationsTest::GetNotificationCount() { | 254 int NotificationsTest::GetNotificationCount() { |
| 265 if (message_center::IsRichNotificationEnabled()) { | 255 if (message_center::IsRichNotificationEnabled()) { |
| 266 return message_center::MessageCenter::Get()->NotificationCount(); | 256 return message_center::MessageCenter::Get()->NotificationCount(); |
| 267 } else { | 257 } else { |
| 268 return BalloonNotificationUIManager::GetInstanceForTesting()-> | 258 return BalloonNotificationUIManager::GetInstanceForTesting()-> |
| 269 balloon_collection()->GetActiveBalloons().size(); | 259 balloon_collection()->GetActiveBalloons().size(); |
| 270 } | 260 } |
| 271 } | 261 } |
| 272 | 262 |
| 273 NotificationChangeObserver* NotificationsTest::CreateObserver() { | 263 NotificationChangeObserver* NotificationsTest::CreateObserver() { |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 476 ContentSettingsPattern::FromURLNoWildcard(origin)); | 466 ContentSettingsPattern::FromURLNoWildcard(origin)); |
| 477 } | 467 } |
| 478 | 468 |
| 479 DesktopNotificationService* NotificationsTest::GetDesktopNotificationService() { | 469 DesktopNotificationService* NotificationsTest::GetDesktopNotificationService() { |
| 480 Profile* profile = browser()->profile(); | 470 Profile* profile = browser()->profile(); |
| 481 return DesktopNotificationServiceFactory::GetForProfile(profile); | 471 return DesktopNotificationServiceFactory::GetForProfile(profile); |
| 482 } | 472 } |
| 483 | 473 |
| 484 // If this flakes, use http://crbug.com/62311 and http://crbug.com/74428. | 474 // If this flakes, use http://crbug.com/62311 and http://crbug.com/74428. |
| 485 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestUserGestureInfobar) { | 475 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestUserGestureInfobar) { |
| 476 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 477 |
| 486 ui_test_utils::NavigateToURL( | 478 ui_test_utils::NavigateToURL( |
| 487 browser(), | 479 browser(), |
| 488 test_server()->GetURL( | 480 embedded_test_server()->GetURL( |
| 489 "files/notifications/notifications_request_function.html")); | 481 "/notifications/notifications_request_function.html")); |
| 490 | 482 |
| 491 // Request permission by calling request() while eval'ing an inline script; | 483 // Request permission by calling request() while eval'ing an inline script; |
| 492 // That's considered a user gesture to webkit, and should produce an infobar. | 484 // That's considered a user gesture to webkit, and should produce an infobar. |
| 493 bool result; | 485 bool result; |
| 494 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( | 486 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( |
| 495 browser()->tab_strip_model()->GetActiveWebContents(), | 487 browser()->tab_strip_model()->GetActiveWebContents(), |
| 496 "window.domAutomationController.send(request());", | 488 "window.domAutomationController.send(request());", |
| 497 &result)); | 489 &result)); |
| 498 EXPECT_TRUE(result); | 490 EXPECT_TRUE(result); |
| 499 | 491 |
| 500 EXPECT_EQ(1U, InfoBarService::FromWebContents( | 492 EXPECT_EQ(1U, InfoBarService::FromWebContents( |
| 501 browser()->tab_strip_model()->GetWebContentsAt(0))->infobar_count()); | 493 browser()->tab_strip_model()->GetWebContentsAt(0))->infobar_count()); |
| 502 } | 494 } |
| 503 | 495 |
| 504 // If this flakes, use http://crbug.com/62311. | 496 // If this flakes, use http://crbug.com/62311. |
| 505 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestNoUserGestureInfobar) { | 497 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestNoUserGestureInfobar) { |
| 498 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 499 |
| 506 // Load a page which just does a request; no user gesture should result | 500 // Load a page which just does a request; no user gesture should result |
| 507 // in no infobar. | 501 // in no infobar. |
| 508 ui_test_utils::NavigateToURL( | 502 ui_test_utils::NavigateToURL( |
| 509 browser(), | 503 browser(), |
| 510 test_server()->GetURL( | 504 embedded_test_server()->GetURL( |
| 511 "files/notifications/notifications_request_inline.html")); | 505 "/notifications/notifications_request_inline.html")); |
| 512 | 506 |
| 513 EXPECT_EQ(0U, InfoBarService::FromWebContents( | 507 EXPECT_EQ(0U, InfoBarService::FromWebContents( |
| 514 browser()->tab_strip_model()->GetWebContentsAt(0))->infobar_count()); | 508 browser()->tab_strip_model()->GetWebContentsAt(0))->infobar_count()); |
| 515 } | 509 } |
| 516 | 510 |
| 517 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestCreateSimpleNotification) { | 511 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestCreateSimpleNotification) { |
| 518 #if defined(OS_MACOSX) | 512 #if defined(OS_MACOSX) |
| 519 // TODO(kbr): re-enable: http://crbug.com/222296 | 513 // TODO(kbr): re-enable: http://crbug.com/222296 |
| 520 if (base::mac::IsOSMountainLionOrLater()) | 514 if (base::mac::IsOSMountainLionOrLater()) |
| 521 return; | 515 return; |
| 522 #endif | 516 #endif |
| 523 | 517 |
| 518 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 519 |
| 524 // Creates a simple notification. | 520 // Creates a simple notification. |
| 525 AllowAllOrigins(); | 521 AllowAllOrigins(); |
| 526 ui_test_utils::NavigateToURL(browser(), test_page_url_); | 522 ui_test_utils::NavigateToURL(browser(), GetTestPageURL()); |
| 527 | 523 |
| 528 std::string result = CreateSimpleNotification(browser(), true); | 524 std::string result = CreateSimpleNotification(browser(), true); |
| 529 EXPECT_NE("-1", result); | 525 EXPECT_NE("-1", result); |
| 530 | 526 |
| 531 GURL EXPECTED_ICON_URL = test_server()->GetURL(kExpectedIconUrl); | 527 GURL EXPECTED_ICON_URL = embedded_test_server()->GetURL(kExpectedIconUrl); |
| 532 ASSERT_EQ(1, GetNotificationCount()); | 528 ASSERT_EQ(1, GetNotificationCount()); |
| 533 if (message_center::IsRichNotificationEnabled()) { | 529 if (message_center::IsRichNotificationEnabled()) { |
| 534 message_center::NotificationList::Notifications notifications = | 530 message_center::NotificationList::Notifications notifications = |
| 535 message_center::MessageCenter::Get()->GetNotifications(); | 531 message_center::MessageCenter::Get()->GetNotifications(); |
| 536 EXPECT_EQ(ASCIIToUTF16("My Title"), (*notifications.rbegin())->title()); | 532 EXPECT_EQ(ASCIIToUTF16("My Title"), (*notifications.rbegin())->title()); |
| 537 EXPECT_EQ(ASCIIToUTF16("My Body"), (*notifications.rbegin())->message()); | 533 EXPECT_EQ(ASCIIToUTF16("My Body"), (*notifications.rbegin())->message()); |
| 538 } else { | 534 } else { |
| 539 const std::deque<Balloon*>& balloons = GetActiveBalloons(); | 535 const std::deque<Balloon*>& balloons = GetActiveBalloons(); |
| 540 ASSERT_EQ(1U, balloons.size()); | 536 ASSERT_EQ(1U, balloons.size()); |
| 541 Balloon* balloon = balloons[0]; | 537 Balloon* balloon = balloons[0]; |
| 542 const Notification& notification = balloon->notification(); | 538 const Notification& notification = balloon->notification(); |
| 543 EXPECT_EQ(EXPECTED_ICON_URL, notification.icon_url()); | 539 EXPECT_EQ(EXPECTED_ICON_URL, notification.icon_url()); |
| 544 EXPECT_EQ(ASCIIToUTF16("My Title"), notification.title()); | 540 EXPECT_EQ(ASCIIToUTF16("My Title"), notification.title()); |
| 545 EXPECT_EQ(ASCIIToUTF16("My Body"), notification.message()); | 541 EXPECT_EQ(ASCIIToUTF16("My Body"), notification.message()); |
| 546 } | 542 } |
| 547 } | 543 } |
| 548 | 544 |
| 549 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestCloseNotification) { | 545 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestCloseNotification) { |
| 550 #if defined(OS_MACOSX) | 546 #if defined(OS_MACOSX) |
| 551 // TODO(kbr): re-enable: http://crbug.com/222296 | 547 // TODO(kbr): re-enable: http://crbug.com/222296 |
| 552 if (base::mac::IsOSMountainLionOrLater()) | 548 if (base::mac::IsOSMountainLionOrLater()) |
| 553 return; | 549 return; |
| 554 #endif | 550 #endif |
| 555 | 551 |
| 552 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 553 |
| 556 // Creates a notification and closes it. | 554 // Creates a notification and closes it. |
| 557 AllowAllOrigins(); | 555 AllowAllOrigins(); |
| 558 ui_test_utils::NavigateToURL(browser(), test_page_url_); | 556 ui_test_utils::NavigateToURL(browser(), GetTestPageURL()); |
| 559 | 557 |
| 560 std::string result = CreateSimpleNotification(browser(), true); | 558 std::string result = CreateSimpleNotification(browser(), true); |
| 561 EXPECT_NE("-1", result); | 559 EXPECT_NE("-1", result); |
| 562 ASSERT_EQ(1, GetNotificationCount()); | 560 ASSERT_EQ(1, GetNotificationCount()); |
| 563 | 561 |
| 564 if (message_center::IsRichNotificationEnabled()) { | 562 if (message_center::IsRichNotificationEnabled()) { |
| 565 message_center::NotificationList::Notifications notifications = | 563 message_center::NotificationList::Notifications notifications = |
| 566 message_center::MessageCenter::Get()->GetNotifications(); | 564 message_center::MessageCenter::Get()->GetNotifications(); |
| 567 message_center::MessageCenter::Get()->RemoveNotification( | 565 message_center::MessageCenter::Get()->RemoveNotification( |
| 568 (*notifications.rbegin())->id(), | 566 (*notifications.rbegin())->id(), |
| 569 true); // by_user | 567 true); // by_user |
| 570 } else { | 568 } else { |
| 571 const std::deque<Balloon*>& balloons = GetActiveBalloons(); | 569 const std::deque<Balloon*>& balloons = GetActiveBalloons(); |
| 572 EXPECT_TRUE(CloseNotificationAndWait(balloons[0]->notification())); | 570 EXPECT_TRUE(CloseNotificationAndWait(balloons[0]->notification())); |
| 573 } | 571 } |
| 574 | 572 |
| 575 ASSERT_EQ(0, GetNotificationCount()); | 573 ASSERT_EQ(0, GetNotificationCount()); |
| 576 } | 574 } |
| 577 | 575 |
| 578 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestCancelNotification) { | 576 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestCancelNotification) { |
| 579 #if defined(OS_MACOSX) | 577 #if defined(OS_MACOSX) |
| 580 // TODO(kbr): re-enable: http://crbug.com/222296 | 578 // TODO(kbr): re-enable: http://crbug.com/222296 |
| 581 if (base::mac::IsOSMountainLionOrLater()) | 579 if (base::mac::IsOSMountainLionOrLater()) |
| 582 return; | 580 return; |
| 583 #endif | 581 #endif |
| 584 | 582 |
| 583 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 584 |
| 585 // Creates a notification and cancels it in the origin page. | 585 // Creates a notification and cancels it in the origin page. |
| 586 AllowAllOrigins(); | 586 AllowAllOrigins(); |
| 587 ui_test_utils::NavigateToURL(browser(), test_page_url_); | 587 ui_test_utils::NavigateToURL(browser(), GetTestPageURL()); |
| 588 | 588 |
| 589 std::string note_id = CreateSimpleNotification(browser(), true); | 589 std::string note_id = CreateSimpleNotification(browser(), true); |
| 590 EXPECT_NE(note_id, "-1"); | 590 EXPECT_NE(note_id, "-1"); |
| 591 | 591 |
| 592 ASSERT_EQ(1, GetNotificationCount()); | 592 ASSERT_EQ(1, GetNotificationCount()); |
| 593 ASSERT_TRUE(CancelNotification(note_id.c_str(), browser())); | 593 ASSERT_TRUE(CancelNotification(note_id.c_str(), browser())); |
| 594 ASSERT_EQ(0, GetNotificationCount()); | 594 ASSERT_EQ(0, GetNotificationCount()); |
| 595 } | 595 } |
| 596 | 596 |
| 597 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestPermissionInfobarAppears) { | 597 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestPermissionInfobarAppears) { |
| 598 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 599 |
| 598 // Requests notification privileges and verifies the infobar appears. | 600 // Requests notification privileges and verifies the infobar appears. |
| 599 ui_test_utils::NavigateToURL(browser(), test_page_url_); | 601 ui_test_utils::NavigateToURL(browser(), GetTestPageURL()); |
| 600 ASSERT_TRUE(RequestPermissionAndWait(browser())); | 602 ASSERT_TRUE(RequestPermissionAndWait(browser())); |
| 601 | 603 |
| 602 ASSERT_EQ(0, GetNotificationCount()); | 604 ASSERT_EQ(0, GetNotificationCount()); |
| 603 VerifyInfobar(browser(), 0); | 605 VerifyInfobar(browser(), 0); |
| 604 } | 606 } |
| 605 | 607 |
| 606 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestAllowOnPermissionInfobar) { | 608 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestAllowOnPermissionInfobar) { |
| 607 #if defined(OS_MACOSX) | 609 #if defined(OS_MACOSX) |
| 608 // TODO(kbr): re-enable: http://crbug.com/222296 | 610 // TODO(kbr): re-enable: http://crbug.com/222296 |
| 609 if (base::mac::IsOSMountainLionOrLater()) | 611 if (base::mac::IsOSMountainLionOrLater()) |
| 610 return; | 612 return; |
| 611 #endif | 613 #endif |
| 612 | 614 |
| 615 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 616 |
| 613 // Tries to create a notification and clicks allow on the infobar. | 617 // Tries to create a notification and clicks allow on the infobar. |
| 614 ui_test_utils::NavigateToURL(browser(), test_page_url_); | 618 ui_test_utils::NavigateToURL(browser(), GetTestPageURL()); |
| 615 // This notification should not be shown because we do not have permission. | 619 // This notification should not be shown because we do not have permission. |
| 616 CreateSimpleNotification(browser(), false); | 620 CreateSimpleNotification(browser(), false); |
| 617 ASSERT_EQ(0, GetNotificationCount()); | 621 ASSERT_EQ(0, GetNotificationCount()); |
| 618 | 622 |
| 619 ASSERT_TRUE(RequestPermissionAndWait(browser())); | 623 ASSERT_TRUE(RequestPermissionAndWait(browser())); |
| 620 ASSERT_TRUE(PerformActionOnInfobar(browser(), ALLOW, 0, 0)); | 624 ASSERT_TRUE(PerformActionOnInfobar(browser(), ALLOW, 0, 0)); |
| 621 | 625 |
| 622 CreateSimpleNotification(browser(), true); | 626 CreateSimpleNotification(browser(), true); |
| 623 EXPECT_EQ(1, GetNotificationCount()); | 627 EXPECT_EQ(1, GetNotificationCount()); |
| 624 } | 628 } |
| 625 | 629 |
| 626 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestDenyOnPermissionInfobar) { | 630 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestDenyOnPermissionInfobar) { |
| 631 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 632 |
| 627 // Test that no notification is created | 633 // Test that no notification is created |
| 628 // when Deny is chosen from permission infobar. | 634 // when Deny is chosen from permission infobar. |
| 629 ui_test_utils::NavigateToURL(browser(), test_page_url_); | 635 ui_test_utils::NavigateToURL(browser(), GetTestPageURL()); |
| 630 ASSERT_TRUE(RequestPermissionAndWait(browser())); | 636 ASSERT_TRUE(RequestPermissionAndWait(browser())); |
| 631 PerformActionOnInfobar(browser(), DENY, 0, 0); | 637 PerformActionOnInfobar(browser(), DENY, 0, 0); |
| 632 CreateSimpleNotification(browser(), false); | 638 CreateSimpleNotification(browser(), false); |
| 633 ASSERT_EQ(0, GetNotificationCount()); | 639 ASSERT_EQ(0, GetNotificationCount()); |
| 634 ContentSettingsForOneType settings; | 640 ContentSettingsForOneType settings; |
| 635 GetPrefsByContentSetting(CONTENT_SETTING_BLOCK, &settings); | 641 GetPrefsByContentSetting(CONTENT_SETTING_BLOCK, &settings); |
| 636 EXPECT_TRUE(CheckOriginInSetting(settings, test_page_url_)); | 642 EXPECT_TRUE(CheckOriginInSetting(settings, GetTestPageURL())); |
| 637 } | 643 } |
| 638 | 644 |
| 639 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestClosePermissionInfobar) { | 645 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestClosePermissionInfobar) { |
| 646 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 647 |
| 640 // Test that no notification is created when permission infobar is dismissed. | 648 // Test that no notification is created when permission infobar is dismissed. |
| 641 ui_test_utils::NavigateToURL(browser(), test_page_url_); | 649 ui_test_utils::NavigateToURL(browser(), GetTestPageURL()); |
| 642 ASSERT_TRUE(RequestPermissionAndWait(browser())); | 650 ASSERT_TRUE(RequestPermissionAndWait(browser())); |
| 643 PerformActionOnInfobar(browser(), DISMISS, 0, 0); | 651 PerformActionOnInfobar(browser(), DISMISS, 0, 0); |
| 644 CreateSimpleNotification(browser(), false); | 652 CreateSimpleNotification(browser(), false); |
| 645 ASSERT_EQ(0, GetNotificationCount()); | 653 ASSERT_EQ(0, GetNotificationCount()); |
| 646 ContentSettingsForOneType settings; | 654 ContentSettingsForOneType settings; |
| 647 GetPrefsByContentSetting(CONTENT_SETTING_BLOCK, &settings); | 655 GetPrefsByContentSetting(CONTENT_SETTING_BLOCK, &settings); |
| 648 EXPECT_EQ(0U, settings.size()); | 656 EXPECT_EQ(0U, settings.size()); |
| 649 } | 657 } |
| 650 | 658 |
| 651 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestAllowNotificationsFromAllSites) { | 659 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestAllowNotificationsFromAllSites) { |
| 652 #if defined(OS_MACOSX) | 660 #if defined(OS_MACOSX) |
| 653 // TODO(kbr): re-enable: http://crbug.com/222296 | 661 // TODO(kbr): re-enable: http://crbug.com/222296 |
| 654 if (base::mac::IsOSMountainLionOrLater()) | 662 if (base::mac::IsOSMountainLionOrLater()) |
| 655 return; | 663 return; |
| 656 #endif | 664 #endif |
| 665 |
| 666 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 667 |
| 657 // Verify that all domains can be allowed to show notifications. | 668 // Verify that all domains can be allowed to show notifications. |
| 658 SetDefaultPermissionSetting(CONTENT_SETTING_ALLOW); | 669 SetDefaultPermissionSetting(CONTENT_SETTING_ALLOW); |
| 659 ui_test_utils::NavigateToURL(browser(), test_page_url_); | 670 ui_test_utils::NavigateToURL(browser(), GetTestPageURL()); |
| 660 | 671 |
| 661 std::string result = CreateSimpleNotification(browser(), true); | 672 std::string result = CreateSimpleNotification(browser(), true); |
| 662 EXPECT_NE("-1", result); | 673 EXPECT_NE("-1", result); |
| 663 | 674 |
| 664 ASSERT_EQ(1, GetNotificationCount()); | 675 ASSERT_EQ(1, GetNotificationCount()); |
| 665 EXPECT_EQ(0U, InfoBarService::FromWebContents( | 676 EXPECT_EQ(0U, InfoBarService::FromWebContents( |
| 666 browser()->tab_strip_model()->GetWebContentsAt(0))->infobar_count()); | 677 browser()->tab_strip_model()->GetWebContentsAt(0))->infobar_count()); |
| 667 } | 678 } |
| 668 | 679 |
| 669 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestDenyNotificationsFromAllSites) { | 680 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestDenyNotificationsFromAllSites) { |
| 681 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 682 |
| 670 // Verify that no domain can show notifications. | 683 // Verify that no domain can show notifications. |
| 671 SetDefaultPermissionSetting(CONTENT_SETTING_BLOCK); | 684 SetDefaultPermissionSetting(CONTENT_SETTING_BLOCK); |
| 672 ui_test_utils::NavigateToURL(browser(), test_page_url_); | 685 ui_test_utils::NavigateToURL(browser(), GetTestPageURL()); |
| 673 | 686 |
| 674 std::string result = CreateSimpleNotification(browser(), false); | 687 std::string result = CreateSimpleNotification(browser(), false); |
| 675 EXPECT_EQ("-1", result); | 688 EXPECT_EQ("-1", result); |
| 676 | 689 |
| 677 ASSERT_EQ(0, GetNotificationCount()); | 690 ASSERT_EQ(0, GetNotificationCount()); |
| 678 } | 691 } |
| 679 | 692 |
| 680 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestDenyDomainAndAllowAll) { | 693 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestDenyDomainAndAllowAll) { |
| 694 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 695 |
| 681 // Verify that denying a domain and allowing all shouldn't show | 696 // Verify that denying a domain and allowing all shouldn't show |
| 682 // notifications from the denied domain. | 697 // notifications from the denied domain. |
| 683 DenyOrigin(test_page_url_.GetOrigin()); | 698 DenyOrigin(GetTestPageURL().GetOrigin()); |
| 684 SetDefaultPermissionSetting(CONTENT_SETTING_ALLOW); | 699 SetDefaultPermissionSetting(CONTENT_SETTING_ALLOW); |
| 685 | 700 |
| 686 ui_test_utils::NavigateToURL(browser(), test_page_url_); | 701 ui_test_utils::NavigateToURL(browser(), GetTestPageURL()); |
| 687 | 702 |
| 688 std::string result = CreateSimpleNotification(browser(), false); | 703 std::string result = CreateSimpleNotification(browser(), false); |
| 689 EXPECT_EQ("-1", result); | 704 EXPECT_EQ("-1", result); |
| 690 | 705 |
| 691 ASSERT_EQ(0, GetNotificationCount()); | 706 ASSERT_EQ(0, GetNotificationCount()); |
| 692 } | 707 } |
| 693 | 708 |
| 694 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestAllowDomainAndDenyAll) { | 709 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestAllowDomainAndDenyAll) { |
| 695 #if defined(OS_MACOSX) | 710 #if defined(OS_MACOSX) |
| 696 // TODO(kbr): re-enable: http://crbug.com/222296 | 711 // TODO(kbr): re-enable: http://crbug.com/222296 |
| 697 if (base::mac::IsOSMountainLionOrLater()) | 712 if (base::mac::IsOSMountainLionOrLater()) |
| 698 return; | 713 return; |
| 699 #endif | 714 #endif |
| 715 |
| 716 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 717 |
| 700 // Verify that allowing a domain and denying all others should show | 718 // Verify that allowing a domain and denying all others should show |
| 701 // notifications from the allowed domain. | 719 // notifications from the allowed domain. |
| 702 AllowOrigin(test_page_url_.GetOrigin()); | 720 AllowOrigin(GetTestPageURL().GetOrigin()); |
| 703 SetDefaultPermissionSetting(CONTENT_SETTING_BLOCK); | 721 SetDefaultPermissionSetting(CONTENT_SETTING_BLOCK); |
| 704 | 722 |
| 705 ui_test_utils::NavigateToURL(browser(), test_page_url_); | 723 ui_test_utils::NavigateToURL(browser(), GetTestPageURL()); |
| 706 | 724 |
| 707 std::string result = CreateSimpleNotification(browser(), true); | 725 std::string result = CreateSimpleNotification(browser(), true); |
| 708 EXPECT_NE("-1", result); | 726 EXPECT_NE("-1", result); |
| 709 | 727 |
| 710 ASSERT_EQ(1, GetNotificationCount()); | 728 ASSERT_EQ(1, GetNotificationCount()); |
| 711 } | 729 } |
| 712 | 730 |
| 713 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestDenyAndThenAllowDomain) { | 731 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestDenyAndThenAllowDomain) { |
| 714 #if defined(OS_MACOSX) | 732 #if defined(OS_MACOSX) |
| 715 // TODO(kbr): re-enable: http://crbug.com/222296 | 733 // TODO(kbr): re-enable: http://crbug.com/222296 |
| 716 if (base::mac::IsOSMountainLionOrLater()) | 734 if (base::mac::IsOSMountainLionOrLater()) |
| 717 return; | 735 return; |
| 718 #endif | 736 #endif |
| 737 |
| 738 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 739 |
| 719 // Verify that denying and again allowing should show notifications. | 740 // Verify that denying and again allowing should show notifications. |
| 720 DenyOrigin(test_page_url_.GetOrigin()); | 741 DenyOrigin(GetTestPageURL().GetOrigin()); |
| 721 | 742 |
| 722 ui_test_utils::NavigateToURL(browser(), test_page_url_); | 743 ui_test_utils::NavigateToURL(browser(), GetTestPageURL()); |
| 723 | 744 |
| 724 std::string result = CreateSimpleNotification(browser(), false); | 745 std::string result = CreateSimpleNotification(browser(), false); |
| 725 EXPECT_EQ("-1", result); | 746 EXPECT_EQ("-1", result); |
| 726 | 747 |
| 727 ASSERT_EQ(0, GetNotificationCount()); | 748 ASSERT_EQ(0, GetNotificationCount()); |
| 728 | 749 |
| 729 AllowOrigin(test_page_url_.GetOrigin()); | 750 AllowOrigin(GetTestPageURL().GetOrigin()); |
| 730 result = CreateSimpleNotification(browser(), true); | 751 result = CreateSimpleNotification(browser(), true); |
| 731 EXPECT_NE("-1", result); | 752 EXPECT_NE("-1", result); |
| 732 | 753 |
| 733 ASSERT_EQ(1, GetNotificationCount()); | 754 ASSERT_EQ(1, GetNotificationCount()); |
| 734 EXPECT_EQ(0U, InfoBarService::FromWebContents( | 755 EXPECT_EQ(0U, InfoBarService::FromWebContents( |
| 735 browser()->tab_strip_model()->GetWebContentsAt(0))->infobar_count()); | 756 browser()->tab_strip_model()->GetWebContentsAt(0))->infobar_count()); |
| 736 } | 757 } |
| 737 | 758 |
| 738 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestCreateDenyCloseNotifications) { | 759 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestCreateDenyCloseNotifications) { |
| 739 #if defined(OS_MACOSX) | 760 #if defined(OS_MACOSX) |
| 740 // TODO(kbr): re-enable: http://crbug.com/222296 | 761 // TODO(kbr): re-enable: http://crbug.com/222296 |
| 741 if (base::mac::IsOSMountainLionOrLater()) | 762 if (base::mac::IsOSMountainLionOrLater()) |
| 742 return; | 763 return; |
| 743 #endif | 764 #endif |
| 765 |
| 766 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 767 |
| 744 // Verify able to create, deny, and close the notification. | 768 // Verify able to create, deny, and close the notification. |
| 745 AllowAllOrigins(); | 769 AllowAllOrigins(); |
| 746 ui_test_utils::NavigateToURL(browser(), test_page_url_); | 770 ui_test_utils::NavigateToURL(browser(), GetTestPageURL()); |
| 747 CreateSimpleNotification(browser(), true); | 771 CreateSimpleNotification(browser(), true); |
| 748 ASSERT_EQ(1, GetNotificationCount()); | 772 ASSERT_EQ(1, GetNotificationCount()); |
| 749 | 773 |
| 750 DenyOrigin(test_page_url_.GetOrigin()); | 774 DenyOrigin(GetTestPageURL().GetOrigin()); |
| 751 ContentSettingsForOneType settings; | 775 ContentSettingsForOneType settings; |
| 752 GetPrefsByContentSetting(CONTENT_SETTING_BLOCK, &settings); | 776 GetPrefsByContentSetting(CONTENT_SETTING_BLOCK, &settings); |
| 753 ASSERT_TRUE(CheckOriginInSetting(settings, test_page_url_.GetOrigin())); | 777 ASSERT_TRUE(CheckOriginInSetting(settings, GetTestPageURL().GetOrigin())); |
| 754 | 778 |
| 755 EXPECT_EQ(1, GetNotificationCount()); | 779 EXPECT_EQ(1, GetNotificationCount()); |
| 756 if (message_center::IsRichNotificationEnabled()) { | 780 if (message_center::IsRichNotificationEnabled()) { |
| 757 message_center::NotificationList::Notifications notifications = | 781 message_center::NotificationList::Notifications notifications = |
| 758 message_center::MessageCenter::Get()->GetNotifications(); | 782 message_center::MessageCenter::Get()->GetNotifications(); |
| 759 message_center::MessageCenter::Get()->RemoveNotification( | 783 message_center::MessageCenter::Get()->RemoveNotification( |
| 760 (*notifications.rbegin())->id(), | 784 (*notifications.rbegin())->id(), |
| 761 true); // by_user | 785 true); // by_user |
| 762 } else { | 786 } else { |
| 763 const std::deque<Balloon*>& balloons = GetActiveBalloons(); | 787 const std::deque<Balloon*>& balloons = GetActiveBalloons(); |
| 764 ASSERT_TRUE(CloseNotificationAndWait(balloons[0]->notification())); | 788 ASSERT_TRUE(CloseNotificationAndWait(balloons[0]->notification())); |
| 765 } | 789 } |
| 766 ASSERT_EQ(0, GetNotificationCount()); | 790 ASSERT_EQ(0, GetNotificationCount()); |
| 767 } | 791 } |
| 768 | 792 |
| 769 // Crashes on Linux/Win. See http://crbug.com/160657. | 793 // Crashes on Linux/Win. See http://crbug.com/160657. |
| 770 IN_PROC_BROWSER_TEST_F( | 794 IN_PROC_BROWSER_TEST_F( |
| 771 NotificationsTest, | 795 NotificationsTest, |
| 772 DISABLED_TestOriginPrefsNotSavedInIncognito) { | 796 DISABLED_TestOriginPrefsNotSavedInIncognito) { |
| 797 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 798 |
| 773 // Verify that allow/deny origin preferences are not saved in incognito. | 799 // Verify that allow/deny origin preferences are not saved in incognito. |
| 774 Browser* incognito = CreateIncognitoBrowser(); | 800 Browser* incognito = CreateIncognitoBrowser(); |
| 775 ui_test_utils::NavigateToURL(incognito, test_page_url_); | 801 ui_test_utils::NavigateToURL(incognito, GetTestPageURL()); |
| 776 ASSERT_TRUE(RequestPermissionAndWait(incognito)); | 802 ASSERT_TRUE(RequestPermissionAndWait(incognito)); |
| 777 PerformActionOnInfobar(incognito, DENY, 0, 0); | 803 PerformActionOnInfobar(incognito, DENY, 0, 0); |
| 778 CloseBrowserWindow(incognito); | 804 CloseBrowserWindow(incognito); |
| 779 | 805 |
| 780 incognito = CreateIncognitoBrowser(); | 806 incognito = CreateIncognitoBrowser(); |
| 781 ui_test_utils::NavigateToURL(incognito, test_page_url_); | 807 ui_test_utils::NavigateToURL(incognito, GetTestPageURL()); |
| 782 ASSERT_TRUE(RequestPermissionAndWait(incognito)); | 808 ASSERT_TRUE(RequestPermissionAndWait(incognito)); |
| 783 PerformActionOnInfobar(incognito, ALLOW, 0, 0); | 809 PerformActionOnInfobar(incognito, ALLOW, 0, 0); |
| 784 CreateSimpleNotification(incognito, true); | 810 CreateSimpleNotification(incognito, true); |
| 785 ASSERT_EQ(1, GetNotificationCount()); | 811 ASSERT_EQ(1, GetNotificationCount()); |
| 786 CloseBrowserWindow(incognito); | 812 CloseBrowserWindow(incognito); |
| 787 | 813 |
| 788 incognito = CreateIncognitoBrowser(); | 814 incognito = CreateIncognitoBrowser(); |
| 789 ui_test_utils::NavigateToURL(incognito, test_page_url_); | 815 ui_test_utils::NavigateToURL(incognito, GetTestPageURL()); |
| 790 ASSERT_TRUE(RequestPermissionAndWait(incognito)); | 816 ASSERT_TRUE(RequestPermissionAndWait(incognito)); |
| 791 | 817 |
| 792 ContentSettingsForOneType settings; | 818 ContentSettingsForOneType settings; |
| 793 GetPrefsByContentSetting(CONTENT_SETTING_BLOCK, &settings); | 819 GetPrefsByContentSetting(CONTENT_SETTING_BLOCK, &settings); |
| 794 EXPECT_EQ(0U, settings.size()); | 820 EXPECT_EQ(0U, settings.size()); |
| 795 GetPrefsByContentSetting(CONTENT_SETTING_ALLOW, &settings); | 821 GetPrefsByContentSetting(CONTENT_SETTING_ALLOW, &settings); |
| 796 EXPECT_EQ(0U, settings.size()); | 822 EXPECT_EQ(0U, settings.size()); |
| 797 } | 823 } |
| 798 | 824 |
| 799 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestExitBrowserWithInfobar) { | 825 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestExitBrowserWithInfobar) { |
| 826 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 827 |
| 800 // Exit the browser window, when the infobar appears. | 828 // Exit the browser window, when the infobar appears. |
| 801 ui_test_utils::NavigateToURL(browser(), test_page_url_); | 829 ui_test_utils::NavigateToURL(browser(), GetTestPageURL()); |
| 802 ASSERT_TRUE(RequestPermissionAndWait(browser())); | 830 ASSERT_TRUE(RequestPermissionAndWait(browser())); |
| 803 } | 831 } |
| 804 | 832 |
| 805 // Times out on Windows and Linux. http://crbug.com/168976 | 833 // Times out on Windows and Linux. http://crbug.com/168976 |
| 806 #if defined(OS_WIN) || defined(OS_LINUX) | 834 #if defined(OS_WIN) || defined(OS_LINUX) |
| 807 #define MAYBE_TestCrashTabWithPermissionInfobar \ | 835 #define MAYBE_TestCrashTabWithPermissionInfobar \ |
| 808 DISABLED_TestCrashTabWithPermissionInfobar | 836 DISABLED_TestCrashTabWithPermissionInfobar |
| 809 #else | 837 #else |
| 810 #define MAYBE_TestCrashTabWithPermissionInfobar \ | 838 #define MAYBE_TestCrashTabWithPermissionInfobar \ |
| 811 TestCrashTabWithPermissionInfobar | 839 TestCrashTabWithPermissionInfobar |
| 812 #endif | 840 #endif |
| 813 IN_PROC_BROWSER_TEST_F(NotificationsTest, | 841 IN_PROC_BROWSER_TEST_F(NotificationsTest, |
| 814 MAYBE_TestCrashTabWithPermissionInfobar) { | 842 MAYBE_TestCrashTabWithPermissionInfobar) { |
| 843 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 844 |
| 815 // Test crashing the tab with permission infobar doesn't crash Chrome. | 845 // Test crashing the tab with permission infobar doesn't crash Chrome. |
| 816 ui_test_utils::NavigateToURLWithDisposition( | 846 ui_test_utils::NavigateToURLWithDisposition( |
| 817 browser(), | 847 browser(), |
| 818 empty_page_url_, | 848 embedded_test_server()->GetURL("/empty.html"), |
| 819 NEW_BACKGROUND_TAB, | 849 NEW_BACKGROUND_TAB, |
| 820 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); | 850 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); |
| 821 browser()->tab_strip_model()->ActivateTabAt(0, true); | 851 browser()->tab_strip_model()->ActivateTabAt(0, true); |
| 822 ui_test_utils::NavigateToURL(browser(), test_page_url_); | 852 ui_test_utils::NavigateToURL(browser(), GetTestPageURL()); |
| 823 ASSERT_TRUE(RequestPermissionAndWait(browser())); | 853 ASSERT_TRUE(RequestPermissionAndWait(browser())); |
| 824 CrashTab(browser(), 0); | 854 CrashTab(browser(), 0); |
| 825 } | 855 } |
| 826 | 856 |
| 827 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestKillNotificationProcess) { | 857 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestKillNotificationProcess) { |
| 828 // Notifications don't have their own process with the message center. | 858 // Notifications don't have their own process with the message center. |
| 829 if (message_center::IsRichNotificationEnabled()) | 859 if (message_center::IsRichNotificationEnabled()) |
| 830 return; | 860 return; |
| 831 | 861 |
| 832 #if defined(OS_MACOSX) | 862 #if defined(OS_MACOSX) |
| 833 // TODO(kbr): re-enable: http://crbug.com/222296 | 863 // TODO(kbr): re-enable: http://crbug.com/222296 |
| 834 if (base::mac::IsOSMountainLionOrLater()) | 864 if (base::mac::IsOSMountainLionOrLater()) |
| 835 return; | 865 return; |
| 836 #endif | 866 #endif |
| 867 |
| 868 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 869 |
| 837 // Test killing a notification doesn't crash Chrome. | 870 // Test killing a notification doesn't crash Chrome. |
| 838 AllowAllOrigins(); | 871 AllowAllOrigins(); |
| 839 ui_test_utils::NavigateToURL(browser(), test_page_url_); | 872 ui_test_utils::NavigateToURL(browser(), GetTestPageURL()); |
| 840 CreateSimpleNotification(browser(), true); | 873 CreateSimpleNotification(browser(), true); |
| 841 ASSERT_EQ(1, GetNotificationCount()); | 874 ASSERT_EQ(1, GetNotificationCount()); |
| 842 | 875 |
| 843 const std::deque<Balloon*>& balloons = GetActiveBalloons(); | 876 const std::deque<Balloon*>& balloons = GetActiveBalloons(); |
| 844 ASSERT_EQ(1U, balloons.size()); | 877 ASSERT_EQ(1U, balloons.size()); |
| 845 CrashNotification(balloons[0]); | 878 CrashNotification(balloons[0]); |
| 846 ASSERT_EQ(0, GetNotificationCount()); | 879 ASSERT_EQ(0, GetNotificationCount()); |
| 847 } | 880 } |
| 848 | 881 |
| 849 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestIncognitoNotification) { | 882 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestIncognitoNotification) { |
| 850 #if defined(OS_MACOSX) | 883 #if defined(OS_MACOSX) |
| 851 // TODO(kbr): re-enable: http://crbug.com/222296 | 884 // TODO(kbr): re-enable: http://crbug.com/222296 |
| 852 if (base::mac::IsOSMountainLionOrLater()) | 885 if (base::mac::IsOSMountainLionOrLater()) |
| 853 return; | 886 return; |
| 854 #endif | 887 #endif |
| 888 |
| 889 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 890 |
| 855 // Test notifications in incognito window. | 891 // Test notifications in incognito window. |
| 856 Browser* browser = CreateIncognitoBrowser(); | 892 Browser* browser = CreateIncognitoBrowser(); |
| 857 ui_test_utils::NavigateToURL(browser, test_page_url_); | 893 ui_test_utils::NavigateToURL(browser, GetTestPageURL()); |
| 858 browser->tab_strip_model()->ActivateTabAt(0, true); | 894 browser->tab_strip_model()->ActivateTabAt(0, true); |
| 859 ASSERT_TRUE(RequestPermissionAndWait(browser)); | 895 ASSERT_TRUE(RequestPermissionAndWait(browser)); |
| 860 PerformActionOnInfobar(browser, ALLOW, 0, 0); | 896 PerformActionOnInfobar(browser, ALLOW, 0, 0); |
| 861 CreateSimpleNotification(browser, true); | 897 CreateSimpleNotification(browser, true); |
| 862 ASSERT_EQ(1, GetNotificationCount()); | 898 ASSERT_EQ(1, GetNotificationCount()); |
| 863 } | 899 } |
| 864 | 900 |
| 865 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestCloseTabWithPermissionInfobar) { | 901 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestCloseTabWithPermissionInfobar) { |
| 902 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 903 |
| 866 // Test that user can close tab when infobar present. | 904 // Test that user can close tab when infobar present. |
| 867 ui_test_utils::NavigateToURLWithDisposition( | 905 ui_test_utils::NavigateToURLWithDisposition( |
| 868 browser(), | 906 browser(), |
| 869 GURL("about:blank"), | 907 GURL("about:blank"), |
| 870 NEW_BACKGROUND_TAB, | 908 NEW_BACKGROUND_TAB, |
| 871 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); | 909 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); |
| 872 browser()->tab_strip_model()->ActivateTabAt(0, true); | 910 browser()->tab_strip_model()->ActivateTabAt(0, true); |
| 873 ui_test_utils::NavigateToURL(browser(), test_page_url_); | 911 ui_test_utils::NavigateToURL(browser(), GetTestPageURL()); |
| 874 ASSERT_TRUE(RequestPermissionAndWait(browser())); | 912 ASSERT_TRUE(RequestPermissionAndWait(browser())); |
| 875 content::WindowedNotificationObserver observer( | 913 content::WindowedNotificationObserver observer( |
| 876 content::NOTIFICATION_WEB_CONTENTS_DESTROYED, | 914 content::NOTIFICATION_WEB_CONTENTS_DESTROYED, |
| 877 content::NotificationService::AllSources()); | 915 content::NotificationService::AllSources()); |
| 878 browser()->tab_strip_model()->CloseWebContentsAt(0, | 916 browser()->tab_strip_model()->CloseWebContentsAt(0, |
| 879 TabStripModel::CLOSE_NONE); | 917 TabStripModel::CLOSE_NONE); |
| 880 observer.Wait(); | 918 observer.Wait(); |
| 881 } | 919 } |
| 882 | 920 |
| 883 IN_PROC_BROWSER_TEST_F( | 921 IN_PROC_BROWSER_TEST_F( |
| 884 NotificationsTest, | 922 NotificationsTest, |
| 885 TestNavigateAwayWithPermissionInfobar) { | 923 TestNavigateAwayWithPermissionInfobar) { |
| 886 #if defined(OS_MACOSX) | 924 #if defined(OS_MACOSX) |
| 887 // TODO(kbr): re-enable: http://crbug.com/222296 | 925 // TODO(kbr): re-enable: http://crbug.com/222296 |
| 888 if (base::mac::IsOSMountainLionOrLater()) | 926 if (base::mac::IsOSMountainLionOrLater()) |
| 889 return; | 927 return; |
| 890 #endif | 928 #endif |
| 929 |
| 930 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 931 |
| 891 // Test navigating away when an infobar is present, | 932 // Test navigating away when an infobar is present, |
| 892 // then trying to create a notification from the same page. | 933 // then trying to create a notification from the same page. |
| 893 ui_test_utils::NavigateToURLWithDisposition( | 934 ui_test_utils::NavigateToURLWithDisposition( |
| 894 browser(), | 935 browser(), |
| 895 GURL("about:blank"), | 936 GURL("about:blank"), |
| 896 NEW_BACKGROUND_TAB, | 937 NEW_BACKGROUND_TAB, |
| 897 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); | 938 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); |
| 898 browser()->tab_strip_model()->ActivateTabAt(0, true); | 939 browser()->tab_strip_model()->ActivateTabAt(0, true); |
| 899 ui_test_utils::NavigateToURL(browser(), test_page_url_); | 940 ui_test_utils::NavigateToURL(browser(), GetTestPageURL()); |
| 900 ASSERT_TRUE(RequestPermissionAndWait(browser())); | 941 ASSERT_TRUE(RequestPermissionAndWait(browser())); |
| 901 ui_test_utils::NavigateToURL(browser(), test_page_url_); | 942 ui_test_utils::NavigateToURL(browser(), GetTestPageURL()); |
| 902 ASSERT_TRUE(RequestPermissionAndWait(browser())); | 943 ASSERT_TRUE(RequestPermissionAndWait(browser())); |
| 903 PerformActionOnInfobar(browser(), ALLOW, 0, 0); | 944 PerformActionOnInfobar(browser(), ALLOW, 0, 0); |
| 904 CreateSimpleNotification(browser(), true); | 945 CreateSimpleNotification(browser(), true); |
| 905 ASSERT_EQ(1, GetNotificationCount()); | 946 ASSERT_EQ(1, GetNotificationCount()); |
| 906 } | 947 } |
| 907 | 948 |
| 908 // See crbug.com/248470 | 949 // See crbug.com/248470 |
| 909 #if defined(OS_LINUX) | 950 #if defined(OS_LINUX) |
| 910 #define MAYBE_TestCrashRendererNotificationRemain \ | 951 #define MAYBE_TestCrashRendererNotificationRemain \ |
| 911 DISABLED_TestCrashRendererNotificationRemain | 952 DISABLED_TestCrashRendererNotificationRemain |
| 912 #else | 953 #else |
| 913 #define MAYBE_TestCrashRendererNotificationRemain \ | 954 #define MAYBE_TestCrashRendererNotificationRemain \ |
| 914 TestCrashRendererNotificationRemain | 955 TestCrashRendererNotificationRemain |
| 915 #endif | 956 #endif |
| 916 | 957 |
| 917 IN_PROC_BROWSER_TEST_F(NotificationsTest, | 958 IN_PROC_BROWSER_TEST_F(NotificationsTest, |
| 918 MAYBE_TestCrashRendererNotificationRemain) { | 959 MAYBE_TestCrashRendererNotificationRemain) { |
| 919 #if defined(OS_MACOSX) | 960 #if defined(OS_MACOSX) |
| 920 // TODO(kbr): re-enable: http://crbug.com/222296 | 961 // TODO(kbr): re-enable: http://crbug.com/222296 |
| 921 if (base::mac::IsOSMountainLionOrLater()) | 962 if (base::mac::IsOSMountainLionOrLater()) |
| 922 return; | 963 return; |
| 923 #endif | 964 #endif |
| 965 |
| 966 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 967 |
| 924 // Test crashing renderer does not close or crash notification. | 968 // Test crashing renderer does not close or crash notification. |
| 925 AllowAllOrigins(); | 969 AllowAllOrigins(); |
| 926 ui_test_utils::NavigateToURLWithDisposition( | 970 ui_test_utils::NavigateToURLWithDisposition( |
| 927 browser(), | 971 browser(), |
| 928 GURL("about:blank"), | 972 GURL("about:blank"), |
| 929 NEW_BACKGROUND_TAB, | 973 NEW_BACKGROUND_TAB, |
| 930 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); | 974 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); |
| 931 browser()->tab_strip_model()->ActivateTabAt(0, true); | 975 browser()->tab_strip_model()->ActivateTabAt(0, true); |
| 932 ui_test_utils::NavigateToURL(browser(), test_page_url_); | 976 ui_test_utils::NavigateToURL(browser(), GetTestPageURL()); |
| 933 CreateSimpleNotification(browser(), true); | 977 CreateSimpleNotification(browser(), true); |
| 934 ASSERT_EQ(1, GetNotificationCount()); | 978 ASSERT_EQ(1, GetNotificationCount()); |
| 935 CrashTab(browser(), 0); | 979 CrashTab(browser(), 0); |
| 936 ASSERT_EQ(1, GetNotificationCount()); | 980 ASSERT_EQ(1, GetNotificationCount()); |
| 937 } | 981 } |
| 938 | 982 |
| 939 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestNotificationReplacement) { | 983 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestNotificationReplacement) { |
| 940 #if defined(OS_MACOSX) | 984 #if defined(OS_MACOSX) |
| 941 // TODO(kbr): re-enable: http://crbug.com/222296 | 985 // TODO(kbr): re-enable: http://crbug.com/222296 |
| 942 if (base::mac::IsOSMountainLionOrLater()) | 986 if (base::mac::IsOSMountainLionOrLater()) |
| 943 return; | 987 return; |
| 944 #endif | 988 #endif |
| 989 |
| 990 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 991 |
| 945 // Test that we can replace a notification using the replaceId. | 992 // Test that we can replace a notification using the replaceId. |
| 946 AllowAllOrigins(); | 993 AllowAllOrigins(); |
| 947 | 994 |
| 948 ui_test_utils::NavigateToURL(browser(), test_page_url_); | 995 ui_test_utils::NavigateToURL(browser(), GetTestPageURL()); |
| 949 | 996 |
| 950 std::string result = CreateNotification( | 997 std::string result = CreateNotification( |
| 951 browser(), true, "abc.png", "Title1", "Body1", "chat"); | 998 browser(), true, "abc.png", "Title1", "Body1", "chat"); |
| 952 EXPECT_NE("-1", result); | 999 EXPECT_NE("-1", result); |
| 953 | 1000 |
| 954 ASSERT_EQ(1, GetNotificationCount()); | 1001 ASSERT_EQ(1, GetNotificationCount()); |
| 955 | 1002 |
| 956 result = CreateNotification( | 1003 result = CreateNotification( |
| 957 browser(), false, "no_such_file.png", "Title2", "Body2", "chat"); | 1004 browser(), false, "no_such_file.png", "Title2", "Body2", "chat"); |
| 958 EXPECT_NE("-1", result); | 1005 EXPECT_NE("-1", result); |
| 959 | 1006 |
| 960 if (message_center::IsRichNotificationEnabled()) { | 1007 if (message_center::IsRichNotificationEnabled()) { |
| 961 ASSERT_EQ(1, GetNotificationCount()); | 1008 ASSERT_EQ(1, GetNotificationCount()); |
| 962 message_center::NotificationList::Notifications notifications = | 1009 message_center::NotificationList::Notifications notifications = |
| 963 message_center::MessageCenter::Get()->GetNotifications(); | 1010 message_center::MessageCenter::Get()->GetNotifications(); |
| 964 EXPECT_EQ(ASCIIToUTF16("Title2"), (*notifications.rbegin())->title()); | 1011 EXPECT_EQ(ASCIIToUTF16("Title2"), (*notifications.rbegin())->title()); |
| 965 EXPECT_EQ(ASCIIToUTF16("Body2"), (*notifications.rbegin())->message()); | 1012 EXPECT_EQ(ASCIIToUTF16("Body2"), (*notifications.rbegin())->message()); |
| 966 } else { | 1013 } else { |
| 967 const std::deque<Balloon*>& balloons = GetActiveBalloons(); | 1014 const std::deque<Balloon*>& balloons = GetActiveBalloons(); |
| 968 ASSERT_EQ(1U, balloons.size()); | 1015 ASSERT_EQ(1U, balloons.size()); |
| 969 Balloon* balloon = balloons[0]; | 1016 Balloon* balloon = balloons[0]; |
| 970 const Notification& notification = balloon->notification(); | 1017 const Notification& notification = balloon->notification(); |
| 971 GURL EXPECTED_ICON_URL = test_server()->GetURL(kExpectedIconUrl); | 1018 GURL EXPECTED_ICON_URL = embedded_test_server()->GetURL(kExpectedIconUrl); |
| 972 EXPECT_EQ(EXPECTED_ICON_URL, notification.icon_url()); | 1019 EXPECT_EQ(EXPECTED_ICON_URL, notification.icon_url()); |
| 973 EXPECT_EQ(ASCIIToUTF16("Title2"), notification.title()); | 1020 EXPECT_EQ(ASCIIToUTF16("Title2"), notification.title()); |
| 974 EXPECT_EQ(ASCIIToUTF16("Body2"), notification.message()); | 1021 EXPECT_EQ(ASCIIToUTF16("Body2"), notification.message()); |
| 975 } | 1022 } |
| 976 } | 1023 } |
| OLD | NEW |