OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 <string> | 5 #include <string> |
6 | 6 |
7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "chrome/browser/notifications/notification.h" | 10 #include "chrome/browser/notifications/notification.h" |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 | 146 |
147 // TODO(petewil): Improve ctor to pass in an image and type so this test can | 147 // TODO(petewil): Improve ctor to pass in an image and type so this test can |
148 // pass on actual data. | 148 // pass on actual data. |
149 TEST_F(SyncedNotificationTest, GetImageURLTest) { | 149 TEST_F(SyncedNotificationTest, GetImageURLTest) { |
150 GURL found_image_url = notification1_->GetImageUrl(); | 150 GURL found_image_url = notification1_->GetImageUrl(); |
151 GURL expected_image_url = GURL(kImageUrl1); | 151 GURL expected_image_url = GURL(kImageUrl1); |
152 | 152 |
153 EXPECT_EQ(expected_image_url, found_image_url); | 153 EXPECT_EQ(expected_image_url, found_image_url); |
154 } | 154 } |
155 | 155 |
156 // TODO(petewil): test with a multi-line message | |
157 TEST_F(SyncedNotificationTest, GetTextTest) { | 156 TEST_F(SyncedNotificationTest, GetTextTest) { |
158 std::string found_text = notification1_->GetText(); | 157 std::string found_text = notification1_->GetText(); |
159 std::string expected_text(kText1); | 158 std::string expected_text(kText1); |
160 | 159 |
161 EXPECT_EQ(expected_text, found_text); | 160 EXPECT_EQ(expected_text, found_text); |
162 } | 161 } |
163 | 162 |
164 TEST_F(SyncedNotificationTest, GetCreationTimeTest) { | 163 TEST_F(SyncedNotificationTest, GetCreationTimeTest) { |
165 uint64 found_time = notification1_->GetCreationTime(); | 164 uint64 found_time = notification1_->GetCreationTime(); |
166 EXPECT_EQ(kFakeCreationTime, found_time); | 165 EXPECT_EQ(kFakeCreationTime, found_time); |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
250 EXPECT_EQ(notification5->GetReadState(), notification2_->GetReadState()); | 249 EXPECT_EQ(notification5->GetReadState(), notification2_->GetReadState()); |
251 EXPECT_FALSE(notification5->EqualsIgnoringReadState(*notification1_)); | 250 EXPECT_FALSE(notification5->EqualsIgnoringReadState(*notification1_)); |
252 } | 251 } |
253 | 252 |
254 TEST_F(SyncedNotificationTest, ShowTest) { | 253 TEST_F(SyncedNotificationTest, ShowTest) { |
255 | 254 |
256 if (!UseRichNotifications()) | 255 if (!UseRichNotifications()) |
257 return; | 256 return; |
258 | 257 |
259 // Call the method under test using the pre-populated data. | 258 // Call the method under test using the pre-populated data. |
260 notification1_->Show(notification_manager(), NULL, NULL); | 259 notification1_->set_notification_manager(notification_manager()); |
| 260 notification1_->Show(NULL); |
261 | 261 |
262 const Notification notification = notification_manager()->notification(); | 262 const Notification notification = notification_manager()->notification(); |
263 | 263 |
264 // Check the base fields of the notification. | 264 // Check the base fields of the notification. |
265 EXPECT_EQ(message_center::NOTIFICATION_TYPE_IMAGE, notification.type()); | 265 EXPECT_EQ(message_center::NOTIFICATION_TYPE_IMAGE, notification.type()); |
266 EXPECT_EQ(std::string(kTitle1), base::UTF16ToUTF8(notification.title())); | 266 EXPECT_EQ(std::string(kTitle1), base::UTF16ToUTF8(notification.title())); |
267 EXPECT_EQ(std::string(kText1), base::UTF16ToUTF8(notification.message())); | 267 EXPECT_EQ(std::string(kText1), base::UTF16ToUTF8(notification.message())); |
268 EXPECT_EQ(std::string(kExpectedOriginUrl), notification.origin_url().spec()); | 268 EXPECT_EQ(std::string(kExpectedOriginUrl), notification.origin_url().spec()); |
269 EXPECT_EQ(std::string(kKey1), base::UTF16ToUTF8(notification.replace_id())); | 269 EXPECT_EQ(std::string(kKey1), base::UTF16ToUTF8(notification.replace_id())); |
270 | 270 |
271 EXPECT_EQ(kFakeCreationTime, notification.timestamp().ToDoubleT()); | 271 EXPECT_EQ(kFakeCreationTime, notification.timestamp().ToDoubleT()); |
272 EXPECT_EQ(kNotificationPriority, notification.priority()); | 272 EXPECT_EQ(kNotificationPriority, notification.priority()); |
273 } | 273 } |
274 | 274 |
275 TEST_F(SyncedNotificationTest, DismissTest) { | 275 TEST_F(SyncedNotificationTest, DismissTest) { |
276 | 276 |
277 if (!UseRichNotifications()) | 277 if (!UseRichNotifications()) |
278 return; | 278 return; |
279 | 279 |
| 280 notification4_->set_notification_manager(notification_manager()); |
280 // Call the method under test using a dismissed notification. | 281 // Call the method under test using a dismissed notification. |
281 notification4_->Show(notification_manager(), NULL, NULL); | 282 notification4_->Show(NULL); |
282 | 283 |
283 EXPECT_EQ(std::string(kKey1), notification_manager()->dismissed_id()); | 284 EXPECT_EQ(std::string(kKey1), notification_manager()->dismissed_id()); |
284 } | 285 } |
285 | 286 |
286 TEST_F(SyncedNotificationTest, AddBitmapToFetchQueueTest) { | 287 TEST_F(SyncedNotificationTest, CreateBitmapFetcherTest) { |
287 scoped_ptr<SyncedNotification> notification6; | 288 scoped_ptr<SyncedNotification> notification6; |
288 notification6.reset(new SyncedNotification(sync_data1_)); | 289 notification6.reset(new SyncedNotification(sync_data1_)); |
289 | 290 |
290 // Add two bitmaps to the queue. | 291 // Add two bitmaps to the queue. |
291 notification6->AddBitmapToFetchQueue(GURL(kIconUrl1)); | 292 notification6->CreateBitmapFetcher(GURL(kIconUrl1)); |
292 notification6->AddBitmapToFetchQueue(GURL(kIconUrl2)); | 293 notification6->CreateBitmapFetcher(GURL(kIconUrl2)); |
293 | 294 |
294 EXPECT_EQ(GURL(kIconUrl1), notification6->fetchers_[0]->url()); | 295 EXPECT_EQ(GURL(kIconUrl1), notification6->fetchers_[0]->url()); |
295 EXPECT_EQ(GURL(kIconUrl2), notification6->fetchers_[1]->url()); | 296 EXPECT_EQ(GURL(kIconUrl2), notification6->fetchers_[1]->url()); |
296 | 297 |
297 notification6->AddBitmapToFetchQueue(GURL(kIconUrl2)); | 298 notification6->CreateBitmapFetcher(GURL(kIconUrl2)); |
298 } | 299 } |
299 | 300 |
300 TEST_F(SyncedNotificationTest, OnFetchCompleteTest) { | 301 TEST_F(SyncedNotificationTest, OnFetchCompleteTest) { |
301 if (!UseRichNotifications()) | 302 if (!UseRichNotifications()) |
302 return; | 303 return; |
303 | 304 |
304 // Set up the internal state that FetchBitmaps() would have set. | 305 // Set up the internal state that FetchBitmaps() would have set. |
305 notification1_->notification_manager_ = notification_manager(); | 306 notification1_->notification_manager_ = notification_manager(); |
306 | 307 |
307 // Add the bitmaps to the queue for us to match up. | 308 // Add the bitmaps to the queue for us to match up. |
308 notification1_->AddBitmapToFetchQueue(GURL(kIconUrl1)); | 309 notification1_->CreateBitmapFetcher(GURL(kIconUrl1)); |
309 notification1_->AddBitmapToFetchQueue(GURL(kImageUrl1)); | 310 notification1_->CreateBitmapFetcher(GURL(kImageUrl1)); |
310 notification1_->AddBitmapToFetchQueue(GURL(kButtonOneIconUrl)); | 311 notification1_->CreateBitmapFetcher(GURL(kButtonOneIconUrl)); |
311 notification1_->AddBitmapToFetchQueue(GURL(kButtonTwoIconUrl)); | 312 notification1_->CreateBitmapFetcher(GURL(kButtonTwoIconUrl)); |
312 | 313 |
313 // Put some realistic looking bitmap data into the url_fetcher. | 314 // Put some realistic looking bitmap data into the url_fetcher. |
314 SkBitmap bitmap; | 315 SkBitmap bitmap; |
315 | 316 |
316 // Put a real bitmap into "bitmap". 2x2 bitmap of green 32 bit pixels. | 317 // Put a real bitmap into "bitmap". 2x2 bitmap of green 32 bit pixels. |
317 bitmap.setConfig(SkBitmap::kARGB_8888_Config, 2, 2); | 318 bitmap.setConfig(SkBitmap::kARGB_8888_Config, 2, 2); |
318 bitmap.allocPixels(); | 319 bitmap.allocPixels(); |
319 bitmap.eraseColor(SK_ColorGREEN); | 320 bitmap.eraseColor(SK_ColorGREEN); |
320 | 321 |
321 // Allocate the button_bitmaps_ array as the calling function normally would. | 322 // Allocate the button_bitmaps_ array as the calling function normally would. |
(...skipping 20 matching lines...) Expand all Loading... |
342 EXPECT_EQ( | 343 EXPECT_EQ( |
343 std::string(kText1), | 344 std::string(kText1), |
344 base::UTF16ToUTF8(notification_manager()->notification().message())); | 345 base::UTF16ToUTF8(notification_manager()->notification().message())); |
345 | 346 |
346 // TODO(petewil): Check that the bitmap in the notification is what we expect. | 347 // TODO(petewil): Check that the bitmap in the notification is what we expect. |
347 // This fails today, the type info is different. | 348 // This fails today, the type info is different. |
348 // EXPECT_TRUE(gfx::BitmapsAreEqual( | 349 // EXPECT_TRUE(gfx::BitmapsAreEqual( |
349 // image, notification1_->GetAppIconBitmap())); | 350 // image, notification1_->GetAppIconBitmap())); |
350 } | 351 } |
351 | 352 |
352 | 353 // TODO(petewil): Empty bitmap should count as a successful fetch. |
353 TEST_F(SyncedNotificationTest, EmptyBitmapTest) { | 354 TEST_F(SyncedNotificationTest, EmptyBitmapTest) { |
354 if (!UseRichNotifications()) | 355 if (!UseRichNotifications()) |
355 return; | 356 return; |
356 | 357 |
357 // Set up the internal state that FetchBitmaps() would have set. | 358 // Set up the internal state that FetchBitmaps() would have set. |
358 notification1_->notification_manager_ = notification_manager(); | 359 notification1_->notification_manager_ = notification_manager(); |
359 | 360 |
360 // Add the bitmaps to the queue for us to match up. | 361 // Add the bitmaps to the queue for us to match up. |
361 notification1_->AddBitmapToFetchQueue(GURL(kIconUrl1)); | 362 notification1_->CreateBitmapFetcher(GURL(kIconUrl1)); |
362 notification1_->AddBitmapToFetchQueue(GURL(kImageUrl1)); | 363 notification1_->CreateBitmapFetcher(GURL(kImageUrl1)); |
363 notification1_->AddBitmapToFetchQueue(GURL(kButtonOneIconUrl)); | 364 notification1_->CreateBitmapFetcher(GURL(kButtonOneIconUrl)); |
364 notification1_->AddBitmapToFetchQueue(GURL(kButtonTwoIconUrl)); | 365 notification1_->CreateBitmapFetcher(GURL(kButtonTwoIconUrl)); |
365 | 366 |
366 // Put some realistic looking bitmap data into the url_fetcher. | 367 // Put some realistic looking bitmap data into the url_fetcher. |
367 SkBitmap bitmap; | 368 SkBitmap bitmap; |
368 SkBitmap empty_bitmap; | 369 SkBitmap empty_bitmap; |
369 | 370 |
370 // Put a real bitmap into "bitmap". 2x2 bitmap of green 32 bit pixels. | 371 // Put a real bitmap into "bitmap". 2x2 bitmap of green 32 bit pixels. |
371 bitmap.setConfig(SkBitmap::kARGB_8888_Config, 2, 2); | 372 bitmap.setConfig(SkBitmap::kARGB_8888_Config, 2, 2); |
372 bitmap.allocPixels(); | 373 bitmap.allocPixels(); |
373 bitmap.eraseColor(SK_ColorGREEN); | 374 bitmap.eraseColor(SK_ColorGREEN); |
374 | 375 |
(...skipping 17 matching lines...) Expand all Loading... |
392 // Since we check Show() thoroughly in its own test, we only check cursorily. | 393 // Since we check Show() thoroughly in its own test, we only check cursorily. |
393 EXPECT_EQ(message_center::NOTIFICATION_TYPE_IMAGE, | 394 EXPECT_EQ(message_center::NOTIFICATION_TYPE_IMAGE, |
394 notification_manager()->notification().type()); | 395 notification_manager()->notification().type()); |
395 EXPECT_EQ(std::string(kTitle1), | 396 EXPECT_EQ(std::string(kTitle1), |
396 base::UTF16ToUTF8(notification_manager()->notification().title())); | 397 base::UTF16ToUTF8(notification_manager()->notification().title())); |
397 EXPECT_EQ( | 398 EXPECT_EQ( |
398 std::string(kText1), | 399 std::string(kText1), |
399 base::UTF16ToUTF8(notification_manager()->notification().message())); | 400 base::UTF16ToUTF8(notification_manager()->notification().message())); |
400 } | 401 } |
401 | 402 |
| 403 TEST_F(SyncedNotificationTest, ShowIfNewlyEnabledTest) { |
| 404 if (!UseRichNotifications()) |
| 405 return; |
| 406 |
| 407 notification1_->set_notification_manager(notification_manager()); |
| 408 |
| 409 // Call the method using the wrong app id, nothing should get shown. |
| 410 notification1_->ShowAllForAppId(NULL, kAppId2); |
| 411 |
| 412 // Ensure no notification was generated and shown. |
| 413 const Notification notification1 = notification_manager()->notification(); |
| 414 EXPECT_EQ(std::string(), base::UTF16ToUTF8(notification1.replace_id())); |
| 415 |
| 416 // Call the method under test using the pre-populated data. |
| 417 notification1_->ShowAllForAppId(NULL, kAppId1); |
| 418 |
| 419 const Notification notification2 = notification_manager()->notification(); |
| 420 |
| 421 // Check the base fields of the notification. |
| 422 EXPECT_EQ(message_center::NOTIFICATION_TYPE_IMAGE, notification2.type()); |
| 423 EXPECT_EQ(std::string(kTitle1), base::UTF16ToUTF8(notification2.title())); |
| 424 EXPECT_EQ(std::string(kText1), base::UTF16ToUTF8(notification2.message())); |
| 425 EXPECT_EQ(std::string(kExpectedOriginUrl), notification2.origin_url().spec()); |
| 426 EXPECT_EQ(std::string(kKey1), base::UTF16ToUTF8(notification2.replace_id())); |
| 427 |
| 428 EXPECT_EQ(kFakeCreationTime, notification2.timestamp().ToDoubleT()); |
| 429 EXPECT_EQ(kNotificationPriority, notification2.priority()); |
| 430 } |
| 431 |
| 432 TEST_F(SyncedNotificationTest, HideIfNewlyRemovedTest) { |
| 433 if (!UseRichNotifications()) |
| 434 return; |
| 435 |
| 436 // Add the notification to the notification manger, so it exists before we |
| 437 // we remove it. |
| 438 notification1_->set_notification_manager(notification_manager()); |
| 439 notification1_->Show(NULL); |
| 440 const Notification* found1 = notification_manager()->FindById(kKey1); |
| 441 EXPECT_NE(reinterpret_cast<Notification*>(NULL), found1); |
| 442 |
| 443 // Call the method under test using the pre-populated data. |
| 444 notification1_->HideAllForAppId(kAppId1); |
| 445 |
| 446 // Ensure the notification was removed from the notification manager |
| 447 EXPECT_EQ(std::string(kKey1), notification_manager()->dismissed_id()); |
| 448 } |
| 449 |
402 // TODO(petewil): Add a test for a notification being read and or deleted. | 450 // TODO(petewil): Add a test for a notification being read and or deleted. |
403 | 451 |
404 } // namespace notifier | 452 } // namespace notifier |
OLD | NEW |