diff options
author | alemate@chromium.org <alemate@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-05-12 23:21:54 +0000 |
---|---|---|
committer | alemate@chromium.org <alemate@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-05-12 23:21:54 +0000 |
commit | 1f52a5735ee2ef7f9dba863dd5fb84e749724da2 (patch) | |
tree | 200ba473e3ea9680f51cafdb5a535bcf8c4b66f6 /net/url_request | |
parent | 81c91240529d94ee4436e78f1d6f74e76c3373d8 (diff) | |
download | chromium_src-1f52a5735ee2ef7f9dba863dd5fb84e749724da2.zip chromium_src-1f52a5735ee2ef7f9dba863dd5fb84e749724da2.tar.gz chromium_src-1f52a5735ee2ef7f9dba863dd5fb84e749724da2.tar.bz2 |
Add browser test for CustomizationWallpaperDownloader.
Also implements TestURLFetcher::SaveResponseToTemporaryFile(),
and explicitly allows ScopedIO in TestURLFetcher, as it doesn't support
asynchronous IO by design.
Note to tree sheriffs: this CL can break tests using FakeURLFetcherFactory.
BUG=366614
TEST=none
Review URL: https://codereview.chromium.org/253833006
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@269907 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/url_request')
-rw-r--r-- | net/url_request/test_url_fetcher_factory.cc | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/net/url_request/test_url_fetcher_factory.cc b/net/url_request/test_url_fetcher_factory.cc index d6c6611..bd4f5e1 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(); } } |