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

Side by Side Diff: chrome/browser/chromeos/gdata/gdata_file_system_unittest.cc

Issue 10790135: chromeos: Rename MockGDataSyncClient to MocKGDataCacheObserver (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 5 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 <errno.h>
6 #include <string> 5 #include <string>
7 #include <vector> 6 #include <vector>
8 7
9 #include "base/bind.h" 8 #include "base/bind.h"
10 #include "base/bind_helpers.h"
11 #include "base/file_path.h" 9 #include "base/file_path.h"
12 #include "base/file_util.h" 10 #include "base/file_util.h"
13 #include "base/json/json_file_value_serializer.h" 11 #include "base/json/json_file_value_serializer.h"
14 #include "base/memory/ref_counted.h"
15 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
16 #include "base/message_loop.h" 13 #include "base/message_loop.h"
17 #include "base/path_service.h" 14 #include "base/path_service.h"
18 #include "base/scoped_temp_dir.h" 15 #include "base/scoped_temp_dir.h"
19 #include "base/string16.h"
20 #include "base/string_util.h"
21 #include "base/stringprintf.h" 16 #include "base/stringprintf.h"
22 #include "base/threading/sequenced_worker_pool.h" 17 #include "base/threading/sequenced_worker_pool.h"
23 #include "base/time.h"
24 #include "base/utf_string_conversions.h"
25 #include "base/values.h" 18 #include "base/values.h"
26 #include "chrome/browser/chromeos/cros/cros_library.h" 19 #include "chrome/browser/chromeos/cros/cros_library.h"
27 #include "chrome/browser/chromeos/gdata/drive_webapps_registry.h" 20 #include "chrome/browser/chromeos/gdata/drive_webapps_registry.h"
28 #include "chrome/browser/chromeos/gdata/gdata.pb.h" 21 #include "chrome/browser/chromeos/gdata/gdata.pb.h"
29 #include "chrome/browser/chromeos/gdata/gdata_file_system.h" 22 #include "chrome/browser/chromeos/gdata/gdata_file_system.h"
30 #include "chrome/browser/chromeos/gdata/gdata_test_util.h" 23 #include "chrome/browser/chromeos/gdata/gdata_test_util.h"
31 #include "chrome/browser/chromeos/gdata/gdata_util.h" 24 #include "chrome/browser/chromeos/gdata/gdata_util.h"
32 #include "chrome/browser/chromeos/gdata/gdata_wapi_parser.h"
33 #include "chrome/browser/chromeos/gdata/mock_directory_change_observer.h" 25 #include "chrome/browser/chromeos/gdata/mock_directory_change_observer.h"
26 #include "chrome/browser/chromeos/gdata/mock_gdata_cache_observer.h"
34 #include "chrome/browser/chromeos/gdata/mock_gdata_documents_service.h" 27 #include "chrome/browser/chromeos/gdata/mock_gdata_documents_service.h"
35 #include "chrome/browser/chromeos/gdata/mock_gdata_sync_client.h"
36 #include "chrome/common/chrome_paths.h" 28 #include "chrome/common/chrome_paths.h"
37 #include "chrome/test/base/testing_profile.h" 29 #include "chrome/test/base/testing_profile.h"
38 #include "content/public/browser/browser_thread.h" 30 #include "content/public/browser/browser_thread.h"
39 #include "content/public/test/test_browser_thread.h" 31 #include "content/public/test/test_browser_thread.h"
40 #include "testing/gmock/include/gmock/gmock.h" 32 #include "testing/gmock/include/gmock/gmock.h"
41 #include "testing/gtest/include/gtest/gtest.h" 33 #include "testing/gtest/include/gtest/gtest.h"
42 34
43 using ::testing::AnyNumber;
44 using ::testing::AtLeast; 35 using ::testing::AtLeast;
45 using ::testing::Eq; 36 using ::testing::Eq;
46 using ::testing::IsNull;
47 using ::testing::Ne;
48 using ::testing::NotNull; 37 using ::testing::NotNull;
49 using ::testing::Return; 38 using ::testing::Return;
50 using ::testing::ReturnNull;
51 using ::testing::StrictMock; 39 using ::testing::StrictMock;
52 using ::testing::_; 40 using ::testing::_;
53 41
54 using base::Value;
55 using base::DictionaryValue;
56 using base::ListValue;
57 using content::BrowserThread;
58
59 namespace gdata { 42 namespace gdata {
60 namespace { 43 namespace {
61 44
62 const char kSymLinkToDevNull[] = "/dev/null"; 45 const char kSymLinkToDevNull[] = "/dev/null";
63 46
64 const int64 kLotsOfSpace = kMinFreeSpace * 10; 47 const int64 kLotsOfSpace = kMinFreeSpace * 10;
65 48
66 struct PathToVerify {
67 PathToVerify(const FilePath& in_path_to_scan,
68 const FilePath& in_expected_existing_path) :
69 path_to_scan(in_path_to_scan),
70 expected_existing_path(in_expected_existing_path) {
71 }
72
73 FilePath path_to_scan;
74 FilePath expected_existing_path;
75 };
76
77 struct SearchResultPair { 49 struct SearchResultPair {
78 const char* path; 50 const char* path;
79 const bool is_directory; 51 const bool is_directory;
80 }; 52 };
81 53
82 // Callback to GDataFileSystem::Search used in ContentSearch tests. 54 // Callback to GDataFileSystem::Search used in ContentSearch tests.
83 // Verifies returned vector of results. 55 // Verifies returned vector of results.
84 void DriveSearchCallback( 56 void DriveSearchCallback(
85 MessageLoop* message_loop, 57 MessageLoop* message_loop,
86 const SearchResultPair* expected_results, 58 const SearchResultPair* expected_results,
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 mock_webapps_registry_.reset(new StrictMock<MockDriveWebAppsRegistry>); 242 mock_webapps_registry_.reset(new StrictMock<MockDriveWebAppsRegistry>);
271 243
272 ASSERT_FALSE(file_system_); 244 ASSERT_FALSE(file_system_);
273 file_system_ = new GDataFileSystem(profile_.get(), 245 file_system_ = new GDataFileSystem(profile_.get(),
274 cache_, 246 cache_,
275 mock_doc_service_, 247 mock_doc_service_,
276 mock_uploader_.get(), 248 mock_uploader_.get(),
277 mock_webapps_registry_.get(), 249 mock_webapps_registry_.get(),
278 blocking_task_runner_); 250 blocking_task_runner_);
279 251
280 mock_sync_client_.reset(new StrictMock<MockGDataSyncClient>); 252 mock_cache_observer_.reset(new StrictMock<MockGDataCacheObserver>);
281 cache_->AddObserver(mock_sync_client_.get()); 253 cache_->AddObserver(mock_cache_observer_.get());
282 254
283 mock_directory_observer_.reset(new StrictMock<MockDirectoryChangeObserver>); 255 mock_directory_observer_.reset(new StrictMock<MockDirectoryChangeObserver>);
284 file_system_->AddObserver(mock_directory_observer_.get()); 256 file_system_->AddObserver(mock_directory_observer_.get());
285 257
286 file_system_->Initialize(); 258 file_system_->Initialize();
287 cache_->RequestInitializeOnUIThread(); 259 cache_->RequestInitializeOnUIThread();
288 test_util::RunBlockingPoolTask(); 260 test_util::RunBlockingPoolTask();
289 } 261 }
290 262
291 virtual void TearDown() OVERRIDE { 263 virtual void TearDown() OVERRIDE {
(...skipping 566 matching lines...) Expand 10 before | Expand all | Expand 10 after
858 content::TestBrowserThread io_thread_; 830 content::TestBrowserThread io_thread_;
859 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_; 831 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_;
860 scoped_ptr<TestingProfile> profile_; 832 scoped_ptr<TestingProfile> profile_;
861 scoped_refptr<CallbackHelper> callback_helper_; 833 scoped_refptr<CallbackHelper> callback_helper_;
862 GDataCache* cache_; 834 GDataCache* cache_;
863 scoped_ptr<StrictMock<MockGDataUploader> > mock_uploader_; 835 scoped_ptr<StrictMock<MockGDataUploader> > mock_uploader_;
864 GDataFileSystem* file_system_; 836 GDataFileSystem* file_system_;
865 StrictMock<MockDocumentsService>* mock_doc_service_; 837 StrictMock<MockDocumentsService>* mock_doc_service_;
866 scoped_ptr<StrictMock<MockDriveWebAppsRegistry> > mock_webapps_registry_; 838 scoped_ptr<StrictMock<MockDriveWebAppsRegistry> > mock_webapps_registry_;
867 StrictMock<MockFreeDiskSpaceGetter>* mock_free_disk_space_checker_; 839 StrictMock<MockFreeDiskSpaceGetter>* mock_free_disk_space_checker_;
868 scoped_ptr<StrictMock<MockGDataSyncClient> > mock_sync_client_; 840 scoped_ptr<StrictMock<MockGDataCacheObserver> > mock_cache_observer_;
869 scoped_ptr<StrictMock<MockDirectoryChangeObserver> > mock_directory_observer_; 841 scoped_ptr<StrictMock<MockDirectoryChangeObserver> > mock_directory_observer_;
870 842
871 int num_callback_invocations_; 843 int num_callback_invocations_;
872 GDataFileError expected_error_; 844 GDataFileError expected_error_;
873 int expected_cache_state_; 845 int expected_cache_state_;
874 GDataCache::CacheSubDirectoryType expected_sub_dir_type_; 846 GDataCache::CacheSubDirectoryType expected_sub_dir_type_;
875 bool expected_success_; 847 bool expected_success_;
876 bool expect_outgoing_symlink_; 848 bool expect_outgoing_symlink_;
877 std::string expected_file_extension_; 849 std::string expected_file_extension_;
878 int root_feed_changestamp_; 850 int root_feed_changestamp_;
(...skipping 1398 matching lines...) Expand 10 before | Expand all | Expand 10 after
2277 2249
2278 TEST_F(GDataFileSystemTest, UpdateFileByResourceId_PersistentFile) { 2250 TEST_F(GDataFileSystemTest, UpdateFileByResourceId_PersistentFile) {
2279 LoadRootFeedDocument("root_feed.json"); 2251 LoadRootFeedDocument("root_feed.json");
2280 2252
2281 // This is a file defined in root_feed.json. 2253 // This is a file defined in root_feed.json.
2282 const FilePath kFilePath(FILE_PATH_LITERAL("drive/File 1.txt")); 2254 const FilePath kFilePath(FILE_PATH_LITERAL("drive/File 1.txt"));
2283 const std::string kResourceId("file:2_file_resource_id"); 2255 const std::string kResourceId("file:2_file_resource_id");
2284 const std::string kMd5("3b4382ebefec6e743578c76bbd0575ce"); 2256 const std::string kMd5("3b4382ebefec6e743578c76bbd0575ce");
2285 2257
2286 // Pin the file so it'll be store in "persistent" directory. 2258 // Pin the file so it'll be store in "persistent" directory.
2287 EXPECT_CALL(*mock_sync_client_, OnCachePinned(kResourceId, kMd5)).Times(1); 2259 EXPECT_CALL(*mock_cache_observer_, OnCachePinned(kResourceId, kMd5)).Times(1);
2288 TestPin(kResourceId, 2260 TestPin(kResourceId,
2289 kMd5, 2261 kMd5,
2290 GDATA_FILE_OK, 2262 GDATA_FILE_OK,
2291 test_util::TEST_CACHE_STATE_PINNED, 2263 test_util::TEST_CACHE_STATE_PINNED,
2292 GDataCache::CACHE_TYPE_TMP); 2264 GDataCache::CACHE_TYPE_TMP);
2293 2265
2294 // First store a file to cache. A cache file will be created at: 2266 // First store a file to cache. A cache file will be created at:
2295 // GCache/v1/persistent/<kResourceId>.<kMd5> 2267 // GCache/v1/persistent/<kResourceId>.<kMd5>
2296 const FilePath original_cache_file_path = 2268 const FilePath original_cache_file_path =
2297 GDataCache::GetCacheRootPath(profile_.get()) 2269 GDataCache::GetCacheRootPath(profile_.get())
(...skipping 22 matching lines...) Expand all
2320 const FilePath dirty_cache_file_path = 2292 const FilePath dirty_cache_file_path =
2321 GDataCache::GetCacheRootPath(profile_.get()) 2293 GDataCache::GetCacheRootPath(profile_.get())
2322 .AppendASCII("persistent") 2294 .AppendASCII("persistent")
2323 .AppendASCII(kResourceId + ".local"); 2295 .AppendASCII(kResourceId + ".local");
2324 ASSERT_FALSE(file_util::PathExists(original_cache_file_path)); 2296 ASSERT_FALSE(file_util::PathExists(original_cache_file_path));
2325 ASSERT_TRUE(file_util::PathExists(dirty_cache_file_path)); 2297 ASSERT_TRUE(file_util::PathExists(dirty_cache_file_path));
2326 2298
2327 // Commit the dirty bit. The cache file name remains the same 2299 // Commit the dirty bit. The cache file name remains the same
2328 // but a symlink will be created at: 2300 // but a symlink will be created at:
2329 // GCache/v1/outgoing/<kResourceId> 2301 // GCache/v1/outgoing/<kResourceId>
2330 EXPECT_CALL(*mock_sync_client_, OnCacheCommitted(kResourceId)).Times(1); 2302 EXPECT_CALL(*mock_cache_observer_, OnCacheCommitted(kResourceId)).Times(1);
2331 TestCommitDirty(kResourceId, 2303 TestCommitDirty(kResourceId,
2332 kMd5, 2304 kMd5,
2333 GDATA_FILE_OK, 2305 GDATA_FILE_OK,
2334 test_util::TEST_CACHE_STATE_PRESENT | 2306 test_util::TEST_CACHE_STATE_PRESENT |
2335 test_util::TEST_CACHE_STATE_PINNED | 2307 test_util::TEST_CACHE_STATE_PINNED |
2336 test_util::TEST_CACHE_STATE_DIRTY | 2308 test_util::TEST_CACHE_STATE_DIRTY |
2337 test_util::TEST_CACHE_STATE_PERSISTENT, 2309 test_util::TEST_CACHE_STATE_PERSISTENT,
2338 GDataCache::CACHE_TYPE_PERSISTENT); 2310 GDataCache::CACHE_TYPE_PERSISTENT);
2339 const FilePath outgoing_symlink_path = 2311 const FilePath outgoing_symlink_path =
2340 GDataCache::GetCacheRootPath(profile_.get()) 2312 GDataCache::GetCacheRootPath(profile_.get())
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
2508 scoped_ptr<GDataEntryProto> entry_proto(GetEntryInfoByPathSync(kFileInRoot)); 2480 scoped_ptr<GDataEntryProto> entry_proto(GetEntryInfoByPathSync(kFileInRoot));
2509 FilePath downloaded_file = GetCachePathForFile( 2481 FilePath downloaded_file = GetCachePathForFile(
2510 entry_proto->resource_id(), 2482 entry_proto->resource_id(),
2511 entry_proto->file_specific_info().file_md5()); 2483 entry_proto->file_specific_info().file_md5());
2512 const int64 file_size = entry_proto->file_info().size(); 2484 const int64 file_size = entry_proto->file_info().size();
2513 const std::string& file_resource_id = 2485 const std::string& file_resource_id =
2514 entry_proto->resource_id(); 2486 entry_proto->resource_id();
2515 const std::string& file_md5 = entry_proto->file_specific_info().file_md5(); 2487 const std::string& file_md5 = entry_proto->file_specific_info().file_md5();
2516 2488
2517 // A dirty file is created on close. 2489 // A dirty file is created on close.
2518 EXPECT_CALL(*mock_sync_client_, OnCacheCommitted(file_resource_id)).Times(1); 2490 EXPECT_CALL(*mock_cache_observer_, OnCacheCommitted(file_resource_id))
2491 .Times(1);
2519 2492
2520 // Pretend we have enough space. 2493 // Pretend we have enough space.
2521 EXPECT_CALL(*mock_free_disk_space_checker_, AmountOfFreeDiskSpace()) 2494 EXPECT_CALL(*mock_free_disk_space_checker_, AmountOfFreeDiskSpace())
2522 .Times(2).WillRepeatedly(Return(file_size + kMinFreeSpace)); 2495 .Times(2).WillRepeatedly(Return(file_size + kMinFreeSpace));
2523 2496
2524 const std::string kExpectedFileData = "test file data"; 2497 const std::string kExpectedFileData = "test file data";
2525 mock_doc_service_->set_file_data(new std::string(kExpectedFileData)); 2498 mock_doc_service_->set_file_data(new std::string(kExpectedFileData));
2526 2499
2527 // Before Download starts metadata from server will be fetched. 2500 // Before Download starts metadata from server will be fetched.
2528 // We will read content url from the result. 2501 // We will read content url from the result.
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
2577 2550
2578 // Try to close the same file twice. 2551 // Try to close the same file twice.
2579 file_system_->CloseFile(kFileInRoot, close_file_callback); 2552 file_system_->CloseFile(kFileInRoot, close_file_callback);
2580 message_loop_.Run(); 2553 message_loop_.Run();
2581 2554
2582 // It must fail. 2555 // It must fail.
2583 EXPECT_EQ(GDATA_FILE_ERROR_NOT_FOUND, callback_helper_->last_error_); 2556 EXPECT_EQ(GDATA_FILE_ERROR_NOT_FOUND, callback_helper_->last_error_);
2584 } 2557 }
2585 2558
2586 } // namespace gdata 2559 } // namespace gdata
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/gdata/gdata_cache_unittest.cc ('k') | chrome/browser/chromeos/gdata/gdata_sync_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698