blob: 3c313e65d476d243842935d172046266cfa18dc0 [file] [log] [blame]
[email protected]330278c2012-07-05 09:43:551// Copyright (c) 2012 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]15de8142012-10-11 06:00:545#include "chrome/browser/chromeos/drive/drive_cache.h"
[email protected]21ed99072012-09-13 01:49:336
[email protected]2333b2a12013-04-26 07:22:227#include <string>
[email protected]79c3752d2012-07-17 12:10:088#include <vector>
9
[email protected]330278c2012-07-05 09:43:5510#include "base/file_util.h"
[email protected]2333b2a12013-04-26 07:22:2211#include "base/files/scoped_temp_dir.h"
[email protected]330278c2012-07-05 09:43:5512#include "base/message_loop.h"
[email protected]ddbf2052012-07-13 15:07:0213#include "base/threading/sequenced_worker_pool.h"
[email protected]15de8142012-10-11 06:00:5414#include "chrome/browser/chromeos/drive/drive.pb.h"
[email protected]cf64404b2012-12-14 07:12:5015#include "chrome/browser/chromeos/drive/fake_free_disk_space_getter.h"
[email protected]4fa2fd5d2013-04-26 03:42:5216#include "chrome/browser/chromeos/drive/file_system_util.h"
[email protected]bd547ad82013-04-26 04:52:2917#include "chrome/browser/chromeos/drive/mock_cache_observer.h"
[email protected]92931d72013-04-24 05:16:1518#include "chrome/browser/chromeos/drive/test_util.h"
[email protected]7601e182013-03-22 09:38:0219#include "chrome/browser/google_apis/test_util.h"
[email protected]330278c2012-07-05 09:43:5520#include "content/public/test/test_browser_thread.h"
21#include "testing/gmock/include/gmock/gmock.h"
22#include "testing/gtest/include/gtest/gtest.h"
23
[email protected]330278c2012-07-05 09:43:5524using ::testing::StrictMock;
25
[email protected]d9d04df2012-10-12 07:06:3526namespace drive {
[email protected]330278c2012-07-05 09:43:5527namespace {
28
[email protected]5d8abd22012-11-14 08:31:0329struct TestCacheResource {
30 const char* source_file;
31 const char* resource_id;
32 const char* md5;
33 bool is_pinned;
34 bool is_dirty;
35} const test_cache_resources[] = {
[email protected]330278c2012-07-05 09:43:5536 // Cache resource in tmp dir, i.e. not pinned or dirty.
[email protected]21ed99072012-09-13 01:49:3337 { "gdata/root_feed.json", "tmp:resource_id", "md5_tmp_alphanumeric",
[email protected]5d8abd22012-11-14 08:31:0338 false, false },
[email protected]330278c2012-07-05 09:43:5539 // Cache resource in tmp dir, i.e. not pinned or dirty, with resource_id
[email protected]5d8abd22012-11-14 08:31:0340 // containing non-alphanumeric characters.
[email protected]16696472013-04-22 05:42:2141 { "gdata/empty_feed.json", "tmp:`~!@#$%^&*()-_=+[{|]}\\;',<.>/?",
[email protected]5d8abd22012-11-14 08:31:0342 "md5_tmp_non_alphanumeric", false, false },
43 // Cache resource that is pinned and persistent.
[email protected]16696472013-04-22 05:42:2144 { "gdata/directory_entry.json", "pinned:existing", "md5_pinned_existing",
[email protected]5d8abd22012-11-14 08:31:0345 true, false },
46 // Cache resource with a non-existent source file that is pinned.
47 { "", "pinned:non-existent", "md5_pinned_non_existent", true, false },
48 // Cache resource that is dirty.
[email protected]21ed99072012-09-13 01:49:3349 { "gdata/account_metadata.json", "dirty:existing", "md5_dirty_existing",
[email protected]5d8abd22012-11-14 08:31:0350 false, true },
51 // Cache resource that is pinned and dirty.
[email protected]21ed99072012-09-13 01:49:3352 { "gdata/basic_feed.json", "dirty_and_pinned:existing",
[email protected]5d8abd22012-11-14 08:31:0353 "md5_dirty_and_pinned_existing", true, true },
[email protected]330278c2012-07-05 09:43:5554};
55
56const int64 kLotsOfSpace = kMinFreeSpace * 10;
57
58struct PathToVerify {
[email protected]650b2d52013-02-10 03:41:4559 PathToVerify(const base::FilePath& in_path_to_scan,
60 const base::FilePath& in_expected_existing_path) :
[email protected]330278c2012-07-05 09:43:5561 path_to_scan(in_path_to_scan),
62 expected_existing_path(in_expected_existing_path) {
63 }
64
[email protected]650b2d52013-02-10 03:41:4565 base::FilePath path_to_scan;
66 base::FilePath expected_existing_path;
[email protected]330278c2012-07-05 09:43:5567};
[email protected]a288c382012-07-11 20:05:4868
[email protected]d68ede02012-11-07 14:30:5369// Copies results from Iterate().
70void OnIterate(std::vector<std::string>* out_resource_ids,
71 std::vector<DriveCacheEntry>* out_cache_entries,
72 const std::string& resource_id,
73 const DriveCacheEntry& cache_entry) {
74 out_resource_ids->push_back(resource_id);
75 out_cache_entries->push_back(cache_entry);
[email protected]cd236432012-07-27 18:03:3076}
77
[email protected]d68ede02012-11-07 14:30:5378// Called upon completion of Iterate().
79void OnIterateCompleted(bool* out_is_called) {
80 *out_is_called = true;
[email protected]cd236432012-07-27 18:03:3081}
82
[email protected]4743aa1c2012-07-13 14:54:2383} // namespace
[email protected]330278c2012-07-05 09:43:5584
[email protected]fb371812012-08-22 16:05:2385class DriveCacheTest : public testing::Test {
[email protected]330278c2012-07-05 09:43:5586 protected:
[email protected]fb371812012-08-22 16:05:2387 DriveCacheTest()
[email protected]330278c2012-07-05 09:43:5588 : ui_thread_(content::BrowserThread::UI, &message_loop_),
[email protected]78a158b2013-04-23 06:57:4989 expected_error_(FILE_ERROR_OK),
[email protected]330278c2012-07-05 09:43:5590 expected_cache_state_(0),
[email protected]fb371812012-08-22 16:05:2391 expected_sub_dir_type_(DriveCache::CACHE_TYPE_META),
[email protected]330278c2012-07-05 09:43:5592 expected_success_(true),
[email protected]2333b2a12013-04-26 07:22:2293 expect_outgoing_symlink_(false) {
[email protected]330278c2012-07-05 09:43:5594 }
95
96 virtual void SetUp() OVERRIDE {
[email protected]2333b2a12013-04-26 07:22:2297 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
[email protected]cf64404b2012-12-14 07:12:5098 fake_free_disk_space_getter_.reset(new FakeFreeDiskSpaceGetter);
[email protected]330278c2012-07-05 09:43:5599
[email protected]ddbf2052012-07-13 15:07:02100 scoped_refptr<base::SequencedWorkerPool> pool =
101 content::BrowserThread::GetBlockingPool();
102 blocking_task_runner_ =
103 pool->GetSequencedTaskRunner(pool->GetSequenceToken());
[email protected]2333b2a12013-04-26 07:22:22104 cache_.reset(new DriveCache(temp_dir_.path(),
[email protected]c0a3b8e82013-03-18 21:07:45105 blocking_task_runner_,
106 fake_free_disk_space_getter_.get()));
[email protected]330278c2012-07-05 09:43:55107
[email protected]bd547ad82013-04-26 04:52:29108 mock_cache_observer_.reset(new StrictMock<MockCacheObserver>);
[email protected]4743aa1c2012-07-13 14:54:23109 cache_->AddObserver(mock_cache_observer_.get());
[email protected]330278c2012-07-05 09:43:55110
[email protected]e76fd272013-03-25 13:37:14111 bool success = false;
[email protected]77fb1a62012-11-01 13:42:32112 cache_->RequestInitialize(
[email protected]e76fd272013-03-25 13:37:14113 google_apis::test_util::CreateCopyResultCallback(&success));
[email protected]fb0fc202012-10-22 09:30:28114 google_apis::test_util::RunBlockingPoolTask();
[email protected]e76fd272013-03-25 13:37:14115 ASSERT_TRUE(success);
[email protected]330278c2012-07-05 09:43:55116 }
117
118 virtual void TearDown() OVERRIDE {
[email protected]c0a3b8e82013-03-18 21:07:45119 cache_.reset();
[email protected]330278c2012-07-05 09:43:55120 }
121
[email protected]5d8abd22012-11-14 08:31:03122 void PrepareTestCacheResources() {
[email protected]cf64404b2012-12-14 07:12:50123 fake_free_disk_space_getter_->set_fake_free_disk_space(kLotsOfSpace);
[email protected]330278c2012-07-05 09:43:55124
[email protected]5d8abd22012-11-14 08:31:03125 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_cache_resources); ++i) {
126 const struct TestCacheResource& resource = test_cache_resources[i];
127 // Copy file from data dir to cache.
128 if (!std::string(resource.source_file).empty()) {
[email protected]650b2d52013-02-10 03:41:45129 base::FilePath source_path =
[email protected]3ac6b8f2013-03-08 14:12:38130 google_apis::test_util::GetTestFilePath(
131 std::string("chromeos/") + resource.source_file);
[email protected]5d8abd22012-11-14 08:31:03132
[email protected]78a158b2013-04-23 06:57:49133 FileError error = FILE_ERROR_OK;
[email protected]717e43c2012-11-22 07:47:39134 cache_->Store(
135 resource.resource_id,
136 resource.md5,
137 source_path,
138 DriveCache::FILE_OPERATION_COPY,
[email protected]7601e182013-03-22 09:38:02139 google_apis::test_util::CreateCopyResultCallback(&error));
[email protected]5d8abd22012-11-14 08:31:03140 google_apis::test_util::RunBlockingPoolTask();
[email protected]78a158b2013-04-23 06:57:49141 EXPECT_EQ(FILE_ERROR_OK, error);
[email protected]330278c2012-07-05 09:43:55142 }
[email protected]5d8abd22012-11-14 08:31:03143 // Pin.
144 if (resource.is_pinned) {
[email protected]78a158b2013-04-23 06:57:49145 FileError error = FILE_ERROR_OK;
[email protected]5d8abd22012-11-14 08:31:03146 EXPECT_CALL(*mock_cache_observer_,
147 OnCachePinned(resource.resource_id, resource.md5)).Times(1);
[email protected]717e43c2012-11-22 07:47:39148 cache_->Pin(
149 resource.resource_id,
150 resource.md5,
[email protected]7601e182013-03-22 09:38:02151 google_apis::test_util::CreateCopyResultCallback(&error));
[email protected]5d8abd22012-11-14 08:31:03152 google_apis::test_util::RunBlockingPoolTask();
[email protected]78a158b2013-04-23 06:57:49153 EXPECT_EQ(FILE_ERROR_OK, error);
[email protected]330278c2012-07-05 09:43:55154 }
[email protected]5d8abd22012-11-14 08:31:03155 // Mark dirty.
156 if (resource.is_dirty) {
[email protected]78a158b2013-04-23 06:57:49157 FileError error = FILE_ERROR_OK;
[email protected]717e43c2012-11-22 07:47:39158 cache_->MarkDirty(
159 resource.resource_id,
160 resource.md5,
[email protected]7601e182013-03-22 09:38:02161 google_apis::test_util::CreateCopyResultCallback(&error));
[email protected]5d8abd22012-11-14 08:31:03162 google_apis::test_util::RunBlockingPoolTask();
[email protected]78a158b2013-04-23 06:57:49163 EXPECT_EQ(FILE_ERROR_OK, error);
[email protected]330278c2012-07-05 09:43:55164
[email protected]5d8abd22012-11-14 08:31:03165 EXPECT_CALL(*mock_cache_observer_,
166 OnCacheCommitted(resource.resource_id)).Times(1);
[email protected]717e43c2012-11-22 07:47:39167 cache_->CommitDirty(
168 resource.resource_id,
169 resource.md5,
[email protected]7601e182013-03-22 09:38:02170 google_apis::test_util::CreateCopyResultCallback(&error));
[email protected]5d8abd22012-11-14 08:31:03171 google_apis::test_util::RunBlockingPoolTask();
[email protected]78a158b2013-04-23 06:57:49172 EXPECT_EQ(FILE_ERROR_OK, error);
[email protected]330278c2012-07-05 09:43:55173 }
174 }
[email protected]330278c2012-07-05 09:43:55175 }
176
177 void TestGetFileFromCacheByResourceIdAndMd5(
178 const std::string& resource_id,
179 const std::string& md5,
[email protected]78a158b2013-04-23 06:57:49180 FileError expected_error,
[email protected]330278c2012-07-05 09:43:55181 const std::string& expected_file_extension) {
[email protected]78a158b2013-04-23 06:57:49182 FileError error = FILE_ERROR_OK;
[email protected]650b2d52013-02-10 03:41:45183 base::FilePath cache_file_path;
[email protected]e76fd272013-03-25 13:37:14184 cache_->GetFile(resource_id, md5,
185 google_apis::test_util::CreateCopyResultCallback(
186 &error, &cache_file_path));
[email protected]fb0fc202012-10-22 09:30:28187 google_apis::test_util::RunBlockingPoolTask();
[email protected]717e43c2012-11-22 07:47:39188
189 EXPECT_EQ(expected_error, error);
[email protected]78a158b2013-04-23 06:57:49190 if (error == FILE_ERROR_OK) {
[email protected]717e43c2012-11-22 07:47:39191 // Verify filename of |cache_file_path|.
[email protected]650b2d52013-02-10 03:41:45192 base::FilePath base_name = cache_file_path.BaseName();
[email protected]717e43c2012-11-22 07:47:39193 EXPECT_EQ(util::EscapeCacheFileName(resource_id) +
[email protected]650b2d52013-02-10 03:41:45194 base::FilePath::kExtensionSeparator +
[email protected]717e43c2012-11-22 07:47:39195 util::EscapeCacheFileName(
196 expected_file_extension.empty() ?
197 md5 : expected_file_extension),
198 base_name.value());
199 } else {
200 EXPECT_TRUE(cache_file_path.empty());
201 }
[email protected]330278c2012-07-05 09:43:55202 }
203
204 void TestStoreToCache(
205 const std::string& resource_id,
206 const std::string& md5,
[email protected]650b2d52013-02-10 03:41:45207 const base::FilePath& source_path,
[email protected]78a158b2013-04-23 06:57:49208 FileError expected_error,
[email protected]330278c2012-07-05 09:43:55209 int expected_cache_state,
[email protected]fb371812012-08-22 16:05:23210 DriveCache::CacheSubDirectoryType expected_sub_dir_type) {
[email protected]330278c2012-07-05 09:43:55211 expected_error_ = expected_error;
212 expected_cache_state_ = expected_cache_state;
213 expected_sub_dir_type_ = expected_sub_dir_type;
214
[email protected]78a158b2013-04-23 06:57:49215 FileError error = FILE_ERROR_OK;
[email protected]77fb1a62012-11-01 13:42:32216 cache_->Store(resource_id, md5, source_path,
217 DriveCache::FILE_OPERATION_COPY,
[email protected]7601e182013-03-22 09:38:02218 google_apis::test_util::CreateCopyResultCallback(&error));
[email protected]fb0fc202012-10-22 09:30:28219 google_apis::test_util::RunBlockingPoolTask();
[email protected]2a2c4152012-11-26 11:34:50220 VerifyCacheFileState(error, resource_id, md5);
[email protected]330278c2012-07-05 09:43:55221 }
222
223 void TestRemoveFromCache(const std::string& resource_id,
[email protected]78a158b2013-04-23 06:57:49224 FileError expected_error) {
[email protected]330278c2012-07-05 09:43:55225 expected_error_ = expected_error;
226
[email protected]78a158b2013-04-23 06:57:49227 FileError error = FILE_ERROR_OK;
[email protected]2a2c4152012-11-26 11:34:50228 cache_->Remove(
229 resource_id,
[email protected]7601e182013-03-22 09:38:02230 google_apis::test_util::CreateCopyResultCallback(&error));
[email protected]fb0fc202012-10-22 09:30:28231 google_apis::test_util::RunBlockingPoolTask();
[email protected]2a2c4152012-11-26 11:34:50232 VerifyRemoveFromCache(error, resource_id, "");
[email protected]330278c2012-07-05 09:43:55233 }
234
[email protected]78a158b2013-04-23 06:57:49235 void VerifyRemoveFromCache(FileError error,
[email protected]330278c2012-07-05 09:43:55236 const std::string& resource_id,
237 const std::string& md5) {
[email protected]330278c2012-07-05 09:43:55238 EXPECT_EQ(expected_error_, error);
239
240 // Verify cache map.
[email protected]28a64092012-08-21 10:01:12241 DriveCacheEntry cache_entry;
[email protected]b22f87f2012-07-12 10:53:17242 const bool cache_entry_found =
243 GetCacheEntryFromOriginThread(resource_id, md5, &cache_entry);
244 if (cache_entry_found)
[email protected]02821102012-07-12 20:19:17245 EXPECT_TRUE(cache_entry.is_dirty());
[email protected]330278c2012-07-05 09:43:55246
247 // If entry doesn't exist, verify that:
248 // - no files with "<resource_id>.* exists in persistent and tmp dirs
249 // - no "<resource_id>" symlink exists in pinned and outgoing dirs.
250 std::vector<PathToVerify> paths_to_verify;
251 paths_to_verify.push_back( // Index 0: CACHE_TYPE_TMP.
252 PathToVerify(cache_->GetCacheFilePath(resource_id, "*",
[email protected]fb371812012-08-22 16:05:23253 DriveCache::CACHE_TYPE_TMP,
[email protected]650b2d52013-02-10 03:41:45254 DriveCache::CACHED_FILE_FROM_SERVER), base::FilePath()));
[email protected]330278c2012-07-05 09:43:55255 paths_to_verify.push_back( // Index 1: CACHE_TYPE_PERSISTENT.
256 PathToVerify(cache_->GetCacheFilePath(resource_id, "*",
[email protected]fb371812012-08-22 16:05:23257 DriveCache::CACHE_TYPE_PERSISTENT,
[email protected]650b2d52013-02-10 03:41:45258 DriveCache::CACHED_FILE_FROM_SERVER), base::FilePath()));
[email protected]ae248f02013-03-06 12:55:41259 paths_to_verify.push_back( // Index 2: CACHE_TYPE_OUTGOING.
[email protected]330278c2012-07-05 09:43:55260 PathToVerify(cache_->GetCacheFilePath(resource_id, "",
[email protected]fb371812012-08-22 16:05:23261 DriveCache::CACHE_TYPE_OUTGOING,
[email protected]650b2d52013-02-10 03:41:45262 DriveCache::CACHED_FILE_FROM_SERVER), base::FilePath()));
[email protected]b22f87f2012-07-12 10:53:17263 if (!cache_entry_found) {
[email protected]330278c2012-07-05 09:43:55264 for (size_t i = 0; i < paths_to_verify.size(); ++i) {
265 file_util::FileEnumerator enumerator(
266 paths_to_verify[i].path_to_scan.DirName(), false /* not recursive*/,
[email protected]84c3f162012-08-12 01:57:23267 file_util::FileEnumerator::FILES |
268 file_util::FileEnumerator::SHOW_SYM_LINKS,
[email protected]330278c2012-07-05 09:43:55269 paths_to_verify[i].path_to_scan.BaseName().value());
270 EXPECT_TRUE(enumerator.Next().empty());
271 }
272 } else {
273 // Entry is dirty, verify that:
274 // - no files with "<resource_id>.*" exist in tmp dir
275 // - only 1 "<resource_id>.local" exists in persistent dir
276 // - only 1 <resource_id> exists in outgoing dir
277 // - if entry is pinned, only 1 <resource_id> exists in pinned dir.
278
279 // Change expected_existing_path of CACHE_TYPE_PERSISTENT (index 1).
280 paths_to_verify[1].expected_existing_path =
281 GetCacheFilePath(resource_id,
282 std::string(),
[email protected]fb371812012-08-22 16:05:23283 DriveCache::CACHE_TYPE_PERSISTENT,
284 DriveCache::CACHED_FILE_LOCALLY_MODIFIED);
[email protected]330278c2012-07-05 09:43:55285
[email protected]ae248f02013-03-06 12:55:41286 // Change expected_existing_path of CACHE_TYPE_OUTGOING (index 2).
287 paths_to_verify[2].expected_existing_path =
[email protected]330278c2012-07-05 09:43:55288 GetCacheFilePath(resource_id,
289 std::string(),
[email protected]fb371812012-08-22 16:05:23290 DriveCache::CACHE_TYPE_OUTGOING,
291 DriveCache::CACHED_FILE_FROM_SERVER);
[email protected]330278c2012-07-05 09:43:55292
[email protected]330278c2012-07-05 09:43:55293 for (size_t i = 0; i < paths_to_verify.size(); ++i) {
294 const struct PathToVerify& verify = paths_to_verify[i];
295 file_util::FileEnumerator enumerator(
[email protected]84c3f162012-08-12 01:57:23296 verify.path_to_scan.DirName(), false /* not recursive */,
297 file_util::FileEnumerator::FILES |
298 file_util::FileEnumerator::SHOW_SYM_LINKS,
[email protected]330278c2012-07-05 09:43:55299 verify.path_to_scan.BaseName().value());
300 size_t num_files_found = 0;
[email protected]650b2d52013-02-10 03:41:45301 for (base::FilePath current = enumerator.Next(); !current.empty();
[email protected]330278c2012-07-05 09:43:55302 current = enumerator.Next()) {
303 ++num_files_found;
304 EXPECT_EQ(verify.expected_existing_path, current);
305 }
306 if (verify.expected_existing_path.empty())
307 EXPECT_EQ(0U, num_files_found);
308 else
309 EXPECT_EQ(1U, num_files_found);
310 }
311 }
312 }
313
314 void TestPin(
315 const std::string& resource_id,
316 const std::string& md5,
[email protected]78a158b2013-04-23 06:57:49317 FileError expected_error,
[email protected]330278c2012-07-05 09:43:55318 int expected_cache_state,
[email protected]fb371812012-08-22 16:05:23319 DriveCache::CacheSubDirectoryType expected_sub_dir_type) {
[email protected]330278c2012-07-05 09:43:55320 expected_error_ = expected_error;
321 expected_cache_state_ = expected_cache_state;
322 expected_sub_dir_type_ = expected_sub_dir_type;
323
[email protected]78a158b2013-04-23 06:57:49324 FileError error = FILE_ERROR_OK;
[email protected]77fb1a62012-11-01 13:42:32325 cache_->Pin(resource_id, md5,
[email protected]7601e182013-03-22 09:38:02326 google_apis::test_util::CreateCopyResultCallback(&error));
[email protected]fb0fc202012-10-22 09:30:28327 google_apis::test_util::RunBlockingPoolTask();
[email protected]2a2c4152012-11-26 11:34:50328 VerifyCacheFileState(error, resource_id, md5);
[email protected]330278c2012-07-05 09:43:55329 }
330
331 void TestUnpin(
332 const std::string& resource_id,
333 const std::string& md5,
[email protected]78a158b2013-04-23 06:57:49334 FileError expected_error,
[email protected]330278c2012-07-05 09:43:55335 int expected_cache_state,
[email protected]fb371812012-08-22 16:05:23336 DriveCache::CacheSubDirectoryType expected_sub_dir_type) {
[email protected]330278c2012-07-05 09:43:55337 expected_error_ = expected_error;
338 expected_cache_state_ = expected_cache_state;
339 expected_sub_dir_type_ = expected_sub_dir_type;
340
[email protected]78a158b2013-04-23 06:57:49341 FileError error = FILE_ERROR_OK;
[email protected]77fb1a62012-11-01 13:42:32342 cache_->Unpin(resource_id, md5,
[email protected]7601e182013-03-22 09:38:02343 google_apis::test_util::CreateCopyResultCallback(&error));
[email protected]fb0fc202012-10-22 09:30:28344 google_apis::test_util::RunBlockingPoolTask();
[email protected]2a2c4152012-11-26 11:34:50345 VerifyCacheFileState(error, resource_id, md5);
[email protected]330278c2012-07-05 09:43:55346 }
347
[email protected]bc809e42012-11-28 04:46:29348 void TestMarkDirty(const std::string& resource_id,
349 const std::string& md5,
[email protected]78a158b2013-04-23 06:57:49350 FileError expected_error,
[email protected]bc809e42012-11-28 04:46:29351 int expected_cache_state,
352 DriveCache::CacheSubDirectoryType expected_sub_dir_type) {
[email protected]330278c2012-07-05 09:43:55353 expected_error_ = expected_error;
354 expected_cache_state_ = expected_cache_state;
355 expected_sub_dir_type_ = expected_sub_dir_type;
356 expect_outgoing_symlink_ = false;
357
[email protected]78a158b2013-04-23 06:57:49358 FileError error = FILE_ERROR_OK;
[email protected]717e43c2012-11-22 07:47:39359 cache_->MarkDirty(
360 resource_id, md5,
[email protected]7601e182013-03-22 09:38:02361 google_apis::test_util::CreateCopyResultCallback(&error));
[email protected]fb0fc202012-10-22 09:30:28362 google_apis::test_util::RunBlockingPoolTask();
[email protected]330278c2012-07-05 09:43:55363
[email protected]330278c2012-07-05 09:43:55364 VerifyCacheFileState(error, resource_id, md5);
365
[email protected]bc809e42012-11-28 04:46:29366 // Verify filename.
[email protected]78a158b2013-04-23 06:57:49367 if (error == FILE_ERROR_OK) {
[email protected]650b2d52013-02-10 03:41:45368 base::FilePath cache_file_path;
[email protected]e76fd272013-03-25 13:37:14369 cache_->GetFile(resource_id, md5,
370 google_apis::test_util::CreateCopyResultCallback(
371 &error, &cache_file_path));
[email protected]bc809e42012-11-28 04:46:29372 google_apis::test_util::RunBlockingPoolTask();
373
[email protected]78a158b2013-04-23 06:57:49374 EXPECT_EQ(FILE_ERROR_OK, error);
[email protected]650b2d52013-02-10 03:41:45375 base::FilePath base_name = cache_file_path.BaseName();
[email protected]330278c2012-07-05 09:43:55376 EXPECT_EQ(util::EscapeCacheFileName(resource_id) +
[email protected]650b2d52013-02-10 03:41:45377 base::FilePath::kExtensionSeparator +
[email protected]330278c2012-07-05 09:43:55378 "local",
379 base_name.value());
[email protected]330278c2012-07-05 09:43:55380 }
381 }
382
383 void TestCommitDirty(
384 const std::string& resource_id,
385 const std::string& md5,
[email protected]78a158b2013-04-23 06:57:49386 FileError expected_error,
[email protected]330278c2012-07-05 09:43:55387 int expected_cache_state,
[email protected]fb371812012-08-22 16:05:23388 DriveCache::CacheSubDirectoryType expected_sub_dir_type) {
[email protected]330278c2012-07-05 09:43:55389 expected_error_ = expected_error;
390 expected_cache_state_ = expected_cache_state;
391 expected_sub_dir_type_ = expected_sub_dir_type;
392 expect_outgoing_symlink_ = true;
393
[email protected]78a158b2013-04-23 06:57:49394 FileError error = FILE_ERROR_OK;
[email protected]717e43c2012-11-22 07:47:39395 cache_->CommitDirty(
396 resource_id, md5,
[email protected]7601e182013-03-22 09:38:02397 google_apis::test_util::CreateCopyResultCallback(&error));
[email protected]fb0fc202012-10-22 09:30:28398 google_apis::test_util::RunBlockingPoolTask();
[email protected]2a2c4152012-11-26 11:34:50399 VerifyCacheFileState(error, resource_id, md5);
[email protected]330278c2012-07-05 09:43:55400 }
401
402 void TestClearDirty(
403 const std::string& resource_id,
404 const std::string& md5,
[email protected]78a158b2013-04-23 06:57:49405 FileError expected_error,
[email protected]330278c2012-07-05 09:43:55406 int expected_cache_state,
[email protected]fb371812012-08-22 16:05:23407 DriveCache::CacheSubDirectoryType expected_sub_dir_type) {
[email protected]330278c2012-07-05 09:43:55408 expected_error_ = expected_error;
409 expected_cache_state_ = expected_cache_state;
410 expected_sub_dir_type_ = expected_sub_dir_type;
411 expect_outgoing_symlink_ = false;
412
[email protected]78a158b2013-04-23 06:57:49413 FileError error = FILE_ERROR_OK;
[email protected]717e43c2012-11-22 07:47:39414 cache_->ClearDirty(
415 resource_id, md5,
[email protected]7601e182013-03-22 09:38:02416 google_apis::test_util::CreateCopyResultCallback(&error));
[email protected]fb0fc202012-10-22 09:30:28417 google_apis::test_util::RunBlockingPoolTask();
[email protected]2a2c4152012-11-26 11:34:50418 VerifyCacheFileState(error, resource_id, md5);
[email protected]330278c2012-07-05 09:43:55419 }
420
[email protected]9564c1502012-11-28 12:12:16421 void TestMarkAsMounted(
[email protected]330278c2012-07-05 09:43:55422 const std::string& resource_id,
423 const std::string& md5,
[email protected]78a158b2013-04-23 06:57:49424 FileError expected_error,
[email protected]330278c2012-07-05 09:43:55425 int expected_cache_state,
[email protected]fb371812012-08-22 16:05:23426 DriveCache::CacheSubDirectoryType expected_sub_dir_type) {
[email protected]330278c2012-07-05 09:43:55427 expected_error_ = expected_error;
428 expected_cache_state_ = expected_cache_state;
429 expected_sub_dir_type_ = expected_sub_dir_type;
430 expect_outgoing_symlink_ = false;
431
[email protected]78a158b2013-04-23 06:57:49432 FileError error = FILE_ERROR_OK;
[email protected]650b2d52013-02-10 03:41:45433 base::FilePath cache_file_path;
[email protected]e76fd272013-03-25 13:37:14434 cache_->MarkAsMounted(resource_id, md5,
435 google_apis::test_util::CreateCopyResultCallback(
436 &error, &cache_file_path));
[email protected]fb0fc202012-10-22 09:30:28437 google_apis::test_util::RunBlockingPoolTask();
[email protected]330278c2012-07-05 09:43:55438
[email protected]717e43c2012-11-22 07:47:39439 EXPECT_TRUE(file_util::PathExists(cache_file_path));
440 EXPECT_EQ(cache_file_path,
441 cache_->GetCacheFilePath(resource_id,
442 md5,
443 expected_sub_dir_type_,
[email protected]9564c1502012-11-28 12:12:16444 DriveCache::CACHED_FILE_MOUNTED));
445 }
446
447 void TestMarkAsUnmounted(
448 const std::string& resource_id,
449 const std::string& md5,
[email protected]650b2d52013-02-10 03:41:45450 const base::FilePath& file_path,
[email protected]78a158b2013-04-23 06:57:49451 FileError expected_error,
[email protected]9564c1502012-11-28 12:12:16452 int expected_cache_state,
453 DriveCache::CacheSubDirectoryType expected_sub_dir_type) {
454 expected_error_ = expected_error;
455 expected_cache_state_ = expected_cache_state;
456 expected_sub_dir_type_ = expected_sub_dir_type;
457 expect_outgoing_symlink_ = false;
458
[email protected]78a158b2013-04-23 06:57:49459 FileError error = FILE_ERROR_OK;
[email protected]9564c1502012-11-28 12:12:16460 cache_->MarkAsUnmounted(
461 file_path,
[email protected]7601e182013-03-22 09:38:02462 google_apis::test_util::CreateCopyResultCallback(&error));
[email protected]9564c1502012-11-28 12:12:16463 google_apis::test_util::RunBlockingPoolTask();
464
[email protected]650b2d52013-02-10 03:41:45465 base::FilePath cache_file_path;
[email protected]e76fd272013-03-25 13:37:14466 cache_->GetFile(resource_id, md5,
467 google_apis::test_util::CreateCopyResultCallback(
468 &error, &cache_file_path));
[email protected]9564c1502012-11-28 12:12:16469 google_apis::test_util::RunBlockingPoolTask();
[email protected]78a158b2013-04-23 06:57:49470 EXPECT_EQ(FILE_ERROR_OK, error);
[email protected]9564c1502012-11-28 12:12:16471
472 EXPECT_TRUE(file_util::PathExists(cache_file_path));
473 EXPECT_EQ(cache_file_path,
474 cache_->GetCacheFilePath(resource_id,
475 md5,
476 expected_sub_dir_type_,
[email protected]717e43c2012-11-22 07:47:39477 DriveCache::CACHED_FILE_FROM_SERVER));
[email protected]330278c2012-07-05 09:43:55478 }
479
[email protected]78a158b2013-04-23 06:57:49480 void VerifyCacheFileState(FileError error,
[email protected]330278c2012-07-05 09:43:55481 const std::string& resource_id,
482 const std::string& md5) {
[email protected]330278c2012-07-05 09:43:55483 EXPECT_EQ(expected_error_, error);
484
485 // Verify cache map.
[email protected]28a64092012-08-21 10:01:12486 DriveCacheEntry cache_entry;
[email protected]b22f87f2012-07-12 10:53:17487 const bool cache_entry_found =
488 GetCacheEntryFromOriginThread(resource_id, md5, &cache_entry);
[email protected]02821102012-07-12 20:19:17489 if (test_util::ToCacheEntry(expected_cache_state_).is_present() ||
490 test_util::ToCacheEntry(expected_cache_state_).is_pinned()) {
[email protected]b22f87f2012-07-12 10:53:17491 ASSERT_TRUE(cache_entry_found);
[email protected]48477fe2012-07-12 17:45:08492 EXPECT_TRUE(test_util::CacheStatesEqual(
493 test_util::ToCacheEntry(expected_cache_state_),
494 cache_entry));
[email protected]fae353a2012-07-11 23:30:27495 EXPECT_EQ(expected_sub_dir_type_,
[email protected]fb371812012-08-22 16:05:23496 DriveCache::GetSubDirectoryType(cache_entry));
[email protected]330278c2012-07-05 09:43:55497 } else {
[email protected]b22f87f2012-07-12 10:53:17498 EXPECT_FALSE(cache_entry_found);
[email protected]330278c2012-07-05 09:43:55499 }
500
501 // Verify actual cache file.
[email protected]650b2d52013-02-10 03:41:45502 base::FilePath dest_path = cache_->GetCacheFilePath(
[email protected]330278c2012-07-05 09:43:55503 resource_id,
504 md5,
[email protected]02821102012-07-12 20:19:17505 test_util::ToCacheEntry(expected_cache_state_).is_pinned() ||
506 test_util::ToCacheEntry(expected_cache_state_).is_dirty() ?
[email protected]fb371812012-08-22 16:05:23507 DriveCache::CACHE_TYPE_PERSISTENT :
508 DriveCache::CACHE_TYPE_TMP,
[email protected]02821102012-07-12 20:19:17509 test_util::ToCacheEntry(expected_cache_state_).is_dirty() ?
[email protected]fb371812012-08-22 16:05:23510 DriveCache::CACHED_FILE_LOCALLY_MODIFIED :
511 DriveCache::CACHED_FILE_FROM_SERVER);
[email protected]330278c2012-07-05 09:43:55512 bool exists = file_util::PathExists(dest_path);
[email protected]02821102012-07-12 20:19:17513 if (test_util::ToCacheEntry(expected_cache_state_).is_present())
[email protected]330278c2012-07-05 09:43:55514 EXPECT_TRUE(exists);
515 else
516 EXPECT_FALSE(exists);
517
[email protected]330278c2012-07-05 09:43:55518 // Verify symlink in outgoing dir.
[email protected]ae248f02013-03-06 12:55:41519 base::FilePath symlink_path = cache_->GetCacheFilePath(
[email protected]330278c2012-07-05 09:43:55520 resource_id,
521 std::string(),
[email protected]fb371812012-08-22 16:05:23522 DriveCache::CACHE_TYPE_OUTGOING,
523 DriveCache::CACHED_FILE_FROM_SERVER);
[email protected]fba59542012-12-18 06:05:38524 // Check that outgoing symlink exists, without dereferencing to target path.
[email protected]330278c2012-07-05 09:43:55525 exists = file_util::IsLink(symlink_path);
526 if (expect_outgoing_symlink_ &&
[email protected]02821102012-07-12 20:19:17527 test_util::ToCacheEntry(expected_cache_state_).is_dirty()) {
[email protected]330278c2012-07-05 09:43:55528 EXPECT_TRUE(exists);
[email protected]650b2d52013-02-10 03:41:45529 base::FilePath target_path;
[email protected]330278c2012-07-05 09:43:55530 EXPECT_TRUE(file_util::ReadSymbolicLink(symlink_path, &target_path));
[email protected]2333b2a12013-04-26 07:22:22531 EXPECT_NE(util::kSymLinkToDevNull, target_path.value());
[email protected]02821102012-07-12 20:19:17532 if (test_util::ToCacheEntry(expected_cache_state_).is_present())
[email protected]330278c2012-07-05 09:43:55533 EXPECT_EQ(dest_path, target_path);
534 } else {
535 EXPECT_FALSE(exists);
536 }
537 }
538
[email protected]650b2d52013-02-10 03:41:45539 base::FilePath GetCacheFilePath(const std::string& resource_id,
[email protected]330278c2012-07-05 09:43:55540 const std::string& md5,
[email protected]fb371812012-08-22 16:05:23541 DriveCache::CacheSubDirectoryType sub_dir_type,
542 DriveCache::CachedFileOrigin file_origin) {
[email protected]330278c2012-07-05 09:43:55543 return cache_->GetCacheFilePath(resource_id, md5, sub_dir_type,
544 file_origin);
545 }
546
547 // Helper function to call GetCacheEntry from origin thread.
[email protected]b22f87f2012-07-12 10:53:17548 bool GetCacheEntryFromOriginThread(const std::string& resource_id,
549 const std::string& md5,
[email protected]28a64092012-08-21 10:01:12550 DriveCacheEntry* cache_entry) {
[email protected]b22f87f2012-07-12 10:53:17551 bool result = false;
[email protected]e76fd272013-03-25 13:37:14552 cache_->GetCacheEntry(resource_id, md5,
553 google_apis::test_util::CreateCopyResultCallback(
554 &result, cache_entry));
[email protected]fb0fc202012-10-22 09:30:28555 google_apis::test_util::RunBlockingPoolTask();
[email protected]b22f87f2012-07-12 10:53:17556 return result;
[email protected]330278c2012-07-05 09:43:55557 }
558
[email protected]330278c2012-07-05 09:43:55559 // Returns true if the cache entry exists for the given resource ID and MD5.
560 bool CacheEntryExists(const std::string& resource_id,
561 const std::string& md5) {
[email protected]28a64092012-08-21 10:01:12562 DriveCacheEntry cache_entry;
[email protected]b22f87f2012-07-12 10:53:17563 return GetCacheEntryFromOriginThread(resource_id, md5, &cache_entry);
[email protected]330278c2012-07-05 09:43:55564 }
565
566 void TestGetCacheFilePath(const std::string& resource_id,
567 const std::string& md5,
568 const std::string& expected_filename) {
[email protected]650b2d52013-02-10 03:41:45569 base::FilePath actual_path = cache_->GetCacheFilePath(
[email protected]330278c2012-07-05 09:43:55570 resource_id,
571 md5,
[email protected]fb371812012-08-22 16:05:23572 DriveCache::CACHE_TYPE_TMP,
573 DriveCache::CACHED_FILE_FROM_SERVER);
[email protected]650b2d52013-02-10 03:41:45574 base::FilePath expected_path =
[email protected]fb371812012-08-22 16:05:23575 cache_->GetCacheDirectoryPath(DriveCache::CACHE_TYPE_TMP);
[email protected]2333b2a12013-04-26 07:22:22576 expected_path = expected_path.Append(
577 base::FilePath::FromUTF8Unsafe(expected_filename));
[email protected]330278c2012-07-05 09:43:55578 EXPECT_EQ(expected_path, actual_path);
579
[email protected]650b2d52013-02-10 03:41:45580 base::FilePath base_name = actual_path.BaseName();
[email protected]330278c2012-07-05 09:43:55581
[email protected]650b2d52013-02-10 03:41:45582 // base::FilePath::Extension returns ".", so strip it.
[email protected]330278c2012-07-05 09:43:55583 std::string unescaped_md5 = util::UnescapeCacheFileName(
584 base_name.Extension().substr(1));
585 EXPECT_EQ(md5, unescaped_md5);
586 std::string unescaped_resource_id = util::UnescapeCacheFileName(
587 base_name.RemoveExtension().value());
588 EXPECT_EQ(resource_id, unescaped_resource_id);
589 }
590
[email protected]f861b392012-08-03 20:41:12591 // Returns the number of the cache files with name <resource_id>, and Confirm
592 // that they have the <md5>. This should return 1 or 0.
593 size_t CountCacheFiles(const std::string& resource_id,
594 const std::string& md5) {
[email protected]650b2d52013-02-10 03:41:45595 base::FilePath path = GetCacheFilePath(
[email protected]f861b392012-08-03 20:41:12596 resource_id, "*",
597 (test_util::ToCacheEntry(expected_cache_state_).is_pinned() ?
[email protected]fb371812012-08-22 16:05:23598 DriveCache::CACHE_TYPE_PERSISTENT :
599 DriveCache::CACHE_TYPE_TMP),
600 DriveCache::CACHED_FILE_FROM_SERVER);
[email protected]f861b392012-08-03 20:41:12601 file_util::FileEnumerator enumerator(path.DirName(), false,
602 file_util::FileEnumerator::FILES,
603 path.BaseName().value());
604 size_t num_files_found = 0;
[email protected]650b2d52013-02-10 03:41:45605 for (base::FilePath current = enumerator.Next(); !current.empty();
[email protected]f861b392012-08-03 20:41:12606 current = enumerator.Next()) {
607 ++num_files_found;
608 EXPECT_EQ(util::EscapeCacheFileName(resource_id) +
[email protected]650b2d52013-02-10 03:41:45609 base::FilePath::kExtensionSeparator +
[email protected]f861b392012-08-03 20:41:12610 util::EscapeCacheFileName(md5),
611 current.BaseName().value());
612 }
613 return num_files_found;
614 }
615
[email protected]330278c2012-07-05 09:43:55616 MessageLoopForUI message_loop_;
[email protected]330278c2012-07-05 09:43:55617 content::TestBrowserThread ui_thread_;
[email protected]ddbf2052012-07-13 15:07:02618 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_;
[email protected]2333b2a12013-04-26 07:22:22619 base::ScopedTempDir temp_dir_;
620
[email protected]c0a3b8e82013-03-18 21:07:45621 scoped_ptr<DriveCache, test_util::DestroyHelperForTests> cache_;
[email protected]cf64404b2012-12-14 07:12:50622 scoped_ptr<FakeFreeDiskSpaceGetter> fake_free_disk_space_getter_;
[email protected]bd547ad82013-04-26 04:52:29623 scoped_ptr<StrictMock<MockCacheObserver> > mock_cache_observer_;
[email protected]330278c2012-07-05 09:43:55624
[email protected]78a158b2013-04-23 06:57:49625 FileError expected_error_;
[email protected]330278c2012-07-05 09:43:55626 int expected_cache_state_;
[email protected]fb371812012-08-22 16:05:23627 DriveCache::CacheSubDirectoryType expected_sub_dir_type_;
[email protected]330278c2012-07-05 09:43:55628 bool expected_success_;
629 bool expect_outgoing_symlink_;
630 std::string expected_file_extension_;
[email protected]330278c2012-07-05 09:43:55631};
632
[email protected]fb371812012-08-22 16:05:23633TEST_F(DriveCacheTest, GetCacheFilePath) {
[email protected]330278c2012-07-05 09:43:55634 // Use alphanumeric characters for resource id.
635 std::string resource_id("pdf:1a2b");
636 std::string md5("abcdef0123456789");
637 TestGetCacheFilePath(resource_id, md5,
[email protected]650b2d52013-02-10 03:41:45638 resource_id + base::FilePath::kExtensionSeparator + md5);
[email protected]330278c2012-07-05 09:43:55639
640 // Use non-alphanumeric characters for resource id, including '.' which is an
641 // extension separator, to test that the characters are escaped and unescaped
642 // correctly, and '.' doesn't mess up the filename format and operations.
643 resource_id = "pdf:`~!@#$%^&*()-_=+[{|]}\\;',<.>/?";
644 std::string escaped_resource_id = util::EscapeCacheFileName(resource_id);
645 std::string escaped_md5 = util::EscapeCacheFileName(md5);
[email protected]650b2d52013-02-10 03:41:45646 TestGetCacheFilePath(
647 resource_id, md5, escaped_resource_id +
648 base::FilePath::kExtensionSeparator + escaped_md5);
[email protected]330278c2012-07-05 09:43:55649}
650
[email protected]fb371812012-08-22 16:05:23651TEST_F(DriveCacheTest, StoreToCacheSimple) {
[email protected]cf64404b2012-12-14 07:12:50652 fake_free_disk_space_getter_->set_fake_free_disk_space(kLotsOfSpace);
[email protected]f0c67002012-08-15 04:10:38653
[email protected]330278c2012-07-05 09:43:55654 std::string resource_id("pdf:1a2b");
655 std::string md5("abcdef0123456789");
656
657 // Store an existing file.
[email protected]fb0fc202012-10-22 09:30:28658 TestStoreToCache(
659 resource_id, md5,
[email protected]3ac6b8f2013-03-08 14:12:38660 google_apis::test_util::GetTestFilePath("chromeos/gdata/root_feed.json"),
[email protected]78a158b2013-04-23 06:57:49661 FILE_ERROR_OK, test_util::TEST_CACHE_STATE_PRESENT,
[email protected]fb0fc202012-10-22 09:30:28662 DriveCache::CACHE_TYPE_TMP);
[email protected]330278c2012-07-05 09:43:55663
664 // Store a non-existent file to the same |resource_id| and |md5|.
[email protected]650b2d52013-02-10 03:41:45665 TestStoreToCache(resource_id, md5, base::FilePath("./non_existent.json"),
[email protected]78a158b2013-04-23 06:57:49666 FILE_ERROR_FAILED,
[email protected]02821102012-07-12 20:19:17667 test_util::TEST_CACHE_STATE_PRESENT,
[email protected]fb371812012-08-22 16:05:23668 DriveCache::CACHE_TYPE_TMP);
[email protected]330278c2012-07-05 09:43:55669
670 // Store a different existing file to the same |resource_id| but different
671 // |md5|.
672 md5 = "new_md5";
[email protected]fb0fc202012-10-22 09:30:28673 TestStoreToCache(
674 resource_id, md5,
[email protected]3ac6b8f2013-03-08 14:12:38675 google_apis::test_util::GetTestFilePath(
[email protected]16696472013-04-22 05:42:21676 "chromeos/gdata/empty_feed.json"),
[email protected]78a158b2013-04-23 06:57:49677 FILE_ERROR_OK, test_util::TEST_CACHE_STATE_PRESENT,
[email protected]fb0fc202012-10-22 09:30:28678 DriveCache::CACHE_TYPE_TMP);
[email protected]330278c2012-07-05 09:43:55679
680 // Verify that there's only one file with name <resource_id>, i.e. previously
681 // cached file with the different md5 should be deleted.
[email protected]f861b392012-08-03 20:41:12682 EXPECT_EQ(1U, CountCacheFiles(resource_id, md5));
[email protected]330278c2012-07-05 09:43:55683}
684
[email protected]fb371812012-08-22 16:05:23685TEST_F(DriveCacheTest, GetFromCacheSimple) {
[email protected]cf64404b2012-12-14 07:12:50686 fake_free_disk_space_getter_->set_fake_free_disk_space(kLotsOfSpace);
[email protected]f0c67002012-08-15 04:10:38687
[email protected]330278c2012-07-05 09:43:55688 std::string resource_id("pdf:1a2b");
689 std::string md5("abcdef0123456789");
690 // First store a file to cache.
[email protected]fb0fc202012-10-22 09:30:28691 TestStoreToCache(
692 resource_id, md5,
[email protected]3ac6b8f2013-03-08 14:12:38693 google_apis::test_util::GetTestFilePath("chromeos/gdata/root_feed.json"),
[email protected]78a158b2013-04-23 06:57:49694 FILE_ERROR_OK, test_util::TEST_CACHE_STATE_PRESENT,
[email protected]fb0fc202012-10-22 09:30:28695 DriveCache::CACHE_TYPE_TMP);
[email protected]330278c2012-07-05 09:43:55696
697 // Then try to get the existing file from cache.
[email protected]330278c2012-07-05 09:43:55698 TestGetFileFromCacheByResourceIdAndMd5(
[email protected]78a158b2013-04-23 06:57:49699 resource_id, md5, FILE_ERROR_OK, md5);
[email protected]330278c2012-07-05 09:43:55700
701 // Get file from cache with same resource id as existing file but different
702 // md5.
[email protected]330278c2012-07-05 09:43:55703 TestGetFileFromCacheByResourceIdAndMd5(
[email protected]78a158b2013-04-23 06:57:49704 resource_id, "9999", FILE_ERROR_NOT_FOUND, md5);
[email protected]330278c2012-07-05 09:43:55705
706 // Get file from cache with different resource id from existing file but same
707 // md5.
[email protected]330278c2012-07-05 09:43:55708 resource_id = "document:1a2b";
709 TestGetFileFromCacheByResourceIdAndMd5(
[email protected]78a158b2013-04-23 06:57:49710 resource_id, md5, FILE_ERROR_NOT_FOUND, md5);
[email protected]330278c2012-07-05 09:43:55711}
712
[email protected]fb371812012-08-22 16:05:23713TEST_F(DriveCacheTest, RemoveFromCacheSimple) {
[email protected]cf64404b2012-12-14 07:12:50714 fake_free_disk_space_getter_->set_fake_free_disk_space(kLotsOfSpace);
[email protected]f0c67002012-08-15 04:10:38715
[email protected]330278c2012-07-05 09:43:55716 // Use alphanumeric characters for resource id.
717 std::string resource_id("pdf:1a2b");
718 std::string md5("abcdef0123456789");
719 // First store a file to cache.
[email protected]fb0fc202012-10-22 09:30:28720 TestStoreToCache(
721 resource_id, md5,
[email protected]3ac6b8f2013-03-08 14:12:38722 google_apis::test_util::GetTestFilePath("chromeos/gdata/root_feed.json"),
[email protected]78a158b2013-04-23 06:57:49723 FILE_ERROR_OK, test_util::TEST_CACHE_STATE_PRESENT,
[email protected]fb0fc202012-10-22 09:30:28724 DriveCache::CACHE_TYPE_TMP);
[email protected]330278c2012-07-05 09:43:55725
726 // Then try to remove existing file from cache.
[email protected]78a158b2013-04-23 06:57:49727 TestRemoveFromCache(resource_id, FILE_ERROR_OK);
[email protected]330278c2012-07-05 09:43:55728
729 // Repeat using non-alphanumeric characters for resource id, including '.'
730 // which is an extension separator.
731 resource_id = "pdf:`~!@#$%^&*()-_=+[{|]}\\;',<.>/?";
[email protected]fb0fc202012-10-22 09:30:28732 TestStoreToCache(
733 resource_id, md5,
[email protected]3ac6b8f2013-03-08 14:12:38734 google_apis::test_util::GetTestFilePath("chromeos/gdata/root_feed.json"),
[email protected]78a158b2013-04-23 06:57:49735 FILE_ERROR_OK, test_util::TEST_CACHE_STATE_PRESENT,
[email protected]fb0fc202012-10-22 09:30:28736 DriveCache::CACHE_TYPE_TMP);
[email protected]330278c2012-07-05 09:43:55737
[email protected]78a158b2013-04-23 06:57:49738 TestRemoveFromCache(resource_id, FILE_ERROR_OK);
[email protected]330278c2012-07-05 09:43:55739}
740
[email protected]fb371812012-08-22 16:05:23741TEST_F(DriveCacheTest, PinAndUnpin) {
[email protected]cf64404b2012-12-14 07:12:50742 fake_free_disk_space_getter_->set_fake_free_disk_space(kLotsOfSpace);
[email protected]330278c2012-07-05 09:43:55743
744 std::string resource_id("pdf:1a2b");
745 std::string md5("abcdef0123456789");
[email protected]4743aa1c2012-07-13 14:54:23746 EXPECT_CALL(*mock_cache_observer_, OnCachePinned(resource_id, md5)).Times(2);
747 EXPECT_CALL(*mock_cache_observer_, OnCacheUnpinned(resource_id, md5))
748 .Times(1);
[email protected]330278c2012-07-05 09:43:55749
750 // First store a file to cache.
[email protected]fb0fc202012-10-22 09:30:28751 TestStoreToCache(
752 resource_id, md5,
[email protected]3ac6b8f2013-03-08 14:12:38753 google_apis::test_util::GetTestFilePath("chromeos/gdata/root_feed.json"),
[email protected]78a158b2013-04-23 06:57:49754 FILE_ERROR_OK, test_util::TEST_CACHE_STATE_PRESENT,
[email protected]fb0fc202012-10-22 09:30:28755 DriveCache::CACHE_TYPE_TMP);
[email protected]330278c2012-07-05 09:43:55756
757 // Pin the existing file in cache.
[email protected]78a158b2013-04-23 06:57:49758 TestPin(resource_id, md5, FILE_ERROR_OK,
[email protected]02821102012-07-12 20:19:17759 test_util::TEST_CACHE_STATE_PRESENT |
760 test_util::TEST_CACHE_STATE_PINNED |
761 test_util::TEST_CACHE_STATE_PERSISTENT,
[email protected]fb371812012-08-22 16:05:23762 DriveCache::CACHE_TYPE_PERSISTENT);
[email protected]330278c2012-07-05 09:43:55763
764 // Unpin the existing file in cache.
[email protected]78a158b2013-04-23 06:57:49765 TestUnpin(resource_id, md5, FILE_ERROR_OK,
[email protected]02821102012-07-12 20:19:17766 test_util::TEST_CACHE_STATE_PRESENT,
[email protected]fb371812012-08-22 16:05:23767 DriveCache::CACHE_TYPE_TMP);
[email protected]330278c2012-07-05 09:43:55768
769 // Pin back the same existing file in cache.
[email protected]78a158b2013-04-23 06:57:49770 TestPin(resource_id, md5, FILE_ERROR_OK,
[email protected]02821102012-07-12 20:19:17771 test_util::TEST_CACHE_STATE_PRESENT |
772 test_util::TEST_CACHE_STATE_PINNED |
773 test_util::TEST_CACHE_STATE_PERSISTENT,
[email protected]fb371812012-08-22 16:05:23774 DriveCache::CACHE_TYPE_PERSISTENT);
[email protected]330278c2012-07-05 09:43:55775
776 // Pin a non-existent file in cache.
777 resource_id = "document:1a2b";
[email protected]4743aa1c2012-07-13 14:54:23778 EXPECT_CALL(*mock_cache_observer_, OnCachePinned(resource_id, md5)).Times(1);
779 EXPECT_CALL(*mock_cache_observer_, OnCacheUnpinned(resource_id, md5))
780 .Times(1);
[email protected]330278c2012-07-05 09:43:55781
[email protected]78a158b2013-04-23 06:57:49782 TestPin(resource_id, md5, FILE_ERROR_OK,
[email protected]02821102012-07-12 20:19:17783 test_util::TEST_CACHE_STATE_PINNED,
[email protected]fb371812012-08-22 16:05:23784 DriveCache::CACHE_TYPE_TMP);
[email protected]330278c2012-07-05 09:43:55785
786 // Unpin the previously pinned non-existent file in cache.
[email protected]78a158b2013-04-23 06:57:49787 TestUnpin(resource_id, md5, FILE_ERROR_OK,
[email protected]02821102012-07-12 20:19:17788 test_util::TEST_CACHE_STATE_NONE,
[email protected]fb371812012-08-22 16:05:23789 DriveCache::CACHE_TYPE_TMP);
[email protected]330278c2012-07-05 09:43:55790
791 // Unpin a file that doesn't exist in cache and is not pinned, i.e. cache
792 // has zero knowledge of the file.
793 resource_id = "not-in-cache:1a2b";
794 // Because unpinning will fail, OnCacheUnpinned() won't be run.
[email protected]4743aa1c2012-07-13 14:54:23795 EXPECT_CALL(*mock_cache_observer_, OnCacheUnpinned(resource_id, md5))
796 .Times(0);
[email protected]330278c2012-07-05 09:43:55797
[email protected]78a158b2013-04-23 06:57:49798 TestUnpin(resource_id, md5, FILE_ERROR_NOT_FOUND,
[email protected]02821102012-07-12 20:19:17799 test_util::TEST_CACHE_STATE_NONE,
[email protected]fb371812012-08-22 16:05:23800 DriveCache::CACHE_TYPE_TMP /* non-applicable */);
[email protected]330278c2012-07-05 09:43:55801}
802
[email protected]fb371812012-08-22 16:05:23803TEST_F(DriveCacheTest, StoreToCachePinned) {
[email protected]cf64404b2012-12-14 07:12:50804 fake_free_disk_space_getter_->set_fake_free_disk_space(kLotsOfSpace);
[email protected]f0c67002012-08-15 04:10:38805
[email protected]330278c2012-07-05 09:43:55806 std::string resource_id("pdf:1a2b");
807 std::string md5("abcdef0123456789");
[email protected]4743aa1c2012-07-13 14:54:23808 EXPECT_CALL(*mock_cache_observer_, OnCachePinned(resource_id, md5)).Times(1);
[email protected]330278c2012-07-05 09:43:55809
810 // Pin a non-existent file.
[email protected]78a158b2013-04-23 06:57:49811 TestPin(resource_id, md5, FILE_ERROR_OK,
[email protected]02821102012-07-12 20:19:17812 test_util::TEST_CACHE_STATE_PINNED,
[email protected]fb371812012-08-22 16:05:23813 DriveCache::CACHE_TYPE_TMP);
[email protected]330278c2012-07-05 09:43:55814
815 // Store an existing file to a previously pinned file.
[email protected]fb0fc202012-10-22 09:30:28816 TestStoreToCache(
817 resource_id, md5,
[email protected]3ac6b8f2013-03-08 14:12:38818 google_apis::test_util::GetTestFilePath("chromeos/gdata/root_feed.json"),
[email protected]78a158b2013-04-23 06:57:49819 FILE_ERROR_OK,
[email protected]fb0fc202012-10-22 09:30:28820 test_util::TEST_CACHE_STATE_PRESENT |
821 test_util::TEST_CACHE_STATE_PINNED |
822 test_util::TEST_CACHE_STATE_PERSISTENT,
823 DriveCache::CACHE_TYPE_PERSISTENT);
[email protected]330278c2012-07-05 09:43:55824
825 // Store a non-existent file to a previously pinned and stored file.
[email protected]650b2d52013-02-10 03:41:45826 TestStoreToCache(resource_id, md5, base::FilePath("./non_existent.json"),
[email protected]78a158b2013-04-23 06:57:49827 FILE_ERROR_FAILED,
[email protected]02821102012-07-12 20:19:17828 test_util::TEST_CACHE_STATE_PRESENT |
829 test_util::TEST_CACHE_STATE_PINNED |
830 test_util::TEST_CACHE_STATE_PERSISTENT,
[email protected]fb371812012-08-22 16:05:23831 DriveCache::CACHE_TYPE_PERSISTENT);
[email protected]330278c2012-07-05 09:43:55832}
833
[email protected]fb371812012-08-22 16:05:23834TEST_F(DriveCacheTest, GetFromCachePinned) {
[email protected]cf64404b2012-12-14 07:12:50835 fake_free_disk_space_getter_->set_fake_free_disk_space(kLotsOfSpace);
[email protected]f0c67002012-08-15 04:10:38836
[email protected]330278c2012-07-05 09:43:55837 std::string resource_id("pdf:1a2b");
838 std::string md5("abcdef0123456789");
[email protected]4743aa1c2012-07-13 14:54:23839 EXPECT_CALL(*mock_cache_observer_, OnCachePinned(resource_id, md5)).Times(1);
[email protected]330278c2012-07-05 09:43:55840
841 // Pin a non-existent file.
[email protected]78a158b2013-04-23 06:57:49842 TestPin(resource_id, md5, FILE_ERROR_OK,
[email protected]02821102012-07-12 20:19:17843 test_util::TEST_CACHE_STATE_PINNED,
[email protected]fb371812012-08-22 16:05:23844 DriveCache::CACHE_TYPE_TMP);
[email protected]330278c2012-07-05 09:43:55845
846 // Get the non-existent pinned file from cache.
[email protected]330278c2012-07-05 09:43:55847 TestGetFileFromCacheByResourceIdAndMd5(
[email protected]78a158b2013-04-23 06:57:49848 resource_id, md5, FILE_ERROR_NOT_FOUND, md5);
[email protected]330278c2012-07-05 09:43:55849
850 // Store an existing file to the previously pinned non-existent file.
[email protected]fb0fc202012-10-22 09:30:28851 TestStoreToCache(
852 resource_id, md5,
[email protected]3ac6b8f2013-03-08 14:12:38853 google_apis::test_util::GetTestFilePath("chromeos/gdata/root_feed.json"),
[email protected]78a158b2013-04-23 06:57:49854 FILE_ERROR_OK,
[email protected]fb0fc202012-10-22 09:30:28855 test_util::TEST_CACHE_STATE_PRESENT |
856 test_util::TEST_CACHE_STATE_PINNED |
857 test_util::TEST_CACHE_STATE_PERSISTENT,
858 DriveCache::CACHE_TYPE_PERSISTENT);
[email protected]330278c2012-07-05 09:43:55859
860 // Get the previously pinned and stored file from cache.
[email protected]330278c2012-07-05 09:43:55861 TestGetFileFromCacheByResourceIdAndMd5(
[email protected]78a158b2013-04-23 06:57:49862 resource_id, md5, FILE_ERROR_OK, md5);
[email protected]330278c2012-07-05 09:43:55863}
864
[email protected]fb371812012-08-22 16:05:23865TEST_F(DriveCacheTest, RemoveFromCachePinned) {
[email protected]cf64404b2012-12-14 07:12:50866 fake_free_disk_space_getter_->set_fake_free_disk_space(kLotsOfSpace);
[email protected]f0c67002012-08-15 04:10:38867
[email protected]330278c2012-07-05 09:43:55868 // Use alphanumeric characters for resource_id.
869 std::string resource_id("pdf:1a2b");
870 std::string md5("abcdef0123456789");
[email protected]4743aa1c2012-07-13 14:54:23871 EXPECT_CALL(*mock_cache_observer_, OnCachePinned(resource_id, md5)).Times(1);
[email protected]330278c2012-07-05 09:43:55872
873 // Store a file to cache, and pin it.
[email protected]fb0fc202012-10-22 09:30:28874 TestStoreToCache(
875 resource_id, md5,
[email protected]3ac6b8f2013-03-08 14:12:38876 google_apis::test_util::GetTestFilePath("chromeos/gdata/root_feed.json"),
[email protected]78a158b2013-04-23 06:57:49877 FILE_ERROR_OK, test_util::TEST_CACHE_STATE_PRESENT,
[email protected]fb0fc202012-10-22 09:30:28878 DriveCache::CACHE_TYPE_TMP);
[email protected]78a158b2013-04-23 06:57:49879 TestPin(resource_id, md5, FILE_ERROR_OK,
[email protected]02821102012-07-12 20:19:17880 test_util::TEST_CACHE_STATE_PRESENT |
881 test_util::TEST_CACHE_STATE_PINNED |
882 test_util::TEST_CACHE_STATE_PERSISTENT,
[email protected]fb371812012-08-22 16:05:23883 DriveCache::CACHE_TYPE_PERSISTENT);
[email protected]330278c2012-07-05 09:43:55884
885 // Remove |resource_id| from cache.
[email protected]78a158b2013-04-23 06:57:49886 TestRemoveFromCache(resource_id, FILE_ERROR_OK);
[email protected]330278c2012-07-05 09:43:55887
888 // Repeat using non-alphanumeric characters for resource id, including '.'
889 // which is an extension separator.
890 resource_id = "pdf:`~!@#$%^&*()-_=+[{|]}\\;',<.>/?";
[email protected]4743aa1c2012-07-13 14:54:23891 EXPECT_CALL(*mock_cache_observer_, OnCachePinned(resource_id, md5)).Times(1);
[email protected]330278c2012-07-05 09:43:55892
[email protected]fb0fc202012-10-22 09:30:28893 TestStoreToCache(
894 resource_id, md5,
[email protected]3ac6b8f2013-03-08 14:12:38895 google_apis::test_util::GetTestFilePath("chromeos/gdata/root_feed.json"),
[email protected]78a158b2013-04-23 06:57:49896 FILE_ERROR_OK, test_util::TEST_CACHE_STATE_PRESENT,
[email protected]fb0fc202012-10-22 09:30:28897 DriveCache::CACHE_TYPE_TMP);
[email protected]78a158b2013-04-23 06:57:49898 TestPin(resource_id, md5, FILE_ERROR_OK,
[email protected]02821102012-07-12 20:19:17899 test_util::TEST_CACHE_STATE_PRESENT |
900 test_util::TEST_CACHE_STATE_PINNED |
901 test_util::TEST_CACHE_STATE_PERSISTENT,
[email protected]fb371812012-08-22 16:05:23902 DriveCache::CACHE_TYPE_PERSISTENT);
[email protected]330278c2012-07-05 09:43:55903
[email protected]78a158b2013-04-23 06:57:49904 TestRemoveFromCache(resource_id, FILE_ERROR_OK);
[email protected]330278c2012-07-05 09:43:55905}
906
[email protected]fb371812012-08-22 16:05:23907TEST_F(DriveCacheTest, DirtyCacheSimple) {
[email protected]cf64404b2012-12-14 07:12:50908 fake_free_disk_space_getter_->set_fake_free_disk_space(kLotsOfSpace);
[email protected]f0c67002012-08-15 04:10:38909
[email protected]330278c2012-07-05 09:43:55910 std::string resource_id("pdf:1a2b");
911 std::string md5("abcdef0123456789");
[email protected]4743aa1c2012-07-13 14:54:23912 EXPECT_CALL(*mock_cache_observer_, OnCacheCommitted(resource_id)).Times(1);
[email protected]330278c2012-07-05 09:43:55913
914 // First store a file to cache.
[email protected]fb0fc202012-10-22 09:30:28915 TestStoreToCache(
916 resource_id, md5,
[email protected]3ac6b8f2013-03-08 14:12:38917 google_apis::test_util::GetTestFilePath("chromeos/gdata/root_feed.json"),
[email protected]78a158b2013-04-23 06:57:49918 FILE_ERROR_OK, test_util::TEST_CACHE_STATE_PRESENT,
[email protected]fb0fc202012-10-22 09:30:28919 DriveCache::CACHE_TYPE_TMP);
[email protected]330278c2012-07-05 09:43:55920
921 // Mark the file dirty.
[email protected]78a158b2013-04-23 06:57:49922 TestMarkDirty(resource_id, md5, FILE_ERROR_OK,
[email protected]02821102012-07-12 20:19:17923 test_util::TEST_CACHE_STATE_PRESENT |
924 test_util::TEST_CACHE_STATE_DIRTY |
925 test_util::TEST_CACHE_STATE_PERSISTENT,
[email protected]fb371812012-08-22 16:05:23926 DriveCache::CACHE_TYPE_PERSISTENT);
[email protected]330278c2012-07-05 09:43:55927
928 // Commit the file dirty.
[email protected]78a158b2013-04-23 06:57:49929 TestCommitDirty(resource_id, md5, FILE_ERROR_OK,
[email protected]02821102012-07-12 20:19:17930 test_util::TEST_CACHE_STATE_PRESENT |
931 test_util::TEST_CACHE_STATE_DIRTY |
932 test_util::TEST_CACHE_STATE_PERSISTENT,
[email protected]fb371812012-08-22 16:05:23933 DriveCache::CACHE_TYPE_PERSISTENT);
[email protected]330278c2012-07-05 09:43:55934
935 // Clear dirty state of the file.
[email protected]78a158b2013-04-23 06:57:49936 TestClearDirty(resource_id, md5, FILE_ERROR_OK,
[email protected]02821102012-07-12 20:19:17937 test_util::TEST_CACHE_STATE_PRESENT,
[email protected]fb371812012-08-22 16:05:23938 DriveCache::CACHE_TYPE_TMP);
[email protected]330278c2012-07-05 09:43:55939}
940
[email protected]fb371812012-08-22 16:05:23941TEST_F(DriveCacheTest, DirtyCachePinned) {
[email protected]cf64404b2012-12-14 07:12:50942 fake_free_disk_space_getter_->set_fake_free_disk_space(kLotsOfSpace);
[email protected]f0c67002012-08-15 04:10:38943
[email protected]330278c2012-07-05 09:43:55944 std::string resource_id("pdf:1a2b");
945 std::string md5("abcdef0123456789");
[email protected]4743aa1c2012-07-13 14:54:23946 EXPECT_CALL(*mock_cache_observer_, OnCachePinned(resource_id, md5)).Times(1);
947 EXPECT_CALL(*mock_cache_observer_, OnCacheCommitted(resource_id)).Times(1);
[email protected]330278c2012-07-05 09:43:55948
949 // First store a file to cache and pin it.
[email protected]fb0fc202012-10-22 09:30:28950 TestStoreToCache(
951 resource_id, md5,
[email protected]3ac6b8f2013-03-08 14:12:38952 google_apis::test_util::GetTestFilePath("chromeos/gdata/root_feed.json"),
[email protected]78a158b2013-04-23 06:57:49953 FILE_ERROR_OK, test_util::TEST_CACHE_STATE_PRESENT,
[email protected]fb0fc202012-10-22 09:30:28954 DriveCache::CACHE_TYPE_TMP);
[email protected]78a158b2013-04-23 06:57:49955 TestPin(resource_id, md5, FILE_ERROR_OK,
[email protected]02821102012-07-12 20:19:17956 test_util::TEST_CACHE_STATE_PRESENT |
957 test_util::TEST_CACHE_STATE_PINNED |
958 test_util::TEST_CACHE_STATE_PERSISTENT,
[email protected]fb371812012-08-22 16:05:23959 DriveCache::CACHE_TYPE_PERSISTENT);
[email protected]330278c2012-07-05 09:43:55960
961 // Mark the file dirty.
[email protected]78a158b2013-04-23 06:57:49962 TestMarkDirty(resource_id, md5, FILE_ERROR_OK,
[email protected]02821102012-07-12 20:19:17963 test_util::TEST_CACHE_STATE_PRESENT |
964 test_util::TEST_CACHE_STATE_DIRTY |
965 test_util::TEST_CACHE_STATE_PINNED |
966 test_util::TEST_CACHE_STATE_PERSISTENT,
[email protected]fb371812012-08-22 16:05:23967 DriveCache::CACHE_TYPE_PERSISTENT);
[email protected]330278c2012-07-05 09:43:55968
969 // Commit the file dirty.
[email protected]78a158b2013-04-23 06:57:49970 TestCommitDirty(resource_id, md5, FILE_ERROR_OK,
[email protected]02821102012-07-12 20:19:17971 test_util::TEST_CACHE_STATE_PRESENT |
972 test_util::TEST_CACHE_STATE_DIRTY |
973 test_util::TEST_CACHE_STATE_PINNED |
974 test_util::TEST_CACHE_STATE_PERSISTENT,
[email protected]fb371812012-08-22 16:05:23975 DriveCache::CACHE_TYPE_PERSISTENT);
[email protected]330278c2012-07-05 09:43:55976
977 // Clear dirty state of the file.
[email protected]78a158b2013-04-23 06:57:49978 TestClearDirty(resource_id, md5, FILE_ERROR_OK,
[email protected]02821102012-07-12 20:19:17979 test_util::TEST_CACHE_STATE_PRESENT |
980 test_util::TEST_CACHE_STATE_PINNED |
981 test_util::TEST_CACHE_STATE_PERSISTENT,
[email protected]fb371812012-08-22 16:05:23982 DriveCache::CACHE_TYPE_PERSISTENT);
[email protected]330278c2012-07-05 09:43:55983}
984
985// Test is disabled because it is flaky (http://crbug.com/134146)
[email protected]fb371812012-08-22 16:05:23986TEST_F(DriveCacheTest, PinAndUnpinDirtyCache) {
[email protected]cf64404b2012-12-14 07:12:50987 fake_free_disk_space_getter_->set_fake_free_disk_space(kLotsOfSpace);
[email protected]330278c2012-07-05 09:43:55988
989 std::string resource_id("pdf:1a2b");
990 std::string md5("abcdef0123456789");
[email protected]4743aa1c2012-07-13 14:54:23991 EXPECT_CALL(*mock_cache_observer_, OnCachePinned(resource_id, md5)).Times(1);
992 EXPECT_CALL(*mock_cache_observer_, OnCacheUnpinned(resource_id, md5))
993 .Times(1);
[email protected]330278c2012-07-05 09:43:55994
995 // First store a file to cache and mark it as dirty.
[email protected]fb0fc202012-10-22 09:30:28996 TestStoreToCache(
997 resource_id, md5,
[email protected]3ac6b8f2013-03-08 14:12:38998 google_apis::test_util::GetTestFilePath("chromeos/gdata/root_feed.json"),
[email protected]78a158b2013-04-23 06:57:49999 FILE_ERROR_OK, test_util::TEST_CACHE_STATE_PRESENT,
[email protected]fb0fc202012-10-22 09:30:281000 DriveCache::CACHE_TYPE_TMP);
[email protected]78a158b2013-04-23 06:57:491001 TestMarkDirty(resource_id, md5, FILE_ERROR_OK,
[email protected]02821102012-07-12 20:19:171002 test_util::TEST_CACHE_STATE_PRESENT |
1003 test_util::TEST_CACHE_STATE_DIRTY |
1004 test_util::TEST_CACHE_STATE_PERSISTENT,
[email protected]fb371812012-08-22 16:05:231005 DriveCache::CACHE_TYPE_PERSISTENT);
[email protected]330278c2012-07-05 09:43:551006
1007 // Verifies dirty file exists.
[email protected]e9663392013-04-12 09:55:151008 base::FilePath dirty_path;
[email protected]78a158b2013-04-23 06:57:491009 FileError error = FILE_ERROR_FAILED;
[email protected]e9663392013-04-12 09:55:151010 cache_->GetFile(
1011 resource_id, md5,
1012 google_apis::test_util::CreateCopyResultCallback(&error, &dirty_path));
1013 google_apis::test_util::RunBlockingPoolTask();
[email protected]78a158b2013-04-23 06:57:491014 EXPECT_EQ(FILE_ERROR_OK, error);
[email protected]330278c2012-07-05 09:43:551015 EXPECT_TRUE(file_util::PathExists(dirty_path));
1016
1017 // Pin the dirty file.
[email protected]78a158b2013-04-23 06:57:491018 TestPin(resource_id, md5, FILE_ERROR_OK,
[email protected]02821102012-07-12 20:19:171019 test_util::TEST_CACHE_STATE_PRESENT |
1020 test_util::TEST_CACHE_STATE_DIRTY |
1021 test_util::TEST_CACHE_STATE_PINNED |
1022 test_util::TEST_CACHE_STATE_PERSISTENT,
[email protected]fb371812012-08-22 16:05:231023 DriveCache::CACHE_TYPE_PERSISTENT);
[email protected]330278c2012-07-05 09:43:551024
1025 // Verify dirty file still exist at the same pathname.
1026 EXPECT_TRUE(file_util::PathExists(dirty_path));
1027
1028 // Unpin the dirty file.
[email protected]78a158b2013-04-23 06:57:491029 TestUnpin(resource_id, md5, FILE_ERROR_OK,
[email protected]02821102012-07-12 20:19:171030 test_util::TEST_CACHE_STATE_PRESENT |
1031 test_util::TEST_CACHE_STATE_DIRTY |
1032 test_util::TEST_CACHE_STATE_PERSISTENT,
[email protected]fb371812012-08-22 16:05:231033 DriveCache::CACHE_TYPE_PERSISTENT);
[email protected]330278c2012-07-05 09:43:551034
1035 // Verify dirty file still exist at the same pathname.
1036 EXPECT_TRUE(file_util::PathExists(dirty_path));
1037}
1038
[email protected]fb371812012-08-22 16:05:231039TEST_F(DriveCacheTest, DirtyCacheRepetitive) {
[email protected]cf64404b2012-12-14 07:12:501040 fake_free_disk_space_getter_->set_fake_free_disk_space(kLotsOfSpace);
[email protected]f0c67002012-08-15 04:10:381041
[email protected]330278c2012-07-05 09:43:551042 std::string resource_id("pdf:1a2b");
1043 std::string md5("abcdef0123456789");
[email protected]4743aa1c2012-07-13 14:54:231044 EXPECT_CALL(*mock_cache_observer_, OnCacheCommitted(resource_id)).Times(3);
[email protected]330278c2012-07-05 09:43:551045
1046 // First store a file to cache.
[email protected]fb0fc202012-10-22 09:30:281047 TestStoreToCache(
1048 resource_id, md5,
[email protected]3ac6b8f2013-03-08 14:12:381049 google_apis::test_util::GetTestFilePath("chromeos/gdata/root_feed.json"),
[email protected]78a158b2013-04-23 06:57:491050 FILE_ERROR_OK, test_util::TEST_CACHE_STATE_PRESENT,
[email protected]fb0fc202012-10-22 09:30:281051 DriveCache::CACHE_TYPE_TMP);
[email protected]330278c2012-07-05 09:43:551052
1053 // Mark the file dirty.
[email protected]78a158b2013-04-23 06:57:491054 TestMarkDirty(resource_id, md5, FILE_ERROR_OK,
[email protected]02821102012-07-12 20:19:171055 test_util::TEST_CACHE_STATE_PRESENT |
1056 test_util::TEST_CACHE_STATE_DIRTY |
1057 test_util::TEST_CACHE_STATE_PERSISTENT,
[email protected]fb371812012-08-22 16:05:231058 DriveCache::CACHE_TYPE_PERSISTENT);
[email protected]330278c2012-07-05 09:43:551059
1060 // Again, mark the file dirty. Nothing should change.
[email protected]78a158b2013-04-23 06:57:491061 TestMarkDirty(resource_id, md5, FILE_ERROR_OK,
[email protected]02821102012-07-12 20:19:171062 test_util::TEST_CACHE_STATE_PRESENT |
1063 test_util::TEST_CACHE_STATE_DIRTY |
1064 test_util::TEST_CACHE_STATE_PERSISTENT,
[email protected]fb371812012-08-22 16:05:231065 DriveCache::CACHE_TYPE_PERSISTENT);
[email protected]330278c2012-07-05 09:43:551066
1067 // Commit the file dirty. Outgoing symlink should be created.
[email protected]78a158b2013-04-23 06:57:491068 TestCommitDirty(resource_id, md5, FILE_ERROR_OK,
[email protected]02821102012-07-12 20:19:171069 test_util::TEST_CACHE_STATE_PRESENT |
1070 test_util::TEST_CACHE_STATE_DIRTY |
1071 test_util::TEST_CACHE_STATE_PERSISTENT,
[email protected]fb371812012-08-22 16:05:231072 DriveCache::CACHE_TYPE_PERSISTENT);
[email protected]330278c2012-07-05 09:43:551073
1074 // Again, commit the file dirty. Nothing should change.
[email protected]78a158b2013-04-23 06:57:491075 TestCommitDirty(resource_id, md5, FILE_ERROR_OK,
[email protected]02821102012-07-12 20:19:171076 test_util::TEST_CACHE_STATE_PRESENT |
1077 test_util::TEST_CACHE_STATE_DIRTY |
1078 test_util::TEST_CACHE_STATE_PERSISTENT,
[email protected]fb371812012-08-22 16:05:231079 DriveCache::CACHE_TYPE_PERSISTENT);
[email protected]330278c2012-07-05 09:43:551080
[email protected]cdbfb4382013-03-24 10:11:091081 // Mark the file dirty again after it's being committed. Outgoing symlink
[email protected]330278c2012-07-05 09:43:551082 // should be deleted.
[email protected]78a158b2013-04-23 06:57:491083 TestMarkDirty(resource_id, md5, FILE_ERROR_OK,
[email protected]02821102012-07-12 20:19:171084 test_util::TEST_CACHE_STATE_PRESENT |
1085 test_util::TEST_CACHE_STATE_DIRTY |
1086 test_util::TEST_CACHE_STATE_PERSISTENT,
[email protected]fb371812012-08-22 16:05:231087 DriveCache::CACHE_TYPE_PERSISTENT);
[email protected]330278c2012-07-05 09:43:551088
1089 // Commit the file dirty. Outgoing symlink should be created again.
[email protected]78a158b2013-04-23 06:57:491090 TestCommitDirty(resource_id, md5, FILE_ERROR_OK,
[email protected]02821102012-07-12 20:19:171091 test_util::TEST_CACHE_STATE_PRESENT |
1092 test_util::TEST_CACHE_STATE_DIRTY |
1093 test_util::TEST_CACHE_STATE_PERSISTENT,
[email protected]fb371812012-08-22 16:05:231094 DriveCache::CACHE_TYPE_PERSISTENT);
[email protected]330278c2012-07-05 09:43:551095
1096 // Clear dirty state of the file.
[email protected]78a158b2013-04-23 06:57:491097 TestClearDirty(resource_id, md5, FILE_ERROR_OK,
[email protected]02821102012-07-12 20:19:171098 test_util::TEST_CACHE_STATE_PRESENT,
[email protected]fb371812012-08-22 16:05:231099 DriveCache::CACHE_TYPE_TMP);
[email protected]330278c2012-07-05 09:43:551100
1101 // Again, clear dirty state of the file, which is no longer dirty.
[email protected]78a158b2013-04-23 06:57:491102 TestClearDirty(resource_id, md5, FILE_ERROR_INVALID_OPERATION,
[email protected]02821102012-07-12 20:19:171103 test_util::TEST_CACHE_STATE_PRESENT,
[email protected]fb371812012-08-22 16:05:231104 DriveCache::CACHE_TYPE_TMP);
[email protected]330278c2012-07-05 09:43:551105}
1106
[email protected]fb371812012-08-22 16:05:231107TEST_F(DriveCacheTest, DirtyCacheInvalid) {
[email protected]cf64404b2012-12-14 07:12:501108 fake_free_disk_space_getter_->set_fake_free_disk_space(kLotsOfSpace);
[email protected]f0c67002012-08-15 04:10:381109
[email protected]330278c2012-07-05 09:43:551110 std::string resource_id("pdf:1a2b");
1111 std::string md5("abcdef0123456789");
1112
1113 // Mark a non-existent file dirty.
[email protected]78a158b2013-04-23 06:57:491114 TestMarkDirty(resource_id, md5, FILE_ERROR_NOT_FOUND,
[email protected]02821102012-07-12 20:19:171115 test_util::TEST_CACHE_STATE_NONE,
[email protected]fb371812012-08-22 16:05:231116 DriveCache::CACHE_TYPE_TMP);
[email protected]330278c2012-07-05 09:43:551117
1118 // Commit a non-existent file dirty.
[email protected]78a158b2013-04-23 06:57:491119 TestCommitDirty(resource_id, md5, FILE_ERROR_NOT_FOUND,
[email protected]02821102012-07-12 20:19:171120 test_util::TEST_CACHE_STATE_NONE,
[email protected]fb371812012-08-22 16:05:231121 DriveCache::CACHE_TYPE_TMP);
[email protected]330278c2012-07-05 09:43:551122
1123 // Clear dirty state of a non-existent file.
[email protected]78a158b2013-04-23 06:57:491124 TestClearDirty(resource_id, md5, FILE_ERROR_NOT_FOUND,
[email protected]02821102012-07-12 20:19:171125 test_util::TEST_CACHE_STATE_NONE,
[email protected]fb371812012-08-22 16:05:231126 DriveCache::CACHE_TYPE_TMP);
[email protected]330278c2012-07-05 09:43:551127
1128 // Store a file to cache.
[email protected]fb0fc202012-10-22 09:30:281129 TestStoreToCache(
1130 resource_id, md5,
[email protected]3ac6b8f2013-03-08 14:12:381131 google_apis::test_util::GetTestFilePath("chromeos/gdata/root_feed.json"),
[email protected]78a158b2013-04-23 06:57:491132 FILE_ERROR_OK, test_util::TEST_CACHE_STATE_PRESENT,
[email protected]fb0fc202012-10-22 09:30:281133 DriveCache::CACHE_TYPE_TMP);
[email protected]330278c2012-07-05 09:43:551134
1135 // Commit a non-dirty existing file dirty.
[email protected]78a158b2013-04-23 06:57:491136 TestCommitDirty(resource_id, md5, FILE_ERROR_INVALID_OPERATION,
[email protected]02821102012-07-12 20:19:171137 test_util::TEST_CACHE_STATE_PRESENT,
[email protected]fb371812012-08-22 16:05:231138 DriveCache::CACHE_TYPE_TMP);
[email protected]330278c2012-07-05 09:43:551139
1140 // Clear dirty state of a non-dirty existing file.
[email protected]78a158b2013-04-23 06:57:491141 TestClearDirty(resource_id, md5, FILE_ERROR_INVALID_OPERATION,
[email protected]02821102012-07-12 20:19:171142 test_util::TEST_CACHE_STATE_PRESENT,
[email protected]fb371812012-08-22 16:05:231143 DriveCache::CACHE_TYPE_TMP);
[email protected]330278c2012-07-05 09:43:551144
1145 // Mark an existing file dirty, then store a new file to the same resource id
1146 // but different md5, which should fail.
[email protected]78a158b2013-04-23 06:57:491147 TestMarkDirty(resource_id, md5, FILE_ERROR_OK,
[email protected]02821102012-07-12 20:19:171148 test_util::TEST_CACHE_STATE_PRESENT |
1149 test_util::TEST_CACHE_STATE_DIRTY |
1150 test_util::TEST_CACHE_STATE_PERSISTENT,
[email protected]fb371812012-08-22 16:05:231151 DriveCache::CACHE_TYPE_PERSISTENT);
[email protected]330278c2012-07-05 09:43:551152 md5 = "new_md5";
[email protected]fb0fc202012-10-22 09:30:281153 TestStoreToCache(
1154 resource_id, md5,
[email protected]3ac6b8f2013-03-08 14:12:381155 google_apis::test_util::GetTestFilePath(
[email protected]16696472013-04-22 05:42:211156 "chromeos/gdata/empty_feed.json"),
[email protected]78a158b2013-04-23 06:57:491157 FILE_ERROR_IN_USE,
[email protected]fb0fc202012-10-22 09:30:281158 test_util::TEST_CACHE_STATE_PRESENT |
1159 test_util::TEST_CACHE_STATE_DIRTY |
1160 test_util::TEST_CACHE_STATE_PERSISTENT,
1161 DriveCache::CACHE_TYPE_PERSISTENT);
[email protected]330278c2012-07-05 09:43:551162}
1163
[email protected]fb371812012-08-22 16:05:231164TEST_F(DriveCacheTest, RemoveFromDirtyCache) {
[email protected]cf64404b2012-12-14 07:12:501165 fake_free_disk_space_getter_->set_fake_free_disk_space(kLotsOfSpace);
[email protected]f0c67002012-08-15 04:10:381166
[email protected]330278c2012-07-05 09:43:551167 std::string resource_id("pdf:1a2b");
1168 std::string md5("abcdef0123456789");
[email protected]4743aa1c2012-07-13 14:54:231169 EXPECT_CALL(*mock_cache_observer_, OnCachePinned(resource_id, md5)).Times(1);
1170 EXPECT_CALL(*mock_cache_observer_, OnCacheCommitted(resource_id)).Times(1);
[email protected]330278c2012-07-05 09:43:551171
1172 // Store a file to cache, pin it, mark it dirty and commit it.
[email protected]fb0fc202012-10-22 09:30:281173 TestStoreToCache(
1174 resource_id, md5,
[email protected]3ac6b8f2013-03-08 14:12:381175 google_apis::test_util::GetTestFilePath("chromeos/gdata/root_feed.json"),
[email protected]78a158b2013-04-23 06:57:491176 FILE_ERROR_OK, test_util::TEST_CACHE_STATE_PRESENT,
[email protected]fb0fc202012-10-22 09:30:281177 DriveCache::CACHE_TYPE_TMP);
[email protected]78a158b2013-04-23 06:57:491178 TestPin(resource_id, md5, FILE_ERROR_OK,
[email protected]02821102012-07-12 20:19:171179 test_util::TEST_CACHE_STATE_PRESENT |
1180 test_util::TEST_CACHE_STATE_PINNED |
1181 test_util::TEST_CACHE_STATE_PERSISTENT,
[email protected]fb371812012-08-22 16:05:231182 DriveCache::CACHE_TYPE_PERSISTENT);
[email protected]78a158b2013-04-23 06:57:491183 TestMarkDirty(resource_id, md5, FILE_ERROR_OK,
[email protected]02821102012-07-12 20:19:171184 test_util::TEST_CACHE_STATE_PRESENT |
1185 test_util::TEST_CACHE_STATE_PINNED |
1186 test_util::TEST_CACHE_STATE_DIRTY |
1187 test_util::TEST_CACHE_STATE_PERSISTENT,
[email protected]fb371812012-08-22 16:05:231188 DriveCache::CACHE_TYPE_PERSISTENT);
[email protected]78a158b2013-04-23 06:57:491189 TestCommitDirty(resource_id, md5, FILE_ERROR_OK,
[email protected]02821102012-07-12 20:19:171190 test_util::TEST_CACHE_STATE_PRESENT |
1191 test_util::TEST_CACHE_STATE_PINNED |
1192 test_util::TEST_CACHE_STATE_DIRTY |
1193 test_util::TEST_CACHE_STATE_PERSISTENT,
[email protected]fb371812012-08-22 16:05:231194 DriveCache::CACHE_TYPE_PERSISTENT);
[email protected]330278c2012-07-05 09:43:551195
1196 // Try to remove the file. Since file is dirty, it and the corresponding
1197 // pinned and outgoing symlinks should not be removed.
[email protected]78a158b2013-04-23 06:57:491198 TestRemoveFromCache(resource_id, FILE_ERROR_OK);
[email protected]330278c2012-07-05 09:43:551199}
1200
[email protected]fb371812012-08-22 16:05:231201TEST_F(DriveCacheTest, MountUnmount) {
[email protected]cf64404b2012-12-14 07:12:501202 fake_free_disk_space_getter_->set_fake_free_disk_space(kLotsOfSpace);
[email protected]f0c67002012-08-15 04:10:381203
[email protected]330278c2012-07-05 09:43:551204 std::string resource_id("pdf:1a2b");
1205 std::string md5("abcdef0123456789");
1206
1207 // First store a file to cache in the tmp subdir.
[email protected]fb0fc202012-10-22 09:30:281208 TestStoreToCache(
1209 resource_id, md5,
[email protected]3ac6b8f2013-03-08 14:12:381210 google_apis::test_util::GetTestFilePath("chromeos/gdata/root_feed.json"),
[email protected]78a158b2013-04-23 06:57:491211 FILE_ERROR_OK, test_util::TEST_CACHE_STATE_PRESENT,
[email protected]fb0fc202012-10-22 09:30:281212 DriveCache::CACHE_TYPE_TMP);
[email protected]330278c2012-07-05 09:43:551213
1214 // Mark the file mounted.
[email protected]35c1f9b2013-02-07 07:39:421215 TestMarkAsMounted(resource_id,
1216 md5,
[email protected]78a158b2013-04-23 06:57:491217 FILE_ERROR_OK,
[email protected]9564c1502012-11-28 12:12:161218 test_util::TEST_CACHE_STATE_PRESENT |
1219 test_util::TEST_CACHE_STATE_MOUNTED |
1220 test_util::TEST_CACHE_STATE_PERSISTENT,
1221 DriveCache::CACHE_TYPE_PERSISTENT);
[email protected]330278c2012-07-05 09:43:551222 EXPECT_TRUE(CacheEntryExists(resource_id, md5));
1223
1224 // Clear mounted state of the file.
[email protected]e9663392013-04-12 09:55:151225 base::FilePath file_path;
[email protected]78a158b2013-04-23 06:57:491226 FileError error = FILE_ERROR_FAILED;
[email protected]e9663392013-04-12 09:55:151227 cache_->GetFile(
1228 resource_id, md5,
1229 google_apis::test_util::CreateCopyResultCallback(&error, &file_path));
1230 google_apis::test_util::RunBlockingPoolTask();
[email protected]78a158b2013-04-23 06:57:491231 EXPECT_EQ(FILE_ERROR_OK, error);
[email protected]e9663392013-04-12 09:55:151232
[email protected]9564c1502012-11-28 12:12:161233 TestMarkAsUnmounted(resource_id, md5, file_path,
[email protected]78a158b2013-04-23 06:57:491234 FILE_ERROR_OK,
[email protected]02821102012-07-12 20:19:171235 test_util::TEST_CACHE_STATE_PRESENT,
[email protected]fb371812012-08-22 16:05:231236 DriveCache::CACHE_TYPE_TMP);
[email protected]330278c2012-07-05 09:43:551237 EXPECT_TRUE(CacheEntryExists(resource_id, md5));
1238
1239 // Try to remove the file.
[email protected]78a158b2013-04-23 06:57:491240 TestRemoveFromCache(resource_id, FILE_ERROR_OK);
[email protected]330278c2012-07-05 09:43:551241}
1242
[email protected]d68ede02012-11-07 14:30:531243TEST_F(DriveCacheTest, Iterate) {
[email protected]5d8abd22012-11-14 08:31:031244 PrepareTestCacheResources();
[email protected]cd236432012-07-27 18:03:301245
1246 std::vector<std::string> resource_ids;
[email protected]d68ede02012-11-07 14:30:531247 std::vector<DriveCacheEntry> cache_entries;
1248 bool completed = false;
1249 cache_->Iterate(
1250 base::Bind(&OnIterate, &resource_ids, &cache_entries),
1251 base::Bind(&OnIterateCompleted, &completed));
[email protected]fb0fc202012-10-22 09:30:281252 google_apis::test_util::RunBlockingPoolTask();
[email protected]cd236432012-07-27 18:03:301253
[email protected]d68ede02012-11-07 14:30:531254 ASSERT_TRUE(completed);
[email protected]cd236432012-07-27 18:03:301255
1256 sort(resource_ids.begin(), resource_ids.end());
1257 ASSERT_EQ(6U, resource_ids.size());
1258 EXPECT_EQ("dirty:existing", resource_ids[0]);
1259 EXPECT_EQ("dirty_and_pinned:existing", resource_ids[1]);
1260 EXPECT_EQ("pinned:existing", resource_ids[2]);
1261 EXPECT_EQ("pinned:non-existent", resource_ids[3]);
1262 EXPECT_EQ("tmp:`~!@#$%^&*()-_=+[{|]}\\;',<.>/?", resource_ids[4]);
1263 EXPECT_EQ("tmp:resource_id", resource_ids[5]);
[email protected]d68ede02012-11-07 14:30:531264
1265 ASSERT_EQ(6U, cache_entries.size());
[email protected]cd236432012-07-27 18:03:301266}
1267
[email protected]f861b392012-08-03 20:41:121268
[email protected]77fb1a62012-11-01 13:42:321269TEST_F(DriveCacheTest, ClearAll) {
[email protected]cf64404b2012-12-14 07:12:501270 fake_free_disk_space_getter_->set_fake_free_disk_space(kLotsOfSpace);
[email protected]f0c67002012-08-15 04:10:381271
[email protected]f861b392012-08-03 20:41:121272 std::string resource_id("pdf:1a2b");
1273 std::string md5("abcdef0123456789");
1274
1275 // Store an existing file.
[email protected]fb0fc202012-10-22 09:30:281276 TestStoreToCache(
1277 resource_id, md5,
[email protected]3ac6b8f2013-03-08 14:12:381278 google_apis::test_util::GetTestFilePath("chromeos/gdata/root_feed.json"),
[email protected]78a158b2013-04-23 06:57:491279 FILE_ERROR_OK, test_util::TEST_CACHE_STATE_PRESENT,
[email protected]fb0fc202012-10-22 09:30:281280 DriveCache::CACHE_TYPE_TMP);
[email protected]f861b392012-08-03 20:41:121281
1282 // Verify that there's only one cached file.
1283 EXPECT_EQ(1U, CountCacheFiles(resource_id, md5));
1284
1285 // Clear cache.
[email protected]bdd947c2012-11-06 04:35:341286 bool success = false;
[email protected]e76fd272013-03-25 13:37:141287 cache_->ClearAll(google_apis::test_util::CreateCopyResultCallback(&success));
[email protected]fb0fc202012-10-22 09:30:281288 google_apis::test_util::RunBlockingPoolTask();
[email protected]bdd947c2012-11-06 04:35:341289 EXPECT_TRUE(success);
[email protected]f861b392012-08-03 20:41:121290
1291 // Verify that all the cache is removed.
[email protected]78a158b2013-04-23 06:57:491292 expected_error_ = FILE_ERROR_OK;
1293 VerifyRemoveFromCache(FILE_ERROR_OK, resource_id, md5);
[email protected]f861b392012-08-03 20:41:121294 EXPECT_EQ(0U, CountCacheFiles(resource_id, md5));
1295}
1296
[email protected]fb371812012-08-22 16:05:231297TEST_F(DriveCacheTest, StoreToCacheNoSpace) {
[email protected]cf64404b2012-12-14 07:12:501298 fake_free_disk_space_getter_->set_fake_free_disk_space(0);
[email protected]f0c67002012-08-15 04:10:381299
1300 std::string resource_id("pdf:1a2b");
1301 std::string md5("abcdef0123456789");
1302
1303 // Try to store an existing file.
[email protected]fb0fc202012-10-22 09:30:281304 TestStoreToCache(
1305 resource_id, md5,
[email protected]3ac6b8f2013-03-08 14:12:381306 google_apis::test_util::GetTestFilePath("chromeos/gdata/root_feed.json"),
[email protected]78a158b2013-04-23 06:57:491307 FILE_ERROR_NO_SPACE,
[email protected]fb0fc202012-10-22 09:30:281308 test_util::TEST_CACHE_STATE_NONE,
1309 DriveCache::CACHE_TYPE_TMP);
[email protected]f0c67002012-08-15 04:10:381310
1311 // Verify that there's no files added.
1312 EXPECT_EQ(0U, CountCacheFiles(resource_id, md5));
1313}
1314
[email protected]322e0032012-10-07 01:55:531315// Don't use TEST_F, as we don't want SetUp() and TearDown() for this test.
1316TEST(DriveCacheExtraTest, InitializationFailure) {
1317 MessageLoopForUI message_loop;
1318 content::TestBrowserThread ui_thread(content::BrowserThread::UI,
1319 &message_loop);
1320
1321 scoped_refptr<base::SequencedWorkerPool> pool =
1322 content::BrowserThread::GetBlockingPool();
1323
1324 // Set the cache root to a non existent path, so the initialization fails.
[email protected]c0a3b8e82013-03-18 21:07:451325 scoped_ptr<DriveCache, test_util::DestroyHelperForTests> cache(new DriveCache(
[email protected]650b2d52013-02-10 03:41:451326 base::FilePath::FromUTF8Unsafe("/somewhere/nonexistent/blah/blah"),
[email protected]f6fd98a2012-12-14 00:04:021327 pool->GetSequencedTaskRunner(pool->GetSequenceToken()),
[email protected]c0a3b8e82013-03-18 21:07:451328 NULL /* free_disk_space_getter */));
[email protected]322e0032012-10-07 01:55:531329
[email protected]e76fd272013-03-25 13:37:141330 bool success = true;
[email protected]77fb1a62012-11-01 13:42:321331 cache->RequestInitialize(
[email protected]e76fd272013-03-25 13:37:141332 google_apis::test_util::CreateCopyResultCallback(&success));
[email protected]fb0fc202012-10-22 09:30:281333 google_apis::test_util::RunBlockingPoolTask();
[email protected]322e0032012-10-07 01:55:531334 EXPECT_FALSE(success);
[email protected]322e0032012-10-07 01:55:531335}
[email protected]f0c67002012-08-15 04:10:381336
[email protected]d9d04df2012-10-12 07:06:351337} // namespace drive