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

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

Issue 17004011: drive: DriveIntegrationService owns ResourceMetadataStorage (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix a nit 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/resource_metadata.h" 5 #include "chrome/browser/chromeos/drive/resource_metadata.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 class ResourceMetadataTestOnUIThread : public testing::Test { 116 class ResourceMetadataTestOnUIThread : public testing::Test {
117 protected: 117 protected:
118 virtual void SetUp() OVERRIDE { 118 virtual void SetUp() OVERRIDE {
119 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 119 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
120 120
121 base::ThreadRestrictions::SetIOAllowed(false); // For strict thread check. 121 base::ThreadRestrictions::SetIOAllowed(false); // For strict thread check.
122 scoped_refptr<base::SequencedWorkerPool> pool = 122 scoped_refptr<base::SequencedWorkerPool> pool =
123 content::BrowserThread::GetBlockingPool(); 123 content::BrowserThread::GetBlockingPool();
124 blocking_task_runner_ = 124 blocking_task_runner_ =
125 pool->GetSequencedTaskRunner(pool->GetSequenceToken()); 125 pool->GetSequencedTaskRunner(pool->GetSequenceToken());
126 resource_metadata_.reset(new ResourceMetadata(temp_dir_.path(), 126
127 metadata_storage_.reset(new ResourceMetadataStorage(
128 temp_dir_.path(), blocking_task_runner_));
129 bool success = false;
130 base::PostTaskAndReplyWithResult(
131 blocking_task_runner_,
132 FROM_HERE,
133 base::Bind(&ResourceMetadataStorage::Initialize,
134 base::Unretained(metadata_storage_.get())),
135 google_apis::test_util::CreateCopyResultCallback(&success));
136 google_apis::test_util::RunBlockingPoolTask();
137 ASSERT_TRUE(success);
138
139 resource_metadata_.reset(new ResourceMetadata(metadata_storage_.get(),
127 blocking_task_runner_)); 140 blocking_task_runner_));
128 141
129 FileError error = FILE_ERROR_FAILED; 142 FileError error = FILE_ERROR_FAILED;
130 base::PostTaskAndReplyWithResult( 143 base::PostTaskAndReplyWithResult(
131 blocking_task_runner_, 144 blocking_task_runner_,
132 FROM_HERE, 145 FROM_HERE,
133 base::Bind(&ResourceMetadata::Initialize, 146 base::Bind(&ResourceMetadata::Initialize,
134 base::Unretained(resource_metadata_.get())), 147 base::Unretained(resource_metadata_.get())),
135 google_apis::test_util::CreateCopyResultCallback(&error)); 148 google_apis::test_util::CreateCopyResultCallback(&error));
136 google_apis::test_util::RunBlockingPoolTask(); 149 google_apis::test_util::RunBlockingPoolTask();
137 ASSERT_EQ(FILE_ERROR_OK, error); 150 ASSERT_EQ(FILE_ERROR_OK, error);
138 151
139 blocking_task_runner_->PostTask( 152 blocking_task_runner_->PostTask(
140 FROM_HERE, 153 FROM_HERE,
141 base::Bind(&SetUpEntries, 154 base::Bind(&SetUpEntries,
142 base::Unretained(resource_metadata_.get()))); 155 base::Unretained(resource_metadata_.get())));
143 google_apis::test_util::RunBlockingPoolTask(); 156 google_apis::test_util::RunBlockingPoolTask();
144 } 157 }
145 158
146 virtual void TearDown() OVERRIDE { 159 virtual void TearDown() OVERRIDE {
160 metadata_storage_.reset();
147 resource_metadata_.reset(); 161 resource_metadata_.reset();
148 base::ThreadRestrictions::SetIOAllowed(true); 162 base::ThreadRestrictions::SetIOAllowed(true);
149 } 163 }
150 164
151 // Gets the resource entry by path synchronously. Returns NULL on failure. 165 // Gets the resource entry by path synchronously. Returns NULL on failure.
152 scoped_ptr<ResourceEntry> GetResourceEntryByPathSync( 166 scoped_ptr<ResourceEntry> GetResourceEntryByPathSync(
153 const base::FilePath& file_path) { 167 const base::FilePath& file_path) {
154 FileError error = FILE_ERROR_OK; 168 FileError error = FILE_ERROR_OK;
155 scoped_ptr<ResourceEntry> entry; 169 scoped_ptr<ResourceEntry> entry;
156 resource_metadata_->GetResourceEntryByPathOnUIThread( 170 resource_metadata_->GetResourceEntryByPathOnUIThread(
(...skipping 11 matching lines...) Expand all
168 FileError error = FILE_ERROR_OK; 182 FileError error = FILE_ERROR_OK;
169 scoped_ptr<ResourceEntryVector> entries; 183 scoped_ptr<ResourceEntryVector> entries;
170 resource_metadata_->ReadDirectoryByPathOnUIThread( 184 resource_metadata_->ReadDirectoryByPathOnUIThread(
171 directory_path, 185 directory_path,
172 google_apis::test_util::CreateCopyResultCallback(&error, &entries)); 186 google_apis::test_util::CreateCopyResultCallback(&error, &entries));
173 google_apis::test_util::RunBlockingPoolTask(); 187 google_apis::test_util::RunBlockingPoolTask();
174 EXPECT_TRUE(error == FILE_ERROR_OK || !entries); 188 EXPECT_TRUE(error == FILE_ERROR_OK || !entries);
175 return entries.Pass(); 189 return entries.Pass();
176 } 190 }
177 191
192 content::TestBrowserThreadBundle thread_bundle_;
178 base::ScopedTempDir temp_dir_; 193 base::ScopedTempDir temp_dir_;
179 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_; 194 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_;
195 scoped_ptr<ResourceMetadataStorage, test_util::DestroyHelperForTests>
196 metadata_storage_;
180 scoped_ptr<ResourceMetadata, test_util::DestroyHelperForTests> 197 scoped_ptr<ResourceMetadata, test_util::DestroyHelperForTests>
181 resource_metadata_; 198 resource_metadata_;
182
183 private:
184 content::TestBrowserThreadBundle thread_bundle_;
185 }; 199 };
186 200
187 TEST_F(ResourceMetadataTestOnUIThread, LargestChangestamp) { 201 TEST_F(ResourceMetadataTestOnUIThread, LargestChangestamp) {
188 scoped_ptr<ResourceMetadata, test_util::DestroyHelperForTests>
189 resource_metadata(new ResourceMetadata(temp_dir_.path(),
190 blocking_task_runner_));
191 FileError error = FILE_ERROR_FAILED; 202 FileError error = FILE_ERROR_FAILED;
192 base::PostTaskAndReplyWithResult(
193 blocking_task_runner_,
194 FROM_HERE,
195 base::Bind(&ResourceMetadata::Initialize,
196 base::Unretained(resource_metadata.get())),
197 google_apis::test_util::CreateCopyResultCallback(&error));
198 google_apis::test_util::RunBlockingPoolTask();
199 ASSERT_EQ(FILE_ERROR_OK, error);
200
201 int64 in_changestamp = 123456; 203 int64 in_changestamp = 123456;
202 resource_metadata->SetLargestChangestampOnUIThread( 204 resource_metadata_->SetLargestChangestampOnUIThread(
203 in_changestamp, 205 in_changestamp,
204 google_apis::test_util::CreateCopyResultCallback(&error)); 206 google_apis::test_util::CreateCopyResultCallback(&error));
205 google_apis::test_util::RunBlockingPoolTask(); 207 google_apis::test_util::RunBlockingPoolTask();
206 EXPECT_EQ(FILE_ERROR_OK, error); 208 EXPECT_EQ(FILE_ERROR_OK, error);
207 209
208 int64 out_changestamp = 0; 210 int64 out_changestamp = 0;
209 resource_metadata->GetLargestChangestampOnUIThread( 211 resource_metadata_->GetLargestChangestampOnUIThread(
210 google_apis::test_util::CreateCopyResultCallback(&out_changestamp)); 212 google_apis::test_util::CreateCopyResultCallback(&out_changestamp));
211 google_apis::test_util::RunBlockingPoolTask(); 213 google_apis::test_util::RunBlockingPoolTask();
212 DCHECK_EQ(in_changestamp, out_changestamp); 214 DCHECK_EQ(in_changestamp, out_changestamp);
213 } 215 }
214 216
215 TEST_F(ResourceMetadataTestOnUIThread, GetResourceEntryById_RootDirectory) { 217 TEST_F(ResourceMetadataTestOnUIThread, GetResourceEntryById_RootDirectory) {
216 scoped_ptr<ResourceMetadata, test_util::DestroyHelperForTests> 218 // Look up the root directory by its resource ID.
217 resource_metadata(new ResourceMetadata(temp_dir_.path(),
218 blocking_task_runner_));
219 FileError error = FILE_ERROR_FAILED; 219 FileError error = FILE_ERROR_FAILED;
220 base::PostTaskAndReplyWithResult(
221 blocking_task_runner_,
222 FROM_HERE,
223 base::Bind(&ResourceMetadata::Initialize,
224 base::Unretained(resource_metadata.get())),
225 google_apis::test_util::CreateCopyResultCallback(&error));
226 google_apis::test_util::RunBlockingPoolTask();
227 ASSERT_EQ(FILE_ERROR_OK, error);
228
229 scoped_ptr<ResourceEntry> entry; 220 scoped_ptr<ResourceEntry> entry;
230 221 resource_metadata_->GetResourceEntryByIdOnUIThread(
231 // Look up the root directory by its resource ID.
232 resource_metadata->GetResourceEntryByIdOnUIThread(
233 util::kDriveGrandRootSpecialResourceId, 222 util::kDriveGrandRootSpecialResourceId,
234 google_apis::test_util::CreateCopyResultCallback(&error, &entry)); 223 google_apis::test_util::CreateCopyResultCallback(&error, &entry));
235 google_apis::test_util::RunBlockingPoolTask(); 224 google_apis::test_util::RunBlockingPoolTask();
236 EXPECT_EQ(FILE_ERROR_OK, error); 225 EXPECT_EQ(FILE_ERROR_OK, error);
237 ASSERT_TRUE(entry.get()); 226 ASSERT_TRUE(entry.get());
238 EXPECT_EQ("drive", entry->base_name()); 227 EXPECT_EQ("drive", entry->base_name());
239 } 228 }
240 229
241 TEST_F(ResourceMetadataTestOnUIThread, GetResourceEntryById) { 230 TEST_F(ResourceMetadataTestOnUIThread, GetResourceEntryById) {
242 // Confirm that an existing file is found. 231 // Confirm that an existing file is found.
(...skipping 619 matching lines...) Expand 10 before | Expand all | Expand 10 after
862 ASSERT_TRUE(entries_in_other.get()); 851 ASSERT_TRUE(entries_in_other.get());
863 EXPECT_TRUE(entries_in_other->empty()); 852 EXPECT_TRUE(entries_in_other->empty());
864 } 853 }
865 854
866 // Tests for methods running on the blocking task runner. 855 // Tests for methods running on the blocking task runner.
867 class ResourceMetadataTest : public testing::Test { 856 class ResourceMetadataTest : public testing::Test {
868 protected: 857 protected:
869 virtual void SetUp() OVERRIDE { 858 virtual void SetUp() OVERRIDE {
870 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 859 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
871 860
872 // Use the main thread as the blocking task runner. 861 metadata_storage_.reset(new ResourceMetadataStorage(
862 temp_dir_.path(), base::MessageLoopProxy::current()));
863 ASSERT_TRUE(metadata_storage_->Initialize());
864
873 resource_metadata_.reset(new ResourceMetadata( 865 resource_metadata_.reset(new ResourceMetadata(
874 temp_dir_.path(), base::MessageLoopProxy::current())); 866 metadata_storage_.get(), base::MessageLoopProxy::current()));
875 867
876 ASSERT_EQ(FILE_ERROR_OK, resource_metadata_->Initialize()); 868 ASSERT_EQ(FILE_ERROR_OK, resource_metadata_->Initialize());
877 869
878 SetUpEntries(resource_metadata_.get()); 870 SetUpEntries(resource_metadata_.get());
879 } 871 }
880 872
881 virtual void TearDown() OVERRIDE { 873 virtual void TearDown() OVERRIDE {
882 } 874 }
883 875
884 base::ScopedTempDir temp_dir_; 876 base::ScopedTempDir temp_dir_;
885 content::TestBrowserThreadBundle thread_bundle_; 877 content::TestBrowserThreadBundle thread_bundle_;
878 scoped_ptr<ResourceMetadataStorage, test_util::DestroyHelperForTests>
879 metadata_storage_;
886 scoped_ptr<ResourceMetadata, test_util::DestroyHelperForTests> 880 scoped_ptr<ResourceMetadata, test_util::DestroyHelperForTests>
887 resource_metadata_; 881 resource_metadata_;
888 }; 882 };
889 883
890 TEST_F(ResourceMetadataTest, RefreshEntry) { 884 TEST_F(ResourceMetadataTest, RefreshEntry) {
891 base::FilePath drive_file_path; 885 base::FilePath drive_file_path;
892 ResourceEntry entry; 886 ResourceEntry entry;
893 887
894 // Get file9. 888 // Get file9.
895 EXPECT_EQ(FILE_ERROR_OK, resource_metadata_->GetResourceEntryByPath( 889 EXPECT_EQ(FILE_ERROR_OK, resource_metadata_->GetResourceEntryByPath(
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
1085 else 1079 else
1086 ++directory_count; 1080 ++directory_count;
1087 } 1081 }
1088 1082
1089 EXPECT_EQ(7, file_count); 1083 EXPECT_EQ(7, file_count);
1090 EXPECT_EQ(6, directory_count); 1084 EXPECT_EQ(6, directory_count);
1091 } 1085 }
1092 1086
1093 } // namespace internal 1087 } // namespace internal
1094 } // namespace drive 1088 } // namespace drive
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698