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

Unified Diff: net/url_request/test_url_fetcher_factory.cc

Issue 253833006: Add browser test for CustomizationWallpaperDownloader. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update after review. Created 6 years, 7 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: net/url_request/test_url_fetcher_factory.cc
diff --git a/net/url_request/test_url_fetcher_factory.cc b/net/url_request/test_url_fetcher_factory.cc
index d6c66118f32fe8a5e65ae5d6ff4ff8f8bc1d5298..bd4f5e187a36a1d54be6dcb4934acb5a56763f23 100644
--- a/net/url_request/test_url_fetcher_factory.cc
+++ b/net/url_request/test_url_fetcher_factory.cc
@@ -8,8 +8,10 @@
#include "base/bind.h"
#include "base/compiler_specific.h"
+#include "base/file_util.h"
#include "base/memory/weak_ptr.h"
#include "base/message_loop/message_loop.h"
+#include "base/threading/thread_restrictions.h"
#include "net/base/host_port_pair.h"
#include "net/base/io_buffer.h"
#include "net/base/net_errors.h"
@@ -143,6 +145,12 @@ void TestURLFetcher::SetAutomaticallyRetryOnNetworkChanges(int max_retries) {
void TestURLFetcher::SaveResponseToFileAtPath(
const base::FilePath& file_path,
scoped_refptr<base::SequencedTaskRunner> file_task_runner) {
+ SetResponseFilePath(file_path);
+ // Asynchronous IO is not supported, so file_task_runner is ignored.
+ base::ThreadRestrictions::ScopedAllowIO allow_io;
+ const size_t written_bytes = base::WriteFile(
+ file_path, fake_response_string_.c_str(), fake_response_string_.size());
+ DCHECK_EQ(written_bytes, fake_response_string_.size());
}
void TestURLFetcher::SaveResponseToTemporaryFile(
@@ -151,6 +159,12 @@ void TestURLFetcher::SaveResponseToTemporaryFile(
void TestURLFetcher::SaveResponseWithWriter(
scoped_ptr<URLFetcherResponseWriter> response_writer) {
+ // In class URLFetcherCore this method is called by all three:
+ // GetResponseAsString() / SaveResponseToFileAtPath() /
+ // SaveResponseToTemporaryFile(). But here (in TestURLFetcher), this method
+ // is never used by any of these three methods. So, file writing is expected
+ // to be done in SaveResponseToFileAtPath(), and this method supports only
+ // URLFetcherStringWriter (for testing of this method only).
if (fake_response_destination_ == STRING) {
response_writer_ = response_writer.Pass();
int response = response_writer_->Initialize(CompletionCallback());
@@ -164,8 +178,13 @@ void TestURLFetcher::SaveResponseWithWriter(
DCHECK_EQ(static_cast<int>(fake_response_string_.size()), response);
response = response_writer_->Finish(CompletionCallback());
DCHECK_EQ(OK, response);
- } else {
+ } else if (fake_response_destination_ == TEMP_FILE) {
+ // SaveResponseToFileAtPath() should be called instead of this method to
+ // save file. Asynchronous file writing using URLFetcherFileWriter is not
+ // supported.
NOTIMPLEMENTED();
+ } else {
+ NOTREACHED();
}
}

Powered by Google App Engine
This is Rietveld 408576698