OLD | NEW |
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/mock_directory_change_observer.h" | 20 #include "chrome/browser/chromeos/drive/mock_directory_change_observer.h" |
21 #include "chrome/browser/chromeos/drive/mock_drive_cache_observer.h" | 21 #include "chrome/browser/chromeos/drive/mock_drive_cache_observer.h" |
22 #include "chrome/browser/chromeos/drive/mock_drive_web_apps_registry.h" | 22 #include "chrome/browser/chromeos/drive/mock_drive_web_apps_registry.h" |
23 #include "chrome/browser/chromeos/drive/mock_free_disk_space_getter.h" | 23 #include "chrome/browser/chromeos/drive/mock_free_disk_space_getter.h" |
24 #include "chrome/browser/chromeos/drive/stale_cache_files_remover.h" | 24 #include "chrome/browser/chromeos/drive/stale_cache_files_remover.h" |
25 #include "chrome/browser/google_apis/drive_api_parser.h" | 25 #include "chrome/browser/google_apis/drive_api_parser.h" |
26 #include "chrome/browser/google_apis/drive_uploader.h" | 26 #include "chrome/browser/google_apis/drive_uploader.h" |
27 #include "chrome/browser/google_apis/mock_drive_service.h" | 27 #include "chrome/browser/google_apis/mock_drive_service.h" |
28 #include "chrome/browser/google_apis/mock_drive_uploader.h" | |
29 #include "chrome/browser/google_apis/time_util.h" | 28 #include "chrome/browser/google_apis/time_util.h" |
30 #include "chrome/test/base/testing_profile.h" | 29 #include "chrome/test/base/testing_profile.h" |
31 #include "content/public/browser/browser_thread.h" | 30 #include "content/public/browser/browser_thread.h" |
32 #include "content/public/test/test_browser_thread.h" | 31 #include "content/public/test/test_browser_thread.h" |
33 #include "testing/gmock/include/gmock/gmock.h" | 32 #include "testing/gmock/include/gmock/gmock.h" |
34 #include "testing/gtest/include/gtest/gtest.h" | 33 #include "testing/gtest/include/gtest/gtest.h" |
35 | 34 |
36 using ::testing::AtLeast; | 35 using ::testing::AtLeast; |
37 using ::testing::Eq; | 36 using ::testing::Eq; |
38 using ::testing::NotNull; | 37 using ::testing::NotNull; |
39 using ::testing::Return; | 38 using ::testing::Return; |
40 using ::testing::StrictMock; | 39 using ::testing::StrictMock; |
41 using ::testing::_; | 40 using ::testing::_; |
42 | 41 |
43 namespace drive { | 42 namespace drive { |
44 namespace { | 43 namespace { |
45 | 44 |
46 const int64 kLotsOfSpace = kMinFreeSpace * 10; | 45 const int64 kLotsOfSpace = kMinFreeSpace * 10; |
47 | 46 |
48 // Callback for DriveCache::Store used in RemoveStaleCacheFiles test. | 47 // Callback for DriveCache::Store used in RemoveStaleCacheFiles test. |
49 // Verifies that the result is not an error. | 48 // Verifies that the result is not an error. |
50 void VerifyCacheFileState(DriveFileError error, | 49 void VerifyCacheFileState(DriveFileError error, |
51 const std::string& resource_id, | 50 const std::string& resource_id, |
52 const std::string& md5) { | 51 const std::string& md5) { |
53 EXPECT_EQ(DRIVE_FILE_OK, error); | 52 EXPECT_EQ(DRIVE_FILE_OK, error); |
54 } | 53 } |
55 | 54 |
| 55 // Dummy implementation of DriveUploaderInterface which does nothing. |
| 56 // Used to create a DriveFileSystem object. |
| 57 class DummyDriveUploader : public google_apis::DriveUploaderInterface { |
| 58 public: |
| 59 DummyDriveUploader() {} |
| 60 virtual ~DummyDriveUploader() {} |
| 61 |
| 62 // DriveUploaderInterface overrides. |
| 63 virtual int UploadNewFile( |
| 64 const GURL& upload_location, |
| 65 const FilePath& drive_file_path, |
| 66 const FilePath& local_file_path, |
| 67 const std::string& title, |
| 68 const std::string& content_type, |
| 69 int64 content_length, |
| 70 int64 file_size, |
| 71 const google_apis::UploadCompletionCallback& completion_callback, |
| 72 const google_apis::UploaderReadyCallback& ready_callback) OVERRIDE { |
| 73 NOTREACHED(); |
| 74 return 0; |
| 75 } |
| 76 |
| 77 virtual int StreamExistingFile( |
| 78 const GURL& upload_location, |
| 79 const FilePath& drive_file_path, |
| 80 const FilePath& local_file_path, |
| 81 const std::string& content_type, |
| 82 int64 content_length, |
| 83 int64 file_size, |
| 84 const google_apis::UploadCompletionCallback& completion_callback, |
| 85 const google_apis::UploaderReadyCallback& ready_callback) OVERRIDE { |
| 86 NOTREACHED(); |
| 87 return 0; |
| 88 } |
| 89 |
| 90 virtual int UploadExistingFile( |
| 91 const GURL& upload_location, |
| 92 const FilePath& drive_file_path, |
| 93 const FilePath& local_file_path, |
| 94 const std::string& content_type, |
| 95 int64 file_size, |
| 96 const google_apis::UploadCompletionCallback& completion_callback, |
| 97 const google_apis::UploaderReadyCallback& ready_callback) { |
| 98 NOTREACHED(); |
| 99 return 0; |
| 100 } |
| 101 |
| 102 virtual void UpdateUpload(int upload_id, |
| 103 content::DownloadItem* download) OVERRIDE { |
| 104 NOTREACHED(); |
| 105 } |
| 106 |
| 107 virtual int64 GetUploadedBytes(int upload_id) const OVERRIDE { |
| 108 NOTREACHED(); |
| 109 return 0; |
| 110 } |
| 111 }; |
| 112 |
56 } // namespace | 113 } // namespace |
57 | 114 |
58 class StaleCacheFilesRemoverTest : public testing::Test { | 115 class StaleCacheFilesRemoverTest : public testing::Test { |
59 protected: | 116 protected: |
60 StaleCacheFilesRemoverTest() | 117 StaleCacheFilesRemoverTest() |
61 : ui_thread_(content::BrowserThread::UI, &message_loop_), | 118 : ui_thread_(content::BrowserThread::UI, &message_loop_), |
62 io_thread_(content::BrowserThread::IO), | 119 io_thread_(content::BrowserThread::IO), |
63 cache_(NULL), | 120 cache_(NULL), |
64 file_system_(NULL), | 121 file_system_(NULL), |
65 mock_drive_service_(NULL), | 122 mock_drive_service_(NULL), |
(...skipping 17 matching lines...) Expand all Loading... |
83 SetFreeDiskSpaceGetterForTesting(mock_free_disk_space_checker_); | 140 SetFreeDiskSpaceGetterForTesting(mock_free_disk_space_checker_); |
84 | 141 |
85 scoped_refptr<base::SequencedWorkerPool> pool = | 142 scoped_refptr<base::SequencedWorkerPool> pool = |
86 content::BrowserThread::GetBlockingPool(); | 143 content::BrowserThread::GetBlockingPool(); |
87 blocking_task_runner_ = | 144 blocking_task_runner_ = |
88 pool->GetSequencedTaskRunner(pool->GetSequenceToken()); | 145 pool->GetSequencedTaskRunner(pool->GetSequenceToken()); |
89 | 146 |
90 cache_ = DriveCache::CreateDriveCache( | 147 cache_ = DriveCache::CreateDriveCache( |
91 DriveCache::GetCacheRootPath(profile_.get()), blocking_task_runner_); | 148 DriveCache::GetCacheRootPath(profile_.get()), blocking_task_runner_); |
92 | 149 |
93 mock_uploader_.reset(new StrictMock<google_apis::MockDriveUploader>); | 150 dummy_uploader_.reset(new DummyDriveUploader); |
94 mock_webapps_registry_.reset(new StrictMock<MockDriveWebAppsRegistry>); | 151 mock_webapps_registry_.reset(new StrictMock<MockDriveWebAppsRegistry>); |
95 | 152 |
96 ASSERT_FALSE(file_system_); | 153 ASSERT_FALSE(file_system_); |
97 file_system_ = new DriveFileSystem(profile_.get(), | 154 file_system_ = new DriveFileSystem(profile_.get(), |
98 cache_, | 155 cache_, |
99 mock_drive_service_, | 156 mock_drive_service_, |
100 mock_uploader_.get(), | 157 dummy_uploader_.get(), |
101 mock_webapps_registry_.get(), | 158 mock_webapps_registry_.get(), |
102 blocking_task_runner_); | 159 blocking_task_runner_); |
103 | 160 |
104 mock_cache_observer_.reset(new StrictMock<MockDriveCacheObserver>); | 161 mock_cache_observer_.reset(new StrictMock<MockDriveCacheObserver>); |
105 cache_->AddObserver(mock_cache_observer_.get()); | 162 cache_->AddObserver(mock_cache_observer_.get()); |
106 | 163 |
107 mock_directory_observer_.reset(new StrictMock<MockDirectoryChangeObserver>); | 164 mock_directory_observer_.reset(new StrictMock<MockDirectoryChangeObserver>); |
108 file_system_->AddObserver(mock_directory_observer_.get()); | 165 file_system_->AddObserver(mock_directory_observer_.get()); |
109 | 166 |
110 file_system_->Initialize(); | 167 file_system_->Initialize(); |
(...skipping 22 matching lines...) Expand all Loading... |
133 } | 190 } |
134 | 191 |
135 MessageLoopForUI message_loop_; | 192 MessageLoopForUI message_loop_; |
136 // The order of the test threads is important, do not change the order. | 193 // The order of the test threads is important, do not change the order. |
137 // See also content/browser/browser_thread_impl.cc. | 194 // See also content/browser/browser_thread_impl.cc. |
138 content::TestBrowserThread ui_thread_; | 195 content::TestBrowserThread ui_thread_; |
139 content::TestBrowserThread io_thread_; | 196 content::TestBrowserThread io_thread_; |
140 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_; | 197 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_; |
141 scoped_ptr<TestingProfile> profile_; | 198 scoped_ptr<TestingProfile> profile_; |
142 DriveCache* cache_; | 199 DriveCache* cache_; |
143 scoped_ptr<StrictMock<google_apis::MockDriveUploader> > mock_uploader_; | 200 scoped_ptr<DummyDriveUploader> dummy_uploader_; |
144 DriveFileSystem* file_system_; | 201 DriveFileSystem* file_system_; |
145 StrictMock<google_apis::MockDriveService>* mock_drive_service_; | 202 StrictMock<google_apis::MockDriveService>* mock_drive_service_; |
146 scoped_ptr<StrictMock<MockDriveWebAppsRegistry> > mock_webapps_registry_; | 203 scoped_ptr<StrictMock<MockDriveWebAppsRegistry> > mock_webapps_registry_; |
147 StrictMock<MockFreeDiskSpaceGetter>* mock_free_disk_space_checker_; | 204 StrictMock<MockFreeDiskSpaceGetter>* mock_free_disk_space_checker_; |
148 scoped_ptr<StrictMock<MockDriveCacheObserver> > mock_cache_observer_; | 205 scoped_ptr<StrictMock<MockDriveCacheObserver> > mock_cache_observer_; |
149 scoped_ptr<StrictMock<MockDirectoryChangeObserver> > mock_directory_observer_; | 206 scoped_ptr<StrictMock<MockDirectoryChangeObserver> > mock_directory_observer_; |
150 scoped_ptr<StaleCacheFilesRemover> stale_cache_files_remover_; | 207 scoped_ptr<StaleCacheFilesRemover> stale_cache_files_remover_; |
151 | 208 |
152 int root_feed_changestamp_; | 209 int root_feed_changestamp_; |
153 }; | 210 }; |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
208 | 265 |
209 // Verify that the cache file is deleted. | 266 // Verify that the cache file is deleted. |
210 path = cache_->GetCacheFilePath(resource_id, | 267 path = cache_->GetCacheFilePath(resource_id, |
211 md5, | 268 md5, |
212 DriveCache::CACHE_TYPE_TMP, | 269 DriveCache::CACHE_TYPE_TMP, |
213 DriveCache::CACHED_FILE_FROM_SERVER); | 270 DriveCache::CACHED_FILE_FROM_SERVER); |
214 EXPECT_FALSE(file_util::PathExists(path)); | 271 EXPECT_FALSE(file_util::PathExists(path)); |
215 } | 272 } |
216 | 273 |
217 } // namespace drive | 274 } // namespace drive |
OLD | NEW |