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

Unified Diff: ash/system/web_notification/web_notification_tray_unittest.cc

Issue 11819048: Implement message center on Windows (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Address sky/msw comments + rebase. Created 7 years, 11 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: ash/system/web_notification/web_notification_tray_unittest.cc
diff --git a/ash/system/web_notification/web_notification_tray_unittest.cc b/ash/system/web_notification/web_notification_tray_unittest.cc
index a5a38336450a1555bff21965709e71b87f15c9ad..1523a518ea4490a0976413b6ac5be363f448dd54 100644
--- a/ash/system/web_notification/web_notification_tray_unittest.cc
+++ b/ash/system/web_notification/web_notification_tray_unittest.cc
@@ -9,13 +9,14 @@
#include "ash/root_window_controller.h"
#include "ash/system/status_area_widget.h"
#include "ash/system/tray/system_tray_item.h"
+#include "ash/test/ash_test_base.h"
+#include "base/stringprintf.h"
+#include "base/utf_string_conversions.h"
#include "ui/message_center/message_center_bubble.h"
+#include "ui/message_center/message_center_tray.h"
#include "ui/message_center/message_popup_bubble.h"
#include "ui/message_center/notification_list.h"
#include "ui/notifications/notification_types.h"
-#include "ash/test/ash_test_base.h"
-#include "base/stringprintf.h"
-#include "base/utf_string_conversions.h"
#include "ui/views/controls/label.h"
#include "ui/views/layout/fill_layout.h"
#include "ui/views/view.h"
@@ -34,6 +35,10 @@ WebNotificationTray* GetWebNotificationTray() {
web_notification_tray();
}
+message_center::MessageCenter* get_message_center() {
+ return GetWebNotificationTray()->message_center();
+}
+
class TestDelegate : public message_center::MessageCenter::Delegate {
public:
TestDelegate(message_center::MessageCenter* message_center)
@@ -68,7 +73,7 @@ class TestDelegate : public message_center::MessageCenter::Delegate {
void AddNotification(WebNotificationTray* tray, const std::string& id) {
notification_ids_.insert(id);
- tray->message_center()->AddNotification(
+ get_message_center()->AddNotification(
ui::notifications::NOTIFICATION_TYPE_SIMPLE,
id,
ASCIIToUTF16("Test Web Notification"),
@@ -83,7 +88,7 @@ class TestDelegate : public message_center::MessageCenter::Delegate {
const std::string& new_id) {
notification_ids_.erase(old_id);
notification_ids_.insert(new_id);
- tray->message_center()->UpdateNotification(
+ get_message_center()->UpdateNotification(
old_id, new_id,
ASCIIToUTF16("Updated Web Notification"),
ASCIIToUTF16("Updated message body."),
@@ -91,7 +96,7 @@ class TestDelegate : public message_center::MessageCenter::Delegate {
}
void RemoveNotification(WebNotificationTray* tray, const std::string& id) {
- tray->message_center()->RemoveNotification(id);
+ get_message_center()->RemoveNotification(id);
notification_ids_.erase(id);
}
@@ -118,17 +123,17 @@ TEST_F(WebNotificationTrayTest, WebNotifications) {
// Add a notification.
delegate->AddNotification(tray, "test_id1");
- EXPECT_EQ(1u, tray->message_center()->NotificationCount());
+ EXPECT_EQ(1u, get_message_center()->NotificationCount());
EXPECT_TRUE(message_center->notification_list()->HasNotification("test_id1"));
delegate->AddNotification(tray, "test_id2");
delegate->AddNotification(tray, "test_id2");
- EXPECT_EQ(2u, tray->message_center()->NotificationCount());
+ EXPECT_EQ(2u, get_message_center()->NotificationCount());
EXPECT_TRUE(message_center->notification_list()->HasNotification("test_id2"));
// Ensure that updating a notification does not affect the count.
delegate->UpdateNotification(tray, "test_id2", "test_id3");
delegate->UpdateNotification(tray, "test_id3", "test_id3");
- EXPECT_EQ(2u, tray->message_center()->NotificationCount());
+ EXPECT_EQ(2u, get_message_center()->NotificationCount());
EXPECT_FALSE(delegate->HasNotificationId("test_id2"));
EXPECT_FALSE(message_center->notification_list()->HasNotification(
"test_id2"));
@@ -139,37 +144,37 @@ TEST_F(WebNotificationTrayTest, WebNotifications) {
EXPECT_FALSE(delegate->HasNotificationId("test_id1"));
EXPECT_FALSE(message_center->notification_list()->HasNotification(
"test_id1"));
- EXPECT_EQ(1u, tray->message_center()->NotificationCount());
+ EXPECT_EQ(1u, get_message_center()->NotificationCount());
// Remove the remianing notification.
delegate->RemoveNotification(tray, "test_id3");
- EXPECT_EQ(0u, tray->message_center()->NotificationCount());
+ EXPECT_EQ(0u, get_message_center()->NotificationCount());
EXPECT_FALSE(message_center->notification_list()->HasNotification(
"test_id3"));
}
TEST_F(WebNotificationTrayTest, WebNotificationPopupBubble) {
WebNotificationTray* tray = GetWebNotificationTray();
- scoped_ptr<TestDelegate> delegate(new TestDelegate(tray->message_center()));
+ scoped_ptr<TestDelegate> delegate(new TestDelegate(get_message_center()));
ASSERT_TRUE(tray->GetWidget());
// Adding a notification should show the popup bubble.
delegate->AddNotification(tray, "test_id1");
- EXPECT_TRUE(tray->popup_bubble() != NULL);
+ EXPECT_TRUE(tray->IsPopupVisible());
// Updating a notification should not hide the popup bubble.
delegate->AddNotification(tray, "test_id2");
delegate->UpdateNotification(tray, "test_id2", "test_id3");
- EXPECT_TRUE(tray->popup_bubble() != NULL);
+ EXPECT_TRUE(tray->IsPopupVisible());
// Removing the first notification should not hide the popup bubble.
delegate->RemoveNotification(tray, "test_id1");
- EXPECT_TRUE(tray->popup_bubble() != NULL);
+ EXPECT_TRUE(tray->IsPopupVisible());
// Removing the visible notification should hide the popup bubble.
delegate->RemoveNotification(tray, "test_id3");
- EXPECT_TRUE(tray->popup_bubble() == NULL);
+ EXPECT_FALSE(tray->IsPopupVisible());
}
using message_center::NotificationList;
@@ -177,7 +182,7 @@ using message_center::NotificationList;
TEST_F(WebNotificationTrayTest, ManyMessageCenterNotifications) {
WebNotificationTray* tray = GetWebNotificationTray();
- scoped_ptr<TestDelegate> delegate(new TestDelegate(tray->message_center()));
+ scoped_ptr<TestDelegate> delegate(new TestDelegate(get_message_center()));
// Add the max visible notifications +1, ensure the correct visible number.
size_t notifications_to_add =
@@ -186,18 +191,19 @@ TEST_F(WebNotificationTrayTest, ManyMessageCenterNotifications) {
std::string id = StringPrintf("test_id%d", static_cast<int>(i));
delegate->AddNotification(tray, id);
}
- tray->ShowMessageCenterBubble();
+ bool shown = tray->message_center_tray_->ShowMessageCenterBubble();
+ EXPECT_TRUE(shown);
RunAllPendingInMessageLoop();
EXPECT_TRUE(tray->message_center_bubble() != NULL);
EXPECT_EQ(notifications_to_add,
- tray->message_center()->NotificationCount());
+ get_message_center()->NotificationCount());
EXPECT_EQ(NotificationList::kMaxVisibleMessageCenterNotifications,
tray->GetMessageCenterBubbleForTest()->NumMessageViewsForTest());
}
TEST_F(WebNotificationTrayTest, ManyPopupNotifications) {
WebNotificationTray* tray = GetWebNotificationTray();
- scoped_ptr<TestDelegate> delegate(new TestDelegate(tray->message_center()));
+ scoped_ptr<TestDelegate> delegate(new TestDelegate(get_message_center()));
// Add the max visible popup notifications +1, ensure the correct num visible.
size_t notifications_to_add =
@@ -207,13 +213,15 @@ TEST_F(WebNotificationTrayTest, ManyPopupNotifications) {
delegate->AddNotification(tray, id);
}
// Hide and reshow the bubble so that it is updated immediately, not delayed.
- tray->HidePopupBubble();
- tray->ShowPopupBubble();
- EXPECT_TRUE(tray->popup_bubble() != NULL);
+ tray->SetHidePopupBubble(true);
+ tray->SetHidePopupBubble(false);
+ EXPECT_TRUE(tray->IsPopupVisible());
EXPECT_EQ(notifications_to_add,
- tray->message_center()->NotificationCount());
+ get_message_center()->NotificationCount());
EXPECT_EQ(NotificationList::kMaxVisiblePopupNotifications,
tray->GetPopupBubbleForTest()->NumMessageViewsForTest());
+ get_message_center()->SetDelegate(NULL);
+ get_message_center()->notification_list()->RemoveAllNotifications();
}
} // namespace ash

Powered by Google App Engine
This is Rietveld 408576698