Chromium Code Reviews| Index: chrome/browser/download/notification/download_notification_browsertest.cc |
| diff --git a/chrome/browser/download/notification/download_notification_browsertest.cc b/chrome/browser/download/notification/download_notification_browsertest.cc |
| index 503728d86d000e1304e70f4af56872b2aa9fef42..d16c1fa020b43a423558a06ff485868b03d087fb 100644 |
| --- a/chrome/browser/download/notification/download_notification_browsertest.cc |
| +++ b/chrome/browser/download/notification/download_notification_browsertest.cc |
| @@ -13,6 +13,7 @@ |
| #include "chrome/browser/profiles/profile.h" |
| #include "chrome/browser/signin/signin_manager_factory.h" |
| #include "chrome/browser/ui/browser.h" |
| +#include "chrome/browser/ui/browser_commands.h" |
| #include "chrome/common/chrome_switches.h" |
| #include "chrome/grit/chromium_strings.h" |
| #include "chrome/grit/generated_resources.h" |
| @@ -269,7 +270,6 @@ class DownloadNotificationTest : public DownloadNotificationTestBase { |
| test_delegate.reset(new TestChromeDownloadManagerDelegate(profile)); |
| test_delegate->GetDownloadIdReceiverCallback().Run( |
| content::DownloadItem::kInvalidId + 1); |
| - |
| DownloadServiceFactory::GetForBrowserContext(profile) |
| ->SetDownloadManagerDelegateForTesting(test_delegate.Pass()); |
| @@ -282,12 +282,37 @@ class DownloadNotificationTest : public DownloadNotificationTestBase { |
| ->GetDownloadManagerDelegate()); |
| } |
| + void PrepareIncognitoBrowser() { |
| + incognito_browser_ = CreateIncognitoBrowser(); |
| + Profile* incognito_profile = incognito_browser_->profile(); |
| + |
| + scoped_ptr<TestChromeDownloadManagerDelegate> incognito_test_delegate; |
| + incognito_test_delegate.reset( |
| + new TestChromeDownloadManagerDelegate(incognito_profile)); |
| + incognito_test_delegate->GetDownloadIdReceiverCallback().Run( |
| + content::DownloadItem::kInvalidId + 1); |
| + DownloadServiceFactory::GetForBrowserContext(incognito_profile) |
| + ->SetDownloadManagerDelegateForTesting(incognito_test_delegate.Pass()); |
| + } |
| + |
| + TestChromeDownloadManagerDelegate* GetIncognitoDownloadManagerDelegate() |
| + const { |
| + Profile* incognito_profile = incognito_browser()->profile(); |
| + return static_cast<TestChromeDownloadManagerDelegate*>( |
| + DownloadServiceFactory::GetForBrowserContext(incognito_profile)-> |
| + GetDownloadManagerDelegate()); |
| + } |
| + |
| void CreateDownload() { |
| + return CreateDownloadForBrowser(browser()); |
| + } |
| + |
| + void CreateDownloadForBrowser(Browser* browser) { |
| GURL url(net::URLRequestSlowDownloadJob::kKnownSizeUrl); |
| // Starts a download. |
| NotificationAddObserver download_start_notification_observer; |
| - ui_test_utils::NavigateToURL(browser(), url); |
| + ui_test_utils::NavigateToURL(browser, url); |
| EXPECT_TRUE(download_start_notification_observer.Wait()); |
| // Confirms that a notification is created. |
| @@ -303,7 +328,7 @@ class DownloadNotificationTest : public DownloadNotificationTestBase { |
| // Confirms that a download is also started. |
| std::vector<content::DownloadItem*> downloads; |
| - GetDownloadManager(browser())->GetAllDownloads(&downloads); |
| + GetDownloadManager(browser)->GetAllDownloads(&downloads); |
| EXPECT_EQ(1u, downloads.size()); |
| download_item_ = downloads[0]; |
| ASSERT_TRUE(download_item_); |
| @@ -314,9 +339,11 @@ class DownloadNotificationTest : public DownloadNotificationTestBase { |
| message_center::Notification* notification() const { |
| return GetNotification(notification_id_); |
| } |
| + Browser* incognito_browser() const { return incognito_browser_; } |
| private: |
| content::DownloadItem* download_item_ = nullptr; |
| + Browser* incognito_browser_ = nullptr; |
| std::string notification_id_; |
| }; |
| @@ -538,6 +565,123 @@ IN_PROC_BROWSER_TEST_F(DownloadNotificationTest, |
| EXPECT_EQ(content::DownloadItem::CANCELLED, downloads[0]->GetState()); |
| } |
| +IN_PROC_BROWSER_TEST_F(DownloadNotificationTest, IncognitoDownloadFile) { |
| + PrepareIncognitoBrowser(); |
| + |
| + // Starts an incognito download. |
| + CreateDownloadForBrowser(incognito_browser()); |
| + |
| + EXPECT_EQ(l10n_util::GetStringFUTF16( |
| + IDS_DOWNLOAD_STATUS_IN_PROGRESS_TITLE, |
| + download_item()->GetFileNameToReportUser().LossyDisplayName()), |
| + GetNotification(notification_id())->title()); |
| + EXPECT_EQ(message_center::NOTIFICATION_TYPE_PROGRESS, |
| + GetNotification(notification_id())->type()); |
| + EXPECT_TRUE(download_item()->GetBrowserContext()->IsOffTheRecord()); |
| + |
| + // Requests to complete the download. |
| + ui_test_utils::NavigateToURL( |
| + incognito_browser(), |
| + GURL(net::URLRequestSlowDownloadJob::kFinishDownloadUrl)); |
| + |
| + // Waits for download completion. |
| + while (download_item()->GetState() != content::DownloadItem::COMPLETE) { |
| + NotificationUpdateObserver download_change_notification_observer; |
| + download_change_notification_observer.Wait(); |
|
asanka
2015/05/13 15:10:30
Remind me again why we aren't using something like
yoshiki
2015/05/13 17:03:04
I thought we can write it with DownloadTestObserve
|
| + } |
| + |
| + EXPECT_EQ(l10n_util::GetStringFUTF16( |
| + IDS_DOWNLOAD_STATUS_DOWNLOADED_TITLE, |
| + download_item()->GetFileNameToReportUser().LossyDisplayName()), |
| + GetNotification(notification_id())->title()); |
| + EXPECT_EQ(message_center::NOTIFICATION_TYPE_SIMPLE, |
| + GetNotification(notification_id())->type()); |
| + |
| + // Opens the message center. |
| + GetMessageCenter()->SetVisibility(message_center::VISIBILITY_MESSAGE_CENTER); |
| + |
| + // Try to open the downloaded item by clicking the notification. |
| + EXPECT_FALSE(GetIncognitoDownloadManagerDelegate()->opened()); |
| + GetMessageCenter()->ClickOnNotification(notification_id()); |
| + EXPECT_TRUE(GetIncognitoDownloadManagerDelegate()->opened()); |
| + EXPECT_FALSE(GetDownloadManagerDelegate()->opened()); |
| + |
| + EXPECT_FALSE(GetNotification(notification_id())); |
| + chrome::CloseWindow(incognito_browser()); |
| +} |
| + |
| +IN_PROC_BROWSER_TEST_F(DownloadNotificationTest, |
| + SimultaneousIncognitoAndNormalDownloads) { |
| + PrepareIncognitoBrowser(); |
| + |
| + GURL url_ingocnito(net::URLRequestSlowDownloadJob::kUnknownSizeUrl); |
| + GURL url_normal(net::URLRequestSlowDownloadJob::kKnownSizeUrl); |
| + |
| + // Starts the incognito download. |
| + NotificationAddObserver download_start_notification_observer1; |
| + ui_test_utils::NavigateToURL(incognito_browser(), url_incognito); |
| + EXPECT_TRUE(download_start_notification_observer1.Wait()); |
| + std::string notification_id1 = |
| + download_start_notification_observer1.notification_id(); |
| + EXPECT_FALSE(notification_id1.empty()); |
| + |
| + // Confirms that there is a download. |
| + std::vector<content::DownloadItem*> downloads; |
| + GetDownloadManager(browser())->GetAllDownloads(&downloads); |
| + EXPECT_EQ(0u, downloads.size()); |
| + downloads.clear(); |
| + GetDownloadManager(incognito_browser())->GetAllDownloads(&downloads); |
| + EXPECT_EQ(1u, downloads.size()); |
| + content::DownloadItem* download_incognito = downloads[0]; |
| + |
| + // Starts the normal download. |
| + NotificationAddObserver download_start_notification_observer2; |
| + ui_test_utils::NavigateToURL(browser(), url_normal); |
| + EXPECT_TRUE(download_start_notification_observer2.Wait()); |
| + std::string notification_id2 = |
| + download_start_notification_observer2.notification_id(); |
| + EXPECT_FALSE(notification_id2.empty()); |
| + |
| + // Confirms that there are 2 downloads. |
| + downloads.clear(); |
| + GetDownloadManager(browser())->GetAllDownloads(&downloads); |
| + content::DownloadItem* download_normal = downloads[0]; |
| + EXPECT_EQ(1u, downloads.size()); |
| + EXPECT_NE(download_normal, download_incognito); |
| + downloads.clear(); |
| + GetDownloadManager(incognito_browser())->GetAllDownloads(&downloads); |
| + EXPECT_EQ(1u, downloads.size()); |
| + EXPECT_EQ(download_incognito, downloads[0]); |
| + |
| + // Confirms the types of download notifications are correct. |
| + EXPECT_EQ(message_center::NOTIFICATION_TYPE_PROGRESS, |
| + GetNotification(notification_id1)->type()); |
| + EXPECT_EQ(message_center::NOTIFICATION_TYPE_PROGRESS, |
| + GetNotification(notification_id2)->type()); |
| + |
| + EXPECT_TRUE(download_incognito->GetBrowserContext()->IsOffTheRecord()); |
| + EXPECT_FALSE(download_normal->GetBrowserContext()->IsOffTheRecord()); |
| + |
| + // Requests to complete the downloads. |
| + ui_test_utils::NavigateToURL( |
| + browser(), GURL(net::URLRequestSlowDownloadJob::kFinishDownloadUrl)); |
| + |
| + // Waits for the completion of downloads. |
| + while (download_normal->GetState() != content::DownloadItem::COMPLETE || |
| + download_incognito->GetState() != content::DownloadItem::COMPLETE) { |
| + NotificationUpdateObserver download_change_notification_observer; |
| + download_change_notification_observer.Wait(); |
| + } |
| + |
| + // Confirms the types of download notifications are correct. |
| + EXPECT_EQ(message_center::NOTIFICATION_TYPE_SIMPLE, |
| + GetNotification(notification_id1)->type()); |
| + EXPECT_EQ(message_center::NOTIFICATION_TYPE_SIMPLE, |
| + GetNotification(notification_id2)->type()); |
| + |
| + chrome::CloseWindow(incognito_browser()); |
| +} |
| + |
| ////////////////////////////////////////////////// |
| // Test with multi profiles |
| ////////////////////////////////////////////////// |