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

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

Issue 61623006: Revert 233460 "Prefer opening PDF downloads in the browser." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: 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: trunk/src/chrome/browser/download/chrome_download_manager_delegate_unittest.cc
===================================================================
--- trunk/src/chrome/browser/download/chrome_download_manager_delegate_unittest.cc (revision 233496)
+++ trunk/src/chrome/browser/download/chrome_download_manager_delegate_unittest.cc (working copy)
@@ -9,7 +9,6 @@
#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"
@@ -66,6 +65,13 @@
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 {
@@ -146,7 +152,7 @@
void SetDefaultDownloadPath(const base::FilePath& path);
void DetermineDownloadTarget(DownloadItem* download,
- DownloadTargetInfo* result);
+ DownloadTarget* result);
const base::FilePath& default_download_path() const;
TestChromeDownloadManagerDelegate* delegate();
@@ -154,6 +160,12 @@
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_;
@@ -240,29 +252,30 @@
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,
- DownloadTargetInfo* result) {
- base::RunLoop loop_runner;
+ DownloadTarget* result) {
+ base::WeakPtrFactory<ChromeDownloadManagerDelegateTest> factory(this);
delegate()->DetermineDownloadTarget(
download_item,
- base::Bind(&StoreDownloadTargetInfo, loop_runner.QuitClosure(), result));
- loop_runner.Run();
+ 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;
+}
+
const base::FilePath& ChromeDownloadManagerDelegateTest::default_download_path()
const {
return test_download_dir_.path();
@@ -308,7 +321,7 @@
{
// When the prompt is displayed for the first download, the user selects a
// path in a different directory.
- DownloadTargetInfo result;
+ DownloadTarget result;
base::FilePath expected_prompt_path(GetPathInDownloadDir("foo.txt"));
base::FilePath user_selected_path(GetPathInDownloadDir("bar/baz.txt"));
EXPECT_CALL(*delegate(),
@@ -323,7 +336,7 @@
{
// The prompt path for the second download is the user selected directroy
// from the previous download.
- DownloadTargetInfo result;
+ DownloadTarget result;
base::FilePath expected_prompt_path(GetPathInDownloadDir("bar/foo.txt"));
EXPECT_CALL(*delegate(),
MockPromptUserForDownloadPath(save_as_download.get(),
@@ -336,7 +349,7 @@
{
// Start an automatic download. This one should get the default download
// path since the last download path only affects Save As downloads.
- DownloadTargetInfo result;
+ DownloadTarget result;
base::FilePath expected_path(GetPathInDownloadDir("foo.txt"));
DetermineDownloadTarget(automatic_download.get(), &result);
EXPECT_EQ(expected_path, result.target_path);
@@ -346,7 +359,7 @@
{
// The prompt path for the next download should be the default.
download_prefs()->SetSaveFilePath(download_prefs()->DownloadPath());
- DownloadTargetInfo result;
+ DownloadTarget result;
base::FilePath expected_prompt_path(GetPathInDownloadDir("foo.txt"));
EXPECT_CALL(*delegate(),
MockPromptUserForDownloadPath(save_as_download.get(),

Powered by Google App Engine
This is Rietveld 408576698