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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/message_center/views/notification_view.h" 5 #include "ui/message_center/views/notification_view.h"
6 6
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 #include "third_party/skia/include/core/SkBitmap.h" 10 #include "third_party/skia/include/core/SkBitmap.h"
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 } 158 }
159 159
160 NotificationViewTest::~NotificationViewTest() { 160 NotificationViewTest::~NotificationViewTest() {
161 } 161 }
162 162
163 void NotificationViewTest::SetUp() { 163 void NotificationViewTest::SetUp() {
164 views::ViewsTestBase::SetUp(); 164 views::ViewsTestBase::SetUp();
165 // Create a dummy notification. 165 // Create a dummy notification.
166 SkBitmap bitmap; 166 SkBitmap bitmap;
167 data_.reset(new RichNotificationData()); 167 data_.reset(new RichNotificationData());
168 notification_.reset( 168 notification_.reset(new Notification(
169 new Notification(NOTIFICATION_TYPE_BASE_FORMAT, 169 NOTIFICATION_TYPE_BASE_FORMAT, std::string("notification id"),
170 std::string("notification id"), 170 base::UTF8ToUTF16("title"), base::UTF8ToUTF16("message"),
171 base::UTF8ToUTF16("title"), 171 CreateTestImage(80, 80), base::UTF8ToUTF16("display source"), GURL(),
172 base::UTF8ToUTF16("message"), 172 NotifierId(NotifierId::APPLICATION, "extension_id"), *data_, NULL));
173 CreateTestImage(80, 80),
174 base::UTF8ToUTF16("display source"),
175 NotifierId(NotifierId::APPLICATION, "extension_id"),
176 *data_,
177 NULL));
178 notification_->set_small_image(CreateTestImage(16, 16)); 173 notification_->set_small_image(CreateTestImage(16, 16));
179 notification_->set_image(CreateTestImage(320, 240)); 174 notification_->set_image(CreateTestImage(320, 240));
180 175
181 // Then create a new NotificationView with that single notification. 176 // Then create a new NotificationView with that single notification.
182 notification_view_.reset( 177 notification_view_.reset(
183 NotificationView::Create(this, *notification_, true)); 178 NotificationView::Create(this, *notification_, true));
184 notification_view_->set_owned_by_client(); 179 notification_view_->set_owned_by_client();
185 180
186 views::Widget::InitParams init_params( 181 views::Widget::InitParams init_params(
187 CreateParams(views::Widget::InitParams::TYPE_POPUP)); 182 CreateParams(views::Widget::InitParams::TYPE_POPUP));
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 notification_view()->CreateOrUpdateViews(*notification()); 241 notification_view()->CreateOrUpdateViews(*notification());
247 EXPECT_TRUE(NULL == notification_view()->title_view_); 242 EXPECT_TRUE(NULL == notification_view()->title_view_);
248 EXPECT_TRUE(NULL == notification_view()->message_view_); 243 EXPECT_TRUE(NULL == notification_view()->message_view_);
249 EXPECT_TRUE(NULL == notification_view()->image_view_); 244 EXPECT_TRUE(NULL == notification_view()->image_view_);
250 // We still expect an icon view for all layouts. 245 // We still expect an icon view for all layouts.
251 EXPECT_TRUE(NULL != notification_view()->icon_view_); 246 EXPECT_TRUE(NULL != notification_view()->icon_view_);
252 } 247 }
253 248
254 TEST_F(NotificationViewTest, TestLineLimits) { 249 TEST_F(NotificationViewTest, TestLineLimits) {
255 notification()->set_image(CreateTestImage(0, 0)); 250 notification()->set_image(CreateTestImage(0, 0));
256 notification()->set_context_message(base::ASCIIToUTF16("")); 251 notification()->set_context_message(base::ASCIIToUTF16(""), false);
257 notification_view()->CreateOrUpdateViews(*notification()); 252 notification_view()->CreateOrUpdateViews(*notification());
258 253
259 EXPECT_EQ(5, notification_view()->GetMessageLineLimit(0, 360)); 254 EXPECT_EQ(5, notification_view()->GetMessageLineLimit(0, 360));
260 EXPECT_EQ(5, notification_view()->GetMessageLineLimit(1, 360)); 255 EXPECT_EQ(5, notification_view()->GetMessageLineLimit(1, 360));
261 EXPECT_EQ(3, notification_view()->GetMessageLineLimit(2, 360)); 256 EXPECT_EQ(3, notification_view()->GetMessageLineLimit(2, 360));
262 257
263 notification()->set_image(CreateTestImage(2, 2)); 258 notification()->set_image(CreateTestImage(2, 2));
264 notification_view()->CreateOrUpdateViews(*notification()); 259 notification_view()->CreateOrUpdateViews(*notification());
265 260
266 EXPECT_EQ(2, notification_view()->GetMessageLineLimit(0, 360)); 261 EXPECT_EQ(2, notification_view()->GetMessageLineLimit(0, 360));
267 EXPECT_EQ(2, notification_view()->GetMessageLineLimit(1, 360)); 262 EXPECT_EQ(2, notification_view()->GetMessageLineLimit(1, 360));
268 EXPECT_EQ(1, notification_view()->GetMessageLineLimit(2, 360)); 263 EXPECT_EQ(1, notification_view()->GetMessageLineLimit(2, 360));
269 264
270 notification()->set_context_message(base::UTF8ToUTF16("foo")); 265 notification()->set_context_message(base::ASCIIToUTF16("foo"), false);
271 notification_view()->CreateOrUpdateViews(*notification()); 266 notification_view()->CreateOrUpdateViews(*notification());
272 267
273 EXPECT_TRUE(notification_view()->context_message_view_ != NULL); 268 EXPECT_TRUE(notification_view()->context_message_view_ != NULL);
274 269
275 EXPECT_EQ(1, notification_view()->GetMessageLineLimit(0, 360)); 270 EXPECT_EQ(1, notification_view()->GetMessageLineLimit(0, 360));
276 EXPECT_EQ(1, notification_view()->GetMessageLineLimit(1, 360)); 271 EXPECT_EQ(1, notification_view()->GetMessageLineLimit(1, 360));
277 EXPECT_EQ(0, notification_view()->GetMessageLineLimit(2, 360)); 272 EXPECT_EQ(0, notification_view()->GetMessageLineLimit(2, 360));
278 } 273 }
279 274
280 TEST_F(NotificationViewTest, TestIconSizing) { 275 TEST_F(NotificationViewTest, TestIconSizing) {
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
454 UpdateNotificationViews(); 449 UpdateNotificationViews();
455 450
456 // Double-check that vertical order is correct. 451 // Double-check that vertical order is correct.
457 CheckVerticalOrderInNotification(); 452 CheckVerticalOrderInNotification();
458 453
459 // Tests that views remain in that order even after an update. 454 // Tests that views remain in that order even after an update.
460 UpdateNotificationViews(); 455 UpdateNotificationViews();
461 CheckVerticalOrderInNotification(); 456 CheckVerticalOrderInNotification();
462 } 457 }
463 458
459 TEST_F(NotificationViewTest, FormatContextMessageTest) {
460 const std::string kRegularContextText = "Context Text";
461 const std::string kVeryLongContextText =
462 "VERY VERY VERY VERY VERY VERY VERY VERY VERY VERY VERY VERY"
463 "VERY VERY VERY VERY VERY VERY VERY VERY VERY VERY VERY VERY"
464 "VERY VERY VERY VERY Long Long Long Long Long Long Long Long context";
465
466 const std::string kVeryLongElidedContextText =
467 "VERY VERY VERY VERY VERY VERY VERY VERY VERY VERY VERY VERYVERY VERY "
468 "VERY VERY VERY VERY VERY VERY VERY VERY VERY\xE2\x80\xA6";
469
470 const std::string kUrlContext = "http://chromium.org/hello";
471 const std::string kHostContext = "chromium.org";
472 const std::string kLongUrlContext =
473 "https://"
474 "veryveryveryveryveyryveryveryveryveryveyryveryvery.veryveryveyrylong."
475 "chromium.org/hello";
476
477 Notification notification1(
478 NOTIFICATION_TYPE_BASE_FORMAT, std::string(""), base::UTF8ToUTF16(""),
479 base::UTF8ToUTF16(""), CreateTestImage(80, 80), base::UTF8ToUTF16(""),
480 GURL(), message_center::NotifierId(GURL()), *data(), NULL);
481 notification1.set_context_message(base::ASCIIToUTF16(kRegularContextText),
482 false);
483
484 base::string16 result =
485 notification_view()->FormatContextMessage(notification1);
486 EXPECT_EQ(kRegularContextText, base::UTF16ToUTF8(result));
487
488 notification1.set_context_message(base::ASCIIToUTF16(kVeryLongContextText),
489 false);
490 result = notification_view()->FormatContextMessage(notification1);
491 EXPECT_EQ(kVeryLongElidedContextText, base::UTF16ToUTF8(result));
492
493 Notification notification2(
494 NOTIFICATION_TYPE_BASE_FORMAT, std::string(""), base::UTF8ToUTF16(""),
495 base::UTF8ToUTF16(""), CreateTestImage(80, 80), base::UTF8ToUTF16(""),
496 GURL(kUrlContext), message_center::NotifierId(GURL()), *data(), NULL);
497 notification2.set_context_message(base::ASCIIToUTF16(""), true);
498
499 result = notification_view()->FormatContextMessage(notification2);
500 EXPECT_EQ(kHostContext, base::UTF16ToUTF8(result));
501
502 Notification notification3(
503 NOTIFICATION_TYPE_BASE_FORMAT, std::string(""), base::UTF8ToUTF16(""),
504 base::UTF8ToUTF16(""), CreateTestImage(80, 80), base::UTF8ToUTF16(""),
505 GURL(kLongUrlContext), message_center::NotifierId(GURL()), *data(), NULL);
506 notification3.set_context_message(base::ASCIIToUTF16(""), true);
507 result = notification_view()->FormatContextMessage(notification3);
508
509 // Different platforms elide at different lengths so we do
510 // some generic checking here.
511 // The url has been elided (it starts with an ellipsis)
512 // The end of the domainsuffix is shown
513 // the url piece is not shown
514 EXPECT_TRUE(base::UTF16ToUTF8(result).find(
515 ".veryveryveyrylong.chromium.org") != std::string::npos);
516 EXPECT_TRUE(base::UTF16ToUTF8(result).find("\xE2\x80\xA6") == 0);
517 EXPECT_TRUE(base::UTF16ToUTF8(result).find("hello") == std::string::npos);
518 }
519
464 } // namespace message_center 520 } // namespace message_center
OLDNEW
« 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