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

Side by Side Diff: chrome/browser/media_galleries/fileapi/picasa/picasa_file_util_unittest.cc

Issue 14113053: chrome: Use base::MessageLoop. (Part 3) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase again 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 <set> 5 #include <set>
6 #include <string> 6 #include <string>
7 7
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/files/scoped_temp_dir.h" 9 #include "base/files/scoped_temp_dir.h"
10 #include "base/memory/scoped_vector.h" 10 #include "base/memory/scoped_vector.h"
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 ASSERT_TRUE(test_helper_->WriteColumnFileFromVector( 245 ASSERT_TRUE(test_helper_->WriteColumnFileFromVector(
246 "token", picasa::PMP_TYPE_STRING, token_column)); 246 "token", picasa::PMP_TYPE_STRING, token_column));
247 } 247 }
248 248
249 void VerifyFolderDirectoryList(const ScopedVector<TestFolder>& test_folders) { 249 void VerifyFolderDirectoryList(const ScopedVector<TestFolder>& test_folders) {
250 FileSystemOperation::FileEntryList contents; 250 FileSystemOperation::FileEntryList contents;
251 FileSystemURL url = CreateURL(kPicasaDirFolders); 251 FileSystemURL url = CreateURL(kPicasaDirFolders);
252 bool completed = false; 252 bool completed = false;
253 NewOperation(url)->ReadDirectory( 253 NewOperation(url)->ReadDirectory(
254 url, base::Bind(&DidReadDirectory, &contents, &completed)); 254 url, base::Bind(&DidReadDirectory, &contents, &completed));
255 MessageLoop::current()->RunUntilIdle(); 255 base::MessageLoop::current()->RunUntilIdle();
256 256
257 ASSERT_TRUE(completed); 257 ASSERT_TRUE(completed);
258 ASSERT_EQ(test_folders.size(), contents.size()); 258 ASSERT_EQ(test_folders.size(), contents.size());
259 259
260 for (size_t i = 0; i < contents.size(); ++i) { 260 for (size_t i = 0; i < contents.size(); ++i) {
261 EXPECT_TRUE(contents[i].is_directory); 261 EXPECT_TRUE(contents[i].is_directory);
262 262
263 // Because the timestamp is written out as a floating point Microsoft 263 // Because the timestamp is written out as a floating point Microsoft
264 // variant time, we only expect it to be accurate to within a second. 264 // variant time, we only expect it to be accurate to within a second.
265 base::TimeDelta delta = test_folders[i]->folder_info().timestamp - 265 base::TimeDelta delta = test_folders[i]->folder_info().timestamp -
266 contents[i].last_modified_time; 266 contents[i].last_modified_time;
267 EXPECT_LT(delta, base::TimeDelta::FromSeconds(1)); 267 EXPECT_LT(delta, base::TimeDelta::FromSeconds(1));
268 268
269 FileSystemOperation::FileEntryList folder_contents; 269 FileSystemOperation::FileEntryList folder_contents;
270 FileSystemURL folder_url = CreateURL( 270 FileSystemURL folder_url = CreateURL(
271 std::string(kPicasaDirFolders) + "/" + 271 std::string(kPicasaDirFolders) + "/" +
272 base::FilePath(contents[i].name).AsUTF8Unsafe()); 272 base::FilePath(contents[i].name).AsUTF8Unsafe());
273 bool folder_read_completed = false; 273 bool folder_read_completed = false;
274 NewOperation(folder_url)->ReadDirectory( 274 NewOperation(folder_url)->ReadDirectory(
275 folder_url, 275 folder_url,
276 base::Bind(&DidReadDirectory, &folder_contents, 276 base::Bind(&DidReadDirectory, &folder_contents,
277 &folder_read_completed)); 277 &folder_read_completed));
278 MessageLoop::current()->RunUntilIdle(); 278 base::MessageLoop::current()->RunUntilIdle();
279 279
280 EXPECT_TRUE(folder_read_completed); 280 EXPECT_TRUE(folder_read_completed);
281 281
282 const std::set<std::string>& image_filenames = 282 const std::set<std::string>& image_filenames =
283 test_folders[i]->image_filenames(); 283 test_folders[i]->image_filenames();
284 284
285 EXPECT_EQ(image_filenames.size(), folder_contents.size()); 285 EXPECT_EQ(image_filenames.size(), folder_contents.size());
286 286
287 for (FileSystemOperation::FileEntryList::const_iterator file_it = 287 for (FileSystemOperation::FileEntryList::const_iterator file_it =
288 folder_contents.begin(); file_it != folder_contents.end(); 288 folder_contents.begin(); file_it != folder_contents.end();
289 ++file_it) { 289 ++file_it) {
290 EXPECT_EQ(1u, image_filenames.count( 290 EXPECT_EQ(1u, image_filenames.count(
291 base::FilePath(file_it->name).AsUTF8Unsafe())); 291 base::FilePath(file_it->name).AsUTF8Unsafe()));
292 } 292 }
293 } 293 }
294 } 294 }
295 295
296 std::string DateToPathString(const base::Time& time) { 296 std::string DateToPathString(const base::Time& time) {
297 return PicasaDataProvider::DateToPathString(time); 297 return PicasaDataProvider::DateToPathString(time);
298 } 298 }
299 299
300 void TestNonexistentFolder(const std::string& path_append) { 300 void TestNonexistentFolder(const std::string& path_append) {
301 FileSystemOperation::FileEntryList contents; 301 FileSystemOperation::FileEntryList contents;
302 FileSystemURL url = CreateURL( 302 FileSystemURL url = CreateURL(
303 std::string(kPicasaDirFolders) + path_append); 303 std::string(kPicasaDirFolders) + path_append);
304 bool completed = false; 304 bool completed = false;
305 NewOperation(url)->ReadDirectory( 305 NewOperation(url)->ReadDirectory(
306 url, base::Bind(&DidReadDirectory, &contents, &completed)); 306 url, base::Bind(&DidReadDirectory, &contents, &completed));
307 MessageLoop::current()->RunUntilIdle(); 307 base::MessageLoop::current()->RunUntilIdle();
308 308
309 ASSERT_FALSE(completed); 309 ASSERT_FALSE(completed);
310 } 310 }
311 311
312 FileSystemURL CreateURL(const std::string& virtual_path) { 312 FileSystemURL CreateURL(const std::string& virtual_path) {
313 return file_system_context_->CreateCrackedFileSystemURL( 313 return file_system_context_->CreateCrackedFileSystemURL(
314 GURL("http://www.example.com"), fileapi::kFileSystemTypePicasa, 314 GURL("http://www.example.com"), fileapi::kFileSystemTypePicasa,
315 base::FilePath::FromUTF8Unsafe(virtual_path)); 315 base::FilePath::FromUTF8Unsafe(virtual_path));
316 } 316 }
317 317
318 FileSystemOperation* NewOperation(const FileSystemURL& url) { 318 FileSystemOperation* NewOperation(const FileSystemURL& url) {
319 return file_system_context_->CreateFileSystemOperation(url, NULL); 319 return file_system_context_->CreateFileSystemOperation(url, NULL);
320 } 320 }
321 321
322 scoped_refptr<fileapi::FileSystemContext> file_system_context() { 322 scoped_refptr<fileapi::FileSystemContext> file_system_context() {
323 return file_system_context_; 323 return file_system_context_;
324 } 324 }
325 325
326 private: 326 private:
327 MessageLoop message_loop_; 327 base::MessageLoop message_loop_;
328 328
329 base::ScopedTempDir profile_dir_; 329 base::ScopedTempDir profile_dir_;
330 330
331 scoped_refptr<fileapi::FileSystemContext> file_system_context_; 331 scoped_refptr<fileapi::FileSystemContext> file_system_context_;
332 scoped_ptr<PmpTestHelper> test_helper_; 332 scoped_ptr<PmpTestHelper> test_helper_;
333 333
334 DISALLOW_COPY_AND_ASSIGN(PicasaFileUtilTest); 334 DISALLOW_COPY_AND_ASSIGN(PicasaFileUtilTest);
335 }; 335 };
336 336
337 TEST_F(PicasaFileUtilTest, DateFormat) { 337 TEST_F(PicasaFileUtilTest, DateFormat) {
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
402 EXPECT_TRUE(file_enumerator->IsDirectory()); 402 EXPECT_TRUE(file_enumerator->IsDirectory());
403 } 403 }
404 } 404 }
405 405
406 TEST_F(PicasaFileUtilTest, RootFolders) { 406 TEST_F(PicasaFileUtilTest, RootFolders) {
407 FileSystemOperation::FileEntryList contents; 407 FileSystemOperation::FileEntryList contents;
408 FileSystemURL url = CreateURL(""); 408 FileSystemURL url = CreateURL("");
409 bool completed = false; 409 bool completed = false;
410 NewOperation(url)->ReadDirectory( 410 NewOperation(url)->ReadDirectory(
411 url, base::Bind(&DidReadDirectory, &contents, &completed)); 411 url, base::Bind(&DidReadDirectory, &contents, &completed));
412 MessageLoop::current()->RunUntilIdle(); 412 base::MessageLoop::current()->RunUntilIdle();
413 413
414 ASSERT_TRUE(completed); 414 ASSERT_TRUE(completed);
415 ASSERT_EQ(2u, contents.size()); 415 ASSERT_EQ(2u, contents.size());
416 416
417 EXPECT_TRUE(contents.front().is_directory); 417 EXPECT_TRUE(contents.front().is_directory);
418 EXPECT_TRUE(contents.back().is_directory); 418 EXPECT_TRUE(contents.back().is_directory);
419 419
420 EXPECT_EQ(0, contents.front().size); 420 EXPECT_EQ(0, contents.front().size);
421 EXPECT_EQ(0, contents.back().size); 421 EXPECT_EQ(0, contents.back().size);
422 422
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
474 new TestFolder(base::StringPrintf("folder-%05d", i), 474 new TestFolder(base::StringPrintf("folder-%05d", i),
475 date, 475 date,
476 base::StringPrintf("uid%05d", i), i % 5, i % 3)); 476 base::StringPrintf("uid%05d", i), i % 5, i % 3));
477 } 477 }
478 478
479 SetupFolders(&test_folders); 479 SetupFolders(&test_folders);
480 VerifyFolderDirectoryList(test_folders); 480 VerifyFolderDirectoryList(test_folders);
481 } 481 }
482 482
483 } // namespace chrome 483 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698