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

Side by Side Diff: chrome/browser/chromeos/fileapi/external_file_url_request_job_unittest.cc

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

Powered by Google App Engine
This is Rietveld 408576698