Commit c42c4385 authored by yoshiki's avatar yoshiki Committed by Commit bot

[Download Notification] Add tests of incognito download

BUG=480489
TEST=run newly added tests

Review URL: https://codereview.chromium.org/1139963004

Cr-Commit-Position: refs/heads/master@{#329695}
parent 1b3a81a0
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/signin/signin_manager_factory.h" #include "chrome/browser/signin/signin_manager_factory.h"
#include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_commands.h"
#include "chrome/common/chrome_switches.h" #include "chrome/common/chrome_switches.h"
#include "chrome/grit/chromium_strings.h" #include "chrome/grit/chromium_strings.h"
#include "chrome/grit/generated_resources.h" #include "chrome/grit/generated_resources.h"
...@@ -269,7 +270,6 @@ class DownloadNotificationTest : public DownloadNotificationTestBase { ...@@ -269,7 +270,6 @@ class DownloadNotificationTest : public DownloadNotificationTestBase {
test_delegate.reset(new TestChromeDownloadManagerDelegate(profile)); test_delegate.reset(new TestChromeDownloadManagerDelegate(profile));
test_delegate->GetDownloadIdReceiverCallback().Run( test_delegate->GetDownloadIdReceiverCallback().Run(
content::DownloadItem::kInvalidId + 1); content::DownloadItem::kInvalidId + 1);
DownloadServiceFactory::GetForBrowserContext(profile) DownloadServiceFactory::GetForBrowserContext(profile)
->SetDownloadManagerDelegateForTesting(test_delegate.Pass()); ->SetDownloadManagerDelegateForTesting(test_delegate.Pass());
...@@ -282,12 +282,35 @@ class DownloadNotificationTest : public DownloadNotificationTestBase { ...@@ -282,12 +282,35 @@ class DownloadNotificationTest : public DownloadNotificationTestBase {
->GetDownloadManagerDelegate()); ->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));
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() { void CreateDownload() {
return CreateDownloadForBrowser(browser());
}
void CreateDownloadForBrowser(Browser* browser) {
GURL url(net::URLRequestSlowDownloadJob::kKnownSizeUrl); GURL url(net::URLRequestSlowDownloadJob::kKnownSizeUrl);
// Starts a download. // Starts a download.
NotificationAddObserver download_start_notification_observer; NotificationAddObserver download_start_notification_observer;
ui_test_utils::NavigateToURL(browser(), url); ui_test_utils::NavigateToURL(browser, url);
EXPECT_TRUE(download_start_notification_observer.Wait()); EXPECT_TRUE(download_start_notification_observer.Wait());
// Confirms that a notification is created. // Confirms that a notification is created.
...@@ -303,7 +326,7 @@ class DownloadNotificationTest : public DownloadNotificationTestBase { ...@@ -303,7 +326,7 @@ class DownloadNotificationTest : public DownloadNotificationTestBase {
// Confirms that a download is also started. // Confirms that a download is also started.
std::vector<content::DownloadItem*> downloads; std::vector<content::DownloadItem*> downloads;
GetDownloadManager(browser())->GetAllDownloads(&downloads); GetDownloadManager(browser)->GetAllDownloads(&downloads);
EXPECT_EQ(1u, downloads.size()); EXPECT_EQ(1u, downloads.size());
download_item_ = downloads[0]; download_item_ = downloads[0];
ASSERT_TRUE(download_item_); ASSERT_TRUE(download_item_);
...@@ -314,9 +337,11 @@ class DownloadNotificationTest : public DownloadNotificationTestBase { ...@@ -314,9 +337,11 @@ class DownloadNotificationTest : public DownloadNotificationTestBase {
message_center::Notification* notification() const { message_center::Notification* notification() const {
return GetNotification(notification_id_); return GetNotification(notification_id_);
} }
Browser* incognito_browser() const { return incognito_browser_; }
private: private:
content::DownloadItem* download_item_ = nullptr; content::DownloadItem* download_item_ = nullptr;
Browser* incognito_browser_ = nullptr;
std::string notification_id_; std::string notification_id_;
}; };
...@@ -538,6 +563,123 @@ IN_PROC_BROWSER_TEST_F(DownloadNotificationTest, ...@@ -538,6 +563,123 @@ IN_PROC_BROWSER_TEST_F(DownloadNotificationTest,
EXPECT_EQ(content::DownloadItem::CANCELLED, downloads[0]->GetState()); 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();
}
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_incognito(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 // Test with multi profiles
////////////////////////////////////////////////// //////////////////////////////////////////////////
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment