Moved some message center constants to message_center_constants.h.

BUG=NONE

Review URL: https://chromiumcodereview.appspot.com/14327004

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@195077 0039d316-1c4b-4281-b951-d872f2087c98
parent 561f748a
......@@ -13,6 +13,7 @@
#include "ash/test/ash_test_base.h"
#include "base/stringprintf.h"
#include "base/utf_string_conversions.h"
#include "ui/message_center/message_center_constants.h"
#include "ui/message_center/message_center_tray.h"
#include "ui/message_center/message_center_util.h"
#include "ui/message_center/notification_list.h"
......@@ -146,7 +147,7 @@ using message_center::NotificationList;
TEST_F(WebNotificationTrayTest, DISABLED_ManyMessageCenterNotifications) {
// Add the max visible notifications +1, ensure the correct visible number.
size_t notifications_to_add =
NotificationList::kMaxVisibleMessageCenterNotifications + 1;
message_center::kMaxVisibleMessageCenterNotifications + 1;
for (size_t i = 0; i < notifications_to_add; ++i) {
std::string id = base::StringPrintf("test_id%d", static_cast<int>(i));
AddNotification(id);
......@@ -157,7 +158,7 @@ TEST_F(WebNotificationTrayTest, DISABLED_ManyMessageCenterNotifications) {
EXPECT_TRUE(GetTray()->message_center_bubble() != NULL);
EXPECT_EQ(notifications_to_add,
GetMessageCenter()->NotificationCount());
EXPECT_EQ(NotificationList::kMaxVisibleMessageCenterNotifications,
EXPECT_EQ(message_center::kMaxVisibleMessageCenterNotifications,
GetTray()->GetMessageCenterBubbleForTest()->
NumMessageViewsForTest());
}
......@@ -166,7 +167,7 @@ TEST_F(WebNotificationTrayTest, DISABLED_ManyMessageCenterNotifications) {
TEST_F(WebNotificationTrayTest, DISABLED_ManyPopupNotifications) {
// Add the max visible popup notifications +1, ensure the correct num visible.
size_t notifications_to_add =
NotificationList::kMaxVisiblePopupNotifications + 1;
message_center::kMaxVisiblePopupNotifications + 1;
for (size_t i = 0; i < notifications_to_add; ++i) {
std::string id = base::StringPrintf("test_id%d", static_cast<int>(i));
AddNotification(id);
......@@ -180,9 +181,9 @@ TEST_F(WebNotificationTrayTest, DISABLED_ManyPopupNotifications) {
if (message_center::IsRichNotificationEnabled()) {
NotificationList::PopupNotifications popups =
GetMessageCenter()->GetPopupNotifications();
EXPECT_EQ(NotificationList::kMaxVisiblePopupNotifications, popups.size());
EXPECT_EQ(message_center::kMaxVisiblePopupNotifications, popups.size());
} else {
EXPECT_EQ(NotificationList::kMaxVisiblePopupNotifications,
EXPECT_EQ(message_center::kMaxVisiblePopupNotifications,
GetTray()->GetPopupBubbleForTest()->NumMessageViewsForTest());
}
}
......
......@@ -13,6 +13,7 @@
#include "base/utf_string_conversions.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "content/public/test/test_utils.h"
#include "ui/message_center/message_center_constants.h"
#include "ui/message_center/message_center_tray.h"
#include "ui/message_center/notification_list.h"
#include "ui/message_center/notification_types.h"
......@@ -130,8 +131,7 @@ IN_PROC_BROWSER_TEST_F(WebNotificationTrayWinTest,
message_center::MessageCenter* message_center = tray->message_center();
// Add the max visible notifications +1, ensure the correct visible number.
size_t notifications_to_add =
NotificationList::kMaxVisibleMessageCenterNotifications + 1;
size_t notifications_to_add = kMaxVisibleMessageCenterNotifications + 1;
for (size_t i = 0; i < notifications_to_add; ++i) {
std::string id = base::StringPrintf("test_id%d", static_cast<int>(i));
AddNotification(id);
......@@ -142,7 +142,7 @@ IN_PROC_BROWSER_TEST_F(WebNotificationTrayWinTest,
EXPECT_TRUE(tray->message_center_bubble_.get() != NULL);
EXPECT_EQ(notifications_to_add,
message_center->NotificationCount());
EXPECT_EQ(NotificationList::kMaxVisibleMessageCenterNotifications,
EXPECT_EQ(kMaxVisibleMessageCenterNotifications,
tray->GetMessageCenterBubbleForTest()->NumMessageViewsForTest());
}
......@@ -151,8 +151,7 @@ IN_PROC_BROWSER_TEST_F(WebNotificationTrayWinTest, ManyPopupNotifications) {
message_center::MessageCenter* message_center = tray->message_center();
// Add the max visible popup notifications +1, ensure the correct num visible.
size_t notifications_to_add =
NotificationList::kMaxVisiblePopupNotifications + 1;
size_t notifications_to_add = kMaxVisiblePopupNotifications + 1;
for (size_t i = 0; i < notifications_to_add; ++i) {
std::string id = base::StringPrintf("test_id%d", static_cast<int>(i));
AddNotification(id);
......@@ -165,7 +164,7 @@ IN_PROC_BROWSER_TEST_F(WebNotificationTrayWinTest, ManyPopupNotifications) {
message_center->NotificationCount());
NotificationList::PopupNotifications popups =
message_center->GetPopupNotifications();
EXPECT_EQ(NotificationList::kMaxVisiblePopupNotifications, popups.size());
EXPECT_EQ(kMaxVisiblePopupNotifications, popups.size());
}
} // namespace message_center
......@@ -14,6 +14,10 @@ const int kNotificationIconSize = 80;
const int kNotificationPreferredImageSize = kNotificationWidth;
const int kSettingsIconSize = 16;
// Limits.
const size_t kMaxVisibleMessageCenterNotifications = 100;
const size_t kMaxVisiblePopupNotifications = 3;
// Within a notification ///////////////////////////////////////////////////////
// Pixel dimensions.
......
......@@ -19,6 +19,10 @@ MESSAGE_CENTER_EXPORT extern const int kNotificationIconSize;
MESSAGE_CENTER_EXPORT extern const int kNotificationPreferredImageSize;
MESSAGE_CENTER_EXPORT extern const int kSettingsIconSize;
// Limits.
MESSAGE_CENTER_EXPORT extern const size_t kMaxVisiblePopupNotifications;
MESSAGE_CENTER_EXPORT extern const size_t kMaxVisibleMessageCenterNotifications;
// Within a notification ///////////////////////////////////////////////////////
// Pixel dimensions (H = horizontal, V = vertical).
......
......@@ -9,6 +9,7 @@
#include "base/stl_util.h"
#include "base/time.h"
#include "base/values.h"
#include "ui/message_center/message_center_constants.h"
#include "ui/message_center/notification.h"
#include "ui/message_center/notification_types.h"
......@@ -35,9 +36,6 @@ bool CompareTimestampSerial::operator()(Notification* n1, Notification* n2) {
return false;
}
const size_t NotificationList::kMaxVisibleMessageCenterNotifications = 100;
const size_t NotificationList::kMaxVisiblePopupNotifications = 3;
NotificationList::NotificationList()
: message_center_visible_(false),
unread_count_(0),
......
......@@ -128,9 +128,6 @@ class MESSAGE_CENTER_EXPORT NotificationList {
size_t NotificationCount() const;
size_t unread_count() const { return unread_count_; }
static const size_t kMaxVisiblePopupNotifications;
static const size_t kMaxVisibleMessageCenterNotifications;
private:
friend class test::NotificationListTest;
......
......@@ -10,6 +10,7 @@
#include "base/utf_string_conversions.h"
#include "base/values.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/message_center/message_center_constants.h"
#include "ui/message_center/notification_types.h"
namespace message_center {
......@@ -188,21 +189,18 @@ TEST_F(NotificationListTest, GetNotificationsBySourceOrExtensions) {
TEST_F(NotificationListTest, OldPopupShouldNotBeHidden) {
std::vector<std::string> ids;
for (size_t i = 0; i <= NotificationList::kMaxVisiblePopupNotifications;
i++) {
for (size_t i = 0; i <= kMaxVisiblePopupNotifications; i++)
ids.push_back(AddNotification(NULL));
}
NotificationList::PopupNotifications popups =
notification_list()->GetPopupNotifications();
// The popup should contain the oldest kMaxVisiblePopupNotifications. Newer
// one should come earlier in the popup list. It means, the last element
// of |popups| should be the firstly added one, and so on.
EXPECT_EQ(NotificationList::kMaxVisiblePopupNotifications, popups.size());
EXPECT_EQ(kMaxVisiblePopupNotifications, popups.size());
NotificationList::PopupNotifications::const_reverse_iterator iter =
popups.rbegin();
for (size_t i = 0; i < NotificationList::kMaxVisiblePopupNotifications;
++i, ++iter) {
for (size_t i = 0; i < kMaxVisiblePopupNotifications; ++i, ++iter) {
EXPECT_EQ(ids[i], (*iter)->id()) << i;
}
......@@ -218,27 +216,25 @@ TEST_F(NotificationListTest, Priority) {
ASSERT_EQ(0u, notification_list()->unread_count());
// Default priority has the limit on the number of the popups.
for (size_t i = 0; i <= NotificationList::kMaxVisiblePopupNotifications;
++i) {
for (size_t i = 0; i <= kMaxVisiblePopupNotifications; ++i)
AddNotification(NULL);
}
EXPECT_EQ(NotificationList::kMaxVisiblePopupNotifications + 1,
EXPECT_EQ(kMaxVisiblePopupNotifications + 1,
notification_list()->NotificationCount());
EXPECT_EQ(NotificationList::kMaxVisiblePopupNotifications, GetPopupCounts());
EXPECT_EQ(kMaxVisiblePopupNotifications, GetPopupCounts());
// Low priority: not visible to popups.
notification_list()->SetMessageCenterVisible(true, NULL);
notification_list()->SetMessageCenterVisible(false, NULL);
EXPECT_EQ(0u, notification_list()->unread_count());
AddPriorityNotification(LOW_PRIORITY);
EXPECT_EQ(NotificationList::kMaxVisiblePopupNotifications + 2,
EXPECT_EQ(kMaxVisiblePopupNotifications + 2,
notification_list()->NotificationCount());
EXPECT_EQ(1u, notification_list()->unread_count());
EXPECT_EQ(0u, GetPopupCounts());
// Minimum priority: doesn't update the unread count.
AddPriorityNotification(MIN_PRIORITY);
EXPECT_EQ(NotificationList::kMaxVisiblePopupNotifications + 3,
EXPECT_EQ(kMaxVisiblePopupNotifications + 3,
notification_list()->NotificationCount());
EXPECT_EQ(1u, notification_list()->unread_count());
EXPECT_EQ(0u, GetPopupCounts());
......@@ -246,18 +242,13 @@ TEST_F(NotificationListTest, Priority) {
notification_list()->RemoveAllNotifications();
// Higher priority: no limits to the number of popups.
for (size_t i = 0; i < NotificationList::kMaxVisiblePopupNotifications * 2;
++i) {
for (size_t i = 0; i < kMaxVisiblePopupNotifications * 2; ++i)
AddPriorityNotification(HIGH_PRIORITY);
}
for (size_t i = 0; i < NotificationList::kMaxVisiblePopupNotifications * 2;
++i) {
for (size_t i = 0; i < kMaxVisiblePopupNotifications * 2; ++i)
AddPriorityNotification(MAX_PRIORITY);
}
EXPECT_EQ(NotificationList::kMaxVisiblePopupNotifications * 4,
EXPECT_EQ(kMaxVisiblePopupNotifications * 4,
notification_list()->NotificationCount());
EXPECT_EQ(NotificationList::kMaxVisiblePopupNotifications * 4,
GetPopupCounts());
EXPECT_EQ(kMaxVisiblePopupNotifications * 4, GetPopupCounts());
}
TEST_F(NotificationListTest, HasPopupsWithPriority) {
......@@ -390,8 +381,7 @@ TEST_F(NotificationListTest, MarkSinglePopupAsShown) {
std::string id2 = AddNotification(NULL);
std::string id3 = AddNotification(NULL);
ASSERT_EQ(3u, notification_list()->NotificationCount());
ASSERT_EQ(std::min(static_cast<size_t>(3u),
NotificationList::kMaxVisiblePopupNotifications),
ASSERT_EQ(std::min(static_cast<size_t>(3u), kMaxVisiblePopupNotifications),
GetPopupCounts());
notification_list()->MarkSinglePopupAsShown(id2, true);
......
......@@ -391,10 +391,8 @@ void MessageCenterView::SetNotifications(
for (NotificationList::Notifications::const_iterator iter =
notifications.begin(); iter != notifications.end(); ++iter) {
AddNotification(*(*iter));
if (message_views_.size() >=
NotificationList::kMaxVisibleMessageCenterNotifications) {
if (message_views_.size() >= kMaxVisibleMessageCenterNotifications)
break;
}
}
if (message_views_.empty()) {
views::Label* label = new views::Label(l10n_util::GetStringUTF16(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment