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" |
11 #include "chrome/browser/chromeos/drive/fake_file_system.h" | 11 #include "chrome/browser/chromeos/drive/fake_file_system.h" |
12 #include "chrome/browser/drive/fake_drive_service.h" | 12 #include "chrome/browser/drive/fake_drive_service.h" |
13 #include "content/public/test/test_browser_thread_bundle.h" | 13 #include "content/public/test/test_browser_thread_bundle.h" |
14 #include "google_apis/drive/drive_api_parser.h" | 14 #include "google_apis/drive/drive_api_parser.h" |
15 #include "google_apis/drive/test_util.h" | 15 #include "google_apis/drive/test_util.h" |
16 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
17 #include "webkit/browser/fileapi/file_system_url.h" | 17 #include "storage/browser/fileapi/file_system_url.h" |
18 | 18 |
19 namespace drive { | 19 namespace drive { |
20 | 20 |
21 namespace { | 21 namespace { |
22 | 22 |
23 // Test harness for verifying the behavior of FileTaskExecutor. | 23 // Test harness for verifying the behavior of FileTaskExecutor. |
24 class TestDelegate : public FileTaskExecutorDelegate { | 24 class TestDelegate : public FileTaskExecutorDelegate { |
25 public: | 25 public: |
26 explicit TestDelegate(std::set<std::string>* opend_urls) | 26 explicit TestDelegate(std::set<std::string>* opend_urls) |
27 : opend_urls_(opend_urls), | 27 : opend_urls_(opend_urls), |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 scoped_ptr<FileTaskExecutorDelegate>(delegate_ptr), "test-app-id"); |
101 | 101 |
102 std::vector<fileapi::FileSystemURL> urls; | 102 std::vector<storage::FileSystemURL> urls; |
103 urls.push_back(fileapi::FileSystemURL::CreateForTest( | 103 urls.push_back(storage::FileSystemURL::CreateForTest( |
104 GURL("http://origin/"), | 104 GURL("http://origin/"), |
105 fileapi::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(fileapi::FileSystemURL::CreateForTest( | 107 urls.push_back(storage::FileSystemURL::CreateForTest( |
108 GURL("http://origin/"), | 108 GURL("http://origin/"), |
109 fileapi::kFileSystemTypeDrive, | 109 storage::kFileSystemTypeDrive, |
110 base::FilePath::FromUTF8Unsafe("/special/drive/root/file2.txt"))); | 110 base::FilePath::FromUTF8Unsafe("/special/drive/root/file2.txt"))); |
111 | 111 |
112 extensions::api::file_browser_private::TaskResult result = | 112 extensions::api::file_browser_private::TaskResult result = |
113 extensions::api::file_browser_private::TASK_RESULT_NONE; | 113 extensions::api::file_browser_private::TASK_RESULT_NONE; |
114 executor->Execute(urls, | 114 executor->Execute(urls, |
115 google_apis::test_util::CreateCopyResultCallback(&result)); | 115 google_apis::test_util::CreateCopyResultCallback(&result)); |
116 base::RunLoop().RunUntilIdle(); | 116 base::RunLoop().RunUntilIdle(); |
117 | 117 |
118 EXPECT_EQ(extensions::api::file_browser_private::TASK_RESULT_OPENED, result); | 118 EXPECT_EQ(extensions::api::file_browser_private::TASK_RESULT_OPENED, result); |
119 ASSERT_EQ(2u, opend_urls.size()); | 119 ASSERT_EQ(2u, opend_urls.size()); |
120 EXPECT_TRUE(opend_urls.count("http://openlink/id1/test-app-id")); | 120 EXPECT_TRUE(opend_urls.count("http://openlink/id1/test-app-id")); |
121 EXPECT_TRUE(opend_urls.count("http://openlink/id2/test-app-id")); | 121 EXPECT_TRUE(opend_urls.count("http://openlink/id2/test-app-id")); |
122 } | 122 } |
123 | 123 |
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 scoped_ptr<FileTaskExecutorDelegate>(delegate_ptr), "test-app-id"); |
135 | 135 |
136 std::vector<fileapi::FileSystemURL> urls; | 136 std::vector<storage::FileSystemURL> urls; |
137 urls.push_back(fileapi::FileSystemURL::CreateForTest( | 137 urls.push_back(storage::FileSystemURL::CreateForTest( |
138 GURL("http://origin/"), | 138 GURL("http://origin/"), |
139 fileapi::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_browser_private::TaskResult result = | 142 extensions::api::file_browser_private::TaskResult result = |
143 extensions::api::file_browser_private::TASK_RESULT_NONE; | 143 extensions::api::file_browser_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_browser_private::TASK_RESULT_FAILED, result); | 148 EXPECT_EQ(extensions::api::file_browser_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 |