#include <algorithm>
-#include "base/file_util.h"
+#include "base/files/file_util.h"
#include "base/files/scoped_temp_dir.h"
#include "base/json/json_reader.h"
#include "base/message_loop/message_loop.h"
#include "content/public/browser/storage_partition.h"
#include "content/public/browser/web_contents.h"
#include "content/public/common/content_switches.h"
-#include "content/public/common/page_transition_types.h"
#include "content/public/test/download_test_observer.h"
#include "content/test/net/url_request_slow_download_job.h"
#include "extensions/browser/event_router.h"
#include "net/url_request/url_request_job.h"
#include "net/url_request/url_request_job_factory.h"
#include "net/url_request/url_request_job_factory_impl.h"
-#include "webkit/browser/fileapi/file_system_context.h"
-#include "webkit/browser/fileapi/file_system_operation_runner.h"
-#include "webkit/browser/fileapi/file_system_url.h"
+#include "storage/browser/fileapi/file_system_context.h"
+#include "storage/browser/fileapi/file_system_operation_runner.h"
+#include "storage/browser/fileapi/file_system_url.h"
+#include "ui/base/page_transition_types.h"
using content::BrowserContext;
using content::BrowserThread;
content::WebContents* tab = chrome::AddSelectedTabWithURL(
current_browser(),
extension_->GetResourceURL("empty.html"),
- content::PAGE_TRANSITION_LINK);
+ ui::PAGE_TRANSITION_LINK);
EventRouter::Get(current_browser()->profile())
->AddEventListener(downloads::OnCreated::kEventName,
tab->GetRenderProcessHost(),
content::WebContents* tab = chrome::AddSelectedTabWithURL(
current_browser(),
extension_->GetResourceURL("empty.html"),
- content::PAGE_TRANSITION_LINK);
+ ui::PAGE_TRANSITION_LINK);
EventRouter::Get(current_browser()->profile())
->AddEventListener(downloads::OnDeterminingFilename::kEventName,
tab->GetRenderProcessHost(),
content::WebContents* tab = chrome::AddSelectedTabWithURL(
current_browser(),
extension_->GetResourceURL("empty.html"),
- content::PAGE_TRANSITION_LINK);
+ ui::PAGE_TRANSITION_LINK);
function->set_extension(extension_);
function->SetRenderViewHost(tab->GetRenderViewHost());
}
// Writes an HTML5 file so that it can be downloaded.
class HTML5FileWriter {
public:
- static bool CreateFileForTesting(fileapi::FileSystemContext* context,
- const fileapi::FileSystemURL& path,
- const char*data,
+ static bool CreateFileForTesting(storage::FileSystemContext* context,
+ const storage::FileSystemURL& path,
+ const char* data,
int length) {
// Create a temp file.
base::FilePath temp_file;
}
static void CreateFileForTestingOnIOThread(
- fileapi::FileSystemContext* context,
- const fileapi::FileSystemURL& path,
+ storage::FileSystemContext* context,
+ const storage::FileSystemURL& path,
const base::FilePath& temp_file,
bool* result,
base::WaitableEvent* done_event) {
for (size_t index = 0; index < arraysize(kUnsafeHeaders); ++index) {
std::string download_url = test_server()->GetURL("slow?0").spec();
- EXPECT_STREQ(errors::kInvalidHeader,
+ EXPECT_STREQ(errors::kInvalidHeaderUnsafe,
RunFunctionAndReturnError(new DownloadsDownloadFunction(),
base::StringPrintf(
"[{\"url\": \"%s\","
}
}
+// Tests that invalid header names and values are rejected.
+IN_PROC_BROWSER_TEST_F(DownloadExtensionTest,
+ DownloadExtensionTest_Download_InvalidHeaders) {
+ LoadExtension("downloads_split");
+ ASSERT_TRUE(StartEmbeddedTestServer());
+ ASSERT_TRUE(test_server()->Start());
+ GoOnTheRecord();
+ std::string download_url = test_server()->GetURL("slow?0").spec();
+ EXPECT_STREQ(errors::kInvalidHeaderName,
+ RunFunctionAndReturnError(new DownloadsDownloadFunction(),
+ base::StringPrintf(
+ "[{\"url\": \"%s\","
+ " \"filename\": \"unsafe-header-crlf.txt\","
+ " \"headers\": [{"
+ " \"name\": \"Header\\r\\nSec-Spoof: Hey\\r\\nX-Split:X\","
+ " \"value\": \"unsafe\"}]}]",
+ download_url.c_str())).c_str());
+
+ EXPECT_STREQ(errors::kInvalidHeaderValue,
+ RunFunctionAndReturnError(new DownloadsDownloadFunction(),
+ base::StringPrintf(
+ "[{\"url\": \"%s\","
+ " \"filename\": \"unsafe-header-crlf.txt\","
+ " \"headers\": [{"
+ " \"name\": \"Invalid-value\","
+ " \"value\": \"hey\\r\\nSec-Spoof: Hey\"}]}]",
+ download_url.c_str())).c_str());
+}
+
#if defined(OS_WIN)
#define MAYBE_DownloadExtensionTest_Download_Subdirectory\
DISABLED_DownloadExtensionTest_Download_Subdirectory
// Setup a file in the filesystem which we can download.
ASSERT_TRUE(HTML5FileWriter::CreateFileForTesting(
- BrowserContext::GetDefaultStoragePartition(browser()->profile())->
- GetFileSystemContext(),
- fileapi::FileSystemURL::CreateForTest(GURL(download_url)),
- kPayloadData, strlen(kPayloadData)));
+ BrowserContext::GetDefaultStoragePartition(browser()->profile())
+ ->GetFileSystemContext(),
+ storage::FileSystemURL::CreateForTest(GURL(download_url)),
+ kPayloadData,
+ strlen(kPayloadData)));
// Now download it.
scoped_ptr<base::Value> result(RunFunctionAndReturnResult(
base::FilePath filename;
downloads::FilenameConflictAction conflict_action =
downloads::FILENAME_CONFLICT_ACTION_UNIQUIFY;
- ExtensionWarningSet warnings;
+ WarningSet warnings;
// Empty incumbent determiner
warnings.clear();
EXPECT_EQ(FILE_PATH_LITERAL("a"), filename.value());
EXPECT_EQ(downloads::FILENAME_CONFLICT_ACTION_OVERWRITE, conflict_action);
EXPECT_FALSE(warnings.empty());
- EXPECT_EQ(ExtensionWarning::kDownloadFilenameConflict,
+ EXPECT_EQ(Warning::kDownloadFilenameConflict,
warnings.begin()->warning_type());
EXPECT_EQ("suggester", warnings.begin()->extension_id());
EXPECT_EQ(FILE_PATH_LITERAL("b"), filename.value());
EXPECT_EQ(downloads::FILENAME_CONFLICT_ACTION_PROMPT, conflict_action);
EXPECT_FALSE(warnings.empty());
- EXPECT_EQ(ExtensionWarning::kDownloadFilenameConflict,
+ EXPECT_EQ(Warning::kDownloadFilenameConflict,
warnings.begin()->warning_type());
EXPECT_EQ("incumbent", warnings.begin()->extension_id());
}