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" | |
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 // Callback to GDataCache::StoreOnUIThread used in RemoveStaleCacheFiles test. | |
satorux1
2012/08/17 10:38:41
Callback for
yoshiki
2012/08/18 03:31:51
Done.
| |
78 // Verifies that the result is not an error. | |
79 void VerifyCacheFileState(GDataFileError error, | |
80 const std::string& resource_id, | |
81 const std::string& md5) { | |
82 EXPECT_EQ(GDATA_FILE_OK, error); | |
83 } | |
84 | |
76 // Action used to set mock expectations for | 85 // Action used to set mock expectations for |
77 // DocumentsService::GetDocumentEntry(). | 86 // DocumentsService::GetDocumentEntry(). |
78 ACTION_P2(MockGetDocumentEntry, status, value) { | 87 ACTION_P2(MockGetDocumentEntry, status, value) { |
79 base::MessageLoopProxy::current()->PostTask(FROM_HERE, | 88 base::MessageLoopProxy::current()->PostTask(FROM_HERE, |
80 base::Bind(arg1, status, base::Passed(value))); | 89 base::Bind(arg1, status, base::Passed(value))); |
81 } | 90 } |
82 | 91 |
83 // Action used to set mock expectations for | 92 // Action used to set mock expectations for |
84 // GDataUploaderInterface::UploadExistingFile(). | 93 // GDataUploaderInterface::UploadExistingFile(). |
85 ACTION_P4(MockUploadExistingFile, | 94 ACTION_P4(MockUploadExistingFile, |
(...skipping 2529 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2615 file_md5); | 2624 file_md5); |
2616 | 2625 |
2617 // Try to close the same file twice. | 2626 // Try to close the same file twice. |
2618 file_system_->CloseFile(kFileInRoot, close_file_callback); | 2627 file_system_->CloseFile(kFileInRoot, close_file_callback); |
2619 message_loop_.Run(); | 2628 message_loop_.Run(); |
2620 | 2629 |
2621 // It must fail. | 2630 // It must fail. |
2622 EXPECT_EQ(GDATA_FILE_ERROR_NOT_FOUND, callback_helper_->last_error_); | 2631 EXPECT_EQ(GDATA_FILE_ERROR_NOT_FOUND, callback_helper_->last_error_); |
2623 } | 2632 } |
2624 | 2633 |
2634 TEST_F(GDataFileSystemTest, RemoveStaleCacheFiles) { | |
2635 FilePath dummy_file = GetTestFilePath("root_feed.json"); | |
2636 std::string resource_id("pdf:1a2b"); | |
2637 std::string md5("abcdef0123456789"); | |
2638 | |
2639 // Create a stale cache file. | |
2640 cache_->StoreOnUIThread(resource_id, md5, dummy_file, | |
2641 GDataCache::FILE_OPERATION_COPY, | |
2642 base::Bind(&gdata::VerifyCacheFileState)); | |
2643 test_util::RunBlockingPoolTask(); | |
2644 | |
2645 // Verify that the cache file exists. | |
2646 FilePath path = cache_->GetCacheFilePath(resource_id, | |
2647 md5, | |
2648 GDataCache::CACHE_TYPE_TMP, | |
2649 GDataCache::CACHED_FILE_FROM_SERVER); | |
2650 EXPECT_TRUE(file_util::PathExists(path)); | |
2651 | |
2652 // Verify that the corresponding file entry doesn't exist. | |
2653 EXPECT_CALL(*mock_doc_service_, GetAccountMetadata(_)).Times(1); | |
2654 EXPECT_CALL(*mock_doc_service_, GetDocuments(Eq(GURL()), _, "", _, _)) | |
2655 .Times(1); | |
2656 EXPECT_CALL(*mock_webapps_registry_, UpdateFromFeed(NotNull())).Times(1); | |
2657 | |
2658 scoped_ptr<GDataEntryProto> entry = GetEntryInfoByPathSync(path); | |
2659 ASSERT_FALSE(entry.get()); | |
2660 | |
2661 // Load a root feed. | |
2662 LoadRootFeedDocument("root_feed.json"); | |
2663 | |
2664 base::RunLoop run_loop; | |
2665 run_loop.RunUntilIdle(); | |
2666 | |
2667 // Verify that the cache file is deleted. | |
2668 path = cache_->GetCacheFilePath(resource_id, | |
2669 md5, | |
2670 GDataCache::CACHE_TYPE_TMP, | |
2671 GDataCache::CACHED_FILE_FROM_SERVER); | |
2672 EXPECT_FALSE(file_util::PathExists(path)); | |
2673 } | |
2674 | |
2625 } // namespace gdata | 2675 } // namespace gdata |
OLD | NEW |