Chromium Code Reviews| 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/json/json_file_value_serializer.h" | 11 #include "base/json/json_file_value_serializer.h" |
| 12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/message_loop.h" | 13 #include "base/message_loop.h" |
| 14 #include "base/path_service.h" | 14 #include "base/path_service.h" |
| 15 #include "base/run_loop.h" | |
|
satorux1
2012/08/19 05:24:59
please remove. see below.
yoshiki
2012/08/20 02:39:37
Done.
| |
| 15 #include "base/scoped_temp_dir.h" | 16 #include "base/scoped_temp_dir.h" |
| 16 #include "base/stringprintf.h" | 17 #include "base/stringprintf.h" |
| 17 #include "base/threading/sequenced_worker_pool.h" | 18 #include "base/threading/sequenced_worker_pool.h" |
| 18 #include "base/values.h" | 19 #include "base/values.h" |
| 19 #include "chrome/browser/chromeos/cros/cros_library.h" | 20 #include "chrome/browser/chromeos/cros/cros_library.h" |
| 20 #include "chrome/browser/chromeos/gdata/drive_webapps_registry.h" | 21 #include "chrome/browser/chromeos/gdata/drive_webapps_registry.h" |
| 21 #include "chrome/browser/chromeos/gdata/gdata.pb.h" | 22 #include "chrome/browser/chromeos/gdata/gdata.pb.h" |
| 22 #include "chrome/browser/chromeos/gdata/gdata_file_system.h" | 23 #include "chrome/browser/chromeos/gdata/gdata_file_system.h" |
| 23 #include "chrome/browser/chromeos/gdata/gdata_test_util.h" | 24 #include "chrome/browser/chromeos/gdata/gdata_test_util.h" |
| 24 #include "chrome/browser/chromeos/gdata/gdata_util.h" | 25 #include "chrome/browser/chromeos/gdata/gdata_util.h" |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 66 for (size_t i = 0; i < results->size(); i++) { | 67 for (size_t i = 0; i < results->size(); i++) { |
| 67 EXPECT_EQ(FilePath(expected_results[i].path), | 68 EXPECT_EQ(FilePath(expected_results[i].path), |
| 68 results->at(i).path); | 69 results->at(i).path); |
| 69 EXPECT_EQ(expected_results[i].is_directory, | 70 EXPECT_EQ(expected_results[i].is_directory, |
| 70 results->at(i).is_directory); | 71 results->at(i).is_directory); |
| 71 } | 72 } |
| 72 | 73 |
| 73 message_loop->Quit(); | 74 message_loop->Quit(); |
| 74 } | 75 } |
| 75 | 76 |
| 77 void VerifyCacheFileState(GDataFileError error, | |
|
satorux1
2012/08/16 11:03:53
function comment is missing.
yoshiki
2012/08/17 03:49:59
Done.
| |
| 78 const std::string& resource_id, | |
| 79 const std::string& md5) { | |
| 80 EXPECT_EQ(GDATA_FILE_OK, error); | |
| 81 } | |
| 82 | |
| 76 // Action used to set mock expectations for | 83 // Action used to set mock expectations for |
| 77 // DocumentsService::GetDocumentEntry(). | 84 // DocumentsService::GetDocumentEntry(). |
| 78 ACTION_P2(MockGetDocumentEntry, status, value) { | 85 ACTION_P2(MockGetDocumentEntry, status, value) { |
| 79 base::MessageLoopProxy::current()->PostTask(FROM_HERE, | 86 base::MessageLoopProxy::current()->PostTask(FROM_HERE, |
| 80 base::Bind(arg1, status, base::Passed(value))); | 87 base::Bind(arg1, status, base::Passed(value))); |
| 81 } | 88 } |
| 82 | 89 |
| 83 // Action used to set mock expectations for | 90 // Action used to set mock expectations for |
| 84 // GDataUploaderInterface::UploadExistingFile(). | 91 // GDataUploaderInterface::UploadExistingFile(). |
| 85 ACTION_P4(MockUploadExistingFile, | 92 ACTION_P4(MockUploadExistingFile, |
| (...skipping 2529 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2615 file_md5); | 2622 file_md5); |
| 2616 | 2623 |
| 2617 // Try to close the same file twice. | 2624 // Try to close the same file twice. |
| 2618 file_system_->CloseFile(kFileInRoot, close_file_callback); | 2625 file_system_->CloseFile(kFileInRoot, close_file_callback); |
| 2619 message_loop_.Run(); | 2626 message_loop_.Run(); |
| 2620 | 2627 |
| 2621 // It must fail. | 2628 // It must fail. |
| 2622 EXPECT_EQ(GDATA_FILE_ERROR_NOT_FOUND, callback_helper_->last_error_); | 2629 EXPECT_EQ(GDATA_FILE_ERROR_NOT_FOUND, callback_helper_->last_error_); |
| 2623 } | 2630 } |
| 2624 | 2631 |
| 2632 TEST_F(GDataFileSystemTest, RemoveStaleCacheFiles) { | |
| 2633 FilePath dummy_file = GetTestFilePath("root_feed.json"); | |
| 2634 std::string resource_id("pdf:1a2b"); | |
| 2635 std::string md5("abcdef0123456789"); | |
| 2636 | |
| 2637 // Create a stale cache file. | |
| 2638 cache_->StoreOnUIThread(resource_id, md5, dummy_file, | |
| 2639 GDataCache::FILE_OPERATION_COPY, | |
| 2640 base::Bind(&gdata::VerifyCacheFileState)); | |
| 2641 test_util::RunBlockingPoolTask(); | |
| 2642 | |
| 2643 // Verify that the cache file exists. | |
| 2644 FilePath path = cache_->GetCacheFilePath(resource_id, | |
| 2645 md5, | |
| 2646 GDataCache::CACHE_TYPE_TMP, | |
| 2647 GDataCache::CACHED_FILE_FROM_SERVER); | |
| 2648 EXPECT_TRUE(file_util::PathExists(path)); | |
| 2649 | |
| 2650 // Verify that the corresponding file entry doesn't exist. | |
| 2651 EXPECT_CALL(*mock_doc_service_, GetAccountMetadata(_)).Times(1); | |
| 2652 EXPECT_CALL(*mock_doc_service_, GetDocuments(Eq(GURL()), _, "", _, _)) | |
| 2653 .Times(1); | |
| 2654 EXPECT_CALL(*mock_webapps_registry_, UpdateFromFeed(NotNull())).Times(1); | |
| 2655 | |
| 2656 scoped_ptr<GDataEntryProto> entry = GetEntryInfoByPathSync(path); | |
| 2657 ASSERT_FALSE(entry.get()); | |
| 2658 | |
| 2659 // Load a root feed. | |
| 2660 LoadRootFeedDocument("root_feed.json"); | |
| 2661 | |
| 2662 base::RunLoop run_loop; | |
| 2663 run_loop.RunUntilIdle(); | |
|
satorux1
2012/08/16 11:03:53
this is new to me. why is this used? shouldn't we
yoshiki
2012/08/17 03:49:59
We don't need RunBlockingPoolTask(), because in th
satorux1
2012/08/17 10:38:41
I'm more confused. If feed loading is done synchr
yoshiki
2012/08/18 03:31:51
Sorry for confusion, my comment has a wrong method
satorux1
2012/08/18 11:33:16
Sorry, but I'm still confused. Could you explain w
satorux1
2012/08/19 05:24:59
I guess the synchronization is needed to let the S
yoshiki
2012/08/20 02:39:37
Right.
| |
| 2664 | |
| 2665 // Verify that the cache file is deleted. | |
| 2666 path = cache_->GetCacheFilePath(resource_id, | |
| 2667 md5, | |
| 2668 GDataCache::CACHE_TYPE_TMP, | |
| 2669 GDataCache::CACHED_FILE_FROM_SERVER); | |
| 2670 EXPECT_FALSE(file_util::PathExists(path)); | |
| 2671 } | |
| 2672 | |
| 2625 } // namespace gdata | 2673 } // namespace gdata |
| OLD | NEW |