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

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: Style nit 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
« no previous file with comments | « ui/message_center/views/notification_view.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
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"));
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 kChromeUrl = "chrome://settings";
471 const std::string kUrlContext = "http://chromium.org/hello";
472 const std::string kHostContext = "chromium.org";
473 const std::string kLongUrlContext =
474 "https://"
475 "veryveryveryveryveyryveryveryveryveryveyryveryvery.veryveryveyrylong."
476 "chromium.org/hello";
477
478 Notification notification1(
479 NOTIFICATION_TYPE_BASE_FORMAT, std::string(""), base::UTF8ToUTF16(""),
480 base::UTF8ToUTF16(""), CreateTestImage(80, 80), base::UTF8ToUTF16(""),
481 GURL(), message_center::NotifierId(GURL()), *data(), NULL);
482 notification1.set_context_message(base::ASCIIToUTF16(kRegularContextText));
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 result = notification_view()->FormatContextMessage(notification1);
490 EXPECT_EQ(kVeryLongElidedContextText, base::UTF16ToUTF8(result));
491
492 Notification notification2(
493 NOTIFICATION_TYPE_BASE_FORMAT, std::string(""), base::UTF8ToUTF16(""),
494 base::UTF8ToUTF16(""), CreateTestImage(80, 80), base::UTF8ToUTF16(""),
495 GURL(kUrlContext), message_center::NotifierId(GURL()), *data(), NULL);
496 notification2.set_context_message(base::ASCIIToUTF16(""));
497
498 result = notification_view()->FormatContextMessage(notification2);
499 EXPECT_EQ(kHostContext, base::UTF16ToUTF8(result));
500
501 // Non http url and empty context message should yield an empty context
502 // message.
503 Notification notification3(
504 NOTIFICATION_TYPE_BASE_FORMAT, std::string(""), base::UTF8ToUTF16(""),
505 base::UTF8ToUTF16(""), CreateTestImage(80, 80), base::UTF8ToUTF16(""),
506 GURL(kChromeUrl), message_center::NotifierId(GURL()), *data(), NULL);
507 notification3.set_context_message(base::ASCIIToUTF16(""));
508 result = notification_view()->FormatContextMessage(notification3);
509 EXPECT_TRUE(result.empty());
510
511 // Long http url should be elided
512 Notification notification4(
513 NOTIFICATION_TYPE_BASE_FORMAT, std::string(""), base::UTF8ToUTF16(""),
514 base::UTF8ToUTF16(""), CreateTestImage(80, 80), base::UTF8ToUTF16(""),
515 GURL(kLongUrlContext), message_center::NotifierId(GURL()), *data(), NULL);
516 notification4.set_context_message(base::ASCIIToUTF16(""));
517 result = notification_view()->FormatContextMessage(notification4);
518
519 // Different platforms elide at different lengths so we do
520 // some generic checking here.
521 // The url has been elided (it starts with an ellipsis)
522 // The end of the domainsuffix is shown
523 // the url piece is not shown
524 EXPECT_TRUE(base::UTF16ToUTF8(result).find(
525 ".veryveryveyrylong.chromium.org") != std::string::npos);
526 EXPECT_TRUE(base::UTF16ToUTF8(result).find("\xE2\x80\xA6") == 0);
527 EXPECT_TRUE(base::UTF16ToUTF8(result).find("hello") == std::string::npos);
528 }
529
464 } // namespace message_center 530 } // namespace message_center
OLDNEW
« no previous file with comments | « 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