OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/drive_url_request_job.h" | 5 #include "chrome/browser/chromeos/fileapi/external_file_url_request_job.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
11 #include "base/run_loop.h" | 11 #include "base/run_loop.h" |
12 #include "base/threading/thread.h" | 12 #include "base/threading/thread.h" |
13 #include "chrome/browser/chromeos/drive/drive_file_stream_reader.h" | 13 #include "chrome/browser/chromeos/drive/drive_file_stream_reader.h" |
14 #include "chrome/browser/chromeos/drive/drive_integration_service.h" | 14 #include "chrome/browser/chromeos/drive/drive_integration_service.h" |
15 #include "chrome/browser/chromeos/drive/fake_file_system.h" | 15 #include "chrome/browser/chromeos/drive/fake_file_system.h" |
(...skipping 19 matching lines...) Expand all Loading... |
35 #include "net/http/http_byte_range.h" | 35 #include "net/http/http_byte_range.h" |
36 #include "net/url_request/redirect_info.h" | 36 #include "net/url_request/redirect_info.h" |
37 #include "net/url_request/url_request.h" | 37 #include "net/url_request/url_request.h" |
38 #include "net/url_request/url_request_context.h" | 38 #include "net/url_request/url_request_context.h" |
39 #include "net/url_request/url_request_test_util.h" | 39 #include "net/url_request/url_request_test_util.h" |
40 #include "storage/browser/fileapi/external_mount_points.h" | 40 #include "storage/browser/fileapi/external_mount_points.h" |
41 #include "storage/browser/fileapi/file_system_context.h" | 41 #include "storage/browser/fileapi/file_system_context.h" |
42 #include "testing/gtest/include/gtest/gtest.h" | 42 #include "testing/gtest/include/gtest/gtest.h" |
43 #include "url/gurl.h" | 43 #include "url/gurl.h" |
44 | 44 |
45 namespace drive { | 45 namespace chromeos { |
46 namespace { | 46 namespace { |
47 | 47 |
48 // A simple URLRequestJobFactory implementation to create DriveURLRequestJob. | 48 // A simple URLRequestJobFactory implementation to create |
| 49 // ExternalFileURLRequestJob. |
49 class TestURLRequestJobFactory : public net::URLRequestJobFactory { | 50 class TestURLRequestJobFactory : public net::URLRequestJobFactory { |
50 public: | 51 public: |
51 explicit TestURLRequestJobFactory(void* profile_id) | 52 explicit TestURLRequestJobFactory(void* profile_id) |
52 : profile_id_(profile_id) {} | 53 : profile_id_(profile_id) {} |
53 | 54 |
54 virtual ~TestURLRequestJobFactory() {} | 55 virtual ~TestURLRequestJobFactory() {} |
55 | 56 |
56 // net::URLRequestJobFactory override: | 57 // net::URLRequestJobFactory override: |
57 virtual net::URLRequestJob* MaybeCreateJobWithProtocolHandler( | 58 virtual net::URLRequestJob* MaybeCreateJobWithProtocolHandler( |
58 const std::string& scheme, | 59 const std::string& scheme, |
59 net::URLRequest* request, | 60 net::URLRequest* request, |
60 net::NetworkDelegate* network_delegate) const OVERRIDE { | 61 net::NetworkDelegate* network_delegate) const OVERRIDE { |
61 return new DriveURLRequestJob(profile_id_, request, network_delegate); | 62 return new ExternalFileURLRequestJob( |
| 63 profile_id_, request, network_delegate); |
62 } | 64 } |
63 | 65 |
64 virtual bool IsHandledProtocol(const std::string& scheme) const OVERRIDE { | 66 virtual bool IsHandledProtocol(const std::string& scheme) const OVERRIDE { |
65 return scheme == chrome::kDriveScheme; | 67 return scheme == chrome::kExternalFileScheme; |
66 } | 68 } |
67 | 69 |
68 virtual bool IsHandledURL(const GURL& url) const OVERRIDE { | 70 virtual bool IsHandledURL(const GURL& url) const OVERRIDE { |
69 return url.is_valid() && IsHandledProtocol(url.scheme()); | 71 return url.is_valid() && IsHandledProtocol(url.scheme()); |
70 } | 72 } |
71 | 73 |
72 virtual bool IsSafeRedirectTarget(const GURL& location) const OVERRIDE { | 74 virtual bool IsSafeRedirectTarget(const GURL& location) const OVERRIDE { |
73 return true; | 75 return true; |
74 } | 76 } |
75 | 77 |
(...skipping 18 matching lines...) Expand all Loading... |
94 } | 96 } |
95 | 97 |
96 private: | 98 private: |
97 GURL redirect_url_; | 99 GURL redirect_url_; |
98 | 100 |
99 DISALLOW_COPY_AND_ASSIGN(TestDelegate); | 101 DISALLOW_COPY_AND_ASSIGN(TestDelegate); |
100 }; | 102 }; |
101 | 103 |
102 } // namespace | 104 } // namespace |
103 | 105 |
104 class DriveURLRequestJobTest : public testing::Test { | 106 class ExternalFileURLRequestJobTest : public testing::Test { |
105 protected: | 107 protected: |
106 DriveURLRequestJobTest() | 108 ExternalFileURLRequestJobTest() |
107 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP), | 109 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP), |
108 integration_service_factory_callback_( | 110 integration_service_factory_callback_(base::Bind( |
109 base::Bind(&DriveURLRequestJobTest::CreateDriveIntegrationService, | 111 &ExternalFileURLRequestJobTest::CreateDriveIntegrationService, |
110 base::Unretained(this))), | 112 base::Unretained(this))), |
111 fake_file_system_(NULL) {} | 113 fake_file_system_(NULL) {} |
112 | 114 |
113 virtual ~DriveURLRequestJobTest() { | 115 virtual ~ExternalFileURLRequestJobTest() {} |
114 } | |
115 | 116 |
116 virtual void SetUp() OVERRIDE { | 117 virtual void SetUp() OVERRIDE { |
117 // Create a testing profile. | 118 // Create a testing profile. |
118 profile_manager_.reset( | 119 profile_manager_.reset( |
119 new TestingProfileManager(TestingBrowserProcess::GetGlobal())); | 120 new TestingProfileManager(TestingBrowserProcess::GetGlobal())); |
120 ASSERT_TRUE(profile_manager_->SetUp()); | 121 ASSERT_TRUE(profile_manager_->SetUp()); |
121 Profile* const profile = | 122 Profile* const profile = |
122 profile_manager_->CreateTestingProfile("test-user"); | 123 profile_manager_->CreateTestingProfile("test-user"); |
123 | 124 |
124 // Create the drive integration service for the profile. | 125 // Create the drive integration service for the profile. |
125 integration_service_factory_scope_.reset( | 126 integration_service_factory_scope_.reset( |
126 new DriveIntegrationServiceFactory::ScopedFactoryForTest( | 127 new drive::DriveIntegrationServiceFactory::ScopedFactoryForTest( |
127 &integration_service_factory_callback_)); | 128 &integration_service_factory_callback_)); |
128 DriveIntegrationServiceFactory::GetForProfile(profile); | 129 drive::DriveIntegrationServiceFactory::GetForProfile(profile); |
129 | 130 |
130 // Create the URL request job factory. | 131 // Create the URL request job factory. |
131 test_network_delegate_.reset(new net::TestNetworkDelegate); | 132 test_network_delegate_.reset(new net::TestNetworkDelegate); |
132 test_url_request_job_factory_.reset(new TestURLRequestJobFactory(profile)); | 133 test_url_request_job_factory_.reset(new TestURLRequestJobFactory(profile)); |
133 url_request_context_.reset(new net::URLRequestContext()); | 134 url_request_context_.reset(new net::URLRequestContext()); |
134 url_request_context_->set_job_factory(test_url_request_job_factory_.get()); | 135 url_request_context_->set_job_factory(test_url_request_job_factory_.get()); |
135 url_request_context_->set_network_delegate(test_network_delegate_.get()); | 136 url_request_context_->set_network_delegate(test_network_delegate_.get()); |
136 test_delegate_.reset(new TestDelegate); | 137 test_delegate_.reset(new TestDelegate); |
137 } | 138 } |
138 | 139 |
139 virtual void TearDown() { profile_manager_.reset(); } | 140 virtual void TearDown() { profile_manager_.reset(); } |
140 | 141 |
141 bool ReadDriveFileSync( | 142 bool ReadDriveFileSync(const base::FilePath& file_path, |
142 const base::FilePath& file_path, std::string* out_content) { | 143 std::string* out_content) { |
143 scoped_ptr<base::Thread> worker_thread( | 144 scoped_ptr<base::Thread> worker_thread( |
144 new base::Thread("ReadDriveFileSync")); | 145 new base::Thread("ReadDriveFileSync")); |
145 if (!worker_thread->Start()) | 146 if (!worker_thread->Start()) |
146 return false; | 147 return false; |
147 | 148 |
148 scoped_ptr<DriveFileStreamReader> reader(new DriveFileStreamReader( | 149 scoped_ptr<drive::DriveFileStreamReader> reader( |
149 base::Bind(&DriveURLRequestJobTest::GetFileSystem, | 150 new drive::DriveFileStreamReader( |
150 base::Unretained(this)), | 151 base::Bind(&ExternalFileURLRequestJobTest::GetFileSystem, |
151 worker_thread->message_loop_proxy().get())); | 152 base::Unretained(this)), |
| 153 worker_thread->message_loop_proxy().get())); |
152 int error = net::ERR_FAILED; | 154 int error = net::ERR_FAILED; |
153 scoped_ptr<ResourceEntry> entry; | 155 scoped_ptr<drive::ResourceEntry> entry; |
154 { | 156 { |
155 base::RunLoop run_loop; | 157 base::RunLoop run_loop; |
156 reader->Initialize( | 158 reader->Initialize(file_path, |
157 file_path, | 159 net::HttpByteRange(), |
158 net::HttpByteRange(), | 160 google_apis::test_util::CreateQuitCallback( |
159 google_apis::test_util::CreateQuitCallback( | 161 &run_loop, |
160 &run_loop, | 162 google_apis::test_util::CreateCopyResultCallback( |
161 google_apis::test_util::CreateCopyResultCallback( | 163 &error, &entry))); |
162 &error, &entry))); | |
163 run_loop.Run(); | 164 run_loop.Run(); |
164 } | 165 } |
165 if (error != net::OK || !entry) | 166 if (error != net::OK || !entry) |
166 return false; | 167 return false; |
167 | 168 |
168 // Read data from the reader. | 169 // Read data from the reader. |
169 std::string content; | 170 std::string content; |
170 if (test_util::ReadAllData(reader.get(), &content) != net::OK) | 171 if (drive::test_util::ReadAllData(reader.get(), &content) != net::OK) |
171 return false; | 172 return false; |
172 | 173 |
173 if (static_cast<size_t>(entry->file_info().size()) != content.size()) | 174 if (static_cast<size_t>(entry->file_info().size()) != content.size()) |
174 return false; | 175 return false; |
175 | 176 |
176 *out_content = content; | 177 *out_content = content; |
177 return true; | 178 return true; |
178 } | 179 } |
179 | 180 |
180 scoped_ptr<net::URLRequestContext> url_request_context_; | 181 scoped_ptr<net::URLRequestContext> url_request_context_; |
181 scoped_ptr<TestDelegate> test_delegate_; | 182 scoped_ptr<TestDelegate> test_delegate_; |
182 | 183 |
183 private: | 184 private: |
184 // Create the drive integration service for the |profile| | 185 // Create the drive integration service for the |profile| |
185 DriveIntegrationService* CreateDriveIntegrationService(Profile* profile) { | 186 drive::DriveIntegrationService* CreateDriveIntegrationService( |
186 FakeDriveService* const drive_service = new FakeDriveService; | 187 Profile* profile) { |
187 if (!test_util::SetUpTestEntries(drive_service)) | 188 drive::FakeDriveService* const drive_service = new drive::FakeDriveService; |
| 189 if (!drive::test_util::SetUpTestEntries(drive_service)) |
188 return NULL; | 190 return NULL; |
189 | 191 |
190 const std::string& drive_mount_name = | 192 const std::string& drive_mount_name = |
191 util::GetDriveMountPointPath(profile).BaseName().AsUTF8Unsafe(); | 193 drive::util::GetDriveMountPointPath(profile).BaseName().AsUTF8Unsafe(); |
192 storage::ExternalMountPoints::GetSystemInstance()->RegisterFileSystem( | 194 storage::ExternalMountPoints::GetSystemInstance()->RegisterFileSystem( |
193 drive_mount_name, | 195 drive_mount_name, |
194 storage::kFileSystemTypeDrive, | 196 storage::kFileSystemTypeDrive, |
195 storage::FileSystemMountOption(), | 197 storage::FileSystemMountOption(), |
196 util::GetDriveMountPointPath(profile)); | 198 drive::util::GetDriveMountPointPath(profile)); |
197 DCHECK(!fake_file_system_); | 199 DCHECK(!fake_file_system_); |
198 fake_file_system_ = new test_util::FakeFileSystem(drive_service); | 200 fake_file_system_ = new drive::test_util::FakeFileSystem(drive_service); |
199 if (!drive_cache_dir_.CreateUniqueTempDir()) | 201 if (!drive_cache_dir_.CreateUniqueTempDir()) |
200 return NULL; | 202 return NULL; |
201 return new drive::DriveIntegrationService(profile, | 203 return new drive::DriveIntegrationService(profile, |
202 NULL, | 204 NULL, |
203 drive_service, | 205 drive_service, |
204 drive_mount_name, | 206 drive_mount_name, |
205 drive_cache_dir_.path(), | 207 drive_cache_dir_.path(), |
206 fake_file_system_); | 208 fake_file_system_); |
207 } | 209 } |
208 | 210 |
209 FileSystemInterface* GetFileSystem() { return fake_file_system_; } | 211 drive::FileSystemInterface* GetFileSystem() { return fake_file_system_; } |
210 | 212 |
211 content::TestBrowserThreadBundle thread_bundle_; | 213 content::TestBrowserThreadBundle thread_bundle_; |
212 DriveIntegrationServiceFactory::FactoryCallback | 214 drive::DriveIntegrationServiceFactory::FactoryCallback |
213 integration_service_factory_callback_; | 215 integration_service_factory_callback_; |
214 scoped_ptr<DriveIntegrationServiceFactory::ScopedFactoryForTest> | 216 scoped_ptr<drive::DriveIntegrationServiceFactory::ScopedFactoryForTest> |
215 integration_service_factory_scope_; | 217 integration_service_factory_scope_; |
216 scoped_ptr<DriveIntegrationService> integration_service_; | 218 scoped_ptr<drive::DriveIntegrationService> integration_service_; |
217 test_util::FakeFileSystem* fake_file_system_; | 219 drive::test_util::FakeFileSystem* fake_file_system_; |
218 | 220 |
219 scoped_ptr<net::TestNetworkDelegate> test_network_delegate_; | 221 scoped_ptr<net::TestNetworkDelegate> test_network_delegate_; |
220 scoped_ptr<TestURLRequestJobFactory> test_url_request_job_factory_; | 222 scoped_ptr<TestURLRequestJobFactory> test_url_request_job_factory_; |
221 | 223 |
222 scoped_ptr<TestingProfileManager> profile_manager_; | 224 scoped_ptr<TestingProfileManager> profile_manager_; |
223 base::ScopedTempDir drive_cache_dir_; | 225 base::ScopedTempDir drive_cache_dir_; |
224 scoped_refptr<storage::FileSystemContext> file_system_context_; | 226 scoped_refptr<storage::FileSystemContext> file_system_context_; |
225 }; | 227 }; |
226 | 228 |
227 TEST_F(DriveURLRequestJobTest, NonGetMethod) { | 229 TEST_F(ExternalFileURLRequestJobTest, NonGetMethod) { |
228 scoped_ptr<net::URLRequest> request(url_request_context_->CreateRequest( | 230 scoped_ptr<net::URLRequest> request(url_request_context_->CreateRequest( |
229 GURL("drive:drive/root/File 1.txt"), | 231 GURL("externalfile:drive/root/File 1.txt"), |
230 net::DEFAULT_PRIORITY, | 232 net::DEFAULT_PRIORITY, |
231 test_delegate_.get(), | 233 test_delegate_.get(), |
232 NULL)); | 234 NULL)); |
233 request->set_method("POST"); // Set non "GET" method. | 235 request->set_method("POST"); // Set non "GET" method. |
234 request->Start(); | 236 request->Start(); |
235 | 237 |
236 base::RunLoop().Run(); | 238 base::RunLoop().Run(); |
237 | 239 |
238 EXPECT_EQ(net::URLRequestStatus::FAILED, request->status().status()); | 240 EXPECT_EQ(net::URLRequestStatus::FAILED, request->status().status()); |
239 EXPECT_EQ(net::ERR_METHOD_NOT_SUPPORTED, request->status().error()); | 241 EXPECT_EQ(net::ERR_METHOD_NOT_SUPPORTED, request->status().error()); |
240 } | 242 } |
241 | 243 |
242 TEST_F(DriveURLRequestJobTest, RegularFile) { | 244 TEST_F(ExternalFileURLRequestJobTest, RegularFile) { |
243 const GURL kTestUrl("drive:drive/root/File 1.txt"); | 245 const GURL kTestUrl("externalfile:drive/root/File 1.txt"); |
244 const base::FilePath kTestFilePath("drive/root/File 1.txt"); | 246 const base::FilePath kTestFilePath("drive/root/File 1.txt"); |
245 | 247 |
246 // For the first time, the file should be fetched from the server. | 248 // For the first time, the file should be fetched from the server. |
247 { | 249 { |
248 scoped_ptr<net::URLRequest> request(url_request_context_->CreateRequest( | 250 scoped_ptr<net::URLRequest> request(url_request_context_->CreateRequest( |
249 kTestUrl, | 251 kTestUrl, net::DEFAULT_PRIORITY, test_delegate_.get(), NULL)); |
250 net::DEFAULT_PRIORITY, | |
251 test_delegate_.get(), | |
252 NULL)); | |
253 request->Start(); | 252 request->Start(); |
254 | 253 |
255 base::RunLoop().Run(); | 254 base::RunLoop().Run(); |
256 | 255 |
257 EXPECT_EQ(net::URLRequestStatus::SUCCESS, request->status().status()); | 256 EXPECT_EQ(net::URLRequestStatus::SUCCESS, request->status().status()); |
258 // It looks weird, but the mime type for the "File 1.txt" is "audio/mpeg" | 257 // It looks weird, but the mime type for the "File 1.txt" is "audio/mpeg" |
259 // on the server. | 258 // on the server. |
260 std::string mime_type; | 259 std::string mime_type; |
261 request->GetMimeType(&mime_type); | 260 request->GetMimeType(&mime_type); |
262 EXPECT_EQ("audio/mpeg", mime_type); | 261 EXPECT_EQ("audio/mpeg", mime_type); |
263 | 262 |
264 // Reading file must be done after |request| runs, otherwise | 263 // Reading file must be done after |request| runs, otherwise |
265 // it'll create a local cache file, and we cannot test correctly. | 264 // it'll create a local cache file, and we cannot test correctly. |
266 std::string expected_data; | 265 std::string expected_data; |
267 ASSERT_TRUE(ReadDriveFileSync(kTestFilePath, &expected_data)); | 266 ASSERT_TRUE(ReadDriveFileSync(kTestFilePath, &expected_data)); |
268 EXPECT_EQ(expected_data, test_delegate_->data_received()); | 267 EXPECT_EQ(expected_data, test_delegate_->data_received()); |
269 } | 268 } |
270 | 269 |
271 // For the second time, the locally cached file should be used. | 270 // For the second time, the locally cached file should be used. |
272 // The caching emulation is done by FakeFileSystem. | 271 // The caching emulation is done by FakeFileSystem. |
273 { | 272 { |
274 test_delegate_.reset(new TestDelegate); | 273 test_delegate_.reset(new TestDelegate); |
275 scoped_ptr<net::URLRequest> request(url_request_context_->CreateRequest( | 274 scoped_ptr<net::URLRequest> request(url_request_context_->CreateRequest( |
276 GURL("drive:drive/root/File 1.txt"), | 275 GURL("externalfile:drive/root/File 1.txt"), |
277 net::DEFAULT_PRIORITY, | 276 net::DEFAULT_PRIORITY, |
278 test_delegate_.get(), | 277 test_delegate_.get(), |
279 NULL)); | 278 NULL)); |
280 request->Start(); | 279 request->Start(); |
281 | 280 |
282 base::RunLoop().Run(); | 281 base::RunLoop().Run(); |
283 | 282 |
284 EXPECT_EQ(net::URLRequestStatus::SUCCESS, request->status().status()); | 283 EXPECT_EQ(net::URLRequestStatus::SUCCESS, request->status().status()); |
285 std::string mime_type; | 284 std::string mime_type; |
286 request->GetMimeType(&mime_type); | 285 request->GetMimeType(&mime_type); |
287 EXPECT_EQ("audio/mpeg", mime_type); | 286 EXPECT_EQ("audio/mpeg", mime_type); |
288 | 287 |
289 std::string expected_data; | 288 std::string expected_data; |
290 ASSERT_TRUE(ReadDriveFileSync(kTestFilePath, &expected_data)); | 289 ASSERT_TRUE(ReadDriveFileSync(kTestFilePath, &expected_data)); |
291 EXPECT_EQ(expected_data, test_delegate_->data_received()); | 290 EXPECT_EQ(expected_data, test_delegate_->data_received()); |
292 } | 291 } |
293 } | 292 } |
294 | 293 |
295 TEST_F(DriveURLRequestJobTest, HostedDocument) { | 294 TEST_F(ExternalFileURLRequestJobTest, HostedDocument) { |
296 // Open a gdoc file. | 295 // Open a gdoc file. |
297 test_delegate_->set_quit_on_redirect(true); | 296 test_delegate_->set_quit_on_redirect(true); |
298 scoped_ptr<net::URLRequest> request(url_request_context_->CreateRequest( | 297 scoped_ptr<net::URLRequest> request(url_request_context_->CreateRequest( |
299 GURL("drive:drive/root/Document 1 excludeDir-test.gdoc"), | 298 GURL("externalfile:drive/root/Document 1 excludeDir-test.gdoc"), |
300 net::DEFAULT_PRIORITY, | 299 net::DEFAULT_PRIORITY, |
301 test_delegate_.get(), | 300 test_delegate_.get(), |
302 NULL)); | 301 NULL)); |
303 request->Start(); | 302 request->Start(); |
304 | 303 |
305 base::RunLoop().Run(); | 304 base::RunLoop().Run(); |
306 | 305 |
307 EXPECT_EQ(net::URLRequestStatus::SUCCESS, request->status().status()); | 306 EXPECT_EQ(net::URLRequestStatus::SUCCESS, request->status().status()); |
308 // Make sure that a hosted document triggers redirection. | 307 // Make sure that a hosted document triggers redirection. |
309 EXPECT_TRUE(request->is_redirecting()); | 308 EXPECT_TRUE(request->is_redirecting()); |
310 EXPECT_TRUE(test_delegate_->redirect_url().is_valid()); | 309 EXPECT_TRUE(test_delegate_->redirect_url().is_valid()); |
311 } | 310 } |
312 | 311 |
313 TEST_F(DriveURLRequestJobTest, RootDirectory) { | 312 TEST_F(ExternalFileURLRequestJobTest, RootDirectory) { |
314 scoped_ptr<net::URLRequest> request(url_request_context_->CreateRequest( | 313 scoped_ptr<net::URLRequest> request( |
315 GURL("drive:drive/root"), | 314 url_request_context_->CreateRequest(GURL("externalfile:drive/root"), |
316 net::DEFAULT_PRIORITY, | 315 net::DEFAULT_PRIORITY, |
317 test_delegate_.get(), | 316 test_delegate_.get(), |
318 NULL)); | 317 NULL)); |
319 request->Start(); | 318 request->Start(); |
320 | 319 |
321 base::RunLoop().Run(); | 320 base::RunLoop().Run(); |
322 | 321 |
323 EXPECT_EQ(net::URLRequestStatus::FAILED, request->status().status()); | 322 EXPECT_EQ(net::URLRequestStatus::FAILED, request->status().status()); |
324 EXPECT_EQ(net::ERR_FAILED, request->status().error()); | 323 EXPECT_EQ(net::ERR_FAILED, request->status().error()); |
325 } | 324 } |
326 | 325 |
327 TEST_F(DriveURLRequestJobTest, Directory) { | 326 TEST_F(ExternalFileURLRequestJobTest, Directory) { |
328 scoped_ptr<net::URLRequest> request(url_request_context_->CreateRequest( | 327 scoped_ptr<net::URLRequest> request(url_request_context_->CreateRequest( |
329 GURL("drive:drive/root/Directory 1"), | 328 GURL("externalfile:drive/root/Directory 1"), |
330 net::DEFAULT_PRIORITY, | 329 net::DEFAULT_PRIORITY, |
331 test_delegate_.get(), | 330 test_delegate_.get(), |
332 NULL)); | 331 NULL)); |
333 request->Start(); | 332 request->Start(); |
334 | 333 |
335 base::RunLoop().Run(); | 334 base::RunLoop().Run(); |
336 | 335 |
337 EXPECT_EQ(net::URLRequestStatus::FAILED, request->status().status()); | 336 EXPECT_EQ(net::URLRequestStatus::FAILED, request->status().status()); |
338 EXPECT_EQ(net::ERR_FAILED, request->status().error()); | 337 EXPECT_EQ(net::ERR_FAILED, request->status().error()); |
339 } | 338 } |
340 | 339 |
341 TEST_F(DriveURLRequestJobTest, NonExistingFile) { | 340 TEST_F(ExternalFileURLRequestJobTest, NonExistingFile) { |
342 scoped_ptr<net::URLRequest> request(url_request_context_->CreateRequest( | 341 scoped_ptr<net::URLRequest> request(url_request_context_->CreateRequest( |
343 GURL("drive:drive/root/non-existing-file.txt"), | 342 GURL("externalfile:drive/root/non-existing-file.txt"), |
344 net::DEFAULT_PRIORITY, | 343 net::DEFAULT_PRIORITY, |
345 test_delegate_.get(), | 344 test_delegate_.get(), |
346 NULL)); | 345 NULL)); |
347 request->Start(); | 346 request->Start(); |
348 | 347 |
349 base::RunLoop().Run(); | 348 base::RunLoop().Run(); |
350 | 349 |
351 EXPECT_EQ(net::URLRequestStatus::FAILED, request->status().status()); | 350 EXPECT_EQ(net::URLRequestStatus::FAILED, request->status().status()); |
352 EXPECT_EQ(net::ERR_FILE_NOT_FOUND, request->status().error()); | 351 EXPECT_EQ(net::ERR_FILE_NOT_FOUND, request->status().error()); |
353 } | 352 } |
354 | 353 |
355 TEST_F(DriveURLRequestJobTest, WrongFormat) { | 354 TEST_F(ExternalFileURLRequestJobTest, WrongFormat) { |
356 scoped_ptr<net::URLRequest> request(url_request_context_->CreateRequest( | 355 scoped_ptr<net::URLRequest> request( |
357 GURL("drive:"), | 356 url_request_context_->CreateRequest(GURL("externalfile:"), |
358 net::DEFAULT_PRIORITY, | 357 net::DEFAULT_PRIORITY, |
359 test_delegate_.get(), | 358 test_delegate_.get(), |
360 NULL)); | 359 NULL)); |
361 request->Start(); | 360 request->Start(); |
362 | 361 |
363 base::RunLoop().Run(); | 362 base::RunLoop().Run(); |
364 | 363 |
365 EXPECT_EQ(net::URLRequestStatus::FAILED, request->status().status()); | 364 EXPECT_EQ(net::URLRequestStatus::FAILED, request->status().status()); |
366 EXPECT_EQ(net::ERR_INVALID_URL, request->status().error()); | 365 EXPECT_EQ(net::ERR_INVALID_URL, request->status().error()); |
367 } | 366 } |
368 | 367 |
369 TEST_F(DriveURLRequestJobTest, Cancel) { | 368 TEST_F(ExternalFileURLRequestJobTest, Cancel) { |
370 scoped_ptr<net::URLRequest> request(url_request_context_->CreateRequest( | 369 scoped_ptr<net::URLRequest> request(url_request_context_->CreateRequest( |
371 GURL("drive:drive/root/File 1.txt"), | 370 GURL("externalfile:drive/root/File 1.txt"), |
372 net::DEFAULT_PRIORITY, | 371 net::DEFAULT_PRIORITY, |
373 test_delegate_.get(), | 372 test_delegate_.get(), |
374 NULL)); | 373 NULL)); |
375 | 374 |
376 // Start the request, and cancel it immediately after it. | 375 // Start the request, and cancel it immediately after it. |
377 request->Start(); | 376 request->Start(); |
378 request->Cancel(); | 377 request->Cancel(); |
379 | 378 |
380 base::RunLoop().Run(); | 379 base::RunLoop().Run(); |
381 | 380 |
382 EXPECT_EQ(net::URLRequestStatus::CANCELED, request->status().status()); | 381 EXPECT_EQ(net::URLRequestStatus::CANCELED, request->status().status()); |
383 } | 382 } |
384 | 383 |
385 TEST_F(DriveURLRequestJobTest, RangeHeader) { | 384 TEST_F(ExternalFileURLRequestJobTest, RangeHeader) { |
386 const GURL kTestUrl("drive:drive/root/File 1.txt"); | 385 const GURL kTestUrl("externalfile:drive/root/File 1.txt"); |
387 const base::FilePath kTestFilePath("drive/root/File 1.txt"); | 386 const base::FilePath kTestFilePath("drive/root/File 1.txt"); |
388 | 387 |
389 scoped_ptr<net::URLRequest> request(url_request_context_->CreateRequest( | 388 scoped_ptr<net::URLRequest> request(url_request_context_->CreateRequest( |
390 kTestUrl, | 389 kTestUrl, net::DEFAULT_PRIORITY, test_delegate_.get(), NULL)); |
391 net::DEFAULT_PRIORITY, | |
392 test_delegate_.get(), | |
393 NULL)); | |
394 | 390 |
395 // Set range header. | 391 // Set range header. |
396 request->SetExtraRequestHeaderByName( | 392 request->SetExtraRequestHeaderByName( |
397 "Range", "bytes=3-5", false /* overwrite */); | 393 "Range", "bytes=3-5", false /* overwrite */); |
398 request->Start(); | 394 request->Start(); |
399 | 395 |
400 base::RunLoop().Run(); | 396 base::RunLoop().Run(); |
401 | 397 |
402 EXPECT_EQ(net::URLRequestStatus::SUCCESS, request->status().status()); | 398 EXPECT_EQ(net::URLRequestStatus::SUCCESS, request->status().status()); |
403 | 399 |
404 // Reading file must be done after |request| runs, otherwise | 400 // Reading file must be done after |request| runs, otherwise |
405 // it'll create a local cache file, and we cannot test correctly. | 401 // it'll create a local cache file, and we cannot test correctly. |
406 std::string expected_data; | 402 std::string expected_data; |
407 ASSERT_TRUE(ReadDriveFileSync(kTestFilePath, &expected_data)); | 403 ASSERT_TRUE(ReadDriveFileSync(kTestFilePath, &expected_data)); |
408 EXPECT_EQ(expected_data.substr(3, 3), test_delegate_->data_received()); | 404 EXPECT_EQ(expected_data.substr(3, 3), test_delegate_->data_received()); |
409 } | 405 } |
410 | 406 |
411 TEST_F(DriveURLRequestJobTest, WrongRangeHeader) { | 407 TEST_F(ExternalFileURLRequestJobTest, WrongRangeHeader) { |
412 const GURL kTestUrl("drive:drive/root/File 1.txt"); | 408 const GURL kTestUrl("externalfile:drive/root/File 1.txt"); |
413 | 409 |
414 scoped_ptr<net::URLRequest> request(url_request_context_->CreateRequest( | 410 scoped_ptr<net::URLRequest> request(url_request_context_->CreateRequest( |
415 kTestUrl, | 411 kTestUrl, net::DEFAULT_PRIORITY, test_delegate_.get(), NULL)); |
416 net::DEFAULT_PRIORITY, | |
417 test_delegate_.get(), | |
418 NULL)); | |
419 | 412 |
420 // Set range header. | 413 // Set range header. |
421 request->SetExtraRequestHeaderByName( | 414 request->SetExtraRequestHeaderByName( |
422 "Range", "Wrong Range Header Value", false /* overwrite */); | 415 "Range", "Wrong Range Header Value", false /* overwrite */); |
423 request->Start(); | 416 request->Start(); |
424 | 417 |
425 base::RunLoop().Run(); | 418 base::RunLoop().Run(); |
426 | 419 |
427 EXPECT_EQ(net::URLRequestStatus::FAILED, request->status().status()); | 420 EXPECT_EQ(net::URLRequestStatus::FAILED, request->status().status()); |
428 EXPECT_EQ(net::ERR_REQUEST_RANGE_NOT_SATISFIABLE, request->status().error()); | 421 EXPECT_EQ(net::ERR_REQUEST_RANGE_NOT_SATISFIABLE, request->status().error()); |
429 } | 422 } |
430 | 423 |
431 } // namespace drive | 424 } // namespace chromeos |
OLD | NEW |