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

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: 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 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 notification_view()->CreateOrUpdateViews(*notification()); 246 notification_view()->CreateOrUpdateViews(*notification());
247 EXPECT_TRUE(NULL == notification_view()->title_view_); 247 EXPECT_TRUE(NULL == notification_view()->title_view_);
248 EXPECT_TRUE(NULL == notification_view()->message_view_); 248 EXPECT_TRUE(NULL == notification_view()->message_view_);
249 EXPECT_TRUE(NULL == notification_view()->image_view_); 249 EXPECT_TRUE(NULL == notification_view()->image_view_);
250 // We still expect an icon view for all layouts. 250 // We still expect an icon view for all layouts.
251 EXPECT_TRUE(NULL != notification_view()->icon_view_); 251 EXPECT_TRUE(NULL != notification_view()->icon_view_);
252 } 252 }
253 253
254 TEST_F(NotificationViewTest, TestLineLimits) { 254 TEST_F(NotificationViewTest, TestLineLimits) {
255 notification()->set_image(CreateTestImage(0, 0)); 255 notification()->set_image(CreateTestImage(0, 0));
256 notification()->set_context_message(base::ASCIIToUTF16("")); 256 notification()->set_context_message("", false);
257 notification_view()->CreateOrUpdateViews(*notification()); 257 notification_view()->CreateOrUpdateViews(*notification());
258 258
259 EXPECT_EQ(5, notification_view()->GetMessageLineLimit(0, 360)); 259 EXPECT_EQ(5, notification_view()->GetMessageLineLimit(0, 360));
260 EXPECT_EQ(5, notification_view()->GetMessageLineLimit(1, 360)); 260 EXPECT_EQ(5, notification_view()->GetMessageLineLimit(1, 360));
261 EXPECT_EQ(3, notification_view()->GetMessageLineLimit(2, 360)); 261 EXPECT_EQ(3, notification_view()->GetMessageLineLimit(2, 360));
262 262
263 notification()->set_image(CreateTestImage(2, 2)); 263 notification()->set_image(CreateTestImage(2, 2));
264 notification_view()->CreateOrUpdateViews(*notification()); 264 notification_view()->CreateOrUpdateViews(*notification());
265 265
266 EXPECT_EQ(2, notification_view()->GetMessageLineLimit(0, 360)); 266 EXPECT_EQ(2, notification_view()->GetMessageLineLimit(0, 360));
267 EXPECT_EQ(2, notification_view()->GetMessageLineLimit(1, 360)); 267 EXPECT_EQ(2, notification_view()->GetMessageLineLimit(1, 360));
268 EXPECT_EQ(1, notification_view()->GetMessageLineLimit(2, 360)); 268 EXPECT_EQ(1, notification_view()->GetMessageLineLimit(2, 360));
269 269
270 notification()->set_context_message(base::UTF8ToUTF16("foo")); 270 notification()->set_context_message("foo", false);
271 notification_view()->CreateOrUpdateViews(*notification()); 271 notification_view()->CreateOrUpdateViews(*notification());
272 272
273 EXPECT_TRUE(notification_view()->context_message_view_ != NULL); 273 EXPECT_TRUE(notification_view()->context_message_view_ != NULL);
274 274
275 EXPECT_EQ(1, notification_view()->GetMessageLineLimit(0, 360)); 275 EXPECT_EQ(1, notification_view()->GetMessageLineLimit(0, 360));
276 EXPECT_EQ(1, notification_view()->GetMessageLineLimit(1, 360)); 276 EXPECT_EQ(1, notification_view()->GetMessageLineLimit(1, 360));
277 EXPECT_EQ(0, notification_view()->GetMessageLineLimit(2, 360)); 277 EXPECT_EQ(0, notification_view()->GetMessageLineLimit(2, 360));
278 } 278 }
279 279
280 TEST_F(NotificationViewTest, TestIconSizing) { 280 TEST_F(NotificationViewTest, TestIconSizing) {
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
454 UpdateNotificationViews(); 454 UpdateNotificationViews();
455 455
456 // Double-check that vertical order is correct. 456 // Double-check that vertical order is correct.
457 CheckVerticalOrderInNotification(); 457 CheckVerticalOrderInNotification();
458 458
459 // Tests that views remain in that order even after an update. 459 // Tests that views remain in that order even after an update.
460 UpdateNotificationViews(); 460 UpdateNotificationViews();
461 CheckVerticalOrderInNotification(); 461 CheckVerticalOrderInNotification();
462 } 462 }
463 463
464 TEST_F(NotificationViewTest, FormatContextMessageTest) {
465 const std::string kRegularContextText = "Context Text";
466 const std::string kVeryLongContextText =
467 "VERY VERY VERY VERY VERY VERY VERY VERY VERY VERY VERY VERY"
468 "VERY VERY VERY VERY VERY VERY VERY VERY VERY VERY VERY VERY"
469 "VERY VERY VERY VERY Long Long Long Long Long Long Long Long context";
470
471 const std::string kVeryLongElidedContextText =
472 "VERY VERY VERY VERY VERY VERY VERY VERY VERY VERY VERY VERYVERY VERY "
473 "VERY VERY VERY VERY VERY VERY VERY VERY VERY\xE2\x80\xA6";
474
475 const std::string kUrlContext = "http://chromium.org/hello";
476 const std::string kHostContext = "chromium.org";
477 const std::string kLongUrlContext =
478 "https://veryveryveryveryveyrylong.chromium.org";
479 const std::string kLongElidedHostContext =
480 "\xE2\x80\xA6veryveryveryveyrylong.chromium.org";
481
482 ContextMessage text_context(kRegularContextText, false);
483 base::string16 result =
484 notification_view()->FormatContextMessage(text_context);
485 EXPECT_EQ(kRegularContextText, base::UTF16ToUTF8(result));
486
487 ContextMessage long_text_context(kVeryLongContextText, false);
488 result = notification_view()->FormatContextMessage(long_text_context);
489 EXPECT_EQ(kVeryLongElidedContextText, base::UTF16ToUTF8(result));
490
491 ContextMessage url_context(kUrlContext, true);
492 result = notification_view()->FormatContextMessage(url_context);
493 EXPECT_EQ(kHostContext, base::UTF16ToUTF8(result));
494
495 ContextMessage long_url_context(kLongUrlContext, true);
496 result = notification_view()->FormatContextMessage(long_url_context);
497 EXPECT_EQ(kLongElidedHostContext, base::UTF16ToUTF8(result));
498
499 ContextMessage invalid_url_context("notreallyaurl", true);
500 result = notification_view()->FormatContextMessage(invalid_url_context);
501 EXPECT_EQ("", base::UTF16ToUTF8(result));
502 }
503
464 } // namespace message_center 504 } // namespace message_center
OLDNEW
« ui/message_center/views/constants.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