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

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

Issue 10828385: Rename DocumentsServiceInterface to DriveServiceInterface. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix unnecessary includes. Created 8 years, 4 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 <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/scoped_temp_dir.h" 15 #include "base/scoped_temp_dir.h"
16 #include "base/stringprintf.h" 16 #include "base/stringprintf.h"
17 #include "base/threading/sequenced_worker_pool.h" 17 #include "base/threading/sequenced_worker_pool.h"
18 #include "base/values.h" 18 #include "base/values.h"
19 #include "chrome/browser/chromeos/cros/cros_library.h" 19 #include "chrome/browser/chromeos/cros/cros_library.h"
20 #include "chrome/browser/chromeos/gdata/drive_api_parser.h" 20 #include "chrome/browser/chromeos/gdata/drive_api_parser.h"
21 #include "chrome/browser/chromeos/gdata/drive_webapps_registry.h" 21 #include "chrome/browser/chromeos/gdata/drive_webapps_registry.h"
22 #include "chrome/browser/chromeos/gdata/gdata.pb.h" 22 #include "chrome/browser/chromeos/gdata/gdata.pb.h"
23 #include "chrome/browser/chromeos/gdata/gdata_file_system.h" 23 #include "chrome/browser/chromeos/gdata/gdata_file_system.h"
24 #include "chrome/browser/chromeos/gdata/gdata_test_util.h" 24 #include "chrome/browser/chromeos/gdata/gdata_test_util.h"
25 #include "chrome/browser/chromeos/gdata/gdata_uploader.h" 25 #include "chrome/browser/chromeos/gdata/gdata_uploader.h"
26 #include "chrome/browser/chromeos/gdata/gdata_util.h" 26 #include "chrome/browser/chromeos/gdata/gdata_util.h"
27 #include "chrome/browser/chromeos/gdata/mock_directory_change_observer.h" 27 #include "chrome/browser/chromeos/gdata/mock_directory_change_observer.h"
28 #include "chrome/browser/chromeos/gdata/mock_gdata_cache_observer.h" 28 #include "chrome/browser/chromeos/gdata/mock_gdata_cache_observer.h"
29 #include "chrome/browser/chromeos/gdata/mock_documents_service.h" 29 #include "chrome/browser/chromeos/gdata/mock_drive_service.h"
30 #include "chrome/common/chrome_paths.h" 30 #include "chrome/common/chrome_paths.h"
31 #include "chrome/test/base/testing_profile.h" 31 #include "chrome/test/base/testing_profile.h"
32 #include "content/public/browser/browser_thread.h" 32 #include "content/public/browser/browser_thread.h"
33 #include "content/public/test/test_browser_thread.h" 33 #include "content/public/test/test_browser_thread.h"
34 #include "testing/gmock/include/gmock/gmock.h" 34 #include "testing/gmock/include/gmock/gmock.h"
35 #include "testing/gtest/include/gtest/gtest.h" 35 #include "testing/gtest/include/gtest/gtest.h"
36 36
37 using ::testing::AtLeast; 37 using ::testing::AtLeast;
38 using ::testing::Eq; 38 using ::testing::Eq;
39 using ::testing::NotNull; 39 using ::testing::NotNull;
(...skipping 29 matching lines...) Expand all
69 EXPECT_EQ(FilePath(expected_results[i].path), 69 EXPECT_EQ(FilePath(expected_results[i].path),
70 results->at(i).path); 70 results->at(i).path);
71 EXPECT_EQ(expected_results[i].is_directory, 71 EXPECT_EQ(expected_results[i].is_directory,
72 results->at(i).is_directory); 72 results->at(i).is_directory);
73 } 73 }
74 74
75 message_loop->Quit(); 75 message_loop->Quit();
76 } 76 }
77 77
78 // Action used to set mock expectations for 78 // Action used to set mock expectations for
79 // DocumentsService::GetDocumentEntry(). 79 // DriveServiceInterface::GetDocumentEntry().
80 ACTION_P2(MockGetDocumentEntry, status, value) { 80 ACTION_P2(MockGetDocumentEntry, status, value) {
81 base::MessageLoopProxy::current()->PostTask(FROM_HERE, 81 base::MessageLoopProxy::current()->PostTask(FROM_HERE,
82 base::Bind(arg1, status, base::Passed(value))); 82 base::Bind(arg1, status, base::Passed(value)));
83 } 83 }
84 84
85 // Action used to set mock expectations for 85 // Action used to set mock expectations for
86 // GDataUploaderInterface::UploadExistingFile(). 86 // GDataUploaderInterface::UploadExistingFile().
87 ACTION_P4(MockUploadExistingFile, 87 ACTION_P4(MockUploadExistingFile,
88 error, gdata_path, local_file_path, document_entry) { 88 error, gdata_path, local_file_path, document_entry) {
89 scoped_ptr<UploadFileInfo> upload_file_info(new UploadFileInfo); 89 scoped_ptr<UploadFileInfo> upload_file_info(new UploadFileInfo);
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 MOCK_METHOD1(UpdateFromApplicationList, void(const AppList& applist)); 198 MOCK_METHOD1(UpdateFromApplicationList, void(const AppList& applist));
199 }; 199 };
200 200
201 class GDataFileSystemTest : public testing::Test { 201 class GDataFileSystemTest : public testing::Test {
202 protected: 202 protected:
203 GDataFileSystemTest() 203 GDataFileSystemTest()
204 : ui_thread_(content::BrowserThread::UI, &message_loop_), 204 : ui_thread_(content::BrowserThread::UI, &message_loop_),
205 io_thread_(content::BrowserThread::IO), 205 io_thread_(content::BrowserThread::IO),
206 cache_(NULL), 206 cache_(NULL),
207 file_system_(NULL), 207 file_system_(NULL),
208 mock_doc_service_(NULL), 208 mock_drive_service_(NULL),
209 mock_webapps_registry_(NULL), 209 mock_webapps_registry_(NULL),
210 num_callback_invocations_(0), 210 num_callback_invocations_(0),
211 expected_error_(GDATA_FILE_OK), 211 expected_error_(GDATA_FILE_OK),
212 expected_cache_state_(0), 212 expected_cache_state_(0),
213 expected_sub_dir_type_(GDataCache::CACHE_TYPE_META), 213 expected_sub_dir_type_(GDataCache::CACHE_TYPE_META),
214 expected_success_(true), 214 expected_success_(true),
215 expect_outgoing_symlink_(false), 215 expect_outgoing_symlink_(false),
216 root_feed_changestamp_(0) { 216 root_feed_changestamp_(0) {
217 } 217 }
218 218
219 virtual void SetUp() OVERRIDE { 219 virtual void SetUp() OVERRIDE {
220 chromeos::CrosLibrary::Initialize(true /* use_stub */); 220 chromeos::CrosLibrary::Initialize(true /* use_stub */);
221 io_thread_.StartIOThread(); 221 io_thread_.StartIOThread();
222 222
223 profile_.reset(new TestingProfile); 223 profile_.reset(new TestingProfile);
224 224
225 callback_helper_ = new CallbackHelper; 225 callback_helper_ = new CallbackHelper;
226 226
227 // Allocate and keep a pointer to the mock, and inject it into the 227 // Allocate and keep a pointer to the mock, and inject it into the
228 // GDataFileSystem object, which will own the mock object. 228 // GDataFileSystem object, which will own the mock object.
229 mock_doc_service_ = new StrictMock<MockDocumentsService>; 229 mock_drive_service_ = new StrictMock<MockDriveService>;
230 230
231 EXPECT_CALL(*mock_doc_service_, Initialize(profile_.get())).Times(1); 231 EXPECT_CALL(*mock_drive_service_, Initialize(profile_.get())).Times(1);
232 232
233 // Likewise, this will be owned by GDataFileSystem. 233 // Likewise, this will be owned by GDataFileSystem.
234 mock_free_disk_space_checker_ = new StrictMock<MockFreeDiskSpaceGetter>; 234 mock_free_disk_space_checker_ = new StrictMock<MockFreeDiskSpaceGetter>;
235 SetFreeDiskSpaceGetterForTesting(mock_free_disk_space_checker_); 235 SetFreeDiskSpaceGetterForTesting(mock_free_disk_space_checker_);
236 236
237 scoped_refptr<base::SequencedWorkerPool> pool = 237 scoped_refptr<base::SequencedWorkerPool> pool =
238 content::BrowserThread::GetBlockingPool(); 238 content::BrowserThread::GetBlockingPool();
239 blocking_task_runner_ = 239 blocking_task_runner_ =
240 pool->GetSequencedTaskRunner(pool->GetSequenceToken()); 240 pool->GetSequencedTaskRunner(pool->GetSequenceToken());
241 241
242 cache_ = GDataCache::CreateGDataCacheOnUIThread( 242 cache_ = GDataCache::CreateGDataCacheOnUIThread(
243 GDataCache::GetCacheRootPath(profile_.get()), blocking_task_runner_); 243 GDataCache::GetCacheRootPath(profile_.get()), blocking_task_runner_);
244 244
245 mock_uploader_.reset(new StrictMock<MockGDataUploader>); 245 mock_uploader_.reset(new StrictMock<MockGDataUploader>);
246 mock_webapps_registry_.reset(new StrictMock<MockDriveWebAppsRegistry>); 246 mock_webapps_registry_.reset(new StrictMock<MockDriveWebAppsRegistry>);
247 247
248 ASSERT_FALSE(file_system_); 248 ASSERT_FALSE(file_system_);
249 file_system_ = new GDataFileSystem(profile_.get(), 249 file_system_ = new GDataFileSystem(profile_.get(),
250 cache_, 250 cache_,
251 mock_doc_service_, 251 mock_drive_service_,
252 mock_uploader_.get(), 252 mock_uploader_.get(),
253 mock_webapps_registry_.get(), 253 mock_webapps_registry_.get(),
254 blocking_task_runner_); 254 blocking_task_runner_);
255 255
256 mock_cache_observer_.reset(new StrictMock<MockGDataCacheObserver>); 256 mock_cache_observer_.reset(new StrictMock<MockGDataCacheObserver>);
257 cache_->AddObserver(mock_cache_observer_.get()); 257 cache_->AddObserver(mock_cache_observer_.get());
258 258
259 mock_directory_observer_.reset(new StrictMock<MockDirectoryChangeObserver>); 259 mock_directory_observer_.reset(new StrictMock<MockDirectoryChangeObserver>);
260 file_system_->AddObserver(mock_directory_observer_.get()); 260 file_system_->AddObserver(mock_directory_observer_.get());
261 261
262 file_system_->Initialize(); 262 file_system_->Initialize();
263 cache_->RequestInitializeOnUIThreadForTesting(); 263 cache_->RequestInitializeOnUIThreadForTesting();
264 test_util::RunBlockingPoolTask(); 264 test_util::RunBlockingPoolTask();
265 } 265 }
266 266
267 virtual void TearDown() OVERRIDE { 267 virtual void TearDown() OVERRIDE {
268 ASSERT_TRUE(file_system_); 268 ASSERT_TRUE(file_system_);
269 EXPECT_CALL(*mock_doc_service_, CancelAll()).Times(1); 269 EXPECT_CALL(*mock_drive_service_, CancelAll()).Times(1);
270 delete file_system_; 270 delete file_system_;
271 file_system_ = NULL; 271 file_system_ = NULL;
272 delete mock_doc_service_; 272 delete mock_drive_service_;
273 mock_doc_service_ = NULL; 273 mock_drive_service_ = NULL;
274 SetFreeDiskSpaceGetterForTesting(NULL); 274 SetFreeDiskSpaceGetterForTesting(NULL);
275 cache_->DestroyOnUIThread(); 275 cache_->DestroyOnUIThread();
276 // The cache destruction requires to post a task to the blocking pool. 276 // The cache destruction requires to post a task to the blocking pool.
277 test_util::RunBlockingPoolTask(); 277 test_util::RunBlockingPoolTask();
278 278
279 profile_.reset(NULL); 279 profile_.reset(NULL);
280 chromeos::CrosLibrary::Shutdown(); 280 chromeos::CrosLibrary::Shutdown();
281 } 281 }
282 282
283 // Loads test json file as root ("/drive") element. 283 // Loads test json file as root ("/drive") element.
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after
636 EXPECT_TRUE(target_path.value() != kSymLinkToDevNull); 636 EXPECT_TRUE(target_path.value() != kSymLinkToDevNull);
637 if (test_util::ToCacheEntry(expected_cache_state_).is_present()) 637 if (test_util::ToCacheEntry(expected_cache_state_).is_present())
638 EXPECT_EQ(dest_path, target_path); 638 EXPECT_EQ(dest_path, target_path);
639 } else { 639 } else {
640 EXPECT_FALSE(exists); 640 EXPECT_FALSE(exists);
641 } 641 }
642 } 642 }
643 643
644 void SetExpectationsForGetDocumentEntry(scoped_ptr<base::Value>* document, 644 void SetExpectationsForGetDocumentEntry(scoped_ptr<base::Value>* document,
645 const std::string& resource_id) { 645 const std::string& resource_id) {
646 EXPECT_CALL(*mock_doc_service_, GetDocumentEntry(resource_id, _)) 646 EXPECT_CALL(*mock_drive_service_, GetDocumentEntry(resource_id, _))
647 .WillOnce(MockGetDocumentEntry(gdata::HTTP_SUCCESS, document)); 647 .WillOnce(MockGetDocumentEntry(gdata::HTTP_SUCCESS, document));
648 } 648 }
649 649
650 // Loads serialized proto file from GCache, and makes sure the root 650 // Loads serialized proto file from GCache, and makes sure the root
651 // filesystem has a root at 'drive' 651 // filesystem has a root at 'drive'
652 void TestLoadMetadataFromCache() { 652 void TestLoadMetadataFromCache() {
653 file_system_->LoadRootFeedFromCacheForTesting(); 653 file_system_->LoadRootFeedFromCacheForTesting();
654 test_util::RunBlockingPoolTask(); 654 test_util::RunBlockingPoolTask();
655 } 655 }
656 656
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
838 // The order of the test threads is important, do not change the order. 838 // The order of the test threads is important, do not change the order.
839 // See also content/browser/browser_thread_impl.cc. 839 // See also content/browser/browser_thread_impl.cc.
840 content::TestBrowserThread ui_thread_; 840 content::TestBrowserThread ui_thread_;
841 content::TestBrowserThread io_thread_; 841 content::TestBrowserThread io_thread_;
842 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_; 842 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_;
843 scoped_ptr<TestingProfile> profile_; 843 scoped_ptr<TestingProfile> profile_;
844 scoped_refptr<CallbackHelper> callback_helper_; 844 scoped_refptr<CallbackHelper> callback_helper_;
845 GDataCache* cache_; 845 GDataCache* cache_;
846 scoped_ptr<StrictMock<MockGDataUploader> > mock_uploader_; 846 scoped_ptr<StrictMock<MockGDataUploader> > mock_uploader_;
847 GDataFileSystem* file_system_; 847 GDataFileSystem* file_system_;
848 StrictMock<MockDocumentsService>* mock_doc_service_; 848 StrictMock<MockDriveService>* mock_drive_service_;
849 scoped_ptr<StrictMock<MockDriveWebAppsRegistry> > mock_webapps_registry_; 849 scoped_ptr<StrictMock<MockDriveWebAppsRegistry> > mock_webapps_registry_;
850 StrictMock<MockFreeDiskSpaceGetter>* mock_free_disk_space_checker_; 850 StrictMock<MockFreeDiskSpaceGetter>* mock_free_disk_space_checker_;
851 scoped_ptr<StrictMock<MockGDataCacheObserver> > mock_cache_observer_; 851 scoped_ptr<StrictMock<MockGDataCacheObserver> > mock_cache_observer_;
852 scoped_ptr<StrictMock<MockDirectoryChangeObserver> > mock_directory_observer_; 852 scoped_ptr<StrictMock<MockDirectoryChangeObserver> > mock_directory_observer_;
853 853
854 int num_callback_invocations_; 854 int num_callback_invocations_;
855 GDataFileError expected_error_; 855 GDataFileError expected_error_;
856 int expected_cache_state_; 856 int expected_cache_state_;
857 GDataCache::CacheSubDirectoryType expected_sub_dir_type_; 857 GDataCache::CacheSubDirectoryType expected_sub_dir_type_;
858 bool expected_success_; 858 bool expected_success_;
(...skipping 24 matching lines...) Expand all
883 883
884 TEST_F(GDataFileSystemTest, DuplicatedAsyncInitialization) { 884 TEST_F(GDataFileSystemTest, DuplicatedAsyncInitialization) {
885 int counter = 0; 885 int counter = 0;
886 GetEntryInfoCallback callback = base::Bind( 886 GetEntryInfoCallback callback = base::Bind(
887 &AsyncInitializationCallback, 887 &AsyncInitializationCallback,
888 &counter, 888 &counter,
889 2, 889 2,
890 FilePath(FILE_PATH_LITERAL("drive")), 890 FilePath(FILE_PATH_LITERAL("drive")),
891 &message_loop_); 891 &message_loop_);
892 892
893 EXPECT_CALL(*mock_doc_service_, GetAccountMetadata(_)).Times(1); 893 EXPECT_CALL(*mock_drive_service_, GetAccountMetadata(_)).Times(1);
894 EXPECT_CALL(*mock_doc_service_, 894 EXPECT_CALL(*mock_drive_service_,
895 GetDocuments(Eq(GURL()), _, _, _, _)).Times(1); 895 GetDocuments(Eq(GURL()), _, _, _, _)).Times(1);
896 896
897 EXPECT_CALL(*mock_webapps_registry_, UpdateFromFeed(_)).Times(1); 897 EXPECT_CALL(*mock_webapps_registry_, UpdateFromFeed(_)).Times(1);
898 898
899 file_system_->GetEntryInfoByPath( 899 file_system_->GetEntryInfoByPath(
900 FilePath(FILE_PATH_LITERAL("drive")), callback); 900 FilePath(FILE_PATH_LITERAL("drive")), callback);
901 file_system_->GetEntryInfoByPath( 901 file_system_->GetEntryInfoByPath(
902 FilePath(FILE_PATH_LITERAL("drive")), callback); 902 FilePath(FILE_PATH_LITERAL("drive")), callback);
903 message_loop_.Run(); // Wait to get our result 903 message_loop_.Run(); // Wait to get our result
904 EXPECT_EQ(2, counter); 904 EXPECT_EQ(2, counter);
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after
1221 EXPECT_TRUE(EntryExists(FilePath(FILE_PATH_LITERAL("drive/Dir1/SubDir2")))); 1221 EXPECT_TRUE(EntryExists(FilePath(FILE_PATH_LITERAL("drive/Dir1/SubDir2"))));
1222 EXPECT_TRUE(EntryExists( 1222 EXPECT_TRUE(EntryExists(
1223 FilePath(FILE_PATH_LITERAL("drive/Dir1/SubDir2/File3")))); 1223 FilePath(FILE_PATH_LITERAL("drive/Dir1/SubDir2/File3"))));
1224 } 1224 }
1225 1225
1226 TEST_F(GDataFileSystemTest, CachedFeadLoadingThenServerFeedLoading) { 1226 TEST_F(GDataFileSystemTest, CachedFeadLoadingThenServerFeedLoading) {
1227 SaveTestFileSystem(); 1227 SaveTestFileSystem();
1228 1228
1229 // SaveTestFileSystem and "account_metadata.json" have the same changestamp, 1229 // SaveTestFileSystem and "account_metadata.json" have the same changestamp,
1230 // so no request for new feeds (i.e., call to GetDocuments) should happen. 1230 // so no request for new feeds (i.e., call to GetDocuments) should happen.
1231 mock_doc_service_->set_account_metadata( 1231 mock_drive_service_->set_account_metadata(
1232 LoadJSONFile("account_metadata.json")); 1232 LoadJSONFile("account_metadata.json"));
1233 EXPECT_CALL(*mock_doc_service_, GetAccountMetadata(_)).Times(1); 1233 EXPECT_CALL(*mock_drive_service_, GetAccountMetadata(_)).Times(1);
1234 EXPECT_CALL(*mock_webapps_registry_, UpdateFromFeed(_)).Times(1); 1234 EXPECT_CALL(*mock_webapps_registry_, UpdateFromFeed(_)).Times(1);
1235 EXPECT_CALL(*mock_doc_service_, GetDocuments(_, _, _, _, _)).Times(0); 1235 EXPECT_CALL(*mock_drive_service_, GetDocuments(_, _, _, _, _)).Times(0);
1236 1236
1237 // Kicks loading of cached file system and query for server update. 1237 // Kicks loading of cached file system and query for server update.
1238 EXPECT_TRUE(EntryExists(FilePath(FILE_PATH_LITERAL("drive/File1")))); 1238 EXPECT_TRUE(EntryExists(FilePath(FILE_PATH_LITERAL("drive/File1"))));
1239 1239
1240 // Since the file system has verified that it holds the latest snapshot, 1240 // Since the file system has verified that it holds the latest snapshot,
1241 // it should change its state to FROM_SERVER, which admits periodic refresh. 1241 // it should change its state to FROM_SERVER, which admits periodic refresh.
1242 // To test it, call CheckForUpdates and verify it does try to check updates. 1242 // To test it, call CheckForUpdates and verify it does try to check updates.
1243 mock_doc_service_->set_account_metadata( 1243 mock_drive_service_->set_account_metadata(
1244 LoadJSONFile("account_metadata.json")); 1244 LoadJSONFile("account_metadata.json"));
1245 EXPECT_CALL(*mock_doc_service_, GetAccountMetadata(_)).Times(1); 1245 EXPECT_CALL(*mock_drive_service_, GetAccountMetadata(_)).Times(1);
1246 EXPECT_CALL(*mock_webapps_registry_, UpdateFromFeed(_)).Times(1); 1246 EXPECT_CALL(*mock_webapps_registry_, UpdateFromFeed(_)).Times(1);
1247 1247
1248 file_system_->CheckForUpdates(); 1248 file_system_->CheckForUpdates();
1249 test_util::RunBlockingPoolTask(); 1249 test_util::RunBlockingPoolTask();
1250 } 1250 }
1251 1251
1252 TEST_F(GDataFileSystemTest, TransferFileFromLocalToRemote_RegularFile) { 1252 TEST_F(GDataFileSystemTest, TransferFileFromLocalToRemote_RegularFile) {
1253 EXPECT_CALL(*mock_free_disk_space_checker_, AmountOfFreeDiskSpace()) 1253 EXPECT_CALL(*mock_free_disk_space_checker_, AmountOfFreeDiskSpace())
1254 .Times(AtLeast(1)).WillRepeatedly(Return(kLotsOfSpace)); 1254 .Times(AtLeast(1)).WillRepeatedly(Return(kLotsOfSpace));
1255 1255
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
1306 FILE_PATH_LITERAL("drive/Directory 1/Document 1.gdoc")); 1306 FILE_PATH_LITERAL("drive/Directory 1/Document 1.gdoc"));
1307 EXPECT_FALSE(EntryExists(remote_dest_file_path)); 1307 EXPECT_FALSE(EntryExists(remote_dest_file_path));
1308 1308
1309 // We'll add a file to "Directory 1" directory on Drive. 1309 // We'll add a file to "Directory 1" directory on Drive.
1310 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( 1310 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged(
1311 Eq(FilePath(FILE_PATH_LITERAL("drive/Directory 1"))))).Times(1); 1311 Eq(FilePath(FILE_PATH_LITERAL("drive/Directory 1"))))).Times(1);
1312 1312
1313 // We'll copy a hosted document using CopyDocument. 1313 // We'll copy a hosted document using CopyDocument.
1314 // ".gdoc" suffix should be stripped when copying. 1314 // ".gdoc" suffix should be stripped when copying.
1315 scoped_ptr<base::Value> document(LoadJSONFile("uploaded_document.json")); 1315 scoped_ptr<base::Value> document(LoadJSONFile("uploaded_document.json"));
1316 EXPECT_CALL(*mock_doc_service_, 1316 EXPECT_CALL(*mock_drive_service_,
1317 CopyDocument(kResourceId, 1317 CopyDocument(kResourceId,
1318 FILE_PATH_LITERAL("Document 1"), 1318 FILE_PATH_LITERAL("Document 1"),
1319 _)) 1319 _))
1320 .WillOnce(MockCopyDocument(gdata::HTTP_SUCCESS, &document)); 1320 .WillOnce(MockCopyDocument(gdata::HTTP_SUCCESS, &document));
1321 // We'll then add the hosted document to the destination directory. 1321 // We'll then add the hosted document to the destination directory.
1322 EXPECT_CALL(*mock_doc_service_, 1322 EXPECT_CALL(*mock_drive_service_,
1323 AddResourceToDirectory(_, _, _)).Times(1); 1323 AddResourceToDirectory(_, _, _)).Times(1);
1324 1324
1325 FileOperationCallback callback = 1325 FileOperationCallback callback =
1326 base::Bind(&CallbackHelper::FileOperationCallback, 1326 base::Bind(&CallbackHelper::FileOperationCallback,
1327 callback_helper_.get()); 1327 callback_helper_.get());
1328 1328
1329 // Transfer the local file to Drive. 1329 // Transfer the local file to Drive.
1330 file_system_->TransferFileFromLocalToRemote( 1330 file_system_->TransferFileFromLocalToRemote(
1331 local_src_file_path, remote_dest_file_path, callback); 1331 local_src_file_path, remote_dest_file_path, callback);
1332 test_util::RunBlockingPoolTask(); 1332 test_util::RunBlockingPoolTask();
(...skipping 21 matching lines...) Expand all
1354 FilePath cache_file = GetCachePathForFile( 1354 FilePath cache_file = GetCachePathForFile(
1355 file->resource_id(), 1355 file->resource_id(),
1356 file->file_specific_info().file_md5()); 1356 file->file_specific_info().file_md5());
1357 const int64 file_size = file->file_info().size(); 1357 const int64 file_size = file->file_info().size();
1358 1358
1359 // Pretend we have enough space. 1359 // Pretend we have enough space.
1360 EXPECT_CALL(*mock_free_disk_space_checker_, AmountOfFreeDiskSpace()) 1360 EXPECT_CALL(*mock_free_disk_space_checker_, AmountOfFreeDiskSpace())
1361 .Times(2).WillRepeatedly(Return(file_size + kMinFreeSpace)); 1361 .Times(2).WillRepeatedly(Return(file_size + kMinFreeSpace));
1362 1362
1363 const std::string remote_src_file_data = "Test file data"; 1363 const std::string remote_src_file_data = "Test file data";
1364 mock_doc_service_->set_file_data(new std::string(remote_src_file_data)); 1364 mock_drive_service_->set_file_data(new std::string(remote_src_file_data));
1365 1365
1366 // Before Download starts metadata from server will be fetched. 1366 // Before Download starts metadata from server will be fetched.
1367 // We will read content url from the result. 1367 // We will read content url from the result.
1368 scoped_ptr<base::Value> document(LoadJSONFile("document_to_download.json")); 1368 scoped_ptr<base::Value> document(LoadJSONFile("document_to_download.json"));
1369 SetExpectationsForGetDocumentEntry(&document, "file:2_file_resource_id"); 1369 SetExpectationsForGetDocumentEntry(&document, "file:2_file_resource_id");
1370 1370
1371 // The file is obtained with the mock DocumentsService. 1371 // The file is obtained with the mock DriveService.
1372 EXPECT_CALL(*mock_doc_service_, 1372 EXPECT_CALL(*mock_drive_service_,
1373 DownloadFile(remote_src_file_path, 1373 DownloadFile(remote_src_file_path,
1374 cache_file, 1374 cache_file,
1375 GURL("https://file_content_url_changed/"), 1375 GURL("https://file_content_url_changed/"),
1376 _, _)) 1376 _, _))
1377 .Times(1); 1377 .Times(1);
1378 1378
1379 file_system_->TransferFileFromRemoteToLocal( 1379 file_system_->TransferFileFromRemoteToLocal(
1380 remote_src_file_path, local_dest_file_path, callback); 1380 remote_src_file_path, local_dest_file_path, callback);
1381 test_util::RunBlockingPoolTask(); 1381 test_util::RunBlockingPoolTask();
1382 1382
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
1513 1513
1514 LoadRootFeedDocument("root_feed.json"); 1514 LoadRootFeedDocument("root_feed.json");
1515 1515
1516 ASSERT_TRUE(EntryExists(src_file_path)); 1516 ASSERT_TRUE(EntryExists(src_file_path));
1517 scoped_ptr<GDataEntryProto> src_entry_proto = GetEntryInfoByPathSync( 1517 scoped_ptr<GDataEntryProto> src_entry_proto = GetEntryInfoByPathSync(
1518 src_file_path); 1518 src_file_path);
1519 ASSERT_TRUE(src_entry_proto.get()); 1519 ASSERT_TRUE(src_entry_proto.get());
1520 std::string src_file_resource_id = 1520 std::string src_file_resource_id =
1521 src_entry_proto->resource_id(); 1521 src_entry_proto->resource_id();
1522 1522
1523 EXPECT_CALL(*mock_doc_service_, 1523 EXPECT_CALL(*mock_drive_service_,
1524 RenameResource(GURL(src_entry_proto->edit_url()), 1524 RenameResource(GURL(src_entry_proto->edit_url()),
1525 FILE_PATH_LITERAL("Test.log"), _)); 1525 FILE_PATH_LITERAL("Test.log"), _));
1526 1526
1527 FileOperationCallback callback = 1527 FileOperationCallback callback =
1528 base::Bind(&CallbackHelper::FileOperationCallback, 1528 base::Bind(&CallbackHelper::FileOperationCallback,
1529 callback_helper_.get()); 1529 callback_helper_.get());
1530 1530
1531 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( 1531 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged(
1532 Eq(FilePath(FILE_PATH_LITERAL("drive/Directory 1"))))).Times(1); 1532 Eq(FilePath(FILE_PATH_LITERAL("drive/Directory 1"))))).Times(1);
1533 1533
(...skipping 21 matching lines...) Expand all
1555 src_entry_proto->resource_id(); 1555 src_entry_proto->resource_id();
1556 EXPECT_FALSE(src_entry_proto->edit_url().empty()); 1556 EXPECT_FALSE(src_entry_proto->edit_url().empty());
1557 1557
1558 ASSERT_TRUE(EntryExists(dest_parent_path)); 1558 ASSERT_TRUE(EntryExists(dest_parent_path));
1559 scoped_ptr<GDataEntryProto> dest_parent_proto = GetEntryInfoByPathSync( 1559 scoped_ptr<GDataEntryProto> dest_parent_proto = GetEntryInfoByPathSync(
1560 dest_parent_path); 1560 dest_parent_path);
1561 ASSERT_TRUE(dest_parent_proto.get()); 1561 ASSERT_TRUE(dest_parent_proto.get());
1562 ASSERT_TRUE(dest_parent_proto->file_info().is_directory()); 1562 ASSERT_TRUE(dest_parent_proto->file_info().is_directory());
1563 EXPECT_FALSE(dest_parent_proto->content_url().empty()); 1563 EXPECT_FALSE(dest_parent_proto->content_url().empty());
1564 1564
1565 EXPECT_CALL(*mock_doc_service_, 1565 EXPECT_CALL(*mock_drive_service_,
1566 RenameResource(GURL(src_entry_proto->edit_url()), 1566 RenameResource(GURL(src_entry_proto->edit_url()),
1567 FILE_PATH_LITERAL("Test.log"), _)); 1567 FILE_PATH_LITERAL("Test.log"), _));
1568 EXPECT_CALL(*mock_doc_service_, 1568 EXPECT_CALL(*mock_drive_service_,
1569 AddResourceToDirectory( 1569 AddResourceToDirectory(
1570 GURL(dest_parent_proto->content_url()), 1570 GURL(dest_parent_proto->content_url()),
1571 GURL(src_entry_proto->edit_url()), _)); 1571 GURL(src_entry_proto->edit_url()), _));
1572 1572
1573 FileOperationCallback callback = 1573 FileOperationCallback callback =
1574 base::Bind(&CallbackHelper::FileOperationCallback, 1574 base::Bind(&CallbackHelper::FileOperationCallback,
1575 callback_helper_.get()); 1575 callback_helper_.get());
1576 1576
1577 // Expect notification for both source and destination directories. 1577 // Expect notification for both source and destination directories.
1578 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( 1578 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged(
(...skipping 26 matching lines...) Expand all
1605 src_entry_proto->resource_id(); 1605 src_entry_proto->resource_id();
1606 EXPECT_FALSE(src_entry_proto->edit_url().empty()); 1606 EXPECT_FALSE(src_entry_proto->edit_url().empty());
1607 1607
1608 ASSERT_TRUE(EntryExists(src_parent_path)); 1608 ASSERT_TRUE(EntryExists(src_parent_path));
1609 scoped_ptr<GDataEntryProto> src_parent_proto = GetEntryInfoByPathSync( 1609 scoped_ptr<GDataEntryProto> src_parent_proto = GetEntryInfoByPathSync(
1610 src_parent_path); 1610 src_parent_path);
1611 ASSERT_TRUE(src_parent_proto.get()); 1611 ASSERT_TRUE(src_parent_proto.get());
1612 ASSERT_TRUE(src_parent_proto->file_info().is_directory()); 1612 ASSERT_TRUE(src_parent_proto->file_info().is_directory());
1613 EXPECT_FALSE(src_parent_proto->content_url().empty()); 1613 EXPECT_FALSE(src_parent_proto->content_url().empty());
1614 1614
1615 EXPECT_CALL(*mock_doc_service_, 1615 EXPECT_CALL(*mock_drive_service_,
1616 RenameResource(GURL(src_entry_proto->edit_url()), 1616 RenameResource(GURL(src_entry_proto->edit_url()),
1617 FILE_PATH_LITERAL("Test.log"), _)); 1617 FILE_PATH_LITERAL("Test.log"), _));
1618 EXPECT_CALL(*mock_doc_service_, 1618 EXPECT_CALL(*mock_drive_service_,
1619 RemoveResourceFromDirectory( 1619 RemoveResourceFromDirectory(
1620 GURL(src_parent_proto->content_url()), 1620 GURL(src_parent_proto->content_url()),
1621 GURL(src_entry_proto->edit_url()), 1621 GURL(src_entry_proto->edit_url()),
1622 src_file_resource_id, _)); 1622 src_file_resource_id, _));
1623 1623
1624 FileOperationCallback callback = 1624 FileOperationCallback callback =
1625 base::Bind(&CallbackHelper::FileOperationCallback, 1625 base::Bind(&CallbackHelper::FileOperationCallback,
1626 callback_helper_.get()); 1626 callback_helper_.get());
1627 1627
1628 // Expect notification for both source and destination directories. 1628 // Expect notification for both source and destination directories.
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
1672 1672
1673 ASSERT_TRUE(EntryExists(dest_parent_path)); 1673 ASSERT_TRUE(EntryExists(dest_parent_path));
1674 scoped_ptr<GDataEntryProto> dest_parent_proto = GetEntryInfoByPathSync( 1674 scoped_ptr<GDataEntryProto> dest_parent_proto = GetEntryInfoByPathSync(
1675 dest_parent_path); 1675 dest_parent_path);
1676 ASSERT_TRUE(dest_parent_proto.get()); 1676 ASSERT_TRUE(dest_parent_proto.get());
1677 ASSERT_TRUE(dest_parent_proto->file_info().is_directory()); 1677 ASSERT_TRUE(dest_parent_proto->file_info().is_directory());
1678 EXPECT_FALSE(dest_parent_proto->content_url().empty()); 1678 EXPECT_FALSE(dest_parent_proto->content_url().empty());
1679 1679
1680 EXPECT_FALSE(EntryExists(interim_file_path)); 1680 EXPECT_FALSE(EntryExists(interim_file_path));
1681 1681
1682 EXPECT_CALL(*mock_doc_service_, 1682 EXPECT_CALL(*mock_drive_service_,
1683 RenameResource(GURL(src_entry_proto->edit_url()), 1683 RenameResource(GURL(src_entry_proto->edit_url()),
1684 FILE_PATH_LITERAL("Test.log"), _)); 1684 FILE_PATH_LITERAL("Test.log"), _));
1685 EXPECT_CALL(*mock_doc_service_, 1685 EXPECT_CALL(*mock_drive_service_,
1686 RemoveResourceFromDirectory( 1686 RemoveResourceFromDirectory(
1687 GURL(src_parent_proto->content_url()), 1687 GURL(src_parent_proto->content_url()),
1688 GURL(src_entry_proto->edit_url()), 1688 GURL(src_entry_proto->edit_url()),
1689 src_file_resource_id, _)); 1689 src_file_resource_id, _));
1690 EXPECT_CALL(*mock_doc_service_, 1690 EXPECT_CALL(*mock_drive_service_,
1691 AddResourceToDirectory( 1691 AddResourceToDirectory(
1692 GURL(dest_parent_proto->content_url()), 1692 GURL(dest_parent_proto->content_url()),
1693 GURL(src_entry_proto->edit_url()), 1693 GURL(src_entry_proto->edit_url()),
1694 _)); 1694 _));
1695 1695
1696 FileOperationCallback callback = 1696 FileOperationCallback callback =
1697 base::Bind(&CallbackHelper::FileOperationCallback, 1697 base::Bind(&CallbackHelper::FileOperationCallback,
1698 callback_helper_.get()); 1698 callback_helper_.get());
1699 1699
1700 // Expect notification for both source and destination directories plus 1700 // Expect notification for both source and destination directories plus
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
1933 GDataFileSystem::DIRECTORY_ALREADY_PRESENT, 1933 GDataFileSystem::DIRECTORY_ALREADY_PRESENT,
1934 file_system_->FindFirstMissingParentDirectory( 1934 file_system_->FindFirstMissingParentDirectory(
1935 FilePath(FILE_PATH_LITERAL("drive/Directory 1")), 1935 FilePath(FILE_PATH_LITERAL("drive/Directory 1")),
1936 &last_dir_content_url, 1936 &last_dir_content_url,
1937 &first_missing_parent_path)); 1937 &first_missing_parent_path));
1938 } 1938 }
1939 1939
1940 // Create a directory through the document service 1940 // Create a directory through the document service
1941 TEST_F(GDataFileSystemTest, CreateDirectoryWithService) { 1941 TEST_F(GDataFileSystemTest, CreateDirectoryWithService) {
1942 LoadRootFeedDocument("root_feed.json"); 1942 LoadRootFeedDocument("root_feed.json");
1943 EXPECT_CALL(*mock_doc_service_, 1943 EXPECT_CALL(*mock_drive_service_,
1944 CreateDirectory(_, "Sample Directory Title", _)).Times(1); 1944 CreateDirectory(_, "Sample Directory Title", _)).Times(1);
1945 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( 1945 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged(
1946 Eq(FilePath(FILE_PATH_LITERAL("drive"))))).Times(1); 1946 Eq(FilePath(FILE_PATH_LITERAL("drive"))))).Times(1);
1947 1947
1948 // Set last error so it's not a valid error code. 1948 // Set last error so it's not a valid error code.
1949 callback_helper_->last_error_ = static_cast<GDataFileError>(1); 1949 callback_helper_->last_error_ = static_cast<GDataFileError>(1);
1950 file_system_->CreateDirectory( 1950 file_system_->CreateDirectory(
1951 FilePath(FILE_PATH_LITERAL("drive/Sample Directory Title")), 1951 FilePath(FILE_PATH_LITERAL("drive/Sample Directory Title")),
1952 false, // is_exclusive 1952 false, // is_exclusive
1953 true, // is_recursive 1953 true, // is_recursive
(...skipping 21 matching lines...) Expand all
1975 1975
1976 // Pretend we have enough space. 1976 // Pretend we have enough space.
1977 EXPECT_CALL(*mock_free_disk_space_checker_, AmountOfFreeDiskSpace()) 1977 EXPECT_CALL(*mock_free_disk_space_checker_, AmountOfFreeDiskSpace())
1978 .Times(2).WillRepeatedly(Return(file_size + kMinFreeSpace)); 1978 .Times(2).WillRepeatedly(Return(file_size + kMinFreeSpace));
1979 1979
1980 // Before Download starts metadata from server will be fetched. 1980 // Before Download starts metadata from server will be fetched.
1981 // We will read content url from the result. 1981 // We will read content url from the result.
1982 scoped_ptr<base::Value> document(LoadJSONFile("document_to_download.json")); 1982 scoped_ptr<base::Value> document(LoadJSONFile("document_to_download.json"));
1983 SetExpectationsForGetDocumentEntry(&document, "file:2_file_resource_id"); 1983 SetExpectationsForGetDocumentEntry(&document, "file:2_file_resource_id");
1984 1984
1985 // The file is obtained with the mock DocumentsService. 1985 // The file is obtained with the mock DriveService.
1986 EXPECT_CALL(*mock_doc_service_, 1986 EXPECT_CALL(*mock_drive_service_,
1987 DownloadFile(file_in_root, 1987 DownloadFile(file_in_root,
1988 downloaded_file, 1988 downloaded_file,
1989 GURL("https://file_content_url_changed/"), 1989 GURL("https://file_content_url_changed/"),
1990 _, _)) 1990 _, _))
1991 .Times(1); 1991 .Times(1);
1992 1992
1993 file_system_->GetFileByPath(file_in_root, callback, 1993 file_system_->GetFileByPath(file_in_root, callback,
1994 GetContentCallback()); 1994 GetContentCallback());
1995 test_util::RunBlockingPoolTask(); 1995 test_util::RunBlockingPoolTask();
1996 1996
(...skipping 18 matching lines...) Expand all
2015 2015
2016 // Pretend we have no space at all. 2016 // Pretend we have no space at all.
2017 EXPECT_CALL(*mock_free_disk_space_checker_, AmountOfFreeDiskSpace()) 2017 EXPECT_CALL(*mock_free_disk_space_checker_, AmountOfFreeDiskSpace())
2018 .Times(2).WillRepeatedly(Return(0)); 2018 .Times(2).WillRepeatedly(Return(0));
2019 2019
2020 // Before Download starts metadata from server will be fetched. 2020 // Before Download starts metadata from server will be fetched.
2021 // We will read content url from the result. 2021 // We will read content url from the result.
2022 scoped_ptr<base::Value> document(LoadJSONFile("document_to_download.json")); 2022 scoped_ptr<base::Value> document(LoadJSONFile("document_to_download.json"));
2023 SetExpectationsForGetDocumentEntry(&document, "file:2_file_resource_id"); 2023 SetExpectationsForGetDocumentEntry(&document, "file:2_file_resource_id");
2024 2024
2025 // The file is not obtained with the mock DocumentsService, because of no 2025 // The file is not obtained with the mock DriveService, because of no space.
2026 // space. 2026 EXPECT_CALL(*mock_drive_service_,
2027 EXPECT_CALL(*mock_doc_service_,
2028 DownloadFile(file_in_root, 2027 DownloadFile(file_in_root,
2029 downloaded_file, 2028 downloaded_file,
2030 GURL("https://file_content_url_changed/"), 2029 GURL("https://file_content_url_changed/"),
2031 _, _)) 2030 _, _))
2032 .Times(0); 2031 .Times(0);
2033 2032
2034 file_system_->GetFileByPath(file_in_root, callback, 2033 file_system_->GetFileByPath(file_in_root, callback,
2035 GetContentCallback()); 2034 GetContentCallback());
2036 test_util::RunBlockingPoolTask(); 2035 test_util::RunBlockingPoolTask();
2037 2036
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
2070 test_util::TEST_CACHE_STATE_PRESENT, 2069 test_util::TEST_CACHE_STATE_PRESENT,
2071 GDataCache::CACHE_TYPE_TMP); 2070 GDataCache::CACHE_TYPE_TMP);
2072 ASSERT_TRUE(CacheEntryExists("<resource_id>", "<md5>")); 2071 ASSERT_TRUE(CacheEntryExists("<resource_id>", "<md5>"));
2073 ASSERT_TRUE(CacheFileExists("<resource_id>", "<md5>")); 2072 ASSERT_TRUE(CacheFileExists("<resource_id>", "<md5>"));
2074 2073
2075 // Before Download starts metadata from server will be fetched. 2074 // Before Download starts metadata from server will be fetched.
2076 // We will read content url from the result. 2075 // We will read content url from the result.
2077 scoped_ptr<base::Value> document(LoadJSONFile("document_to_download.json")); 2076 scoped_ptr<base::Value> document(LoadJSONFile("document_to_download.json"));
2078 SetExpectationsForGetDocumentEntry(&document, "file:2_file_resource_id"); 2077 SetExpectationsForGetDocumentEntry(&document, "file:2_file_resource_id");
2079 2078
2080 // The file is obtained with the mock DocumentsService, because of we freed 2079 // The file is obtained with the mock DriveService, because of we freed up the
2081 // up the space. 2080 // space.
2082 EXPECT_CALL(*mock_doc_service_, 2081 EXPECT_CALL(*mock_drive_service_,
2083 DownloadFile(file_in_root, 2082 DownloadFile(file_in_root,
2084 downloaded_file, 2083 downloaded_file,
2085 GURL("https://file_content_url_changed/"), 2084 GURL("https://file_content_url_changed/"),
2086 _, _)) 2085 _, _))
2087 .Times(1); 2086 .Times(1);
2088 2087
2089 file_system_->GetFileByPath(file_in_root, callback, 2088 file_system_->GetFileByPath(file_in_root, callback,
2090 GetContentCallback()); 2089 GetContentCallback());
2091 test_util::RunBlockingPoolTask(); 2090 test_util::RunBlockingPoolTask();
2092 2091
(...skipping 29 matching lines...) Expand all
2122 EXPECT_CALL(*mock_free_disk_space_checker_, AmountOfFreeDiskSpace()) 2121 EXPECT_CALL(*mock_free_disk_space_checker_, AmountOfFreeDiskSpace())
2123 .WillOnce(Return(file_size + kMinFreeSpace)) 2122 .WillOnce(Return(file_size + kMinFreeSpace))
2124 .WillOnce(Return(kMinFreeSpace - 1)) 2123 .WillOnce(Return(kMinFreeSpace - 1))
2125 .WillOnce(Return(kMinFreeSpace - 1)); 2124 .WillOnce(Return(kMinFreeSpace - 1));
2126 2125
2127 // Before Download starts metadata from server will be fetched. 2126 // Before Download starts metadata from server will be fetched.
2128 // We will read content url from the result. 2127 // We will read content url from the result.
2129 scoped_ptr<base::Value> document(LoadJSONFile("document_to_download.json")); 2128 scoped_ptr<base::Value> document(LoadJSONFile("document_to_download.json"));
2130 SetExpectationsForGetDocumentEntry(&document, "file:2_file_resource_id"); 2129 SetExpectationsForGetDocumentEntry(&document, "file:2_file_resource_id");
2131 2130
2132 // The file is obtained with the mock DocumentsService. 2131 // The file is obtained with the mock DriveService.
2133 EXPECT_CALL(*mock_doc_service_, 2132 EXPECT_CALL(*mock_drive_service_,
2134 DownloadFile(file_in_root, 2133 DownloadFile(file_in_root,
2135 downloaded_file, 2134 downloaded_file,
2136 GURL("https://file_content_url_changed/"), 2135 GURL("https://file_content_url_changed/"),
2137 _, _)) 2136 _, _))
2138 .Times(1); 2137 .Times(1);
2139 2138
2140 file_system_->GetFileByPath(file_in_root, callback, 2139 file_system_->GetFileByPath(file_in_root, callback,
2141 GetContentCallback()); 2140 GetContentCallback());
2142 test_util::RunBlockingPoolTask(); 2141 test_util::RunBlockingPoolTask();
2143 2142
(...skipping 19 matching lines...) Expand all
2163 2162
2164 // Store something as cached version of this file. 2163 // Store something as cached version of this file.
2165 TestStoreToCache(entry_proto->resource_id(), 2164 TestStoreToCache(entry_proto->resource_id(),
2166 entry_proto->file_specific_info().file_md5(), 2165 entry_proto->file_specific_info().file_md5(),
2167 GetTestFilePath("root_feed.json"), 2166 GetTestFilePath("root_feed.json"),
2168 GDATA_FILE_OK, 2167 GDATA_FILE_OK,
2169 test_util::TEST_CACHE_STATE_PRESENT, 2168 test_util::TEST_CACHE_STATE_PRESENT,
2170 GDataCache::CACHE_TYPE_TMP); 2169 GDataCache::CACHE_TYPE_TMP);
2171 2170
2172 // Make sure we don't fetch metadata for downloading file. 2171 // Make sure we don't fetch metadata for downloading file.
2173 EXPECT_CALL(*mock_doc_service_, GetDocumentEntry(_, _)).Times(0); 2172 EXPECT_CALL(*mock_drive_service_, GetDocumentEntry(_, _)).Times(0);
2174 2173
2175 // Make sure we don't call downloads at all. 2174 // Make sure we don't call downloads at all.
2176 EXPECT_CALL(*mock_doc_service_, 2175 EXPECT_CALL(*mock_drive_service_,
2177 DownloadFile(file_in_root, 2176 DownloadFile(file_in_root,
2178 downloaded_file, 2177 downloaded_file,
2179 GURL("https://file_content_url_changed/"), 2178 GURL("https://file_content_url_changed/"),
2180 _, _)) 2179 _, _))
2181 .Times(0); 2180 .Times(0);
2182 2181
2183 file_system_->GetFileByPath(file_in_root, callback, 2182 file_system_->GetFileByPath(file_in_root, callback,
2184 GetContentCallback()); 2183 GetContentCallback());
2185 test_util::RunBlockingPoolTask(); 2184 test_util::RunBlockingPoolTask();
2186 2185
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
2227 scoped_ptr<GDataEntryProto> entry_proto(GetEntryInfoByPathSync(file_in_root)); 2226 scoped_ptr<GDataEntryProto> entry_proto(GetEntryInfoByPathSync(file_in_root));
2228 FilePath downloaded_file = GetCachePathForFile( 2227 FilePath downloaded_file = GetCachePathForFile(
2229 entry_proto->resource_id(), 2228 entry_proto->resource_id(),
2230 entry_proto->file_specific_info().file_md5()); 2229 entry_proto->file_specific_info().file_md5());
2231 2230
2232 // Before Download starts metadata from server will be fetched. 2231 // Before Download starts metadata from server will be fetched.
2233 // We will read content url from the result. 2232 // We will read content url from the result.
2234 scoped_ptr<base::Value> document(LoadJSONFile("document_to_download.json")); 2233 scoped_ptr<base::Value> document(LoadJSONFile("document_to_download.json"));
2235 SetExpectationsForGetDocumentEntry(&document, "file:2_file_resource_id"); 2234 SetExpectationsForGetDocumentEntry(&document, "file:2_file_resource_id");
2236 2235
2237 // The file is obtained with the mock DocumentsService, because it's not 2236 // The file is obtained with the mock DriveService, because it's not stored in
2238 // stored in the cache. 2237 // the cache.
2239 EXPECT_CALL(*mock_doc_service_, 2238 EXPECT_CALL(*mock_drive_service_,
2240 DownloadFile(file_in_root, 2239 DownloadFile(file_in_root,
2241 downloaded_file, 2240 downloaded_file,
2242 GURL("https://file_content_url_changed/"), 2241 GURL("https://file_content_url_changed/"),
2243 _, _)) 2242 _, _))
2244 .Times(1); 2243 .Times(1);
2245 2244
2246 file_system_->GetFileByResourceId(entry_proto->resource_id(), 2245 file_system_->GetFileByResourceId(entry_proto->resource_id(),
2247 callback, 2246 callback,
2248 GetContentCallback()); 2247 GetContentCallback());
2249 test_util::RunBlockingPoolTask(); 2248 test_util::RunBlockingPoolTask();
(...skipping 22 matching lines...) Expand all
2272 // Store something as cached version of this file. 2271 // Store something as cached version of this file.
2273 TestStoreToCache(entry_proto->resource_id(), 2272 TestStoreToCache(entry_proto->resource_id(),
2274 entry_proto->file_specific_info().file_md5(), 2273 entry_proto->file_specific_info().file_md5(),
2275 GetTestFilePath("root_feed.json"), 2274 GetTestFilePath("root_feed.json"),
2276 GDATA_FILE_OK, 2275 GDATA_FILE_OK,
2277 test_util::TEST_CACHE_STATE_PRESENT, 2276 test_util::TEST_CACHE_STATE_PRESENT,
2278 GDataCache::CACHE_TYPE_TMP); 2277 GDataCache::CACHE_TYPE_TMP);
2279 2278
2280 // The file is obtained from the cache. 2279 // The file is obtained from the cache.
2281 // Make sure we don't call downloads at all. 2280 // Make sure we don't call downloads at all.
2282 EXPECT_CALL(*mock_doc_service_, DownloadFile(_, _, _, _, _)) 2281 EXPECT_CALL(*mock_drive_service_, DownloadFile(_, _, _, _, _))
2283 .Times(0); 2282 .Times(0);
2284 2283
2285 file_system_->GetFileByResourceId(entry_proto->resource_id(), 2284 file_system_->GetFileByResourceId(entry_proto->resource_id(),
2286 callback, 2285 callback,
2287 GetContentCallback()); 2286 GetContentCallback());
2288 test_util::RunBlockingPoolTask(); 2287 test_util::RunBlockingPoolTask();
2289 2288
2290 EXPECT_EQ(REGULAR_FILE, callback_helper_->file_type_); 2289 EXPECT_EQ(REGULAR_FILE, callback_helper_->file_type_);
2291 EXPECT_EQ(downloaded_file.value(), 2290 EXPECT_EQ(downloaded_file.value(),
2292 callback_helper_->download_path_.value()); 2291 callback_helper_->download_path_.value());
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
2451 callback_helper_.get()); 2450 callback_helper_.get());
2452 2451
2453 file_system_->UpdateFileByResourceId(kResourceId, callback); 2452 file_system_->UpdateFileByResourceId(kResourceId, callback);
2454 test_util::RunBlockingPoolTask(); 2453 test_util::RunBlockingPoolTask();
2455 EXPECT_EQ(GDATA_FILE_ERROR_NOT_FOUND, callback_helper_->last_error_); 2454 EXPECT_EQ(GDATA_FILE_ERROR_NOT_FOUND, callback_helper_->last_error_);
2456 } 2455 }
2457 2456
2458 TEST_F(GDataFileSystemTest, ContentSearch) { 2457 TEST_F(GDataFileSystemTest, ContentSearch) {
2459 LoadRootFeedDocument("root_feed.json"); 2458 LoadRootFeedDocument("root_feed.json");
2460 2459
2461 mock_doc_service_->set_search_result("search_result_feed.json"); 2460 mock_drive_service_->set_search_result("search_result_feed.json");
2462 2461
2463 EXPECT_CALL(*mock_doc_service_, GetDocuments(Eq(GURL()), _, "foo", _, _)) 2462 EXPECT_CALL(*mock_drive_service_, GetDocuments(Eq(GURL()), _, "foo", _, _))
2464 .Times(1); 2463 .Times(1);
2465 2464
2466 const SearchResultPair kExpectedResults[] = { 2465 const SearchResultPair kExpectedResults[] = {
2467 { "drive/Directory 1/SubDirectory File 1.txt", false }, 2466 { "drive/Directory 1/SubDirectory File 1.txt", false },
2468 { "drive/Directory 1", true } 2467 { "drive/Directory 1", true }
2469 }; 2468 };
2470 2469
2471 SearchCallback callback = base::Bind(&DriveSearchCallback, 2470 SearchCallback callback = base::Bind(&DriveSearchCallback,
2472 &message_loop_, kExpectedResults, ARRAYSIZE_UNSAFE(kExpectedResults)); 2471 &message_loop_, kExpectedResults, ARRAYSIZE_UNSAFE(kExpectedResults));
2473 2472
2474 file_system_->Search("foo", GURL(), callback); 2473 file_system_->Search("foo", GURL(), callback);
2475 message_loop_.Run(); // Wait to get our result. 2474 message_loop_.Run(); // Wait to get our result.
2476 } 2475 }
2477 2476
2478 TEST_F(GDataFileSystemTest, ContentSearchWithNewEntry) { 2477 TEST_F(GDataFileSystemTest, ContentSearchWithNewEntry) {
2479 LoadRootFeedDocument("root_feed.json"); 2478 LoadRootFeedDocument("root_feed.json");
2480 2479
2481 // Search result returning two entries "Directory 1/" and 2480 // Search result returning two entries "Directory 1/" and
2482 // "Directory 1/SubDirectory Newly Added File.txt". The latter is not 2481 // "Directory 1/SubDirectory Newly Added File.txt". The latter is not
2483 // contained in the root feed. 2482 // contained in the root feed.
2484 mock_doc_service_->set_search_result( 2483 mock_drive_service_->set_search_result(
2485 "search_result_with_new_entry_feed.json"); 2484 "search_result_with_new_entry_feed.json");
2486 2485
2487 EXPECT_CALL(*mock_doc_service_, GetDocuments(Eq(GURL()), _, "foo", _, _)) 2486 EXPECT_CALL(*mock_drive_service_, GetDocuments(Eq(GURL()), _, "foo", _, _))
2488 .Times(1); 2487 .Times(1);
2489 2488
2490 // As the result of the first Search(), only entries in the current file 2489 // As the result of the first Search(), only entries in the current file
2491 // system snapshot are expected to be returned. 2490 // system snapshot are expected to be returned.
2492 const SearchResultPair kExpectedResults[] = { 2491 const SearchResultPair kExpectedResults[] = {
2493 { "drive/Directory 1", true } 2492 { "drive/Directory 1", true }
2494 }; 2493 };
2495 2494
2496 // At the same time, unknown entry should trigger delta feed request. 2495 // At the same time, unknown entry should trigger delta feed request.
2497 // This will cause notification to observers (e.g., File Browser) so that 2496 // This will cause notification to observers (e.g., File Browser) so that
2498 // they can request search again. 2497 // they can request search again.
2499 EXPECT_CALL(*mock_doc_service_, GetAccountMetadata(_)).Times(1); 2498 EXPECT_CALL(*mock_drive_service_, GetAccountMetadata(_)).Times(1);
2500 EXPECT_CALL(*mock_doc_service_, GetDocuments(Eq(GURL()), _, "", _, _)) 2499 EXPECT_CALL(*mock_drive_service_, GetDocuments(Eq(GURL()), _, "", _, _))
2501 .Times(1); 2500 .Times(1);
2502 EXPECT_CALL(*mock_webapps_registry_, UpdateFromFeed(_)).Times(1); 2501 EXPECT_CALL(*mock_webapps_registry_, UpdateFromFeed(_)).Times(1);
2503 2502
2504 SearchCallback callback = base::Bind(&DriveSearchCallback, 2503 SearchCallback callback = base::Bind(&DriveSearchCallback,
2505 &message_loop_, kExpectedResults, ARRAYSIZE_UNSAFE(kExpectedResults)); 2504 &message_loop_, kExpectedResults, ARRAYSIZE_UNSAFE(kExpectedResults));
2506 2505
2507 file_system_->Search("foo", GURL(), callback); 2506 file_system_->Search("foo", GURL(), callback);
2508 message_loop_.Run(); // Wait to get our result. 2507 message_loop_.Run(); // Wait to get our result.
2509 } 2508 }
2510 2509
2511 TEST_F(GDataFileSystemTest, ContentSearchEmptyResult) { 2510 TEST_F(GDataFileSystemTest, ContentSearchEmptyResult) {
2512 LoadRootFeedDocument("root_feed.json"); 2511 LoadRootFeedDocument("root_feed.json");
2513 2512
2514 mock_doc_service_->set_search_result("empty_feed.json"); 2513 mock_drive_service_->set_search_result("empty_feed.json");
2515 2514
2516 EXPECT_CALL(*mock_doc_service_, GetDocuments(Eq(GURL()), _, "foo", _, _)) 2515 EXPECT_CALL(*mock_drive_service_, GetDocuments(Eq(GURL()), _, "foo", _, _))
2517 .Times(1); 2516 .Times(1);
2518 2517
2519 const SearchResultPair* expected_results = NULL; 2518 const SearchResultPair* expected_results = NULL;
2520 2519
2521 SearchCallback callback = base::Bind(&DriveSearchCallback, 2520 SearchCallback callback = base::Bind(&DriveSearchCallback,
2522 &message_loop_, expected_results, 0u); 2521 &message_loop_, expected_results, 0u);
2523 2522
2524 file_system_->Search("foo", GURL(), callback); 2523 file_system_->Search("foo", GURL(), callback);
2525 message_loop_.Run(); // Wait to get our result. 2524 message_loop_.Run(); // Wait to get our result.
2526 } 2525 }
2527 2526
2528 TEST_F(GDataFileSystemTest, GetAvailableSpace) { 2527 TEST_F(GDataFileSystemTest, GetAvailableSpace) {
2529 GetAvailableSpaceCallback callback = 2528 GetAvailableSpaceCallback callback =
2530 base::Bind(&CallbackHelper::GetAvailableSpaceCallback, 2529 base::Bind(&CallbackHelper::GetAvailableSpaceCallback,
2531 callback_helper_.get()); 2530 callback_helper_.get());
2532 2531
2533 EXPECT_CALL(*mock_doc_service_, GetAccountMetadata(_)); 2532 EXPECT_CALL(*mock_drive_service_, GetAccountMetadata(_));
2534 2533
2535 file_system_->GetAvailableSpace(callback); 2534 file_system_->GetAvailableSpace(callback);
2536 test_util::RunBlockingPoolTask(); 2535 test_util::RunBlockingPoolTask();
2537 EXPECT_EQ(GG_LONGLONG(6789012345), callback_helper_->quota_bytes_used_); 2536 EXPECT_EQ(GG_LONGLONG(6789012345), callback_helper_->quota_bytes_used_);
2538 EXPECT_EQ(GG_LONGLONG(9876543210), callback_helper_->quota_bytes_total_); 2537 EXPECT_EQ(GG_LONGLONG(9876543210), callback_helper_->quota_bytes_total_);
2539 } 2538 }
2540 2539
2541 TEST_F(GDataFileSystemTest, RequestDirectoryRefresh) { 2540 TEST_F(GDataFileSystemTest, RequestDirectoryRefresh) {
2542 LoadRootFeedDocument("root_feed.json"); 2541 LoadRootFeedDocument("root_feed.json");
2543 2542
2544 // We'll fetch documents in the root directory with its resource ID. 2543 // We'll fetch documents in the root directory with its resource ID.
2545 EXPECT_CALL(*mock_doc_service_, 2544 EXPECT_CALL(*mock_drive_service_,
2546 GetDocuments(Eq(GURL()), _, _, kGDataRootDirectoryResourceId, _)) 2545 GetDocuments(Eq(GURL()), _, _, kGDataRootDirectoryResourceId, _))
2547 .Times(1); 2546 .Times(1);
2548 // We'll notify the directory change to the observer. 2547 // We'll notify the directory change to the observer.
2549 EXPECT_CALL(*mock_directory_observer_, 2548 EXPECT_CALL(*mock_directory_observer_,
2550 OnDirectoryChanged(Eq(FilePath(kGDataRootDirectory)))).Times(1); 2549 OnDirectoryChanged(Eq(FilePath(kGDataRootDirectory)))).Times(1);
2551 2550
2552 file_system_->RequestDirectoryRefresh(FilePath(kGDataRootDirectory)); 2551 file_system_->RequestDirectoryRefresh(FilePath(kGDataRootDirectory));
2553 test_util::RunBlockingPoolTask(); 2552 test_util::RunBlockingPoolTask();
2554 } 2553 }
2555 2554
(...skipping 19 matching lines...) Expand all
2575 2574
2576 // A dirty file is created on close. 2575 // A dirty file is created on close.
2577 EXPECT_CALL(*mock_cache_observer_, OnCacheCommitted(file_resource_id)) 2576 EXPECT_CALL(*mock_cache_observer_, OnCacheCommitted(file_resource_id))
2578 .Times(1); 2577 .Times(1);
2579 2578
2580 // Pretend we have enough space. 2579 // Pretend we have enough space.
2581 EXPECT_CALL(*mock_free_disk_space_checker_, AmountOfFreeDiskSpace()) 2580 EXPECT_CALL(*mock_free_disk_space_checker_, AmountOfFreeDiskSpace())
2582 .Times(2).WillRepeatedly(Return(file_size + kMinFreeSpace)); 2581 .Times(2).WillRepeatedly(Return(file_size + kMinFreeSpace));
2583 2582
2584 const std::string kExpectedFileData = "test file data"; 2583 const std::string kExpectedFileData = "test file data";
2585 mock_doc_service_->set_file_data(new std::string(kExpectedFileData)); 2584 mock_drive_service_->set_file_data(new std::string(kExpectedFileData));
2586 2585
2587 // Before Download starts metadata from server will be fetched. 2586 // Before Download starts metadata from server will be fetched.
2588 // We will read content url from the result. 2587 // We will read content url from the result.
2589 scoped_ptr<base::Value> document(LoadJSONFile("document_to_download.json")); 2588 scoped_ptr<base::Value> document(LoadJSONFile("document_to_download.json"));
2590 SetExpectationsForGetDocumentEntry(&document, "file:2_file_resource_id"); 2589 SetExpectationsForGetDocumentEntry(&document, "file:2_file_resource_id");
2591 2590
2592 // The file is obtained with the mock DocumentsService. 2591 // The file is obtained with the mock DriveService.
2593 EXPECT_CALL(*mock_doc_service_, 2592 EXPECT_CALL(*mock_drive_service_,
2594 DownloadFile(kFileInRoot, 2593 DownloadFile(kFileInRoot,
2595 downloaded_file, 2594 downloaded_file,
2596 GURL("https://file_content_url_changed/"), 2595 GURL("https://file_content_url_changed/"),
2597 _, _)) 2596 _, _))
2598 .Times(1); 2597 .Times(1);
2599 2598
2600 // Open kFileInRoot ("drive/File 1.txt"). 2599 // Open kFileInRoot ("drive/File 1.txt").
2601 file_system_->OpenFile(kFileInRoot, callback); 2600 file_system_->OpenFile(kFileInRoot, callback);
2602 message_loop_.Run(); 2601 message_loop_.Run();
2603 const FilePath opened_file_path = callback_helper_->opened_file_path_; 2602 const FilePath opened_file_path = callback_helper_->opened_file_path_;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
2637 2636
2638 // Try to close the same file twice. 2637 // Try to close the same file twice.
2639 file_system_->CloseFile(kFileInRoot, close_file_callback); 2638 file_system_->CloseFile(kFileInRoot, close_file_callback);
2640 message_loop_.Run(); 2639 message_loop_.Run();
2641 2640
2642 // It must fail. 2641 // It must fail.
2643 EXPECT_EQ(GDATA_FILE_ERROR_NOT_FOUND, callback_helper_->last_error_); 2642 EXPECT_EQ(GDATA_FILE_ERROR_NOT_FOUND, callback_helper_->last_error_);
2644 } 2643 }
2645 2644
2646 } // namespace gdata 2645 } // namespace gdata
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/gdata/gdata_file_system.cc ('k') | chrome/browser/chromeos/gdata/gdata_operations.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698