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

Side by Side Diff: chrome/browser/chromeos/gdata/gdata_cache_unittest.cc

Issue 10834052: gdata: Add GDataCache::GetResourceIdsOfAllFiles() (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 4 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
« no previous file with comments | « chrome/browser/chromeos/gdata/gdata_cache.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <vector> 5 #include <vector>
6 6
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/message_loop.h" 8 #include "base/message_loop.h"
9 #include "base/path_service.h" 9 #include "base/path_service.h"
10 #include "base/threading/sequenced_worker_pool.h" 10 #include "base/threading/sequenced_worker_pool.h"
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 FilePath path_to_scan; 91 FilePath path_to_scan;
92 FilePath expected_existing_path; 92 FilePath expected_existing_path;
93 }; 93 };
94 94
95 class MockFreeDiskSpaceGetter : public FreeDiskSpaceGetterInterface { 95 class MockFreeDiskSpaceGetter : public FreeDiskSpaceGetterInterface {
96 public: 96 public:
97 virtual ~MockFreeDiskSpaceGetter() {} 97 virtual ~MockFreeDiskSpaceGetter() {}
98 MOCK_CONST_METHOD0(AmountOfFreeDiskSpace, int64()); 98 MOCK_CONST_METHOD0(AmountOfFreeDiskSpace, int64());
99 }; 99 };
100 100
101 // Copies results from GetResourceIdsOfBacklogCallback.
102 void OnGetResourceIdsOfBacklog(std::vector<std::string>* out_to_fetch,
103 std::vector<std::string>* out_to_upload,
104 const std::vector<std::string>& to_fetch,
105 const std::vector<std::string>& to_upload) {
106 *out_to_fetch = to_fetch;
107 *out_to_upload = to_upload;
108 }
109
110 // Copies results from GetResourceIdsCallback.
111 void OnGetResourceIds(std::vector<std::string>* out_resource_ids,
112 const std::vector<std::string>& resource_ids) {
113 *out_resource_ids = resource_ids;
114 }
115
101 } // namespace 116 } // namespace
102 117
103 class GDataCacheTest : public testing::Test { 118 class GDataCacheTest : public testing::Test {
104 protected: 119 protected:
105 GDataCacheTest() 120 GDataCacheTest()
106 : ui_thread_(content::BrowserThread::UI, &message_loop_), 121 : ui_thread_(content::BrowserThread::UI, &message_loop_),
107 io_thread_(content::BrowserThread::IO), 122 io_thread_(content::BrowserThread::IO),
108 cache_(NULL), 123 cache_(NULL),
109 num_callback_invocations_(0), 124 num_callback_invocations_(0),
110 expected_error_(GDATA_FILE_OK), 125 expected_error_(GDATA_FILE_OK),
(...skipping 1277 matching lines...) Expand 10 before | Expand all | Expand 10 after
1388 GDataCache::CACHE_TYPE_TMP); 1403 GDataCache::CACHE_TYPE_TMP);
1389 EXPECT_EQ(1, num_callback_invocations_); 1404 EXPECT_EQ(1, num_callback_invocations_);
1390 EXPECT_TRUE(CacheEntryExists(resource_id, md5)); 1405 EXPECT_TRUE(CacheEntryExists(resource_id, md5));
1391 1406
1392 // Try to remove the file. 1407 // Try to remove the file.
1393 num_callback_invocations_ = 0; 1408 num_callback_invocations_ = 0;
1394 TestRemoveFromCache(resource_id, GDATA_FILE_OK); 1409 TestRemoveFromCache(resource_id, GDATA_FILE_OK);
1395 EXPECT_EQ(1, num_callback_invocations_); 1410 EXPECT_EQ(1, num_callback_invocations_);
1396 } 1411 }
1397 1412
1413 TEST_F(GDataCacheTest, GetResourceIdsOfBacklogOnUIThread) {
1414 PrepareForInitCacheTest();
1415
1416 std::vector<std::string> to_fetch;
1417 std::vector<std::string> to_upload;
1418 cache_->GetResourceIdsOfBacklogOnUIThread(
1419 base::Bind(&OnGetResourceIdsOfBacklog, &to_fetch, &to_upload));
1420 test_util::RunBlockingPoolTask();
1421
1422 sort(to_fetch.begin(), to_fetch.end());
1423 ASSERT_EQ(1U, to_fetch.size());
1424 EXPECT_EQ("pinned:non-existent", to_fetch[0]);
1425
1426 sort(to_upload.begin(), to_upload.end());
1427 ASSERT_EQ(2U, to_upload.size());
1428 EXPECT_EQ("dirty:existing", to_upload[0]);
1429 EXPECT_EQ("dirty_and_pinned:existing", to_upload[1]);
1430 }
1431
1432 TEST_F(GDataCacheTest, GetResourceIdsOfExistingPinnedFilesOnUIThread) {
1433 PrepareForInitCacheTest();
1434
1435 std::vector<std::string> resource_ids;
1436 cache_->GetResourceIdsOfExistingPinnedFilesOnUIThread(
1437 base::Bind(&OnGetResourceIds, &resource_ids));
1438 test_util::RunBlockingPoolTask();
1439
1440 sort(resource_ids.begin(), resource_ids.end());
1441 ASSERT_EQ(2U, resource_ids.size());
1442 EXPECT_EQ("dirty_and_pinned:existing", resource_ids[0]);
1443 EXPECT_EQ("pinned:existing", resource_ids[1]);
1444 }
1445
1446 TEST_F(GDataCacheTest, GetResourceIdsOfAllFilesOnUIThread) {
1447 PrepareForInitCacheTest();
1448
1449 std::vector<std::string> resource_ids;
1450 cache_->GetResourceIdsOfAllFilesOnUIThread(
1451 base::Bind(&OnGetResourceIds, &resource_ids));
1452 test_util::RunBlockingPoolTask();
1453
1454 sort(resource_ids.begin(), resource_ids.end());
1455 ASSERT_EQ(6U, resource_ids.size());
1456 EXPECT_EQ("dirty:existing", resource_ids[0]);
1457 EXPECT_EQ("dirty_and_pinned:existing", resource_ids[1]);
1458 EXPECT_EQ("pinned:existing", resource_ids[2]);
1459 EXPECT_EQ("pinned:non-existent", resource_ids[3]);
1460 EXPECT_EQ("tmp:`~!@#$%^&*()-_=+[{|]}\\;',<.>/?", resource_ids[4]);
1461 EXPECT_EQ("tmp:resource_id", resource_ids[5]);
1462 }
1463
1398 } // namespace gdata 1464 } // namespace gdata
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/gdata/gdata_cache.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698