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

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

Issue 11819046: drive: Replace local FakeDriveService with google_apis::FakeDriveService (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 11 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/drive/drive_scheduler_unittest.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 <string> 5 #include <string>
6 #include <vector> 6 #include <vector>
7 7
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/file_path.h" 9 #include "base/file_path.h"
10 #include "base/file_util.h" 10 #include "base/file_util.h"
11 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
12 #include "base/message_loop.h" 12 #include "base/message_loop.h"
13 #include "base/stringprintf.h" 13 #include "base/stringprintf.h"
14 #include "base/threading/sequenced_worker_pool.h" 14 #include "base/threading/sequenced_worker_pool.h"
15 #include "base/values.h" 15 #include "base/values.h"
16 #include "chrome/browser/chromeos/drive/drive.pb.h" 16 #include "chrome/browser/chromeos/drive/drive.pb.h"
17 #include "chrome/browser/chromeos/drive/drive_file_system.h" 17 #include "chrome/browser/chromeos/drive/drive_file_system.h"
18 #include "chrome/browser/chromeos/drive/drive_test_util.h" 18 #include "chrome/browser/chromeos/drive/drive_test_util.h"
19 #include "chrome/browser/chromeos/drive/drive_webapps_registry.h" 19 #include "chrome/browser/chromeos/drive/drive_webapps_registry.h"
20 #include "chrome/browser/chromeos/drive/fake_free_disk_space_getter.h" 20 #include "chrome/browser/chromeos/drive/fake_free_disk_space_getter.h"
21 #include "chrome/browser/chromeos/drive/mock_directory_change_observer.h" 21 #include "chrome/browser/chromeos/drive/mock_directory_change_observer.h"
22 #include "chrome/browser/chromeos/drive/mock_drive_cache_observer.h" 22 #include "chrome/browser/chromeos/drive/mock_drive_cache_observer.h"
23 #include "chrome/browser/chromeos/drive/stale_cache_files_remover.h" 23 #include "chrome/browser/chromeos/drive/stale_cache_files_remover.h"
24 #include "chrome/browser/google_apis/drive_api_parser.h" 24 #include "chrome/browser/google_apis/drive_api_parser.h"
25 #include "chrome/browser/google_apis/dummy_drive_service.h" 25 #include "chrome/browser/google_apis/fake_drive_service.h"
26 #include "chrome/browser/google_apis/time_util.h" 26 #include "chrome/browser/google_apis/time_util.h"
27 #include "chrome/test/base/testing_profile.h" 27 #include "chrome/test/base/testing_profile.h"
28 #include "content/public/browser/browser_thread.h" 28 #include "content/public/browser/browser_thread.h"
29 #include "content/public/test/test_browser_thread.h" 29 #include "content/public/test/test_browser_thread.h"
30 #include "testing/gmock/include/gmock/gmock.h" 30 #include "testing/gmock/include/gmock/gmock.h"
31 #include "testing/gtest/include/gtest/gtest.h" 31 #include "testing/gtest/include/gtest/gtest.h"
32 32
33 using ::testing::AtLeast; 33 using ::testing::AtLeast;
34 using ::testing::Eq; 34 using ::testing::Eq;
35 using ::testing::NotNull; 35 using ::testing::NotNull;
36 using ::testing::Return; 36 using ::testing::Return;
37 using ::testing::StrictMock; 37 using ::testing::StrictMock;
38 using ::testing::_; 38 using ::testing::_;
39 39
40 namespace drive { 40 namespace drive {
41 namespace { 41 namespace {
42 42
43 const int64 kLotsOfSpace = kMinFreeSpace * 10; 43 const int64 kLotsOfSpace = kMinFreeSpace * 10;
44 44
45 // Fake DriveService implementation that just returns an empty resource list,
46 // and empty account metadata. This implementation is sufficient to simulate
47 // an empty file system.
48 class FakeDriveService : public google_apis::DummyDriveService {
49 // DummyDriveService overrides.
50 virtual void GetResourceList(
51 const GURL& feed_url,
52 int64 start_changestamp,
53 const std::string& search_query,
54 bool shared_with_me,
55 const std::string& directory_resource_id,
56 const google_apis::GetResourceListCallback& callback) OVERRIDE {
57 scoped_ptr<google_apis::ResourceList> resource_list(
58 new google_apis::ResourceList);
59 MessageLoop::current()->PostTask(
60 FROM_HERE,
61 base::Bind(callback,
62 google_apis::HTTP_SUCCESS,
63 base::Passed(&resource_list)));
64 }
65
66 virtual void GetAccountMetadata(
67 const google_apis::GetAccountMetadataCallback& callback) OVERRIDE {
68 scoped_ptr<google_apis::AccountMetadataFeed> metadata(
69 new google_apis::AccountMetadataFeed);
70 MessageLoop::current()->PostTask(
71 FROM_HERE,
72 base::Bind(callback,
73 google_apis::HTTP_SUCCESS,
74 base::Passed(&metadata)));
75 }
76 };
77
78 } // namespace 45 } // namespace
79 46
80 class StaleCacheFilesRemoverTest : public testing::Test { 47 class StaleCacheFilesRemoverTest : public testing::Test {
81 protected: 48 protected:
82 StaleCacheFilesRemoverTest() 49 StaleCacheFilesRemoverTest()
83 : ui_thread_(content::BrowserThread::UI, &message_loop_), 50 : ui_thread_(content::BrowserThread::UI, &message_loop_),
84 io_thread_(content::BrowserThread::IO), 51 io_thread_(content::BrowserThread::IO),
85 cache_(NULL), 52 cache_(NULL),
86 file_system_(NULL), 53 file_system_(NULL),
87 fake_drive_service_(NULL), 54 fake_drive_service_(NULL),
88 drive_webapps_registry_(NULL), 55 drive_webapps_registry_(NULL),
89 root_feed_changestamp_(0) { 56 root_feed_changestamp_(0) {
90 } 57 }
91 58
92 virtual void SetUp() OVERRIDE { 59 virtual void SetUp() OVERRIDE {
93 io_thread_.StartIOThread(); 60 io_thread_.StartIOThread();
94 61
95 profile_.reset(new TestingProfile); 62 profile_.reset(new TestingProfile);
96 63
97 fake_drive_service_.reset(new FakeDriveService); 64 fake_drive_service_.reset(new google_apis::FakeDriveService);
65 fake_drive_service_->LoadResourceListForWapi(
66 "gdata/root_feed.json");
67 fake_drive_service_->LoadAccountMetadataForWapi(
68 "gdata/account_metadata.json");
69
98 fake_free_disk_space_getter_.reset(new FakeFreeDiskSpaceGetter); 70 fake_free_disk_space_getter_.reset(new FakeFreeDiskSpaceGetter);
99 71
100 scoped_refptr<base::SequencedWorkerPool> pool = 72 scoped_refptr<base::SequencedWorkerPool> pool =
101 content::BrowserThread::GetBlockingPool(); 73 content::BrowserThread::GetBlockingPool();
102 blocking_task_runner_ = 74 blocking_task_runner_ =
103 pool->GetSequencedTaskRunner(pool->GetSequenceToken()); 75 pool->GetSequencedTaskRunner(pool->GetSequenceToken());
104 76
105 // Likewise, this will be owned by DriveFileSystem. 77 // Likewise, this will be owned by DriveFileSystem.
106 cache_ = new DriveCache( 78 cache_ = new DriveCache(
107 DriveCache::GetCacheRootPath(profile_.get()), 79 DriveCache::GetCacheRootPath(profile_.get()),
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 119
148 MessageLoopForUI message_loop_; 120 MessageLoopForUI message_loop_;
149 // The order of the test threads is important, do not change the order. 121 // The order of the test threads is important, do not change the order.
150 // See also content/browser/browser_thread_impl.cc. 122 // See also content/browser/browser_thread_impl.cc.
151 content::TestBrowserThread ui_thread_; 123 content::TestBrowserThread ui_thread_;
152 content::TestBrowserThread io_thread_; 124 content::TestBrowserThread io_thread_;
153 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_; 125 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_;
154 scoped_ptr<TestingProfile> profile_; 126 scoped_ptr<TestingProfile> profile_;
155 DriveCache* cache_; 127 DriveCache* cache_;
156 DriveFileSystem* file_system_; 128 DriveFileSystem* file_system_;
157 scoped_ptr<FakeDriveService> fake_drive_service_; 129 scoped_ptr<google_apis::FakeDriveService> fake_drive_service_;
158 scoped_ptr<DriveWebAppsRegistry> drive_webapps_registry_; 130 scoped_ptr<DriveWebAppsRegistry> drive_webapps_registry_;
159 scoped_ptr<FakeFreeDiskSpaceGetter> fake_free_disk_space_getter_; 131 scoped_ptr<FakeFreeDiskSpaceGetter> fake_free_disk_space_getter_;
160 scoped_ptr<StrictMock<MockDriveCacheObserver> > mock_cache_observer_; 132 scoped_ptr<StrictMock<MockDriveCacheObserver> > mock_cache_observer_;
161 scoped_ptr<StrictMock<MockDirectoryChangeObserver> > mock_directory_observer_; 133 scoped_ptr<StrictMock<MockDirectoryChangeObserver> > mock_directory_observer_;
162 scoped_ptr<StaleCacheFilesRemover> stale_cache_files_remover_; 134 scoped_ptr<StaleCacheFilesRemover> stale_cache_files_remover_;
163 135
164 int root_feed_changestamp_; 136 int root_feed_changestamp_;
165 }; 137 };
166 138
167 TEST_F(StaleCacheFilesRemoverTest, RemoveStaleCacheFiles) { 139 TEST_F(StaleCacheFilesRemoverTest, RemoveStaleCacheFiles) {
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 187
216 // Verify that the cache file is deleted. 188 // Verify that the cache file is deleted.
217 path = cache_->GetCacheFilePath(resource_id, 189 path = cache_->GetCacheFilePath(resource_id,
218 md5, 190 md5,
219 DriveCache::CACHE_TYPE_TMP, 191 DriveCache::CACHE_TYPE_TMP,
220 DriveCache::CACHED_FILE_FROM_SERVER); 192 DriveCache::CACHED_FILE_FROM_SERVER);
221 EXPECT_FALSE(file_util::PathExists(path)); 193 EXPECT_FALSE(file_util::PathExists(path));
222 } 194 }
223 195
224 } // namespace drive 196 } // namespace drive
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/drive/drive_scheduler_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698