diff options
Diffstat (limited to 'chrome/browser')
4 files changed, 211 insertions, 75 deletions
diff --git a/chrome/browser/extensions/extension_crash_recovery_browsertest.cc b/chrome/browser/extensions/extension_crash_recovery_browsertest.cc index 272dbc5..220885c 100644 --- a/chrome/browser/extensions/extension_crash_recovery_browsertest.cc +++ b/chrome/browser/extensions/extension_crash_recovery_browsertest.cc @@ -3,6 +3,7 @@ // found in the LICENSE file. #include "base/process_util.h" +#include "chrome/browser/browser_process.h" #include "chrome/browser/extensions/extension_browsertest.h" #include "chrome/browser/extensions/extension_host.h" #include "chrome/browser/extensions/extension_process_manager.h" @@ -25,6 +26,11 @@ #include "content/public/browser/web_contents.h" #include "content/public/common/result_codes.h" +#if defined(ENABLE_MESSAGE_CENTER) +#include "ui/message_center/message_center.h" +#include "ui/message_center/notification_list.h" +#endif + using content::NavigationController; using content::WebContents; using extensions::Extension; @@ -37,8 +43,12 @@ using extensions::Extension; #define MAYBE_ExtensionCrashRecoveryTest ExtensionCrashRecoveryTest #endif // defined(OS_MAC) || defined(USE_AURA) -class MAYBE_ExtensionCrashRecoveryTest : public ExtensionBrowserTest { +class ExtensionCrashRecoveryTestBase : public ExtensionBrowserTest { protected: + virtual void AcceptNotification(size_t index) = 0; + virtual void CancelNotification(size_t index) = 0; + virtual size_t CountBalloons() = 0; + ExtensionService* GetExtensionService() { return browser()->profile()->GetExtensionService(); } @@ -48,29 +58,6 @@ class MAYBE_ExtensionCrashRecoveryTest : public ExtensionBrowserTest { process_manager(); } - void AcceptNotification(size_t index) { - Balloon* balloon = GetNotificationDelegate(index); - ASSERT_TRUE(balloon); - balloon->OnClick(); - WaitForExtensionLoad(); - } - - void CancelNotification(size_t index) { - Balloon* balloon = GetNotificationDelegate(index); - ASSERT_TRUE(balloon); - BalloonNotificationUIManager* manager = - BalloonNotificationUIManager::GetInstanceForTesting(); - ASSERT_TRUE(manager->CancelById(balloon->notification().notification_id())); - } - - size_t CountBalloons() { - BalloonNotificationUIManager* manager = - BalloonNotificationUIManager::GetInstanceForTesting(); - BalloonCollection::Balloons balloons = - manager->balloon_collection()->GetActiveBalloons(); - return balloons.size(); - } - void CrashExtension(std::string extension_id) { const Extension* extension = GetExtensionService()->GetExtensionById(extension_id, false); @@ -126,6 +113,73 @@ class MAYBE_ExtensionCrashRecoveryTest : public ExtensionBrowserTest { std::string first_extension_id_; std::string second_extension_id_; +}; + +#if defined(ENABLE_MESSAGE_CENTER) + +class MessageCenterExtensionCrashRecoveryTest + : public ExtensionCrashRecoveryTestBase { + protected: + virtual void AcceptNotification(size_t index) { + message_center::MessageCenter* message_center = + message_center::MessageCenter::Get(); + ASSERT_GT(message_center->NotificationCount(), index); + message_center::NotificationList::Notifications::reverse_iterator it = + message_center->GetNotificationList()->GetNotifications().rbegin(); + for (size_t i=0; i < index; ++i) + it++; + std::string id = (*it)->id(); + message_center->OnNotificationClicked(id); + WaitForExtensionLoad(); + } + + virtual void CancelNotification(size_t index) { + message_center::MessageCenter* message_center = + message_center::MessageCenter::Get(); + ASSERT_GT(message_center->NotificationCount(), index); + message_center::NotificationList::Notifications::reverse_iterator it = + message_center->GetNotificationList()->GetNotifications().rbegin(); + for (size_t i=0; i < index; i++) { it++; } + ASSERT_TRUE( + g_browser_process->notification_ui_manager()->CancelById((*it)->id())); + } + + virtual size_t CountBalloons() { + message_center::MessageCenter* message_center = + message_center::MessageCenter::Get(); + return message_center->NotificationCount(); + } +}; + +typedef MessageCenterExtensionCrashRecoveryTest + MAYBE_ExtensionCrashRecoveryTest; + +#else // defined(ENABLED_MESSAGE_CENTER) + +class BalloonExtensionCrashRecoveryTest + : public ExtensionCrashRecoveryTestBase { + protected: + virtual void AcceptNotification(size_t index) { + Balloon* balloon = GetNotificationDelegate(index); + ASSERT_TRUE(balloon); + balloon->OnClick(); + WaitForExtensionLoad(); + } + + virtual void CancelNotification(size_t index) { + Balloon* balloon = GetNotificationDelegate(index); + ASSERT_TRUE(balloon); + std::string id = balloon->notification().notification_id(); + ASSERT_TRUE(g_browser_process->notification_ui_manager()->CancelById(id)); + } + + virtual size_t CountBalloons() { + BalloonNotificationUIManager* manager = + BalloonNotificationUIManager::GetInstanceForTesting(); + BalloonCollection::Balloons balloons = + manager->balloon_collection()->GetActiveBalloons(); + return balloons.size(); + } private: Balloon* GetNotificationDelegate(size_t index) { BalloonNotificationUIManager* manager = @@ -136,6 +190,9 @@ class MAYBE_ExtensionCrashRecoveryTest : public ExtensionBrowserTest { } }; +typedef BalloonExtensionCrashRecoveryTest MAYBE_ExtensionCrashRecoveryTest; +#endif // defined(ENABLE_MESSAGE_CENTER) + IN_PROC_BROWSER_TEST_F(MAYBE_ExtensionCrashRecoveryTest, Basic) { const size_t size_before = GetExtensionService()->extensions()->size(); const size_t crash_size_before = diff --git a/chrome/browser/notifications/message_center_notifications_browsertest.cc b/chrome/browser/notifications/message_center_notifications_browsertest.cc index 8e40886..4118f6c 100644 --- a/chrome/browser/notifications/message_center_notifications_browsertest.cc +++ b/chrome/browser/notifications/message_center_notifications_browsertest.cc @@ -28,10 +28,6 @@ class MessageCenterNotificationsTest : public InProcessBrowserTest { virtual void SetUpCommandLine(CommandLine* command_line) { // This switch enables the new piping of Notifications through Message // Center. -#if defined(ENABLE_MESSAGE_CENTER) - command_line->AppendSwitch( - message_center::switches::kEnableRichNotifications); -#endif } MessageCenterNotificationManager* manager() { diff --git a/chrome/browser/notifications/notification_browsertest.cc b/chrome/browser/notifications/notification_browsertest.cc index cbe836b..d3440de 100644 --- a/chrome/browser/notifications/notification_browsertest.cc +++ b/chrome/browser/notifications/notification_browsertest.cc @@ -45,6 +45,9 @@ #include "testing/gtest/include/gtest/gtest.h" #include "ui/base/window_open_disposition.h" +#if defined(ENABLE_MESSAGE_CENTER) +#include "ui/message_center/message_center.h" +#endif namespace { const char kExpectedIconUrl[] = "files/notifications/no_such_file.png"; @@ -55,6 +58,44 @@ enum InfobarAction { DENY, }; +#if defined(ENABLE_MESSAGE_CENTER) +class MessageCenterChangeObserver + : public message_center::MessageCenter::Observer { + public: + MessageCenterChangeObserver() + : notification_received_(false) { + message_center::MessageCenter::Get()->AddObserver(this); + } + + ~MessageCenterChangeObserver() { + message_center::MessageCenter::Get()->RemoveObserver(this); + } + + bool Wait() { + if (notification_received_) + return true; + + message_loop_runner_ = new content::MessageLoopRunner; + message_loop_runner_->Run(); + return notification_received_; + } + + virtual void OnMessageCenterChanged(bool new_notification) { + notification_received_ = true; + if (message_loop_runner_) + message_loop_runner_->Quit(); + } + + bool notification_received_; + scoped_refptr<content::MessageLoopRunner> message_loop_runner_; + + DISALLOW_COPY_AND_ASSIGN(MessageCenterChangeObserver); +}; + +typedef MessageCenterChangeObserver NotificationChangeObserver; + +#else + class NotificationBalloonChangeObserver : public content::NotificationObserver { public: NotificationBalloonChangeObserver() @@ -129,6 +170,10 @@ class NotificationBalloonChangeObserver : public content::NotificationObserver { DISALLOW_COPY_AND_ASSIGN(NotificationBalloonChangeObserver); }; +typedef NotificationBalloonChangeObserver NotificationChangeObserver; + +#endif // ENABLE_MESSAGE_CENTER + } // namespace class NotificationsTest : public InProcessBrowserTest { @@ -139,13 +184,15 @@ class NotificationsTest : public InProcessBrowserTest { // Overriden from InProcessBrowserTest: virtual void SetUpInProcessBrowserTestFixture() OVERRIDE; - const std::deque<Balloon*>& GetActiveBalloons(); int GetNotificationCount(); - bool CloseNotificationAndWait(const Notification& notification); void CloseBrowserWindow(Browser* browser); void CrashTab(Browser* browser, int index); +#if !defined(ENABLE_MESSAGE_CENTER) + const std::deque<Balloon*>& GetActiveBalloons(); void CrashNotification(Balloon* balloon); + bool CloseNotificationAndWait(const Notification& notification); +#endif void SetDefaultPermissionSetting(ContentSetting setting); void DenyOrigin(const GURL& origin); @@ -189,24 +236,13 @@ void NotificationsTest::SetUpInProcessBrowserTestFixture() { "files/notifications/notification_tester.html"); } -const std::deque<Balloon*>& NotificationsTest::GetActiveBalloons() { - return BalloonNotificationUIManager::GetInstanceForTesting()-> - balloon_collection()->GetActiveBalloons(); -} - int NotificationsTest::GetNotificationCount() { +#if defined(ENABLE_MESSAGE_CENTER) + return message_center::MessageCenter::Get()->NotificationCount(); +#else return BalloonNotificationUIManager::GetInstanceForTesting()-> balloon_collection()->GetActiveBalloons().size(); -} - -bool NotificationsTest::CloseNotificationAndWait( - const Notification& notification) { - NotificationBalloonChangeObserver observer; - bool success = BalloonNotificationUIManager::GetInstanceForTesting()-> - CancelById(notification.notification_id()); - if (success) - return observer.Wait(); - return false; +#endif // defined(ENABLE_MESSAGE_CENTER) } void NotificationsTest::CloseBrowserWindow(Browser* browser) { @@ -221,10 +257,29 @@ void NotificationsTest::CrashTab(Browser* browser, int index) { content::CrashTab(browser->tab_strip_model()->GetWebContentsAt(index)); } +#if !defined(ENABLE_MESSAGE_CENTER) + +const std::deque<Balloon*>& NotificationsTest::GetActiveBalloons() { + return BalloonNotificationUIManager::GetInstanceForTesting()-> + balloon_collection()->GetActiveBalloons(); +} + void NotificationsTest::CrashNotification(Balloon* balloon) { content::CrashTab(balloon->balloon_view()->GetHost()->web_contents()); } +bool NotificationsTest::CloseNotificationAndWait( + const Notification& notification) { + NotificationChangeObserver observer; + bool success = g_browser_process->notification_ui_manager()-> + CancelById(notification.notification_id()); + if (success) + return observer.Wait(); + return false; +} + +#endif // !defined(ENABLE_MESSAGE_CENTER) + void NotificationsTest::SetDefaultPermissionSetting(ContentSetting setting) { DesktopNotificationService* service = GetDesktopNotificationService(); service->SetDefaultContentSetting(setting); @@ -270,7 +325,7 @@ std::string NotificationsTest::CreateNotification( "createNotification('%s', '%s', '%s', '%s');", icon, title, body, replace_id); - NotificationBalloonChangeObserver observer; + NotificationChangeObserver observer; std::string result; bool success = content::ExecuteScriptAndExtractString( browser->tab_strip_model()->GetActiveWebContents(), @@ -315,7 +370,7 @@ bool NotificationsTest::CancelNotification( "cancelNotification('%s');", notification_id); - NotificationBalloonChangeObserver observer; + NotificationChangeObserver observer; std::string result; bool success = content::ExecuteScriptAndExtractString( browser->tab_strip_model()->GetActiveWebContents(), @@ -443,14 +498,24 @@ IN_PROC_BROWSER_TEST_F(NotificationsTest, TestCreateSimpleNotification) { std::string result = CreateSimpleNotification(browser(), true); EXPECT_NE("-1", result); + GURL EXPECTED_ICON_URL = test_server()->GetURL(kExpectedIconUrl); + ASSERT_EQ(1, GetNotificationCount()); +#if defined(ENABLE_MESSAGE_CENTER) + message_center::NotificationList* notification_list = + message_center::MessageCenter::Get()->notification_list(); + message_center::NotificationList::Notifications notifications = + notification_list->GetNotifications(); + EXPECT_EQ(ASCIIToUTF16("My Title"), (*notifications.rbegin())->title()); + EXPECT_EQ(ASCIIToUTF16("My Body"), (*notifications.rbegin())->message()); +#else const std::deque<Balloon*>& balloons = GetActiveBalloons(); ASSERT_EQ(1U, balloons.size()); Balloon* balloon = balloons[0]; const Notification& notification = balloon->notification(); - GURL EXPECTED_ICON_URL = test_server()->GetURL(kExpectedIconUrl); EXPECT_EQ(EXPECTED_ICON_URL, notification.icon_url()); EXPECT_EQ(ASCIIToUTF16("My Title"), notification.title()); EXPECT_EQ(ASCIIToUTF16("My Body"), notification.body()); +#endif } IN_PROC_BROWSER_TEST_F(NotificationsTest, TestCloseNotification) { @@ -460,10 +525,21 @@ IN_PROC_BROWSER_TEST_F(NotificationsTest, TestCloseNotification) { std::string result = CreateSimpleNotification(browser(), true); EXPECT_NE("-1", result); + ASSERT_EQ(1, GetNotificationCount()); +#if defined(ENABLE_MESSAGE_CENTER) + message_center::NotificationList* notification_list = + message_center::MessageCenter::Get()->notification_list(); + message_center::NotificationList::Notifications notifications = + notification_list->GetNotifications(); + message_center::MessageCenter::Get()->SendRemoveNotification( + (*notifications.rbegin())->id(), + true); // by_user +#else const std::deque<Balloon*>& balloons = GetActiveBalloons(); - ASSERT_EQ(1U, balloons.size()); EXPECT_TRUE(CloseNotificationAndWait(balloons[0]->notification())); +#endif // ENABLE_MESSAGE_CENTER + ASSERT_EQ(0, GetNotificationCount()); } @@ -528,23 +604,6 @@ IN_PROC_BROWSER_TEST_F(NotificationsTest, TestClosePermissionInfobar) { EXPECT_EQ(0U, settings.size()); } -IN_PROC_BROWSER_TEST_F(NotificationsTest, TestNotificationWithPropertyMissing) { - // Test that a notification can be created if one property is missing. - AllowAllOrigins(); - ui_test_utils::NavigateToURL(browser(), test_page_url_); - - std::string result = CreateSimpleNotification(browser(), true); - EXPECT_NE("-1", result); - - const std::deque<Balloon*>& balloons = GetActiveBalloons(); - ASSERT_EQ(1U, balloons.size()); - Balloon* balloon = balloons[0]; - const Notification& notification = balloon->notification(); - GURL EXPECTED_ICON_URL = test_server()->GetURL(kExpectedIconUrl); - EXPECT_EQ(EXPECTED_ICON_URL, notification.icon_url()); - EXPECT_EQ(ASCIIToUTF16("My Title"), notification.title()); -} - IN_PROC_BROWSER_TEST_F(NotificationsTest, TestAllowNotificationsFromAllSites) { // Verify that all domains can be allowed to show notifications. SetDefaultPermissionSetting(CONTENT_SETTING_ALLOW); @@ -629,9 +688,19 @@ IN_PROC_BROWSER_TEST_F(NotificationsTest, TestCreateDenyCloseNotifications) { GetPrefsByContentSetting(CONTENT_SETTING_BLOCK, &settings); ASSERT_TRUE(CheckOriginInSetting(settings, test_page_url_.GetOrigin())); - const std::deque<Balloon*>& balloons1 = GetActiveBalloons(); - EXPECT_EQ(1U, balloons1.size()); - ASSERT_TRUE(CloseNotificationAndWait(balloons1[0]->notification())); + EXPECT_EQ(1, GetNotificationCount()); +#if defined(ENABLE_MESSAGE_CENTER) + message_center::NotificationList* notification_list = + message_center::MessageCenter::Get()->notification_list(); + message_center::NotificationList::Notifications notifications = + notification_list->GetNotifications(); + message_center::MessageCenter::Get()->SendRemoveNotification( + (*notifications.rbegin())->id(), + true); // by_user +#else + const std::deque<Balloon*>& balloons = GetActiveBalloons(); + ASSERT_TRUE(CloseNotificationAndWait(balloons[0]->notification())); +#endif // ENABLE_MESSAGE_CENTER ASSERT_EQ(0, GetNotificationCount()); } @@ -693,6 +762,8 @@ IN_PROC_BROWSER_TEST_F(NotificationsTest, CrashTab(browser(), 0); } +// Notifications don't have their own process with the message center. +#if !defined(ENABLE_MESSAGE_CENTER) IN_PROC_BROWSER_TEST_F(NotificationsTest, TestKillNotificationProcess) { // Test killing a notification doesn't crash Chrome. AllowAllOrigins(); @@ -705,6 +776,7 @@ IN_PROC_BROWSER_TEST_F(NotificationsTest, TestKillNotificationProcess) { CrashNotification(balloons[0]); ASSERT_EQ(0, GetNotificationCount()); } +#endif IN_PROC_BROWSER_TEST_F(NotificationsTest, TestIncognitoNotification) { // Test notifications in incognito window. @@ -787,13 +859,24 @@ IN_PROC_BROWSER_TEST_F(NotificationsTest, TestNotificationReplacement) { browser(), false, "no_such_file.png", "Title2", "Body2", "chat"); EXPECT_NE("-1", result); +#if defined(ENABLE_MESSAGE_CENTER) + ASSERT_EQ(1U, GetNotificationCount()); + message_center::NotificationList* notification_list = + message_center::MessageCenter::Get()->notification_list(); + message_center::NotificationList::Notifications notifications = + notification_list->GetNotifications(); + EXPECT_EQ(ASCIIToUTF16("Title2"), (*notifications.rbegin())->title()); + EXPECT_EQ(ASCIIToUTF16("Body2"), (*notifications.rbegin())->message()); +#else const std::deque<Balloon*>& balloons = GetActiveBalloons(); - EXPECT_EQ(1U, balloons.size()); - const Notification& notification = balloons[0]->notification(); + ASSERT_EQ(1U, balloons.size()); + Balloon* balloon = balloons[0]; + const Notification& notification = balloon->notification(); GURL EXPECTED_ICON_URL = test_server()->GetURL(kExpectedIconUrl); EXPECT_EQ(EXPECTED_ICON_URL, notification.icon_url()); EXPECT_EQ(ASCIIToUTF16("Title2"), notification.title()); EXPECT_EQ(ASCIIToUTF16("Body2"), notification.body()); +#endif } #endif // !defined(OS_CHROMEOS) diff --git a/chrome/browser/task_manager/task_manager_notification_browsertest.cc b/chrome/browser/task_manager/task_manager_notification_browsertest.cc index 43756a5..d7667d3 100644 --- a/chrome/browser/task_manager/task_manager_notification_browsertest.cc +++ b/chrome/browser/task_manager/task_manager_notification_browsertest.cc @@ -19,9 +19,9 @@ #include "content/public/common/content_switches.h" #include "testing/gtest/include/gtest/gtest.h" -#if !defined(USE_ASH) -// These tests do not apply on Ash where notifications do not instantiate -// a new renderer. +#if !defined(ENABLE_MESSAGE_CENTER) +// These tests do not apply with Message Center platforms +// where notifications do not instantiate a new renderer. class TaskManagerNotificationBrowserTest : public ExtensionBrowserTest { public: @@ -79,4 +79,4 @@ IN_PROC_BROWSER_TEST_F(TaskManagerNotificationBrowserTest, TaskManagerBrowserTestUtil::WaitForWebResourceChange(1); } -#endif // !USE_ASH +#endif // !ENABLE_MESSAGE_CENTER |