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

Unified Diff: chrome/browser/extensions/api/downloads/downloads_api_browsertest.cc

Issue 22612003: Warn when extensions suggest conflicting download filenames (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: @r216682 Created 7 years, 4 months 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/extensions/api/downloads/downloads_api_browsertest.cc
diff --git a/chrome/browser/extensions/api/downloads/downloads_api_browsertest.cc b/chrome/browser/extensions/api/downloads/downloads_api_browsertest.cc
index 094efb8092da1b9eea60b523e6056a5c3373ed35..e5962afc12d85bcab3b3ac8c7d78296f7a349485 100644
--- a/chrome/browser/extensions/api/downloads/downloads_api_browsertest.cc
+++ b/chrome/browser/extensions/api/downloads/downloads_api_browsertest.cc
@@ -3497,3 +3497,73 @@ TEST(DownloadInterruptReasonEnumsSynced,
#include "content/public/browser/download_interrupt_reason_values.h"
#undef INTERRUPT_REASON
}
+
+TEST(ExtensionDetermineDownloadFilenameInternal,
+ ExtensionDetermineDownloadFilenameInternal) {
+
+ std::string winner_id;
+ base::FilePath filename;
+ extensions::api::downloads::FilenameConflictAction conflict_action =
+ api::FILENAME_CONFLICT_ACTION_UNIQUIFY;
+ extensions::ExtensionWarningSet warnings;
+
+ // Empty incumbent determiner
+ warnings.clear();
+ ExtensionDownloadsEventRouter::DetermineFilenameInternal(
+ base::FilePath(FILE_PATH_LITERAL("a")),
+ api::FILENAME_CONFLICT_ACTION_OVERWRITE,
+ "suggester",
+ base::Time::Now(),
+ "",
+ base::Time(),
+ &winner_id,
+ &filename,
+ &conflict_action,
+ &warnings);
+ EXPECT_EQ("suggester", winner_id);
+ EXPECT_EQ(FILE_PATH_LITERAL("a"), filename.value());
+ EXPECT_EQ(api::FILENAME_CONFLICT_ACTION_OVERWRITE, conflict_action);
+ EXPECT_TRUE(warnings.empty());
+
+ // Incumbent wins
+ warnings.clear();
+ ExtensionDownloadsEventRouter::DetermineFilenameInternal(
+ base::FilePath(FILE_PATH_LITERAL("b")),
+ api::FILENAME_CONFLICT_ACTION_PROMPT,
+ "suggester",
+ base::Time::Now() - base::TimeDelta::FromDays(1),
+ "incumbent",
+ base::Time::Now(),
+ &winner_id,
+ &filename,
+ &conflict_action,
+ &warnings);
+ EXPECT_EQ("incumbent", winner_id);
+ EXPECT_EQ(FILE_PATH_LITERAL("a"), filename.value());
+ EXPECT_EQ(api::FILENAME_CONFLICT_ACTION_OVERWRITE, conflict_action);
+ EXPECT_FALSE(warnings.empty());
+ EXPECT_EQ(extensions::ExtensionWarning::kDownloadFilenameConflict,
+ warnings.begin()->warning_type());
+ EXPECT_EQ("suggester", warnings.begin()->extension_id());
+
+ // Suggester wins
+ warnings.clear();
+ ExtensionDownloadsEventRouter::DetermineFilenameInternal(
+ base::FilePath(FILE_PATH_LITERAL("b")),
+ api::FILENAME_CONFLICT_ACTION_PROMPT,
+ "suggester",
+ base::Time::Now(),
+ "incumbent",
+ base::Time::Now() - base::TimeDelta::FromDays(1),
+ &winner_id,
+ &filename,
+ &conflict_action,
+ &warnings);
+ EXPECT_EQ("suggester", winner_id);
+ EXPECT_EQ(FILE_PATH_LITERAL("b"), filename.value());
+ EXPECT_EQ(api::FILENAME_CONFLICT_ACTION_PROMPT, conflict_action);
+ EXPECT_FALSE(warnings.empty());
+ EXPECT_EQ(extensions::ExtensionWarning::kDownloadFilenameConflict,
+ warnings.begin()->warning_type());
+ EXPECT_EQ("incumbent", warnings.begin()->extension_id());
+}
« no previous file with comments | « chrome/browser/extensions/api/downloads/downloads_api.cc ('k') | chrome/browser/extensions/extension_warning_set.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698