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

Side by Side Diff: chrome/browser/chromeos/file_manager/external_filesystem_apitest.cc

Issue 2695403002: Avoid re-entrancy in DriveIntegrationService testing factory (Closed)
Patch Set: . Created 3 years, 10 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
« no previous file with comments | « no previous file | chrome/browser/extensions/api/file_system/file_system_apitest_chromeos.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "base/bind.h" 5 #include "base/bind.h"
6 #include "base/files/file_path.h" 6 #include "base/files/file_path.h"
7 #include "base/files/file_util.h" 7 #include "base/files/file_util.h"
8 #include "base/files/scoped_temp_dir.h" 8 #include "base/files/scoped_temp_dir.h"
9 #include "base/path_service.h" 9 #include "base/path_service.h"
10 #include "chrome/browser/browser_process.h" 10 #include "chrome/browser/browser_process.h"
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 : ui::SelectFileDialog(listener, policy) {} 85 : ui::SelectFileDialog(listener, policy) {}
86 86
87 void SelectFileImpl(Type type, 87 void SelectFileImpl(Type type,
88 const base::string16& title, 88 const base::string16& title,
89 const base::FilePath& default_path, 89 const base::FilePath& default_path,
90 const FileTypeInfo* file_types, 90 const FileTypeInfo* file_types,
91 int file_type_index, 91 int file_type_index,
92 const base::FilePath::StringType& default_extension, 92 const base::FilePath::StringType& default_extension,
93 gfx::NativeWindow owning_window, 93 gfx::NativeWindow owning_window,
94 void* params) override { 94 void* params) override {
95 listener_->FileSelected( 95 listener_->FileSelected(base::FilePath("/special/drive-user/root/test_dir"),
96 base::FilePath("/special/drive-user/root/test_dir"), 0, NULL); 96 0, nullptr);
97 } 97 }
98 98
99 bool IsRunning(gfx::NativeWindow owning_window) const override { 99 bool IsRunning(gfx::NativeWindow owning_window) const override {
100 return false; 100 return false;
101 } 101 }
102 102
103 void ListenerDestroyed() override {} 103 void ListenerDestroyed() override {}
104 104
105 bool HasMultipleFileTypeChoicesImpl() override { return false; } 105 bool HasMultipleFileTypeChoicesImpl() override { return false; }
106 106
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 if (!google_apis::test_util::WriteStringToFile(test_file, kTestFileContent)) 158 if (!google_apis::test_util::WriteStringToFile(test_file, kTestFileContent))
159 return false; 159 return false;
160 160
161 test_file = test_dir.AppendASCII("empty_test_file.foo"); 161 test_file = test_dir.AppendASCII("empty_test_file.foo");
162 if (!google_apis::test_util::WriteStringToFile(test_file, "")) 162 if (!google_apis::test_util::WriteStringToFile(test_file, ""))
163 return false; 163 return false;
164 164
165 return true; 165 return true;
166 } 166 }
167 167
168 std::unique_ptr<google_apis::FileResource> UpdateDriveEntryTime( 168 void IgnoreDriveEntryResult(google_apis::DriveApiErrorCode error,
169 drive::FakeDriveService* fake_drive_service, 169 std::unique_ptr<google_apis::FileResource> entry) {}
170 const std::string& resource_id, 170
171 const std::string& last_modified, 171 void UpdateDriveEntryTime(drive::FakeDriveService* fake_drive_service,
172 const std::string& last_viewed_by_me) { 172 const std::string& resource_id,
173 const std::string& last_modified,
174 const std::string& last_viewed_by_me) {
173 base::Time last_modified_time, last_viewed_by_me_time; 175 base::Time last_modified_time, last_viewed_by_me_time;
174 if (!google_apis::util::GetTimeFromString(last_modified, 176 ASSERT_TRUE(google_apis::util::GetTimeFromString(last_modified,
175 &last_modified_time) || 177 &last_modified_time) &&
176 !google_apis::util::GetTimeFromString(last_viewed_by_me, 178 google_apis::util::GetTimeFromString(last_viewed_by_me,
177 &last_viewed_by_me_time)) 179 &last_viewed_by_me_time));
178 return std::unique_ptr<google_apis::FileResource>(); 180 fake_drive_service->UpdateResource(resource_id,
179 181 std::string(), // parent_resource_id
180 google_apis::DriveApiErrorCode error = google_apis::DRIVE_OTHER_ERROR; 182 std::string(), // title
181 std::unique_ptr<google_apis::FileResource> entry; 183 last_modified_time, last_viewed_by_me_time,
182 fake_drive_service->UpdateResource( 184 google_apis::drive::Properties(),
183 resource_id, 185 base::Bind(&IgnoreDriveEntryResult));
184 std::string(), // parent_resource_id
185 std::string(), // title
186 last_modified_time, last_viewed_by_me_time,
187 google_apis::drive::Properties(),
188 google_apis::test_util::CreateCopyResultCallback(&error, &entry));
189 base::RunLoop().RunUntilIdle();
190 if (error != google_apis::HTTP_SUCCESS)
191 return std::unique_ptr<google_apis::FileResource>();
192
193 return entry;
194 } 186 }
195 187
196 std::unique_ptr<google_apis::FileResource> AddFileToDriveService( 188 void AddFileToDriveService(drive::FakeDriveService* fake_drive_service,
197 drive::FakeDriveService* fake_drive_service, 189 const std::string& mime_type,
198 const std::string& mime_type, 190 const std::string& content,
199 const std::string& content, 191 const std::string& parent_resource_id,
200 const std::string& parent_resource_id, 192 const std::string& title,
201 const std::string& title, 193 const std::string& last_modified,
202 const std::string& last_modified, 194 const std::string& last_viewed_by_me) {
203 const std::string& last_viewed_by_me) { 195 fake_drive_service->AddNewFileWithResourceId(
204 google_apis::DriveApiErrorCode error = google_apis::DRIVE_OTHER_ERROR; 196 title, mime_type, content, parent_resource_id, title,
205 std::unique_ptr<google_apis::FileResource> entry;
206 fake_drive_service->AddNewFile(
207 mime_type,
208 content,
209 parent_resource_id,
210 title,
211 false, // shared_with_me 197 false, // shared_with_me
212 google_apis::test_util::CreateCopyResultCallback(&error, &entry)); 198 base::Bind(&IgnoreDriveEntryResult));
213 base::RunLoop().RunUntilIdle(); 199 UpdateDriveEntryTime(fake_drive_service, title, last_modified,
214 if (error != google_apis::HTTP_CREATED) 200 last_viewed_by_me);
mtomasz 2017/02/17 02:53:53 We're losing all these error checks, right? This s
215 return std::unique_ptr<google_apis::FileResource>();
216
217 return UpdateDriveEntryTime(fake_drive_service, entry->file_id(),
218 last_modified, last_viewed_by_me);
219 } 201 }
220 202
221 std::unique_ptr<google_apis::FileResource> AddDirectoryToDriveService( 203 void AddDirectoryToDriveService(drive::FakeDriveService* fake_drive_service,
222 drive::FakeDriveService* fake_drive_service, 204 const std::string& parent_resource_id,
223 const std::string& parent_resource_id, 205 const std::string& title,
224 const std::string& title, 206 const std::string& last_modified,
225 const std::string& last_modified, 207 const std::string& last_viewed_by_me) {
226 const std::string& last_viewed_by_me) { 208 fake_drive_service->AddNewDirectoryWithResourceId(
227 google_apis::DriveApiErrorCode error = google_apis::DRIVE_OTHER_ERROR; 209 title, parent_resource_id, title, drive::AddNewDirectoryOptions(),
228 std::unique_ptr<google_apis::FileResource> entry; 210 base::Bind(&IgnoreDriveEntryResult));
229 fake_drive_service->AddNewDirectory( 211 UpdateDriveEntryTime(fake_drive_service, title, last_modified,
230 parent_resource_id, title, drive::AddNewDirectoryOptions(), 212 last_viewed_by_me);
231 google_apis::test_util::CreateCopyResultCallback(&error, &entry));
232 base::RunLoop().RunUntilIdle();
233 if (error != google_apis::HTTP_CREATED)
234 return std::unique_ptr<google_apis::FileResource>();
235
236 return UpdateDriveEntryTime(fake_drive_service, entry->file_id(),
237 last_modified, last_viewed_by_me);
238 } 213 }
239 214
240 // Sets up the drive service state. 215 // Sets up the drive service state.
241 // The hierarchy is the same as for the local file system. 216 // The hierarchy is the same as for the local file system.
242 bool InitializeDriveService( 217 drive::FakeDriveService* CreateDriveService() {
243 drive::FakeDriveService* fake_drive_service, 218 drive::FakeDriveService* service = new drive::FakeDriveService;
244 std::map<std::string, std::string>* out_resource_ids) { 219 service->LoadAppListForDriveApi("drive/applist.json");
245 std::unique_ptr<google_apis::FileResource> entry; 220 AddDirectoryToDriveService(service, service->GetRootResourceId(), "test_dir",
246 221 "2012-01-02T00:00:00.000Z",
247 entry = AddDirectoryToDriveService(fake_drive_service, 222 "2012-01-02T00:00:01.000Z");
248 fake_drive_service->GetRootResourceId(), 223 AddDirectoryToDriveService(service, "test_dir", "empty_test_dir",
249 "test_dir", 224 "2011-11-02T04:00:00.000Z",
250 "2012-01-02T00:00:00.000Z", 225 "2011-11-02T04:00:00.000Z");
251 "2012-01-02T00:00:01.000Z"); 226 AddDirectoryToDriveService(service, "test_dir", "subdir",
252 if (!entry) 227 "2011-04-01T18:34:08.234Z",
253 return false; 228 "2012-01-02T00:00:01.000Z");
254 (*out_resource_ids)[entry->title()] = entry->file_id(); 229 AddFileToDriveService(service, "application/vnd.mozilla.xul+xml",
255 230 kTestFileContent, "test_dir", "test_file.xul",
256 entry = AddDirectoryToDriveService(fake_drive_service, 231 "2011-12-14T00:40:47.330Z", "2012-01-02T00:00:00.000Z");
257 (*out_resource_ids)["test_dir"], 232 AddFileToDriveService(service, "test/ro", kTestFileContent, "test_dir",
258 "empty_test_dir", 233 "test_file.xul.foo", "2012-01-01T10:00:30.000Z",
259 "2011-11-02T04:00:00.000Z", 234 "2012-01-01T00:00:00.000Z");
260 "2011-11-02T04:00:00.000Z"); 235 AddFileToDriveService(service, "image/tiff", kTestFileContent, "test_dir",
261 if (!entry) 236 "test_file.tiff", "2011-04-03T11:11:10.000Z",
262 return false; 237 "2012-01-02T00:00:00.000Z");
263 (*out_resource_ids)[entry->title()] = entry->file_id(); 238 AddFileToDriveService(service, "test/rw", kTestFileContent, "test_dir",
264 239 "test_file.tiff.foo", "2011-12-14T00:40:47.330Z",
265 entry = AddDirectoryToDriveService(fake_drive_service, 240 "2010-01-02T00:00:00.000Z");
266 (*out_resource_ids)["test_dir"], 241 AddFileToDriveService(service, "test/rw", "", "test_dir",
267 "subdir", 242 "empty_test_file.foo", "2011-12-14T00:40:47.330Z",
268 "2011-04-01T18:34:08.234Z", 243 "2011-12-14T00:40:47.330Z");
269 "2012-01-02T00:00:01.000Z"); 244 return service;
270 if (!entry)
271 return false;
272 (*out_resource_ids)[entry->title()] = entry->file_id();
273
274 entry = AddFileToDriveService(fake_drive_service,
275 "application/vnd.mozilla.xul+xml",
276 kTestFileContent,
277 (*out_resource_ids)["test_dir"],
278 "test_file.xul",
279 "2011-12-14T00:40:47.330Z",
280 "2012-01-02T00:00:00.000Z");
281 if (!entry)
282 return false;
283 (*out_resource_ids)[entry->title()] = entry->file_id();
284
285 entry = AddFileToDriveService(fake_drive_service,
286 "test/ro",
287 kTestFileContent,
288 (*out_resource_ids)["test_dir"],
289 "test_file.xul.foo",
290 "2012-01-01T10:00:30.000Z",
291 "2012-01-01T00:00:00.000Z");
292 if (!entry)
293 return false;
294 (*out_resource_ids)[entry->title()] = entry->file_id();
295
296 entry = AddFileToDriveService(fake_drive_service,
297 "image/tiff",
298 kTestFileContent,
299 (*out_resource_ids)["test_dir"],
300 "test_file.tiff",
301 "2011-04-03T11:11:10.000Z",
302 "2012-01-02T00:00:00.000Z");
303 if (!entry)
304 return false;
305 (*out_resource_ids)[entry->title()] = entry->file_id();
306
307 entry = AddFileToDriveService(fake_drive_service,
308 "test/rw",
309 kTestFileContent,
310 (*out_resource_ids)["test_dir"],
311 "test_file.tiff.foo",
312 "2011-12-14T00:40:47.330Z",
313 "2010-01-02T00:00:00.000Z");
314 if (!entry)
315 return false;
316 (*out_resource_ids)[entry->title()] = entry->file_id();
317
318 entry = AddFileToDriveService(fake_drive_service,
319 "test/rw",
320 "",
321 (*out_resource_ids)["test_dir"],
322 "empty_test_file.foo",
323 "2011-12-14T00:40:47.330Z",
324 "2011-12-14T00:40:47.330Z");
325 if (!entry)
326 return false;
327 (*out_resource_ids)[entry->title()] = entry->file_id();
328
329 return true;
330 } 245 }
331 246
332 // Helper class to wait for a background page to load or close again. 247 // Helper class to wait for a background page to load or close again.
333 class BackgroundObserver { 248 class BackgroundObserver {
334 public: 249 public:
335 BackgroundObserver() 250 BackgroundObserver()
336 : page_created_(extensions::NOTIFICATION_EXTENSION_BACKGROUND_PAGE_READY, 251 : page_created_(extensions::NOTIFICATION_EXTENSION_BACKGROUND_PAGE_READY,
337 content::NotificationService::AllSources()), 252 content::NotificationService::AllSources()),
338 page_closed_(extensions::NOTIFICATION_EXTENSION_HOST_DESTROYED, 253 page_closed_(extensions::NOTIFICATION_EXTENSION_HOST_DESTROYED,
339 content::NotificationService::AllSources()) {} 254 content::NotificationService::AllSources()) {}
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
511 } 426 }
512 427
513 private: 428 private:
514 base::ScopedTempDir tmp_dir_; 429 base::ScopedTempDir tmp_dir_;
515 base::FilePath mount_point_dir_; 430 base::FilePath mount_point_dir_;
516 }; 431 };
517 432
518 // Tests for a drive file system. 433 // Tests for a drive file system.
519 class DriveFileSystemExtensionApiTest : public FileSystemExtensionApiTestBase { 434 class DriveFileSystemExtensionApiTest : public FileSystemExtensionApiTestBase {
520 public: 435 public:
521 DriveFileSystemExtensionApiTest() : fake_drive_service_(NULL) {} 436 DriveFileSystemExtensionApiTest() {}
522 ~DriveFileSystemExtensionApiTest() override {} 437 ~DriveFileSystemExtensionApiTest() override {}
523 438
524 // FileSystemExtensionApiTestBase override. 439 // FileSystemExtensionApiTestBase override.
525 void InitTestFileSystem() override { 440 void InitTestFileSystem() override {
526 // Set up cache root to be used by DriveIntegrationService. This has to be 441 // Set up cache root to be used by DriveIntegrationService. This has to be
527 // done before the browser is created because the service instance is 442 // done before the browser is created because the service instance is
528 // initialized by EventRouter. 443 // initialized by EventRouter.
529 ASSERT_TRUE(test_cache_root_.CreateUniqueTempDir()); 444 ASSERT_TRUE(test_cache_root_.CreateUniqueTempDir());
530 445
531 // This callback will get called during Profile creation. 446 // This callback will get called during Profile creation.
532 create_drive_integration_service_ = base::Bind( 447 create_drive_integration_service_ = base::Bind(
533 &DriveFileSystemExtensionApiTest::CreateDriveIntegrationService, 448 &DriveFileSystemExtensionApiTest::CreateDriveIntegrationService,
534 base::Unretained(this)); 449 base::Unretained(this));
535 service_factory_for_test_.reset( 450 service_factory_for_test_.reset(
536 new DriveIntegrationServiceFactory::ScopedFactoryForTest( 451 new DriveIntegrationServiceFactory::ScopedFactoryForTest(
537 &create_drive_integration_service_)); 452 &create_drive_integration_service_));
538 } 453 }
539 454
540 // FileSystemExtensionApiTestBase override. 455 // FileSystemExtensionApiTestBase override.
541 void AddTestMountPoint() override { 456 void AddTestMountPoint() override {
542 test_util::WaitUntilDriveMountPointIsAdded(browser()->profile()); 457 test_util::WaitUntilDriveMountPointIsAdded(browser()->profile());
543 } 458 }
544 459
545 // FileSystemExtensionApiTestBase override. 460 // FileSystemExtensionApiTestBase override.
546 void TearDown() override { 461 void TearDown() override {
547 FileSystemExtensionApiTestBase::TearDown(); 462 FileSystemExtensionApiTestBase::TearDown();
548 ui::SelectFileDialog::SetFactory(NULL); 463 ui::SelectFileDialog::SetFactory(nullptr);
549 } 464 }
550 465
551 protected: 466 protected:
552 // DriveIntegrationService factory function for this test. 467 // DriveIntegrationService factory function for this test.
553 drive::DriveIntegrationService* CreateDriveIntegrationService( 468 drive::DriveIntegrationService* CreateDriveIntegrationService(
554 Profile* profile) { 469 Profile* profile) {
555 // Ignore signin profile. 470 // Ignore signin profile.
556 if (profile->GetPath() == chromeos::ProfileHelper::GetSigninProfileDir()) 471 if (profile->GetPath() == chromeos::ProfileHelper::GetSigninProfileDir())
557 return NULL; 472 return nullptr;
558 473
559 // DriveFileSystemExtensionApiTest doesn't expect that several user profiles 474 // DriveFileSystemExtensionApiTest doesn't expect that several user profiles
560 // could exist simultaneously. 475 // could exist simultaneously.
561 DCHECK(fake_drive_service_ == NULL); 476 DCHECK(!fake_drive_service_);
562 fake_drive_service_ = new drive::FakeDriveService; 477 fake_drive_service_ = CreateDriveService();
563 fake_drive_service_->LoadAppListForDriveApi("drive/applist.json");
564
565 std::map<std::string, std::string> resource_ids;
566 EXPECT_TRUE(InitializeDriveService(fake_drive_service_, &resource_ids));
567
568 return new drive::DriveIntegrationService( 478 return new drive::DriveIntegrationService(
569 profile, nullptr, fake_drive_service_, "", test_cache_root_.GetPath(), 479 profile, nullptr, fake_drive_service_, "", test_cache_root_.GetPath(),
570 nullptr); 480 nullptr);
571 } 481 }
572 482
573 base::ScopedTempDir test_cache_root_; 483 base::ScopedTempDir test_cache_root_;
574 drive::FakeDriveService* fake_drive_service_; 484 drive::FakeDriveService* fake_drive_service_ = nullptr;
575 DriveIntegrationServiceFactory::FactoryCallback 485 DriveIntegrationServiceFactory::FactoryCallback
576 create_drive_integration_service_; 486 create_drive_integration_service_;
577 std::unique_ptr<DriveIntegrationServiceFactory::ScopedFactoryForTest> 487 std::unique_ptr<DriveIntegrationServiceFactory::ScopedFactoryForTest>
578 service_factory_for_test_; 488 service_factory_for_test_;
579 }; 489 };
580 490
581 // Tests for Drive file systems in multi-profile setting. 491 // Tests for Drive file systems in multi-profile setting.
582 class MultiProfileDriveFileSystemExtensionApiTest : 492 class MultiProfileDriveFileSystemExtensionApiTest :
583 public FileSystemExtensionApiTestBase { 493 public FileSystemExtensionApiTestBase {
584 public: 494 public:
585 MultiProfileDriveFileSystemExtensionApiTest() : second_profile_(NULL) {} 495 MultiProfileDriveFileSystemExtensionApiTest() {}
586 496
587 void SetUpOnMainThread() override { 497 void SetUpOnMainThread() override {
588 base::FilePath user_data_directory; 498 base::FilePath user_data_directory;
589 PathService::Get(chrome::DIR_USER_DATA, &user_data_directory); 499 PathService::Get(chrome::DIR_USER_DATA, &user_data_directory);
590 session_manager::SessionManager::Get()->CreateSession( 500 session_manager::SessionManager::Get()->CreateSession(
591 AccountId::FromUserEmail(kSecondProfileAccount), kSecondProfileHash); 501 AccountId::FromUserEmail(kSecondProfileAccount), kSecondProfileHash);
592 // Set up the secondary profile. 502 // Set up the secondary profile.
593 base::FilePath profile_dir = 503 base::FilePath profile_dir =
594 user_data_directory.Append( 504 user_data_directory.Append(
595 chromeos::ProfileHelper::GetUserProfileDir( 505 chromeos::ProfileHelper::GetUserProfileDir(
(...skipping 23 matching lines...) Expand all
619 } 529 }
620 530
621 protected: 531 protected:
622 // DriveIntegrationService factory function for this test. 532 // DriveIntegrationService factory function for this test.
623 drive::DriveIntegrationService* CreateDriveIntegrationService( 533 drive::DriveIntegrationService* CreateDriveIntegrationService(
624 Profile* profile) { 534 Profile* profile) {
625 base::FilePath cache_dir; 535 base::FilePath cache_dir;
626 base::CreateTemporaryDirInDir(tmp_dir_.GetPath(), 536 base::CreateTemporaryDirInDir(tmp_dir_.GetPath(),
627 base::FilePath::StringType(), &cache_dir); 537 base::FilePath::StringType(), &cache_dir);
628 538
629 drive::FakeDriveService* const fake_drive_service = 539 drive::FakeDriveService* const service = CreateDriveService();
630 new drive::FakeDriveService;
631 fake_drive_service->LoadAppListForDriveApi("drive/applist.json");
632 EXPECT_TRUE(InitializeDriveService(fake_drive_service, &resource_ids_));
633
634 return new drive::DriveIntegrationService( 540 return new drive::DriveIntegrationService(
635 profile, NULL, fake_drive_service, std::string(), cache_dir, NULL); 541 profile, nullptr, service, std::string(), cache_dir, nullptr);
636 } 542 }
637 543
638 bool AddTestHostedDocuments() { 544 void AddTestHostedDocuments() {
639 const char kResourceId[] = "unique-id-for-multiprofile-copy-test"; 545 const char kResourceId[] = "unique-id-for-multiprofile-copy-test";
640 drive::FakeDriveService* const main_service = 546 drive::FakeDriveService* const main_service =
641 static_cast<drive::FakeDriveService*>( 547 static_cast<drive::FakeDriveService*>(
642 drive::util::GetDriveServiceByProfile(browser()->profile())); 548 drive::util::GetDriveServiceByProfile(browser()->profile()));
643 drive::FakeDriveService* const sub_service = 549 drive::FakeDriveService* const sub_service =
644 static_cast<drive::FakeDriveService*>( 550 static_cast<drive::FakeDriveService*>(
645 drive::util::GetDriveServiceByProfile(second_profile_)); 551 drive::util::GetDriveServiceByProfile(second_profile_));
646 552
647 google_apis::DriveApiErrorCode error = google_apis::DRIVE_OTHER_ERROR;
648 std::unique_ptr<google_apis::FileResource> entry;
649
650 // Place a hosted document under root/test_dir of the sub profile. 553 // Place a hosted document under root/test_dir of the sub profile.
651 sub_service->AddNewFileWithResourceId( 554 sub_service->AddNewFileWithResourceId(
652 kResourceId, 555 kResourceId, "application/vnd.google-apps.document", "", "test_dir",
653 "application/vnd.google-apps.document", "", 556 "hosted_doc", true, base::Bind(&IgnoreDriveEntryResult));
654 resource_ids_["test_dir"], "hosted_doc", true,
655 google_apis::test_util::CreateCopyResultCallback(&error, &entry));
656 content::RunAllBlockingPoolTasksUntilIdle();
657 if (error != google_apis::HTTP_CREATED)
658 return false;
659 557
660 // Place the hosted document with no parent in the main profile, for 558 // Place the hosted document with no parent in the main profile, for
661 // simulating the situation that the document is shared to the main profile. 559 // simulating the situation that the document is shared to the main profile.
662 error = google_apis::DRIVE_OTHER_ERROR;
663 main_service->AddNewFileWithResourceId( 560 main_service->AddNewFileWithResourceId(
664 kResourceId, 561 kResourceId, "application/vnd.google-apps.document", "", "",
665 "application/vnd.google-apps.document", "", "", "hosted_doc", true, 562 "hosted_doc", true, base::Bind(&IgnoreDriveEntryResult));
666 google_apis::test_util::CreateCopyResultCallback(&error, &entry));
667 content::RunAllBlockingPoolTasksUntilIdle();
668 return (error == google_apis::HTTP_CREATED);
669 } 563 }
670 564
671 base::ScopedTempDir tmp_dir_; 565 base::ScopedTempDir tmp_dir_;
672 DriveIntegrationServiceFactory::FactoryCallback 566 DriveIntegrationServiceFactory::FactoryCallback
673 create_drive_integration_service_; 567 create_drive_integration_service_;
674 std::unique_ptr<DriveIntegrationServiceFactory::ScopedFactoryForTest> 568 std::unique_ptr<DriveIntegrationServiceFactory::ScopedFactoryForTest>
675 service_factory_for_test_; 569 service_factory_for_test_;
676 Profile* second_profile_; 570 Profile* second_profile_ = nullptr;
677 std::map<std::string, std::string> resource_ids_;
678 }; 571 };
679 572
680 class LocalAndDriveFileSystemExtensionApiTest 573 class LocalAndDriveFileSystemExtensionApiTest
681 : public FileSystemExtensionApiTestBase { 574 : public FileSystemExtensionApiTestBase {
682 public: 575 public:
683 LocalAndDriveFileSystemExtensionApiTest() {} 576 LocalAndDriveFileSystemExtensionApiTest() {}
684 ~LocalAndDriveFileSystemExtensionApiTest() override {} 577 ~LocalAndDriveFileSystemExtensionApiTest() override {}
685 578
686 // FileSystemExtensionApiTestBase override. 579 // FileSystemExtensionApiTestBase override.
687 void InitTestFileSystem() override { 580 void InitTestFileSystem() override {
(...skipping 26 matching lines...) Expand all
714 ->AddVolumeForTesting(local_mount_point_dir_, VOLUME_TYPE_TESTING, 607 ->AddVolumeForTesting(local_mount_point_dir_, VOLUME_TYPE_TESTING,
715 chromeos::DEVICE_TYPE_UNKNOWN, 608 chromeos::DEVICE_TYPE_UNKNOWN,
716 false /* read_only */); 609 false /* read_only */);
717 test_util::WaitUntilDriveMountPointIsAdded(browser()->profile()); 610 test_util::WaitUntilDriveMountPointIsAdded(browser()->profile());
718 } 611 }
719 612
720 protected: 613 protected:
721 // DriveIntegrationService factory function for this test. 614 // DriveIntegrationService factory function for this test.
722 drive::DriveIntegrationService* CreateDriveIntegrationService( 615 drive::DriveIntegrationService* CreateDriveIntegrationService(
723 Profile* profile) { 616 Profile* profile) {
724 fake_drive_service_ = new drive::FakeDriveService; 617 fake_drive_service_ = CreateDriveService();
725 fake_drive_service_->LoadAppListForDriveApi("drive/applist.json");
726
727 std::map<std::string, std::string> resource_ids;
728 EXPECT_TRUE(InitializeDriveService(fake_drive_service_, &resource_ids));
729
730 return new drive::DriveIntegrationService( 618 return new drive::DriveIntegrationService(
731 profile, nullptr, fake_drive_service_, "drive", 619 profile, nullptr, fake_drive_service_, "drive",
732 test_cache_root_.GetPath(), nullptr); 620 test_cache_root_.GetPath(), nullptr);
733 } 621 }
734 622
735 private: 623 private:
736 // For local volume. 624 // For local volume.
737 base::ScopedTempDir local_tmp_dir_; 625 base::ScopedTempDir local_tmp_dir_;
738 base::FilePath local_mount_point_dir_; 626 base::FilePath local_mount_point_dir_;
739 627
740 // For drive volume. 628 // For drive volume.
741 base::ScopedTempDir test_cache_root_; 629 base::ScopedTempDir test_cache_root_;
742 drive::FakeDriveService* fake_drive_service_; 630 drive::FakeDriveService* fake_drive_service_ = nullptr;
743 DriveIntegrationServiceFactory::FactoryCallback 631 DriveIntegrationServiceFactory::FactoryCallback
744 create_drive_integration_service_; 632 create_drive_integration_service_;
745 std::unique_ptr<DriveIntegrationServiceFactory::ScopedFactoryForTest> 633 std::unique_ptr<DriveIntegrationServiceFactory::ScopedFactoryForTest>
746 service_factory_for_test_; 634 service_factory_for_test_;
747 }; 635 };
748 636
749 // 637 //
750 // LocalFileSystemExtensionApiTests. 638 // LocalFileSystemExtensionApiTests.
751 // 639 //
752 640
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
859 ui::SelectFileDialog::SetFactory(new FakeSelectFileDialogFactory()); 747 ui::SelectFileDialog::SetFactory(new FakeSelectFileDialogFactory());
860 EXPECT_TRUE(RunFileSystemExtensionApiTest("file_browser/retain_entry", 748 EXPECT_TRUE(RunFileSystemExtensionApiTest("file_browser/retain_entry",
861 FILE_PATH_LITERAL("manifest.json"), 749 FILE_PATH_LITERAL("manifest.json"),
862 "", 750 "",
863 FLAGS_NONE)) 751 FLAGS_NONE))
864 << message_; 752 << message_;
865 } 753 }
866 754
867 IN_PROC_BROWSER_TEST_F(MultiProfileDriveFileSystemExtensionApiTest, 755 IN_PROC_BROWSER_TEST_F(MultiProfileDriveFileSystemExtensionApiTest,
868 CrossProfileCopy) { 756 CrossProfileCopy) {
869 ASSERT_TRUE(AddTestHostedDocuments()); 757 AddTestHostedDocuments();
870 EXPECT_TRUE(RunFileSystemExtensionApiTest( 758 EXPECT_TRUE(RunFileSystemExtensionApiTest(
871 "file_browser/multi_profile_copy", 759 "file_browser/multi_profile_copy",
872 FILE_PATH_LITERAL("manifest.json"), 760 FILE_PATH_LITERAL("manifest.json"),
873 "", 761 "",
874 FLAGS_NONE)) << message_; 762 FLAGS_NONE)) << message_;
875 } 763 }
876 764
877 // 765 //
878 // LocalAndDriveFileSystemExtensionApiTests. 766 // LocalAndDriveFileSystemExtensionApiTests.
879 // 767 //
880 IN_PROC_BROWSER_TEST_F(LocalAndDriveFileSystemExtensionApiTest, 768 IN_PROC_BROWSER_TEST_F(LocalAndDriveFileSystemExtensionApiTest,
881 AppFileHandlerMulti) { 769 AppFileHandlerMulti) {
882 EXPECT_TRUE( 770 EXPECT_TRUE(
883 RunFileSystemExtensionApiTest("file_browser/app_file_handler_multi", 771 RunFileSystemExtensionApiTest("file_browser/app_file_handler_multi",
884 FILE_PATH_LITERAL("manifest.json"), 772 FILE_PATH_LITERAL("manifest.json"),
885 "", 773 "",
886 FLAGS_NONE)) 774 FLAGS_NONE))
887 << message_; 775 << message_;
888 } 776 }
889 } // namespace 777 } // namespace
890 } // namespace file_manager 778 } // namespace file_manager
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/extensions/api/file_system/file_system_apitest_chromeos.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698