| 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.badge = 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 NotificationResources* resources = GetResources(0u); |
| 164 ASSERT_EQ(100, GetResources(0u)->notification_icon.width()); | |
| 165 | 166 |
| 166 ASSERT_EQ(2u, GetResources(0u)->action_icons.size()); | 167 ASSERT_FALSE(resources->notification_icon.drawsNothing()); |
| 167 ASSERT_FALSE(GetResources(0u)->action_icons[0].drawsNothing()); | 168 ASSERT_EQ(100, resources->notification_icon.width()); |
| 168 ASSERT_EQ(110, GetResources(0u)->action_icons[0].width()); | 169 |
| 169 ASSERT_FALSE(GetResources(0u)->action_icons[1].drawsNothing()); | 170 ASSERT_FALSE(resources->badge.drawsNothing()); |
| 170 ASSERT_EQ(120, GetResources(0u)->action_icons[1].width()); | 171 ASSERT_EQ(48, resources->badge.width()); |
| 172 |
| 173 ASSERT_EQ(2u, resources->action_icons.size()); |
| 174 ASSERT_FALSE(resources->action_icons[0].drawsNothing()); |
| 175 ASSERT_EQ(110, resources->action_icons[0].width()); |
| 176 ASSERT_FALSE(resources->action_icons[1].drawsNothing()); |
| 177 ASSERT_EQ(120, resources->action_icons[1].width()); |
| 171 } | 178 } |
| 172 | 179 |
| 173 TEST_F(PendingNotificationsTrackerTest, LargeIconsAreScaledDown) { | 180 TEST_F(PendingNotificationsTrackerTest, LargeIconsAreScaledDown) { |
| 174 blink::WebNotificationData notification_data; | 181 blink::WebNotificationData notification_data; |
| 175 notification_data.icon = RegisterMockedURL(kIcon500x500); | 182 notification_data.icon = RegisterMockedURL(kIcon500x500); |
| 183 notification_data.badge = notification_data.icon; |
| 176 notification_data.actions = | 184 notification_data.actions = |
| 177 blink::WebVector<blink::WebNotificationAction>(static_cast<size_t>(1)); | 185 blink::WebVector<blink::WebNotificationAction>(static_cast<size_t>(1)); |
| 178 notification_data.actions[0].icon = notification_data.icon; | 186 notification_data.actions[0].icon = notification_data.icon; |
| 179 | 187 |
| 180 tracker()->FetchResources( | 188 tracker()->FetchResources( |
| 181 notification_data, nullptr /* delegate */, | 189 notification_data, nullptr /* delegate */, |
| 182 base::Bind(&PendingNotificationsTrackerTest::DidFetchResources, | 190 base::Bind(&PendingNotificationsTrackerTest::DidFetchResources, |
| 183 base::Unretained(this), 0 /* index */)); | 191 base::Unretained(this), 0 /* index */)); |
| 184 | 192 |
| 185 ASSERT_EQ(1u, CountPendingNotifications()); | 193 ASSERT_EQ(1u, CountPendingNotifications()); |
| 186 ASSERT_EQ(0u, CountResources()); | 194 ASSERT_EQ(0u, CountResources()); |
| 187 | 195 |
| 188 base::RunLoop().RunUntilIdle(); | 196 base::RunLoop().RunUntilIdle(); |
| 189 UnitTestSupport()->serveAsynchronousMockedRequests(); | 197 UnitTestSupport()->serveAsynchronousMockedRequests(); |
| 190 | 198 |
| 191 ASSERT_EQ(0u, CountPendingNotifications()); | 199 ASSERT_EQ(0u, CountPendingNotifications()); |
| 192 ASSERT_EQ(1u, CountResources()); | 200 ASSERT_EQ(1u, CountResources()); |
| 193 | 201 |
| 194 ASSERT_FALSE(GetResources(0u)->notification_icon.drawsNothing()); | 202 NotificationResources* resources = GetResources(0u); |
| 203 |
| 204 ASSERT_FALSE(resources->notification_icon.drawsNothing()); |
| 195 ASSERT_EQ(kPlatformNotificationMaxIconSizePx, | 205 ASSERT_EQ(kPlatformNotificationMaxIconSizePx, |
| 196 GetResources(0u)->notification_icon.width()); | 206 resources->notification_icon.width()); |
| 197 ASSERT_EQ(kPlatformNotificationMaxIconSizePx, | 207 ASSERT_EQ(kPlatformNotificationMaxIconSizePx, |
| 198 GetResources(0u)->notification_icon.height()); | 208 resources->notification_icon.height()); |
| 199 | 209 |
| 200 ASSERT_EQ(1u, GetResources(0u)->action_icons.size()); | 210 ASSERT_FALSE(resources->badge.drawsNothing()); |
| 201 ASSERT_FALSE(GetResources(0u)->action_icons[0].drawsNothing()); | 211 ASSERT_EQ(kPlatformNotificationMaxBadgeSizePx, resources->badge.width()); |
| 212 ASSERT_EQ(kPlatformNotificationMaxBadgeSizePx, resources->badge.height()); |
| 213 |
| 214 ASSERT_EQ(1u, resources->action_icons.size()); |
| 215 ASSERT_FALSE(resources->action_icons[0].drawsNothing()); |
| 202 ASSERT_EQ(kPlatformNotificationMaxActionIconSizePx, | 216 ASSERT_EQ(kPlatformNotificationMaxActionIconSizePx, |
| 203 GetResources(0u)->action_icons[0].width()); | 217 resources->action_icons[0].width()); |
| 204 ASSERT_EQ(kPlatformNotificationMaxActionIconSizePx, | 218 ASSERT_EQ(kPlatformNotificationMaxActionIconSizePx, |
| 205 GetResources(0u)->action_icons[0].height()); | 219 resources->action_icons[0].height()); |
| 206 } | 220 } |
| 207 | 221 |
| 208 TEST_F(PendingNotificationsTrackerTest, TwoNotifications) { | 222 TEST_F(PendingNotificationsTrackerTest, TwoNotifications) { |
| 209 blink::WebNotificationData notification_data; | 223 blink::WebNotificationData notification_data; |
| 210 notification_data.icon = RegisterMockedURL(kIcon100x100); | 224 notification_data.icon = RegisterMockedURL(kIcon100x100); |
| 211 | 225 |
| 212 blink::WebNotificationData notification_data_2; | 226 blink::WebNotificationData notification_data_2; |
| 213 notification_data_2.icon = RegisterMockedURL(kIcon110x110); | 227 notification_data_2.icon = RegisterMockedURL(kIcon110x110); |
| 214 | 228 |
| 215 tracker()->FetchResources( | 229 tracker()->FetchResources( |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 276 | 290 |
| 277 base::RunLoop().RunUntilIdle(); | 291 base::RunLoop().RunUntilIdle(); |
| 278 tracker()->CancelResourceFetches(&delegate); | 292 tracker()->CancelResourceFetches(&delegate); |
| 279 | 293 |
| 280 ASSERT_EQ(0u, CountPendingNotifications()); | 294 ASSERT_EQ(0u, CountPendingNotifications()); |
| 281 ASSERT_EQ(0u, CountDelegates()); | 295 ASSERT_EQ(0u, CountDelegates()); |
| 282 ASSERT_EQ(0u, CountResources()); | 296 ASSERT_EQ(0u, CountResources()); |
| 283 } | 297 } |
| 284 | 298 |
| 285 } // namespace content | 299 } // namespace content |
| OLD | NEW |