Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(746)

Unified Diff: chrome/browser/download/chrome_download_manager_delegate_unittest.cc

Issue 55063002: Prefer opening PDF downloads in the browser. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Destroy PluginService once we are done with our plugin tests. Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/download/chrome_download_manager_delegate_unittest.cc
diff --git a/chrome/browser/download/chrome_download_manager_delegate_unittest.cc b/chrome/browser/download/chrome_download_manager_delegate_unittest.cc
index 64707589176af5a52d644fe212841f1c1badadc1..3ea6afab4ace1a643a67f54108fd650c60645afd 100644
--- a/chrome/browser/download/chrome_download_manager_delegate_unittest.cc
+++ b/chrome/browser/download/chrome_download_manager_delegate_unittest.cc
@@ -9,6 +9,7 @@
#include "base/run_loop.h"
#include "chrome/browser/download/chrome_download_manager_delegate.h"
#include "chrome/browser/download/download_prefs.h"
+#include "chrome/browser/download/download_target_info.h"
#include "chrome/common/pref_names.h"
#include "chrome/test/base/chrome_render_view_host_test_harness.h"
#include "chrome/test/base/testing_pref_service_syncable.h"
@@ -65,13 +66,6 @@ ACTION_P2(ScheduleCallback2, result0, result1) {
FROM_HERE, base::Bind(arg0, result0, result1));
}
-struct DownloadTarget {
- base::FilePath target_path;
- base::FilePath intermediate_path;
- DownloadItem::TargetDisposition target_disposition;
- content::DownloadDangerType danger_type;
-};
-
// Subclass of the ChromeDownloadManagerDelegate that uses a mock
// DownloadProtectionService.
class TestChromeDownloadManagerDelegate : public ChromeDownloadManagerDelegate {
@@ -152,7 +146,7 @@ class ChromeDownloadManagerDelegateTest :
void SetDefaultDownloadPath(const base::FilePath& path);
void DetermineDownloadTarget(DownloadItem* download,
- DownloadTarget* result);
+ DownloadTargetInfo* result);
const base::FilePath& default_download_path() const;
TestChromeDownloadManagerDelegate* delegate();
@@ -160,12 +154,6 @@ class ChromeDownloadManagerDelegateTest :
DownloadPrefs* download_prefs();
private:
- void OnDownloadTargetDone(DownloadTarget* result,
- const base::FilePath& target_path,
- DownloadItem::TargetDisposition disposition,
- content::DownloadDangerType danger_type,
- const base::FilePath& intermediate_path);
-
TestingPrefServiceSyncable* pref_service_;
base::ScopedTempDir test_download_dir_;
scoped_ptr<content::MockDownloadManager> download_manager_;
@@ -252,28 +240,27 @@ void ChromeDownloadManagerDelegateTest::SetDefaultDownloadPath(
pref_service_->SetFilePath(prefs::kSaveFileDefaultDirectory, path);
}
+void StoreDownloadTargetInfo(const base::Closure& closure,
+ DownloadTargetInfo* target_info,
+ const base::FilePath& target_path,
+ DownloadItem::TargetDisposition target_disposition,
+ content::DownloadDangerType danger_type,
+ const base::FilePath& intermediate_path) {
+ target_info->target_path = target_path;
+ target_info->target_disposition = target_disposition;
+ target_info->danger_type = danger_type;
+ target_info->intermediate_path = intermediate_path;
+ closure.Run();
+}
+
void ChromeDownloadManagerDelegateTest::DetermineDownloadTarget(
DownloadItem* download_item,
- DownloadTarget* result) {
- base::WeakPtrFactory<ChromeDownloadManagerDelegateTest> factory(this);
+ DownloadTargetInfo* result) {
+ base::RunLoop loop_runner;
delegate()->DetermineDownloadTarget(
download_item,
- base::Bind(&ChromeDownloadManagerDelegateTest::OnDownloadTargetDone,
- factory.GetWeakPtr(), base::Unretained(result)));
- base::RunLoop loop_runner;
- loop_runner.RunUntilIdle();
-}
-
-void ChromeDownloadManagerDelegateTest::OnDownloadTargetDone(
- DownloadTarget* result,
- const base::FilePath& target_path,
- DownloadItem::TargetDisposition target_disposition,
- content::DownloadDangerType danger_type,
- const base::FilePath& intermediate_path) {
- result->target_path = target_path;
- result->intermediate_path = intermediate_path;
- result->target_disposition = target_disposition;
- result->danger_type = danger_type;
+ base::Bind(&StoreDownloadTargetInfo, loop_runner.QuitClosure(), result));
+ loop_runner.Run();
}
const base::FilePath& ChromeDownloadManagerDelegateTest::default_download_path()
@@ -321,7 +308,7 @@ TEST_F(ChromeDownloadManagerDelegateTest, StartDownload_LastSavePath) {
{
// When the prompt is displayed for the first download, the user selects a
// path in a different directory.
- DownloadTarget result;
+ DownloadTargetInfo result;
base::FilePath expected_prompt_path(GetPathInDownloadDir("foo.txt"));
base::FilePath user_selected_path(GetPathInDownloadDir("bar/baz.txt"));
EXPECT_CALL(*delegate(),
@@ -336,7 +323,7 @@ TEST_F(ChromeDownloadManagerDelegateTest, StartDownload_LastSavePath) {
{
// The prompt path for the second download is the user selected directroy
// from the previous download.
- DownloadTarget result;
+ DownloadTargetInfo result;
base::FilePath expected_prompt_path(GetPathInDownloadDir("bar/foo.txt"));
EXPECT_CALL(*delegate(),
MockPromptUserForDownloadPath(save_as_download.get(),
@@ -349,7 +336,7 @@ TEST_F(ChromeDownloadManagerDelegateTest, StartDownload_LastSavePath) {
{
// Start an automatic download. This one should get the default download
// path since the last download path only affects Save As downloads.
- DownloadTarget result;
+ DownloadTargetInfo result;
base::FilePath expected_path(GetPathInDownloadDir("foo.txt"));
DetermineDownloadTarget(automatic_download.get(), &result);
EXPECT_EQ(expected_path, result.target_path);
@@ -359,7 +346,7 @@ TEST_F(ChromeDownloadManagerDelegateTest, StartDownload_LastSavePath) {
{
// The prompt path for the next download should be the default.
download_prefs()->SetSaveFilePath(download_prefs()->DownloadPath());
- DownloadTarget result;
+ DownloadTargetInfo result;
base::FilePath expected_prompt_path(GetPathInDownloadDir("foo.txt"));
EXPECT_CALL(*delegate(),
MockPromptUserForDownloadPath(save_as_download.get(),
« no previous file with comments | « chrome/browser/download/chrome_download_manager_delegate.cc ('k') | chrome/browser/download/download_item_model.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698