diff options
author | hidehiko@chromium.org <hidehiko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-05-01 19:19:14 +0000 |
---|---|---|
committer | hidehiko@chromium.org <hidehiko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-05-01 19:19:14 +0000 |
commit | 1e611debaca35cbcfdbf53f84c0490ef3586f7db (patch) | |
tree | 610eb89d2836f61f24c5808c562a455d1ebd86f6 /chrome/browser/google_apis/test_util.cc | |
parent | 7190fac73c767775c3c3262524816e6507170c63 (diff) | |
download | chromium_src-1e611debaca35cbcfdbf53f84c0490ef3586f7db.zip chromium_src-1e611debaca35cbcfdbf53f84c0490ef3586f7db.tar.gz chromium_src-1e611debaca35cbcfdbf53f84c0490ef3586f7db.tar.bz2 |
Extract two testing utilities to share them among the tests.
WriteStringToFile and CreateFileOfSpecifiedSize are common patterns.
This CL extracts them and share them among some tests.
BUG=127129
TEST=Ran unit_tests
Review URL: https://chromiumcodereview.appspot.com/14771006
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@197683 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/google_apis/test_util.cc')
-rw-r--r-- | chrome/browser/google_apis/test_util.cc | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/chrome/browser/google_apis/test_util.cc b/chrome/browser/google_apis/test_util.cc index 4e7c142..93d592b 100644 --- a/chrome/browser/google_apis/test_util.cc +++ b/chrome/browser/google_apis/test_util.cc @@ -10,6 +10,7 @@ #include "base/message_loop.h" #include "base/path_service.h" #include "base/pending_task.h" +#include "base/rand_util.h" #include "base/string_util.h" #include "base/stringprintf.h" #include "base/strings/string_number_conversions.h" @@ -90,6 +91,29 @@ void RunAndQuit(const base::Closure& closure) { MessageLoop::current()->Quit(); } +bool WriteStringToFile(const base::FilePath& file_path, + const std::string& content) { + int result = file_util::WriteFile(file_path, content.data(), content.size()); + return content.size() == static_cast<size_t>(result); +} + +bool CreateFileOfSpecifiedSize(const base::FilePath& temp_dir, + size_t size, + base::FilePath* path, + std::string* data) { + if (!file_util::CreateTemporaryFileInDir(temp_dir, path)) + return false; + + if (size == 0) { + // Note: RandBytesAsString doesn't support generating an empty string. + data->clear(); + return true; + } + + *data = base::RandBytesAsString(size); + return WriteStringToFile(*path, *data); +} + scoped_ptr<base::Value> LoadJSONFile(const std::string& relative_path) { base::FilePath path = GetTestFilePath(relative_path); |