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

Side by Side Diff: chrome/browser/chromeos/drive/sync_client_unittest.cc

Issue 16628003: drive: Remove FileCacheObserver::OnCacheCommitted (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix PinAndUnpin Created 7 years, 6 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/chromeos/drive/sync_client.h" 5 #include "chrome/browser/chromeos/drive/sync_client.h"
6 6
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/files/file_path.h" 8 #include "base/files/file_path.h"
9 #include "base/files/scoped_temp_dir.h" 9 #include "base/files/scoped_temp_dir.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 57
58 void set_resource_id_to_be_cancelled(const std::string& resource_id) { 58 void set_resource_id_to_be_cancelled(const std::string& resource_id) {
59 resource_id_to_be_cancelled_ = resource_id; 59 resource_id_to_be_cancelled_ = resource_id;
60 } 60 }
61 61
62 private: 62 private:
63 std::string resource_id_to_be_cancelled_; 63 std::string resource_id_to_be_cancelled_;
64 }; 64 };
65 65
66 class DummyOperationObserver : public file_system::OperationObserver { 66 class DummyOperationObserver : public file_system::OperationObserver {
67 // OperationObserver override:
67 virtual void OnDirectoryChangedByOperation( 68 virtual void OnDirectoryChangedByOperation(
68 const base::FilePath& path) OVERRIDE {} 69 const base::FilePath& path) OVERRIDE {}
70 virtual void OnCacheFileUploadNeededByOperation(
71 const std::string& resource_id) OVERRIDE {}
69 }; 72 };
70 73
71 } // namespace 74 } // namespace
72 75
73 class SyncClientTest : public testing::Test { 76 class SyncClientTest : public testing::Test {
74 public: 77 public:
75 virtual void SetUp() OVERRIDE { 78 virtual void SetUp() OVERRIDE {
76 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 79 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
77 80
78 profile_.reset(new TestingProfile); 81 profile_.reset(new TestingProfile);
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 base::RunLoop().RunUntilIdle(); 248 base::RunLoop().RunUntilIdle();
246 EXPECT_EQ(FILE_ERROR_OK, error); 249 EXPECT_EQ(FILE_ERROR_OK, error);
247 250
248 // The file should be unpinned if the user wants the download to be cancelled. 251 // The file should be unpinned if the user wants the download to be cancelled.
249 FileCacheEntry cache_entry; 252 FileCacheEntry cache_entry;
250 EXPECT_FALSE(cache_->GetCacheEntry(resource_ids_["foo"], std::string(), 253 EXPECT_FALSE(cache_->GetCacheEntry(resource_ids_["foo"], std::string(),
251 &cache_entry)); 254 &cache_entry));
252 } 255 }
253 256
254 TEST_F(SyncClientTest, OnCacheUnpinned) { 257 TEST_F(SyncClientTest, OnCacheUnpinned) {
255 sync_client_->AddResourceIdForTesting(SyncClient::FETCH, 258 sync_client_->AddFetchTask(resource_ids_["foo"]);
256 resource_ids_["foo"]); 259 sync_client_->AddFetchTask(resource_ids_["bar"]);
257 sync_client_->AddResourceIdForTesting(SyncClient::FETCH, 260 sync_client_->AddFetchTask(resource_ids_["baz"]);
258 resource_ids_["bar"]);
259 sync_client_->AddResourceIdForTesting(SyncClient::FETCH,
260 resource_ids_["baz"]);
261 ASSERT_EQ(3U, 261 ASSERT_EQ(3U,
262 sync_client_->GetResourceIdsForTesting(SyncClient::FETCH).size()); 262 sync_client_->GetResourceIdsForTesting(SyncClient::FETCH).size());
263 263
264 sync_client_->OnCacheUnpinned(resource_ids_["foo"], std::string()); 264 sync_client_->OnCacheUnpinned(resource_ids_["foo"], std::string());
265 sync_client_->OnCacheUnpinned(resource_ids_["baz"], std::string()); 265 sync_client_->OnCacheUnpinned(resource_ids_["baz"], std::string());
266 base::RunLoop().RunUntilIdle(); 266 base::RunLoop().RunUntilIdle();
267 267
268 // Only "bar" should be fetched. 268 // Only "bar" should be fetched.
269 FileCacheEntry cache_entry; 269 FileCacheEntry cache_entry;
270 EXPECT_TRUE(cache_->GetCacheEntry(resource_ids_["foo"], std::string(), 270 EXPECT_TRUE(cache_->GetCacheEntry(resource_ids_["foo"], std::string(),
271 &cache_entry)); 271 &cache_entry));
272 EXPECT_FALSE(cache_entry.is_present()); 272 EXPECT_FALSE(cache_entry.is_present());
273 273
274 EXPECT_TRUE(cache_->GetCacheEntry(resource_ids_["bar"], std::string(), 274 EXPECT_TRUE(cache_->GetCacheEntry(resource_ids_["bar"], std::string(),
275 &cache_entry)); 275 &cache_entry));
276 EXPECT_TRUE(cache_entry.is_present()); 276 EXPECT_TRUE(cache_entry.is_present());
277 277
278 EXPECT_TRUE(cache_->GetCacheEntry(resource_ids_["baz"], std::string(), 278 EXPECT_TRUE(cache_->GetCacheEntry(resource_ids_["baz"], std::string(),
279 &cache_entry)); 279 &cache_entry));
280 EXPECT_FALSE(cache_entry.is_present()); 280 EXPECT_FALSE(cache_entry.is_present());
281 281
282 } 282 }
283 283
284 TEST_F(SyncClientTest, Deduplication) { 284 TEST_F(SyncClientTest, Deduplication) {
285 sync_client_->AddResourceIdForTesting(SyncClient::FETCH, 285 sync_client_->AddFetchTask(resource_ids_["foo"]);
286 resource_ids_["foo"]);
287 286
288 // Set the delay so that DoSyncLoop() is delayed. 287 // Set the delay so that DoSyncLoop() is delayed.
289 sync_client_->set_delay_for_testing(TestTimeouts::action_max_timeout()); 288 sync_client_->set_delay_for_testing(TestTimeouts::action_max_timeout());
290 // Raise OnCachePinned() event. This shouldn't result in adding the second 289 // Raise OnCachePinned() event. This shouldn't result in adding the second
291 // task, as tasks are de-duplicated. 290 // task, as tasks are de-duplicated.
292 sync_client_->OnCachePinned(resource_ids_["foo"], std::string()); 291 sync_client_->OnCachePinned(resource_ids_["foo"], std::string());
293 292
294 ASSERT_EQ(1U, 293 ASSERT_EQ(1U,
295 sync_client_->GetResourceIdsForTesting(SyncClient::FETCH).size()); 294 sync_client_->GetResourceIdsForTesting(SyncClient::FETCH).size());
296 } 295 }
(...skipping 15 matching lines...) Expand all
312 content.clear(); 311 content.clear();
313 312
314 EXPECT_EQ(FILE_ERROR_OK, cache_->GetFile(resource_ids_["dirty"], 313 EXPECT_EQ(FILE_ERROR_OK, cache_->GetFile(resource_ids_["dirty"],
315 std::string(), &cache_file)); 314 std::string(), &cache_file));
316 EXPECT_TRUE(file_util::ReadFileToString(cache_file, &content)); 315 EXPECT_TRUE(file_util::ReadFileToString(cache_file, &content));
317 EXPECT_EQ(kLocalContent, content); 316 EXPECT_EQ(kLocalContent, content);
318 } 317 }
319 318
320 } // namespace internal 319 } // namespace internal
321 } // namespace drive 320 } // namespace drive
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/drive/sync_client.cc ('k') | chrome/browser/chromeos/drive/test_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698