| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "chrome/browser/chromeos/drive/file_task_executor.h" | 5 #include "chrome/browser/chromeos/drive/file_task_executor.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 } | 41 } |
| 42 | 42 |
| 43 void OpenBrowserWindow(const GURL& open_link) override { | 43 void OpenBrowserWindow(const GURL& open_link) override { |
| 44 opend_urls_->insert(open_link.spec()); | 44 opend_urls_->insert(open_link.spec()); |
| 45 } | 45 } |
| 46 | 46 |
| 47 // Sets up files on the fake Drive service. | 47 // Sets up files on the fake Drive service. |
| 48 bool SetUpTestFiles() { | 48 bool SetUpTestFiles() { |
| 49 { | 49 { |
| 50 google_apis::DriveApiErrorCode result = google_apis::DRIVE_OTHER_ERROR; | 50 google_apis::DriveApiErrorCode result = google_apis::DRIVE_OTHER_ERROR; |
| 51 scoped_ptr<google_apis::FileResource> file; | 51 std::unique_ptr<google_apis::FileResource> file; |
| 52 fake_drive_service_->AddNewFileWithResourceId( | 52 fake_drive_service_->AddNewFileWithResourceId( |
| 53 "id1", | 53 "id1", |
| 54 "text/plain", | 54 "text/plain", |
| 55 "random data", | 55 "random data", |
| 56 fake_drive_service_->GetRootResourceId(), | 56 fake_drive_service_->GetRootResourceId(), |
| 57 "file1.txt", | 57 "file1.txt", |
| 58 false, | 58 false, |
| 59 google_apis::test_util::CreateCopyResultCallback(&result, &file)); | 59 google_apis::test_util::CreateCopyResultCallback(&result, &file)); |
| 60 base::RunLoop().RunUntilIdle(); | 60 base::RunLoop().RunUntilIdle(); |
| 61 if (result != google_apis::HTTP_CREATED) | 61 if (result != google_apis::HTTP_CREATED) |
| 62 return false; | 62 return false; |
| 63 } | 63 } |
| 64 { | 64 { |
| 65 google_apis::DriveApiErrorCode result = google_apis::DRIVE_OTHER_ERROR; | 65 google_apis::DriveApiErrorCode result = google_apis::DRIVE_OTHER_ERROR; |
| 66 scoped_ptr<google_apis::FileResource> file; | 66 std::unique_ptr<google_apis::FileResource> file; |
| 67 fake_drive_service_->AddNewFileWithResourceId( | 67 fake_drive_service_->AddNewFileWithResourceId( |
| 68 "id2", | 68 "id2", |
| 69 "text/plain", | 69 "text/plain", |
| 70 "random data", | 70 "random data", |
| 71 fake_drive_service_->GetRootResourceId(), | 71 fake_drive_service_->GetRootResourceId(), |
| 72 "file2.txt", | 72 "file2.txt", |
| 73 false, | 73 false, |
| 74 google_apis::test_util::CreateCopyResultCallback(&result, &file)); | 74 google_apis::test_util::CreateCopyResultCallback(&result, &file)); |
| 75 base::RunLoop().RunUntilIdle(); | 75 base::RunLoop().RunUntilIdle(); |
| 76 if (result != google_apis::HTTP_CREATED) | 76 if (result != google_apis::HTTP_CREATED) |
| 77 return false; | 77 return false; |
| 78 } | 78 } |
| 79 return true; | 79 return true; |
| 80 } | 80 } |
| 81 | 81 |
| 82 private: | 82 private: |
| 83 std::set<std::string>* const opend_urls_; | 83 std::set<std::string>* const opend_urls_; |
| 84 scoped_ptr<FakeDriveService> fake_drive_service_; | 84 std::unique_ptr<FakeDriveService> fake_drive_service_; |
| 85 scoped_ptr<test_util::FakeFileSystem> fake_file_system_; | 85 std::unique_ptr<test_util::FakeFileSystem> fake_file_system_; |
| 86 }; | 86 }; |
| 87 | 87 |
| 88 } // namespace | 88 } // namespace |
| 89 | 89 |
| 90 TEST(FileTaskExecutorTest, DriveAppOpenSuccess) { | 90 TEST(FileTaskExecutorTest, DriveAppOpenSuccess) { |
| 91 content::TestBrowserThreadBundle thread_bundle; | 91 content::TestBrowserThreadBundle thread_bundle; |
| 92 | 92 |
| 93 std::set<std::string> opend_urls; | 93 std::set<std::string> opend_urls; |
| 94 | 94 |
| 95 // |delegate_ptr| will be owned by |executor|. | 95 // |delegate_ptr| will be owned by |executor|. |
| 96 TestDelegate* const delegate_ptr = new TestDelegate(&opend_urls); | 96 TestDelegate* const delegate_ptr = new TestDelegate(&opend_urls); |
| 97 ASSERT_TRUE(delegate_ptr->SetUpTestFiles()); | 97 ASSERT_TRUE(delegate_ptr->SetUpTestFiles()); |
| 98 // |executor| deletes itself after Execute() is finished. | 98 // |executor| deletes itself after Execute() is finished. |
| 99 FileTaskExecutor* const executor = new FileTaskExecutor( | 99 FileTaskExecutor* const executor = new FileTaskExecutor( |
| 100 scoped_ptr<FileTaskExecutorDelegate>(delegate_ptr), "test-app-id"); | 100 std::unique_ptr<FileTaskExecutorDelegate>(delegate_ptr), "test-app-id"); |
| 101 | 101 |
| 102 std::vector<storage::FileSystemURL> urls; | 102 std::vector<storage::FileSystemURL> urls; |
| 103 urls.push_back(storage::FileSystemURL::CreateForTest( | 103 urls.push_back(storage::FileSystemURL::CreateForTest( |
| 104 GURL("http://origin/"), | 104 GURL("http://origin/"), |
| 105 storage::kFileSystemTypeDrive, | 105 storage::kFileSystemTypeDrive, |
| 106 base::FilePath::FromUTF8Unsafe("/special/drive/root/file1.txt"))); | 106 base::FilePath::FromUTF8Unsafe("/special/drive/root/file1.txt"))); |
| 107 urls.push_back(storage::FileSystemURL::CreateForTest( | 107 urls.push_back(storage::FileSystemURL::CreateForTest( |
| 108 GURL("http://origin/"), | 108 GURL("http://origin/"), |
| 109 storage::kFileSystemTypeDrive, | 109 storage::kFileSystemTypeDrive, |
| 110 base::FilePath::FromUTF8Unsafe("/special/drive/root/file2.txt"))); | 110 base::FilePath::FromUTF8Unsafe("/special/drive/root/file2.txt"))); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 124 TEST(FileTaskExecutorTest, DriveAppOpenFailForNonExistingFile) { | 124 TEST(FileTaskExecutorTest, DriveAppOpenFailForNonExistingFile) { |
| 125 content::TestBrowserThreadBundle thread_bundle; | 125 content::TestBrowserThreadBundle thread_bundle; |
| 126 | 126 |
| 127 std::set<std::string> opend_urls; | 127 std::set<std::string> opend_urls; |
| 128 | 128 |
| 129 // |delegate_ptr| will be owned by |executor|. | 129 // |delegate_ptr| will be owned by |executor|. |
| 130 TestDelegate* const delegate_ptr = new TestDelegate(&opend_urls); | 130 TestDelegate* const delegate_ptr = new TestDelegate(&opend_urls); |
| 131 ASSERT_TRUE(delegate_ptr->SetUpTestFiles()); | 131 ASSERT_TRUE(delegate_ptr->SetUpTestFiles()); |
| 132 // |executor| deletes itself after Execute() is finished. | 132 // |executor| deletes itself after Execute() is finished. |
| 133 FileTaskExecutor* const executor = new FileTaskExecutor( | 133 FileTaskExecutor* const executor = new FileTaskExecutor( |
| 134 scoped_ptr<FileTaskExecutorDelegate>(delegate_ptr), "test-app-id"); | 134 std::unique_ptr<FileTaskExecutorDelegate>(delegate_ptr), "test-app-id"); |
| 135 | 135 |
| 136 std::vector<storage::FileSystemURL> urls; | 136 std::vector<storage::FileSystemURL> urls; |
| 137 urls.push_back(storage::FileSystemURL::CreateForTest( | 137 urls.push_back(storage::FileSystemURL::CreateForTest( |
| 138 GURL("http://origin/"), | 138 GURL("http://origin/"), |
| 139 storage::kFileSystemTypeDrive, | 139 storage::kFileSystemTypeDrive, |
| 140 base::FilePath::FromUTF8Unsafe("/special/drive/root/not-exist.txt"))); | 140 base::FilePath::FromUTF8Unsafe("/special/drive/root/not-exist.txt"))); |
| 141 | 141 |
| 142 extensions::api::file_manager_private::TaskResult result = | 142 extensions::api::file_manager_private::TaskResult result = |
| 143 extensions::api::file_manager_private::TASK_RESULT_NONE; | 143 extensions::api::file_manager_private::TASK_RESULT_NONE; |
| 144 executor->Execute(urls, | 144 executor->Execute(urls, |
| 145 google_apis::test_util::CreateCopyResultCallback(&result)); | 145 google_apis::test_util::CreateCopyResultCallback(&result)); |
| 146 base::RunLoop().RunUntilIdle(); | 146 base::RunLoop().RunUntilIdle(); |
| 147 | 147 |
| 148 EXPECT_EQ(extensions::api::file_manager_private::TASK_RESULT_FAILED, result); | 148 EXPECT_EQ(extensions::api::file_manager_private::TASK_RESULT_FAILED, result); |
| 149 ASSERT_TRUE(opend_urls.empty()); | 149 ASSERT_TRUE(opend_urls.empty()); |
| 150 } | 150 } |
| 151 | 151 |
| 152 } // namespace drive | 152 } // namespace drive |
| OLD | NEW |