OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "base/command_line.h" | 5 #include "base/command_line.h" |
6 #include "base/message_loop/message_loop.h" | 6 #include "base/message_loop/message_loop.h" |
7 #include "base/run_loop.h" | 7 #include "base/run_loop.h" |
8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
9 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 9 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
10 #include "chrome/browser/download/chrome_download_manager_delegate.h" | 10 #include "chrome/browser/download/chrome_download_manager_delegate.h" |
11 #include "chrome/browser/download/download_service.h" | 11 #include "chrome/browser/download/download_service.h" |
12 #include "chrome/browser/download/download_service_factory.h" | 12 #include "chrome/browser/download/download_service_factory.h" |
13 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
14 #include "chrome/browser/signin/signin_manager_factory.h" | 14 #include "chrome/browser/signin/signin_manager_factory.h" |
15 #include "chrome/browser/ui/browser.h" | 15 #include "chrome/browser/ui/browser.h" |
16 #include "chrome/common/chrome_switches.h" | 16 #include "chrome/common/chrome_switches.h" |
17 #include "chrome/grit/chromium_strings.h" | 17 #include "chrome/grit/chromium_strings.h" |
18 #include "chrome/grit/generated_resources.h" | 18 #include "chrome/grit/generated_resources.h" |
19 #include "chrome/test/base/in_process_browser_test.h" | 19 #include "chrome/test/base/in_process_browser_test.h" |
20 #include "chrome/test/base/ui_test_utils.h" | 20 #include "chrome/test/base/ui_test_utils.h" |
21 #include "chromeos/chromeos_switches.h" | 21 #include "chromeos/chromeos_switches.h" |
22 #include "components/signin/core/browser/signin_manager_base.h" | 22 #include "components/signin/core/browser/signin_manager_base.h" |
23 #include "content/public/browser/browser_context.h" | 23 #include "content/public/browser/browser_context.h" |
24 #include "content/public/browser/download_item.h" | 24 #include "content/public/browser/download_item.h" |
25 #include "content/public/browser/download_manager.h" | 25 #include "content/public/browser/download_manager.h" |
| 26 #include "content/public/test/download_test_observer.h" |
26 #include "grit/theme_resources.h" | 27 #include "grit/theme_resources.h" |
27 #include "net/test/url_request/url_request_slow_download_job.h" | 28 #include "net/test/url_request/url_request_slow_download_job.h" |
28 #include "ui/base/l10n/l10n_util.h" | 29 #include "ui/base/l10n/l10n_util.h" |
29 #include "ui/message_center/message_center.h" | 30 #include "ui/message_center/message_center.h" |
30 #include "ui/message_center/message_center_observer.h" | 31 #include "ui/message_center/message_center_observer.h" |
31 #include "url/gurl.h" | 32 #include "url/gurl.h" |
32 | 33 |
33 namespace { | 34 namespace { |
34 | 35 |
35 enum { | 36 enum { |
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
323 IN_PROC_BROWSER_TEST_F(DownloadNotificationTest, DownloadFile) { | 324 IN_PROC_BROWSER_TEST_F(DownloadNotificationTest, DownloadFile) { |
324 CreateDownload(); | 325 CreateDownload(); |
325 | 326 |
326 EXPECT_EQ(l10n_util::GetStringFUTF16( | 327 EXPECT_EQ(l10n_util::GetStringFUTF16( |
327 IDS_DOWNLOAD_STATUS_IN_PROGRESS_TITLE, | 328 IDS_DOWNLOAD_STATUS_IN_PROGRESS_TITLE, |
328 download_item()->GetFileNameToReportUser().LossyDisplayName()), | 329 download_item()->GetFileNameToReportUser().LossyDisplayName()), |
329 GetNotification(notification_id())->title()); | 330 GetNotification(notification_id())->title()); |
330 EXPECT_EQ(message_center::NOTIFICATION_TYPE_PROGRESS, | 331 EXPECT_EQ(message_center::NOTIFICATION_TYPE_PROGRESS, |
331 GetNotification(notification_id())->type()); | 332 GetNotification(notification_id())->type()); |
332 | 333 |
| 334 // Installs observers before requesting the completion. |
| 335 NotificationAddObserver download_notification_add_observer; |
| 336 NotificationRemoveObserver download_notification_remove_observer; |
| 337 |
333 // Requests to complete the download. | 338 // Requests to complete the download. |
334 ui_test_utils::NavigateToURL( | 339 ui_test_utils::NavigateToURL( |
335 browser(), GURL(net::URLRequestSlowDownloadJob::kFinishDownloadUrl)); | 340 browser(), GURL(net::URLRequestSlowDownloadJob::kFinishDownloadUrl)); |
336 | 341 |
337 // Waits for download completion. | 342 // Waits for download completion. |
338 while (download_item()->GetState() != content::DownloadItem::COMPLETE) { | 343 while (download_item()->GetState() != content::DownloadItem::COMPLETE) { |
339 NotificationUpdateObserver download_change_notification_observer; | 344 NotificationUpdateObserver download_change_notification_observer; |
340 download_change_notification_observer.Wait(); | 345 download_change_notification_observer.Wait(); |
341 } | 346 } |
342 | 347 |
| 348 // Waits for new notification is popped up. |
| 349 download_notification_remove_observer.Wait(); |
| 350 download_notification_add_observer.Wait(); |
| 351 |
| 352 // Checks strings. |
343 EXPECT_EQ(l10n_util::GetStringFUTF16( | 353 EXPECT_EQ(l10n_util::GetStringFUTF16( |
344 IDS_DOWNLOAD_STATUS_DOWNLOADED_TITLE, | 354 IDS_DOWNLOAD_STATUS_DOWNLOADED_TITLE, |
345 download_item()->GetFileNameToReportUser().LossyDisplayName()), | 355 download_item()->GetFileNameToReportUser().LossyDisplayName()), |
346 GetNotification(notification_id())->title()); | 356 GetNotification(notification_id())->title()); |
347 EXPECT_EQ(message_center::NOTIFICATION_TYPE_SIMPLE, | 357 EXPECT_EQ(message_center::NOTIFICATION_TYPE_SIMPLE, |
348 GetNotification(notification_id())->type()); | 358 GetNotification(notification_id())->type()); |
349 | 359 |
| 360 // Confirms that there is only one notification. |
| 361 message_center::NotificationList::Notifications |
| 362 visible_notifications = GetMessageCenter()->GetVisibleNotifications(); |
| 363 EXPECT_EQ(1u, visible_notifications.size()); |
| 364 EXPECT_TRUE(IsInNotifications(visible_notifications, notification_id())); |
| 365 |
350 // Opens the message center. | 366 // Opens the message center. |
351 GetMessageCenter()->SetVisibility(message_center::VISIBILITY_MESSAGE_CENTER); | 367 GetMessageCenter()->SetVisibility(message_center::VISIBILITY_MESSAGE_CENTER); |
352 | 368 |
353 // Try to open the downloaded item by clicking the notification. | 369 // Try to open the downloaded item by clicking the notification. |
354 EXPECT_FALSE(GetDownloadManagerDelegate()->opened()); | 370 EXPECT_FALSE(GetDownloadManagerDelegate()->opened()); |
355 GetMessageCenter()->ClickOnNotification(notification_id()); | 371 GetMessageCenter()->ClickOnNotification(notification_id()); |
356 EXPECT_TRUE(GetDownloadManagerDelegate()->opened()); | 372 EXPECT_TRUE(GetDownloadManagerDelegate()->opened()); |
357 | 373 |
358 EXPECT_FALSE(GetNotification(notification_id())); | 374 EXPECT_FALSE(GetNotification(notification_id())); |
359 } | 375 } |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
395 | 411 |
396 // Closes the notification. | 412 // Closes the notification. |
397 NotificationRemoveObserver notification_close_observer; | 413 NotificationRemoveObserver notification_close_observer; |
398 GetMessageCenter()->RemoveNotification(notification_id(), true /* by_user */); | 414 GetMessageCenter()->RemoveNotification(notification_id(), true /* by_user */); |
399 EXPECT_EQ(notification_id(), notification_close_observer.Wait()); | 415 EXPECT_EQ(notification_id(), notification_close_observer.Wait()); |
400 | 416 |
401 EXPECT_EQ(0u, GetMessageCenter()->GetVisibleNotifications().size()); | 417 EXPECT_EQ(0u, GetMessageCenter()->GetVisibleNotifications().size()); |
402 | 418 |
403 // Confirms that a download is still in progress. | 419 // Confirms that a download is still in progress. |
404 std::vector<content::DownloadItem*> downloads; | 420 std::vector<content::DownloadItem*> downloads; |
405 GetDownloadManager(browser())->GetAllDownloads(&downloads); | 421 content::DownloadManager* download_manager = GetDownloadManager(browser()); |
| 422 download_manager->GetAllDownloads(&downloads); |
406 EXPECT_EQ(1u, downloads.size()); | 423 EXPECT_EQ(1u, downloads.size()); |
407 EXPECT_EQ(content::DownloadItem::IN_PROGRESS, downloads[0]->GetState()); | 424 EXPECT_EQ(content::DownloadItem::IN_PROGRESS, downloads[0]->GetState()); |
408 | 425 |
409 // Cleans the downloading. | 426 // Installs observers before requesting the completion. |
410 downloads[0]->Cancel(true); | 427 NotificationAddObserver download_notification_add_observer; |
| 428 content::DownloadTestObserverTerminal download_terminal_observer( |
| 429 download_manager, |
| 430 1u, /* wait_count */ |
| 431 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL); |
| 432 |
| 433 // Requests to complete the download and wait for it. |
| 434 ui_test_utils::NavigateToURL( |
| 435 browser(), GURL(net::URLRequestSlowDownloadJob::kFinishDownloadUrl)); |
| 436 download_terminal_observer.WaitForFinished(); |
| 437 |
| 438 // Waits that new notification is popped up. |
| 439 download_notification_add_observer.Wait(); |
| 440 |
| 441 // Confirms that there is only one notification. |
| 442 message_center::NotificationList::Notifications |
| 443 visible_notifications = GetMessageCenter()->GetVisibleNotifications(); |
| 444 EXPECT_EQ(1u, visible_notifications.size()); |
| 445 EXPECT_TRUE(IsInNotifications(visible_notifications, notification_id())); |
| 446 } |
| 447 |
| 448 IN_PROC_BROWSER_TEST_F(DownloadNotificationTest, InterruptDownload) { |
| 449 CreateDownload(); |
| 450 |
| 451 // Installs observers before requesting. |
| 452 NotificationAddObserver download_notification_add_observer; |
| 453 NotificationRemoveObserver download_notification_remove_observer; |
| 454 content::DownloadTestObserverTerminal download_terminal_observer( |
| 455 GetDownloadManager(browser()), |
| 456 1u, /* wait_count */ |
| 457 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL); |
| 458 |
| 459 // Requests to fail the download and wait for it. |
| 460 ui_test_utils::NavigateToURL( |
| 461 browser(), GURL(net::URLRequestSlowDownloadJob::kErrorDownloadUrl)); |
| 462 download_terminal_observer.WaitForFinished(); |
| 463 |
| 464 // Waits that new notification is popped up. |
| 465 download_notification_remove_observer.Wait(); |
| 466 download_notification_add_observer.Wait(); |
| 467 |
| 468 // Confirms that there is only one notification. |
| 469 message_center::NotificationList::Notifications |
| 470 visible_notifications = GetMessageCenter()->GetVisibleNotifications(); |
| 471 EXPECT_EQ(1u, visible_notifications.size()); |
| 472 EXPECT_TRUE(IsInNotifications(visible_notifications, notification_id())); |
| 473 |
| 474 // Checks strings. |
| 475 EXPECT_EQ(l10n_util::GetStringFUTF16( |
| 476 IDS_DOWNLOAD_STATUS_DOWNLOAD_FAILED_TITLE, |
| 477 download_item()->GetFileNameToReportUser().LossyDisplayName()), |
| 478 GetNotification(notification_id())->title()); |
| 479 EXPECT_EQ(l10n_util::GetStringFUTF16( |
| 480 IDS_DOWNLOAD_STATUS_INTERRUPTED, |
| 481 l10n_util::GetStringUTF16( |
| 482 IDS_DOWNLOAD_INTERRUPTED_STATUS_NETWORK_ERROR)), |
| 483 GetNotification(notification_id())->message()); |
| 484 EXPECT_EQ(message_center::NOTIFICATION_TYPE_SIMPLE, |
| 485 GetNotification(notification_id())->type()); |
| 486 } |
| 487 |
| 488 IN_PROC_BROWSER_TEST_F(DownloadNotificationTest, |
| 489 InterruptDownloadAfterClosingNotification) { |
| 490 CreateDownload(); |
| 491 |
| 492 // Closes the notification. |
| 493 NotificationRemoveObserver notification_close_observer; |
| 494 GetMessageCenter()->RemoveNotification(notification_id(), true /* by_user */); |
| 495 EXPECT_EQ(notification_id(), notification_close_observer.Wait()); |
| 496 |
| 497 EXPECT_EQ(0u, GetMessageCenter()->GetVisibleNotifications().size()); |
| 498 |
| 499 // Confirms that a download is still in progress. |
| 500 std::vector<content::DownloadItem*> downloads; |
| 501 content::DownloadManager* download_manager = GetDownloadManager(browser()); |
| 502 download_manager->GetAllDownloads(&downloads); |
| 503 EXPECT_EQ(1u, downloads.size()); |
| 504 EXPECT_EQ(content::DownloadItem::IN_PROGRESS, downloads[0]->GetState()); |
| 505 |
| 506 // Installs observers before requesting the completion. |
| 507 NotificationAddObserver download_notification_add_observer; |
| 508 content::DownloadTestObserverTerminal download_terminal_observer( |
| 509 download_manager, |
| 510 1u, /* wait_count */ |
| 511 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL); |
| 512 |
| 513 // Requests to fail the download and wait for it. |
| 514 ui_test_utils::NavigateToURL( |
| 515 browser(), GURL(net::URLRequestSlowDownloadJob::kErrorDownloadUrl)); |
| 516 download_terminal_observer.WaitForFinished(); |
| 517 |
| 518 // Waits that new notification is popped up. |
| 519 download_notification_add_observer.Wait(); |
| 520 |
| 521 // Confirms that there is only one notification. |
| 522 message_center::NotificationList::Notifications |
| 523 visible_notifications = GetMessageCenter()->GetVisibleNotifications(); |
| 524 EXPECT_EQ(1u, visible_notifications.size()); |
| 525 EXPECT_TRUE(IsInNotifications(visible_notifications, notification_id())); |
411 } | 526 } |
412 | 527 |
413 IN_PROC_BROWSER_TEST_F(DownloadNotificationTest, DownloadRemoved) { | 528 IN_PROC_BROWSER_TEST_F(DownloadNotificationTest, DownloadRemoved) { |
414 CreateDownload(); | 529 CreateDownload(); |
415 | 530 |
416 NotificationRemoveObserver notification_close_observer; | 531 NotificationRemoveObserver notification_close_observer; |
417 download_item()->Remove(); | 532 download_item()->Remove(); |
418 EXPECT_EQ(notification_id(), notification_close_observer.Wait()); | 533 EXPECT_EQ(notification_id(), notification_close_observer.Wait()); |
419 | 534 |
420 // Confirms that the notification is removed. | 535 // Confirms that the notification is removed. |
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
683 } | 798 } |
684 | 799 |
685 // Confirms the types of download notifications are correct. | 800 // Confirms the types of download notifications are correct. |
686 EXPECT_EQ(message_center::NOTIFICATION_TYPE_SIMPLE, | 801 EXPECT_EQ(message_center::NOTIFICATION_TYPE_SIMPLE, |
687 GetNotification(notification_id1)->type()); | 802 GetNotification(notification_id1)->type()); |
688 EXPECT_EQ(message_center::NOTIFICATION_TYPE_SIMPLE, | 803 EXPECT_EQ(message_center::NOTIFICATION_TYPE_SIMPLE, |
689 GetNotification(notification_id2)->type()); | 804 GetNotification(notification_id2)->type()); |
690 EXPECT_EQ(message_center::NOTIFICATION_TYPE_SIMPLE, | 805 EXPECT_EQ(message_center::NOTIFICATION_TYPE_SIMPLE, |
691 GetNotification(notification_id3)->type()); | 806 GetNotification(notification_id3)->type()); |
692 } | 807 } |
OLD | NEW |