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

Unified Diff: ui/message_center/views/notification_view_unittest.cc

Issue 1292003004: Elide origins displayed on web notifications. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Move origin_url to message_center::Notification Created 5 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: ui/message_center/views/notification_view_unittest.cc
diff --git a/ui/message_center/views/notification_view_unittest.cc b/ui/message_center/views/notification_view_unittest.cc
index 054dfbd97bc7a6c3d351bc25268a5360c166da34..893ecbbd3681e5892b3ab5544c027ff4d9ca5d06 100644
--- a/ui/message_center/views/notification_view_unittest.cc
+++ b/ui/message_center/views/notification_view_unittest.cc
@@ -165,16 +165,11 @@ void NotificationViewTest::SetUp() {
// Create a dummy notification.
SkBitmap bitmap;
data_.reset(new RichNotificationData());
- notification_.reset(
- new Notification(NOTIFICATION_TYPE_BASE_FORMAT,
- std::string("notification id"),
- base::UTF8ToUTF16("title"),
- base::UTF8ToUTF16("message"),
- CreateTestImage(80, 80),
- base::UTF8ToUTF16("display source"),
- NotifierId(NotifierId::APPLICATION, "extension_id"),
- *data_,
- NULL));
+ notification_.reset(new Notification(
+ NOTIFICATION_TYPE_BASE_FORMAT, std::string("notification id"),
+ base::UTF8ToUTF16("title"), base::UTF8ToUTF16("message"),
+ CreateTestImage(80, 80), base::UTF8ToUTF16("display source"), GURL(),
+ NotifierId(NotifierId::APPLICATION, "extension_id"), *data_, NULL));
notification_->set_small_image(CreateTestImage(16, 16));
notification_->set_image(CreateTestImage(320, 240));
@@ -253,7 +248,7 @@ TEST_F(NotificationViewTest, CreateOrUpdateTest) {
TEST_F(NotificationViewTest, TestLineLimits) {
notification()->set_image(CreateTestImage(0, 0));
- notification()->set_context_message(base::ASCIIToUTF16(""));
+ notification()->set_context_message(base::ASCIIToUTF16(""), false);
notification_view()->CreateOrUpdateViews(*notification());
EXPECT_EQ(5, notification_view()->GetMessageLineLimit(0, 360));
@@ -267,7 +262,7 @@ TEST_F(NotificationViewTest, TestLineLimits) {
EXPECT_EQ(2, notification_view()->GetMessageLineLimit(1, 360));
EXPECT_EQ(1, notification_view()->GetMessageLineLimit(2, 360));
- notification()->set_context_message(base::UTF8ToUTF16("foo"));
+ notification()->set_context_message(base::ASCIIToUTF16("foo"), false);
notification_view()->CreateOrUpdateViews(*notification());
EXPECT_TRUE(notification_view()->context_message_view_ != NULL);
@@ -461,4 +456,65 @@ TEST_F(NotificationViewTest, ViewOrderingTest) {
CheckVerticalOrderInNotification();
}
+TEST_F(NotificationViewTest, FormatContextMessageTest) {
+ const std::string kRegularContextText = "Context Text";
+ const std::string kVeryLongContextText =
+ "VERY VERY VERY VERY VERY VERY VERY VERY VERY VERY VERY VERY"
+ "VERY VERY VERY VERY VERY VERY VERY VERY VERY VERY VERY VERY"
+ "VERY VERY VERY VERY Long Long Long Long Long Long Long Long context";
+
+ const std::string kVeryLongElidedContextText =
+ "VERY VERY VERY VERY VERY VERY VERY VERY VERY VERY VERY VERYVERY VERY "
+ "VERY VERY VERY VERY VERY VERY VERY VERY VERY\xE2\x80\xA6";
+
+ const std::string kUrlContext = "http://chromium.org/hello";
+ const std::string kHostContext = "chromium.org";
+ const std::string kLongUrlContext =
+ "https://"
+ "veryveryveryveryveyryveryveryveryveryveyryveryvery.veryveryveyrylong."
+ "chromium.org/hello";
+
+ Notification notification1(
+ NOTIFICATION_TYPE_BASE_FORMAT, std::string(""), base::UTF8ToUTF16(""),
+ base::UTF8ToUTF16(""), CreateTestImage(80, 80), base::UTF8ToUTF16(""),
+ GURL(), message_center::NotifierId(GURL()), *data(), NULL);
+ notification1.set_context_message(base::ASCIIToUTF16(kRegularContextText),
+ false);
+
+ base::string16 result =
+ notification_view()->FormatContextMessage(notification1);
+ EXPECT_EQ(kRegularContextText, base::UTF16ToUTF8(result));
+
+ notification1.set_context_message(base::ASCIIToUTF16(kVeryLongContextText),
+ false);
+ result = notification_view()->FormatContextMessage(notification1);
+ EXPECT_EQ(kVeryLongElidedContextText, base::UTF16ToUTF8(result));
+
+ Notification notification2(
+ NOTIFICATION_TYPE_BASE_FORMAT, std::string(""), base::UTF8ToUTF16(""),
+ base::UTF8ToUTF16(""), CreateTestImage(80, 80), base::UTF8ToUTF16(""),
+ GURL(kUrlContext), message_center::NotifierId(GURL()), *data(), NULL);
+ notification2.set_context_message(base::ASCIIToUTF16(""), true);
+
+ result = notification_view()->FormatContextMessage(notification2);
+ EXPECT_EQ(kHostContext, base::UTF16ToUTF8(result));
+
+ Notification notification3(
+ NOTIFICATION_TYPE_BASE_FORMAT, std::string(""), base::UTF8ToUTF16(""),
+ base::UTF8ToUTF16(""), CreateTestImage(80, 80), base::UTF8ToUTF16(""),
+ GURL(kLongUrlContext), message_center::NotifierId(GURL()), *data(), NULL);
+ notification3.set_context_message(base::ASCIIToUTF16(""), true);
+ result = notification_view()->FormatContextMessage(notification3);
+
+ // Different platforms elide at different lengths so we do
+ // some generic checking here.
+ // The url has been elided (it starts with an ellipsis)
+ // The end of the domainsuffix is shown
+ // the url piece is not shown
+ EXPECT_TRUE(base::UTF16ToUTF8(result).find(
+ ".veryveryveyrylong.chromium.org") != std::string::npos);
+ EXPECT_TRUE(base::UTF16ToUTF8(result).find("\xE2\x80\xA6") == 0);
+ EXPECT_TRUE(base::UTF16ToUTF8(result).find("hello") == std::string::npos);
+}
+
} // namespace message_center
« ui/message_center/notification.h ('K') | « ui/message_center/views/notification_view.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698