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

Side by Side Diff: chrome/browser/notifications/notification_conversion_helper_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 "chrome/browser/notifications/notification_conversion_helper.h" 5 #include "chrome/browser/notifications/notification_conversion_helper.h"
6 6
7 #include "base/strings/utf_string_conversions.h" 7 #include "base/strings/utf_string_conversions.h"
8 #include "chrome/browser/notifications/notification.h" 8 #include "chrome/browser/notifications/notification.h"
9 #include "chrome/browser/notifications/notification_test_util.h" 9 #include "chrome/browser/notifications/notification_test_util.h"
10 #include "chrome/common/extensions/api/notifications.h" 10 #include "chrome/common/extensions/api/notifications.h"
11 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
12 #include "third_party/skia/include/core/SkBitmap.h" 12 #include "third_party/skia/include/core/SkBitmap.h"
13 #include "ui/message_center/notification.h" 13 #include "ui/message_center/notification.h"
14 #include "ui/message_center/notification_types.h" 14 #include "ui/message_center/notification_types.h"
15 #include "url/gurl.h" 15 #include "url/gurl.h"
16 16
17 class NotificationConversionHelperTest : public testing::Test { 17 class NotificationConversionHelperTest : public testing::Test {
18 public: 18 public:
19 NotificationConversionHelperTest() {} 19 NotificationConversionHelperTest() {}
20 20
21 void SetUp() override {} 21 void SetUp() override {}
22 22
23 void TearDown() override {} 23 void TearDown() override {}
24 24
25 protected: 25 protected:
26 scoped_ptr<Notification> CreateNotification( 26 scoped_ptr<Notification> CreateNotification(
27 message_center::NotificationType type) { 27 message_center::NotificationType type) {
28 message_center::RichNotificationData optional_fields; 28 message_center::RichNotificationData optional_fields;
29 optional_fields.priority = 1; 29 optional_fields.priority = 1;
30 optional_fields.context_message = 30 optional_fields.context_message.message =
31 base::UTF8ToUTF16("I am a context message."); 31 base::UTF8ToUTF16("I am a context message.");
32 optional_fields.context_message.use_origin_as_context = false;
32 optional_fields.timestamp = base::Time::FromDoubleT(12345678.9); 33 optional_fields.timestamp = base::Time::FromDoubleT(12345678.9);
33 optional_fields.buttons.push_back( 34 optional_fields.buttons.push_back(
34 message_center::ButtonInfo(base::UTF8ToUTF16("Button 1"))); 35 message_center::ButtonInfo(base::UTF8ToUTF16("Button 1")));
35 optional_fields.buttons.push_back( 36 optional_fields.buttons.push_back(
36 message_center::ButtonInfo(base::UTF8ToUTF16("Button 2"))); 37 message_center::ButtonInfo(base::UTF8ToUTF16("Button 2")));
37 optional_fields.clickable = false; 38 optional_fields.clickable = false;
38 39
39 if (type == message_center::NOTIFICATION_TYPE_IMAGE) 40 if (type == message_center::NOTIFICATION_TYPE_IMAGE)
40 optional_fields.image = gfx::Image(); 41 optional_fields.image = gfx::Image();
41 if (type == message_center::NOTIFICATION_TYPE_MULTIPLE) { 42 if (type == message_center::NOTIFICATION_TYPE_MULTIPLE) {
42 optional_fields.items.push_back(message_center::NotificationItem( 43 optional_fields.items.push_back(message_center::NotificationItem(
43 base::UTF8ToUTF16("Item 1 Title"), 44 base::UTF8ToUTF16("Item 1 Title"),
44 base::UTF8ToUTF16("Item 1 Message"))); 45 base::UTF8ToUTF16("Item 1 Message")));
45 optional_fields.items.push_back(message_center::NotificationItem( 46 optional_fields.items.push_back(message_center::NotificationItem(
46 base::UTF8ToUTF16("Item 2 Title"), 47 base::UTF8ToUTF16("Item 2 Title"),
47 base::UTF8ToUTF16("Item 2 Message"))); 48 base::UTF8ToUTF16("Item 2 Message")));
48 } 49 }
49 if (type == message_center::NOTIFICATION_TYPE_PROGRESS) 50 if (type == message_center::NOTIFICATION_TYPE_PROGRESS)
50 optional_fields.progress = 50; 51 optional_fields.progress = 50;
51 52
52 NotificationDelegate* delegate(new MockNotificationDelegate("id1")); 53 NotificationDelegate* delegate(new MockNotificationDelegate("id1"));
53 54
54 SkBitmap bitmap; 55 SkBitmap bitmap;
55 bitmap.allocN32Pixels(1, 1); 56 bitmap.allocN32Pixels(1, 1);
56 bitmap.eraseColor(SkColorSetRGB(1, 2, 3)); 57 bitmap.eraseColor(SkColorSetRGB(1, 2, 3));
57 gfx::Image icon = gfx::Image::CreateFrom1xBitmap(bitmap); 58 gfx::Image icon = gfx::Image::CreateFrom1xBitmap(bitmap);
58 59
59 scoped_ptr<Notification> notification(new Notification( 60 scoped_ptr<Notification> notification(new Notification(
60 type, 61 type, base::UTF8ToUTF16("Title"),
61 GURL(), 62 base::UTF8ToUTF16("This is a message."), icon,
62 base::UTF8ToUTF16("Title"),
63 base::UTF8ToUTF16("This is a message."),
64 icon,
65 message_center::NotifierId(message_center::NotifierId::APPLICATION, 63 message_center::NotifierId(message_center::NotifierId::APPLICATION,
66 "Notifier 1"), 64 "Notifier 1"),
67 base::UTF8ToUTF16("Notifier's Name"), 65 base::UTF8ToUTF16("Notifier's Name"), GURL(), "id1", optional_fields,
68 "id1",
69 optional_fields,
70 delegate)); 66 delegate));
71 67
72 return notification.Pass(); 68 return notification.Pass();
73 } 69 }
74 70
75 private: 71 private:
76 DISALLOW_COPY_AND_ASSIGN(NotificationConversionHelperTest); 72 DISALLOW_COPY_AND_ASSIGN(NotificationConversionHelperTest);
77 }; 73 };
78 74
79 TEST_F(NotificationConversionHelperTest, NotificationToNotificationOptions) { 75 TEST_F(NotificationConversionHelperTest, NotificationToNotificationOptions) {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 scoped_ptr<extensions::api::notifications::NotificationOptions> options3( 112 scoped_ptr<extensions::api::notifications::NotificationOptions> options3(
117 new extensions::api::notifications::NotificationOptions()); 113 new extensions::api::notifications::NotificationOptions());
118 NotificationConversionHelper::NotificationToNotificationOptions( 114 NotificationConversionHelper::NotificationToNotificationOptions(
119 *(notification3), options3.get()); 115 *(notification3), options3.get());
120 EXPECT_EQ(options3->type, extensions::api::notifications::TEMPLATE_TYPE_LIST); 116 EXPECT_EQ(options3->type, extensions::api::notifications::TEMPLATE_TYPE_LIST);
121 EXPECT_EQ(options3->items->at(0)->title, "Item 1 Title"); 117 EXPECT_EQ(options3->items->at(0)->title, "Item 1 Title");
122 EXPECT_EQ(options3->items->at(0)->message, "Item 1 Message"); 118 EXPECT_EQ(options3->items->at(0)->message, "Item 1 Message");
123 EXPECT_EQ(options3->items->at(1)->title, "Item 2 Title"); 119 EXPECT_EQ(options3->items->at(1)->title, "Item 2 Title");
124 EXPECT_EQ(options3->items->at(1)->message, "Item 2 Message"); 120 EXPECT_EQ(options3->items->at(1)->message, "Item 2 Message");
125 } 121 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698