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

Unified Diff: chrome/browser/notifications/desktop_notifications_unittest.cc

Issue 23361031: [Mac] Delete old balloon and Notification Center notification implementations. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix DCHECK Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/notifications/desktop_notifications_unittest.cc
diff --git a/chrome/browser/notifications/desktop_notifications_unittest.cc b/chrome/browser/notifications/desktop_notifications_unittest.cc
index 9d07c8b84e544677a8da7b920ff6991cdd04dd19..d8f4f731eb92e7a338c6edd43b15405086a2de44 100644
--- a/chrome/browser/notifications/desktop_notifications_unittest.cc
+++ b/chrome/browser/notifications/desktop_notifications_unittest.cc
@@ -18,22 +18,21 @@
#include "ui/base/ime/input_method_initializer.h"
#include "ui/message_center/message_center.h"
-#if defined(USE_ASH)
-#include "ash/shell.h"
-#include "ash/test/test_shell_delegate.h"
-#include "ui/aura/env.h"
-#include "ui/aura/root_window.h"
-#include "ui/compositor/scoped_animation_duration_scale_mode.h"
+#if defined(RUN_MESSAGE_CENTER_TESTS)
+#include "chrome/browser/notifications/message_center_notification_manager.h"
+#include "chrome/browser/notifications/message_center_settings_controller.h"
+#include "chrome/browser/profiles/profile_manager.h"
#endif
-
using content::BrowserThread;
// static
-const int MockBalloonCollection::kMockBalloonSpace = 5;
+std::string DesktopNotificationsTest::log_output_;
+
+#if !defined(RUN_MESSAGE_CENTER_TESTS)
// static
-std::string DesktopNotificationsTest::log_output_;
+const int MockBalloonCollection::kMockBalloonSpace = 5;
MockBalloonCollection::MockBalloonCollection() {}
@@ -92,49 +91,115 @@ int MockBalloonCollection::UppermostVerticalPosition() {
return min;
}
+#else
+
+class TestMessageCenterNotificationManager :
+ public MessageCenterNotificationManager {
+ public:
+ TestMessageCenterNotificationManager(
+ message_center::MessageCenter* message_center,
+ PrefService* local_state,
+ scoped_ptr<message_center::NotifierSettingsProvider> settings_provider)
+ : MessageCenterNotificationManager(message_center,
+ local_state,
+ settings_provider.Pass()) {
+ }
+ virtual ~TestMessageCenterNotificationManager() {}
+
+ virtual bool ShowNotification(const Notification& notification,
+ Profile* profile) OVERRIDE {
+ // Swap in a logging proxy for the purpose of logging calls that
+ // would be made into javascript, then pass this down.
+ Notification test_notification(
+ notification.origin_url(),
+ notification.content_url(),
+ notification.display_source(),
+ notification.replace_id(),
+ new LoggingNotificationProxy(notification.notification_id()));
+ return MessageCenterNotificationManager::ShowNotification(
+ test_notification, profile);
+ }
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(TestMessageCenterNotificationManager);
+};
+
+#endif // !defined(RUN_MESSAGE_CENTER_TESTS)
+
DesktopNotificationsTest::DesktopNotificationsTest()
- : ui_thread_(BrowserThread::UI, &message_loop_) {
+ : ui_thread_(BrowserThread::UI, &message_loop_),
+ aura_test_helper_(&message_loop_) {
}
DesktopNotificationsTest::~DesktopNotificationsTest() {
}
+// static
+void DesktopNotificationsTest::log(const std::string& message) {
+ log_output_.append(message);
+ base::MessageLoop::current()->PostTask(FROM_HERE,
+ base::MessageLoop::current()->QuitClosure());
+}
+
void DesktopNotificationsTest::SetUp() {
ui::InitializeInputMethodForTesting();
-#if defined(USE_ASH)
- ui::ScopedAnimationDurationScaleMode normal_duration_mode(
- ui::ScopedAnimationDurationScaleMode::ZERO_DURATION);
+
+#if defined(USE_AURA)
+ aura_test_helper_.SetUp();
+#endif
+
+ chrome::RegisterLocalState(local_state_.registry());
+
+ profile_manager_.reset(
+ new TestingProfileManager(TestingBrowserProcess::GetGlobal()));
+ ASSERT_TRUE(profile_manager_->SetUp());
+ profile_ = profile_manager_->CreateTestingProfile("notifications_test");
+
+#if defined(RUN_MESSAGE_CENTER_TESTS)
// The message center is notmally initialized on |g_browser_process| which
// is not created for these tests.
message_center::MessageCenter::Initialize();
- // MockBalloonCollection retrieves information about the screen on creation.
- // So it is necessary to make sure the desktop gets created first.
- ash::Shell::CreateInstance(new ash::test::TestShellDelegate);
+ scoped_ptr<message_center::NotifierSettingsProvider> settings_provider(
+ new MessageCenterSettingsController(
+ profile_manager_->profile_info_cache()));
+ ui_manager_.reset(
+ new TestMessageCenterNotificationManager(
+ message_center::MessageCenter::Get(), &local_state_,
+ settings_provider.Pass()));
+#else
+ BalloonNotificationUIManager* balloon_ui_manager =
+ new BalloonNotificationUIManager(&local_state_);
+ ui_manager_.reset(balloon_ui_manager);
+ balloon_collection_ = new MockBalloonCollection();
+ balloon_ui_manager->SetBalloonCollection(balloon_collection_);
#endif
- chrome::RegisterLocalState(local_state_.registry());
- profile_.reset(new TestingProfile());
- ui_manager_.reset(new BalloonNotificationUIManager(&local_state_));
- balloon_collection_ = new MockBalloonCollection();
- ui_manager_->SetBalloonCollection(balloon_collection_);
service_.reset(new DesktopNotificationService(profile(), ui_manager_.get()));
log_output_.clear();
}
void DesktopNotificationsTest::TearDown() {
- service_.reset(NULL);
- ui_manager_.reset(NULL);
- profile_.reset(NULL);
-#if defined(USE_ASH)
- ash::Shell::DeleteInstance();
- // The message center is notmally shutdown on |g_browser_process| which
- // is not created for these tests.
+ service_.reset();
+ ui_manager_.reset();
+ profile_ = NULL;
+ profile_manager_.reset();
+#if defined(RUN_MESSAGE_CENTER_TESTS)
message_center::MessageCenter::Shutdown();
- aura::Env::DeleteInstance();
+#endif
+#if defined(USE_AURA)
+ aura_test_helper_.TearDown();
#endif
ui::ShutdownInputMethodForTesting();
}
+int DesktopNotificationsTest::GetNotificationCount() {
+#if defined(RUN_MESSAGE_CENTER_TESTS)
+ return message_center::MessageCenter::Get()->GetNotifications().size();
+#else
+ return balloon_collection_->count();
+#endif
+}
+
content::ShowDesktopNotificationHostMsgParams
DesktopNotificationsTest::StandardTestNotification() {
content::ShowDesktopNotificationHostMsgParams params;
@@ -155,8 +220,8 @@ TEST_F(DesktopNotificationsTest, TestShow) {
EXPECT_TRUE(service_->ShowDesktopNotification(
params, 0, 0, DesktopNotificationService::PageNotification));
- base::MessageLoopForUI::current()->RunUntilIdle();
- EXPECT_EQ(1, balloon_collection_->count());
+ base::MessageLoopForUI::current()->Run();
+ EXPECT_EQ(1, GetNotificationCount());
content::ShowDesktopNotificationHostMsgParams params2;
params2.origin = GURL("http://www.google.com");
@@ -166,14 +231,15 @@ TEST_F(DesktopNotificationsTest, TestShow) {
EXPECT_TRUE(service_->ShowDesktopNotification(
params2, 0, 0, DesktopNotificationService::PageNotification));
- base::MessageLoopForUI::current()->RunUntilIdle();
- EXPECT_EQ(2, balloon_collection_->count());
+ base::MessageLoopForUI::current()->Run();
+ EXPECT_EQ(2, GetNotificationCount());
EXPECT_EQ("notification displayed\n"
"notification displayed\n",
log_output_);
}
+#if !defined(RUN_MESSAGE_CENTER_TESTS)
TEST_F(DesktopNotificationsTest, TestClose) {
content::ShowDesktopNotificationHostMsgParams params =
StandardTestNotification();
@@ -182,7 +248,7 @@ TEST_F(DesktopNotificationsTest, TestClose) {
// Request a notification; should open a balloon.
EXPECT_TRUE(service_->ShowDesktopNotification(
params, 0, 0, DesktopNotificationService::PageNotification));
- base::MessageLoopForUI::current()->RunUntilIdle();
+ base::MessageLoopForUI::current()->Run();
EXPECT_EQ(1, balloon_collection_->count());
// Close all the open balloons.
@@ -194,6 +260,7 @@ TEST_F(DesktopNotificationsTest, TestClose) {
"notification closed by user\n",
log_output_);
}
+#endif // !defined(RUN_MESSAGE_CENTER_TESTS)
TEST_F(DesktopNotificationsTest, TestCancel) {
int process_id = 0;
@@ -208,23 +275,24 @@ TEST_F(DesktopNotificationsTest, TestCancel) {
EXPECT_TRUE(service_->ShowDesktopNotification(
params, process_id, route_id,
DesktopNotificationService::PageNotification));
- base::MessageLoopForUI::current()->RunUntilIdle();
- EXPECT_EQ(1, balloon_collection_->count());
+ base::MessageLoopForUI::current()->Run();
+ EXPECT_EQ(1, GetNotificationCount());
// Cancel the same notification
service_->CancelDesktopNotification(process_id,
route_id,
notification_id);
- base::MessageLoopForUI::current()->RunUntilIdle();
+ base::MessageLoopForUI::current()->Run();
// Verify that the balloon collection is now empty.
- EXPECT_EQ(0, balloon_collection_->count());
+ EXPECT_EQ(0, GetNotificationCount());
EXPECT_EQ("notification displayed\n"
"notification closed by script\n",
log_output_);
}
-#if defined(OS_WIN) || defined(TOOLKIT_VIEWS)
+#if (defined(OS_WIN) || defined(TOOLKIT_VIEWS)) && \
+ !defined(RUN_MESSAGE_CENTER_TESTS)
TEST_F(DesktopNotificationsTest, TestPositioning) {
content::ShowDesktopNotificationHostMsgParams params =
StandardTestNotification();
@@ -293,13 +361,8 @@ TEST_F(DesktopNotificationsTest, TestCancelByProfile) {
int process_id = 0;
int route_id = 0;
- TestingBrowserProcess* browser_process =
- TestingBrowserProcess::GetGlobal();
- TestingProfileManager profile_manager(browser_process);
- ASSERT_TRUE(profile_manager.SetUp());
-
TestingProfile* second_profile =
- profile_manager.CreateTestingProfile("SecondTestingProfile");
+ profile_manager_->CreateTestingProfile("SecondTestingProfile");
scoped_ptr<DesktopNotificationService> second_service(
new DesktopNotificationService(second_profile, ui_manager_.get()));
@@ -323,13 +386,13 @@ TEST_F(DesktopNotificationsTest, TestCancelByProfile) {
params, process_id, route_id,
DesktopNotificationService::PageNotification));
}
- base::MessageLoopForUI::current()->RunUntilIdle();
+ base::MessageLoopForUI::current()->Run();
ui_manager_->CancelAllByProfile(second_profile);
// Verify that the balloon collection only contains the single
// notification from the first profile.
- EXPECT_EQ(1, balloon_collection_->count());
+ EXPECT_EQ(1, GetNotificationCount());
}
TEST_F(DesktopNotificationsTest, TestCancelBySourceOrigin) {
@@ -360,15 +423,16 @@ TEST_F(DesktopNotificationsTest, TestCancelBySourceOrigin) {
odd_params, process_id, route_id,
DesktopNotificationService::PageNotification));
}
- base::MessageLoopForUI::current()->RunUntilIdle();
+ base::MessageLoopForUI::current()->Run();
ui_manager_->CancelAllBySourceOrigin(odd_params.origin);
// Verify that the balloon collection only contains the single
// notification which is not from the canceled origin.
- EXPECT_EQ(1, balloon_collection_->count());
+ EXPECT_EQ(1, GetNotificationCount());
}
+#if !defined(RUN_MESSAGE_CENTER_TESTS)
TEST_F(DesktopNotificationsTest, TestQueueing) {
int process_id = 0;
int route_id = 0;
@@ -383,7 +447,7 @@ TEST_F(DesktopNotificationsTest, TestQueueing) {
params, process_id, route_id,
DesktopNotificationService::PageNotification));
}
- base::MessageLoopForUI::current()->RunUntilIdle();
+ base::MessageLoopForUI::current()->Run();
// Build up an expected log of what should be happening.
std::string expected_log;
@@ -405,7 +469,7 @@ TEST_F(DesktopNotificationsTest, TestQueueing) {
id <= kLotsOfToasts - balloon_collection_->max_balloon_count();
++id) {
service_->CancelDesktopNotification(process_id, route_id, id);
- base::MessageLoopForUI::current()->RunUntilIdle();
+ base::MessageLoopForUI::current()->Run();
expected_log.append("notification closed by script\n");
expected_log.append("notification displayed\n");
EXPECT_EQ(balloon_collection_->max_balloon_count(),
@@ -417,7 +481,7 @@ TEST_F(DesktopNotificationsTest, TestQueueing) {
for (; id <= kLotsOfToasts; ++id) {
service_->CancelDesktopNotification(process_id, route_id, id);
expected_log.append("notification closed by script\n");
- base::MessageLoopForUI::current()->RunUntilIdle();
+ base::MessageLoopForUI::current()->Run();
EXPECT_EQ(expected_log, log_output_);
}
}
@@ -425,6 +489,7 @@ TEST_F(DesktopNotificationsTest, TestQueueing) {
// Verify that the balloon collection is now empty.
EXPECT_EQ(0, balloon_collection_->count());
}
+#endif // !defined(RUN_MESSAGE_CENTER_TESTS)
TEST_F(DesktopNotificationsTest, TestEarlyDestruction) {
// Create some toasts and then prematurely delete the notification service,
@@ -439,6 +504,8 @@ TEST_F(DesktopNotificationsTest, TestEarlyDestruction) {
service_.reset(NULL);
}
+#if !defined(RUN_MESSAGE_CENTER_TESTS)
+
TEST_F(DesktopNotificationsTest, TestUserInputEscaping) {
// Create a test script with some HTML; assert that it doesn't get into the
// data:// URL that's produced for the balloon.
@@ -450,7 +517,7 @@ TEST_F(DesktopNotificationsTest, TestUserInputEscaping) {
EXPECT_TRUE(service_->ShowDesktopNotification(
params, 0, 0, DesktopNotificationService::PageNotification));
- base::MessageLoopForUI::current()->RunUntilIdle();
+ base::MessageLoopForUI::current()->Run();
EXPECT_EQ(1, balloon_collection_->count());
Balloon* balloon = (*balloon_collection_->balloons().begin());
GURL data_url = balloon->notification().content_url();
@@ -569,3 +636,5 @@ TEST_F(DesktopNotificationsTest, TestPositionPreference) {
int current_x = (*balloons.begin())->GetPosition().x();
EXPECT_LT(current_x, last_x);
}
+
+#endif // !defined(RUN_MESSAGE_CENTER_TESTS)

Powered by Google App Engine
This is Rietveld 408576698