OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "content/child/notifications/pending_notifications_tracker.h" | 5 #include "content/child/notifications/pending_notifications_tracker.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/base_paths.h" | 9 #include "base/base_paths.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 19 matching lines...) Expand all Loading... | |
30 #include "third_party/WebKit/public/platform/modules/notifications/WebNotificati onData.h" | 30 #include "third_party/WebKit/public/platform/modules/notifications/WebNotificati onData.h" |
31 #include "third_party/WebKit/public/platform/modules/notifications/WebNotificati onDelegate.h" | 31 #include "third_party/WebKit/public/platform/modules/notifications/WebNotificati onDelegate.h" |
32 #include "third_party/skia/include/core/SkBitmap.h" | 32 #include "third_party/skia/include/core/SkBitmap.h" |
33 #include "url/gurl.h" | 33 #include "url/gurl.h" |
34 | 34 |
35 namespace content { | 35 namespace content { |
36 | 36 |
37 namespace { | 37 namespace { |
38 | 38 |
39 const char kBaseUrl[] = "http://test.com/"; | 39 const char kBaseUrl[] = "http://test.com/"; |
40 const char kIcon48x48[] = "48x48.png"; | |
40 const char kIcon100x100[] = "100x100.png"; | 41 const char kIcon100x100[] = "100x100.png"; |
41 const char kIcon110x110[] = "110x110.png"; | 42 const char kIcon110x110[] = "110x110.png"; |
42 const char kIcon120x120[] = "120x120.png"; | 43 const char kIcon120x120[] = "120x120.png"; |
43 const char kIcon500x500[] = "500x500.png"; | 44 const char kIcon500x500[] = "500x500.png"; |
44 | 45 |
45 class FakeNotificationDelegate : public blink::WebNotificationDelegate { | 46 class FakeNotificationDelegate : public blink::WebNotificationDelegate { |
46 public: | 47 public: |
47 void dispatchClickEvent() override {} | 48 void dispatchClickEvent() override {} |
48 void dispatchShowEvent() override {} | 49 void dispatchShowEvent() override {} |
49 void dispatchErrorEvent() override {} | 50 void dispatchErrorEvent() override {} |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
134 base::MessageLoop message_loop_; | 135 base::MessageLoop message_loop_; |
135 scoped_ptr<PendingNotificationsTracker> tracker_; | 136 scoped_ptr<PendingNotificationsTracker> tracker_; |
136 std::vector<NotificationResources> resources_; | 137 std::vector<NotificationResources> resources_; |
137 | 138 |
138 DISALLOW_COPY_AND_ASSIGN(PendingNotificationsTrackerTest); | 139 DISALLOW_COPY_AND_ASSIGN(PendingNotificationsTrackerTest); |
139 }; | 140 }; |
140 | 141 |
141 TEST_F(PendingNotificationsTrackerTest, OneNotificationMultipleResources) { | 142 TEST_F(PendingNotificationsTrackerTest, OneNotificationMultipleResources) { |
142 blink::WebNotificationData notification_data; | 143 blink::WebNotificationData notification_data; |
143 notification_data.icon = RegisterMockedURL(kIcon100x100); | 144 notification_data.icon = RegisterMockedURL(kIcon100x100); |
145 notification_data.smallIcon = RegisterMockedURL(kIcon48x48); | |
144 notification_data.actions = | 146 notification_data.actions = |
145 blink::WebVector<blink::WebNotificationAction>(static_cast<size_t>(2)); | 147 blink::WebVector<blink::WebNotificationAction>(static_cast<size_t>(2)); |
146 notification_data.actions[0].icon = RegisterMockedURL(kIcon110x110); | 148 notification_data.actions[0].icon = RegisterMockedURL(kIcon110x110); |
147 notification_data.actions[1].icon = RegisterMockedURL(kIcon120x120); | 149 notification_data.actions[1].icon = RegisterMockedURL(kIcon120x120); |
148 | 150 |
149 tracker()->FetchResources( | 151 tracker()->FetchResources( |
150 notification_data, nullptr /* delegate */, | 152 notification_data, nullptr /* delegate */, |
151 base::Bind(&PendingNotificationsTrackerTest::DidFetchResources, | 153 base::Bind(&PendingNotificationsTrackerTest::DidFetchResources, |
152 base::Unretained(this), 0 /* index */)); | 154 base::Unretained(this), 0 /* index */)); |
153 | 155 |
154 ASSERT_EQ(1u, CountPendingNotifications()); | 156 ASSERT_EQ(1u, CountPendingNotifications()); |
155 ASSERT_EQ(0u, CountResources()); | 157 ASSERT_EQ(0u, CountResources()); |
156 | 158 |
157 base::RunLoop().RunUntilIdle(); | 159 base::RunLoop().RunUntilIdle(); |
158 UnitTestSupport()->serveAsynchronousMockedRequests(); | 160 UnitTestSupport()->serveAsynchronousMockedRequests(); |
159 | 161 |
160 ASSERT_EQ(0u, CountPendingNotifications()); | 162 ASSERT_EQ(0u, CountPendingNotifications()); |
161 ASSERT_EQ(1u, CountResources()); | 163 ASSERT_EQ(1u, CountResources()); |
162 | 164 |
163 ASSERT_FALSE(GetResources(0u)->notification_icon.drawsNothing()); | 165 ASSERT_FALSE(GetResources(0u)->notification_icon.drawsNothing()); |
164 ASSERT_EQ(100, GetResources(0u)->notification_icon.width()); | 166 ASSERT_EQ(100, GetResources(0u)->notification_icon.width()); |
165 | 167 |
168 ASSERT_FALSE(GetResources(0u)->small_icon.drawsNothing()); | |
Peter Beverloo
2016/03/03 17:55:39
nit: would it make sense to have the following in
Michael van Ouwerkerk
2016/03/09 18:28:25
Done.
| |
169 ASSERT_EQ(48, GetResources(0u)->small_icon.width()); | |
170 | |
166 ASSERT_EQ(2u, GetResources(0u)->action_icons.size()); | 171 ASSERT_EQ(2u, GetResources(0u)->action_icons.size()); |
167 ASSERT_FALSE(GetResources(0u)->action_icons[0].drawsNothing()); | 172 ASSERT_FALSE(GetResources(0u)->action_icons[0].drawsNothing()); |
168 ASSERT_EQ(110, GetResources(0u)->action_icons[0].width()); | 173 ASSERT_EQ(110, GetResources(0u)->action_icons[0].width()); |
169 ASSERT_FALSE(GetResources(0u)->action_icons[1].drawsNothing()); | 174 ASSERT_FALSE(GetResources(0u)->action_icons[1].drawsNothing()); |
170 ASSERT_EQ(120, GetResources(0u)->action_icons[1].width()); | 175 ASSERT_EQ(120, GetResources(0u)->action_icons[1].width()); |
171 } | 176 } |
172 | 177 |
173 TEST_F(PendingNotificationsTrackerTest, LargeIconsAreScaledDown) { | 178 TEST_F(PendingNotificationsTrackerTest, LargeIconsAreScaledDown) { |
174 blink::WebNotificationData notification_data; | 179 blink::WebNotificationData notification_data; |
175 notification_data.icon = RegisterMockedURL(kIcon500x500); | 180 notification_data.icon = RegisterMockedURL(kIcon500x500); |
181 notification_data.smallIcon = notification_data.icon; | |
176 notification_data.actions = | 182 notification_data.actions = |
177 blink::WebVector<blink::WebNotificationAction>(static_cast<size_t>(1)); | 183 blink::WebVector<blink::WebNotificationAction>(static_cast<size_t>(1)); |
178 notification_data.actions[0].icon = notification_data.icon; | 184 notification_data.actions[0].icon = notification_data.icon; |
179 | 185 |
180 tracker()->FetchResources( | 186 tracker()->FetchResources( |
181 notification_data, nullptr /* delegate */, | 187 notification_data, nullptr /* delegate */, |
182 base::Bind(&PendingNotificationsTrackerTest::DidFetchResources, | 188 base::Bind(&PendingNotificationsTrackerTest::DidFetchResources, |
183 base::Unretained(this), 0 /* index */)); | 189 base::Unretained(this), 0 /* index */)); |
184 | 190 |
185 ASSERT_EQ(1u, CountPendingNotifications()); | 191 ASSERT_EQ(1u, CountPendingNotifications()); |
186 ASSERT_EQ(0u, CountResources()); | 192 ASSERT_EQ(0u, CountResources()); |
187 | 193 |
188 base::RunLoop().RunUntilIdle(); | 194 base::RunLoop().RunUntilIdle(); |
189 UnitTestSupport()->serveAsynchronousMockedRequests(); | 195 UnitTestSupport()->serveAsynchronousMockedRequests(); |
190 | 196 |
191 ASSERT_EQ(0u, CountPendingNotifications()); | 197 ASSERT_EQ(0u, CountPendingNotifications()); |
192 ASSERT_EQ(1u, CountResources()); | 198 ASSERT_EQ(1u, CountResources()); |
193 | 199 |
194 ASSERT_FALSE(GetResources(0u)->notification_icon.drawsNothing()); | 200 ASSERT_FALSE(GetResources(0u)->notification_icon.drawsNothing()); |
195 ASSERT_EQ(kPlatformNotificationMaxIconSizePx, | 201 ASSERT_EQ(kPlatformNotificationMaxIconSizePx, |
196 GetResources(0u)->notification_icon.width()); | 202 GetResources(0u)->notification_icon.width()); |
197 ASSERT_EQ(kPlatformNotificationMaxIconSizePx, | 203 ASSERT_EQ(kPlatformNotificationMaxIconSizePx, |
198 GetResources(0u)->notification_icon.height()); | 204 GetResources(0u)->notification_icon.height()); |
199 | 205 |
206 ASSERT_FALSE(GetResources(0u)->small_icon.drawsNothing()); | |
207 ASSERT_EQ(kPlatformNotificationMaxSmallIconSizePx, | |
208 GetResources(0u)->small_icon.width()); | |
209 ASSERT_EQ(kPlatformNotificationMaxSmallIconSizePx, | |
210 GetResources(0u)->small_icon.height()); | |
211 | |
200 ASSERT_EQ(1u, GetResources(0u)->action_icons.size()); | 212 ASSERT_EQ(1u, GetResources(0u)->action_icons.size()); |
201 ASSERT_FALSE(GetResources(0u)->action_icons[0].drawsNothing()); | 213 ASSERT_FALSE(GetResources(0u)->action_icons[0].drawsNothing()); |
202 ASSERT_EQ(kPlatformNotificationMaxActionIconSizePx, | 214 ASSERT_EQ(kPlatformNotificationMaxActionIconSizePx, |
203 GetResources(0u)->action_icons[0].width()); | 215 GetResources(0u)->action_icons[0].width()); |
204 ASSERT_EQ(kPlatformNotificationMaxActionIconSizePx, | 216 ASSERT_EQ(kPlatformNotificationMaxActionIconSizePx, |
205 GetResources(0u)->action_icons[0].height()); | 217 GetResources(0u)->action_icons[0].height()); |
206 } | 218 } |
207 | 219 |
208 TEST_F(PendingNotificationsTrackerTest, TwoNotifications) { | 220 TEST_F(PendingNotificationsTrackerTest, TwoNotifications) { |
209 blink::WebNotificationData notification_data; | 221 blink::WebNotificationData notification_data; |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
276 | 288 |
277 base::RunLoop().RunUntilIdle(); | 289 base::RunLoop().RunUntilIdle(); |
278 tracker()->CancelResourceFetches(&delegate); | 290 tracker()->CancelResourceFetches(&delegate); |
279 | 291 |
280 ASSERT_EQ(0u, CountPendingNotifications()); | 292 ASSERT_EQ(0u, CountPendingNotifications()); |
281 ASSERT_EQ(0u, CountDelegates()); | 293 ASSERT_EQ(0u, CountDelegates()); |
282 ASSERT_EQ(0u, CountResources()); | 294 ASSERT_EQ(0u, CountResources()); |
283 } | 295 } |
284 | 296 |
285 } // namespace content | 297 } // namespace content |
OLD | NEW |