| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 // NOTE: These tests are run as part of "unit_tests" (in chrome/test/unit) | 5 // NOTE: These tests are run as part of "unit_tests" (in chrome/test/unit) |
| 6 // rather than as part of test_shell_tests because they rely on being able | 6 // rather than as part of test_shell_tests because they rely on being able |
| 7 // to instantiate a MessageLoop of type TYPE_IO. test_shell_tests uses | 7 // to instantiate a MessageLoop of type TYPE_IO. test_shell_tests uses |
| 8 // TYPE_UI, which URLRequest doesn't allow. | 8 // TYPE_UI, which URLRequest doesn't allow. |
| 9 // | 9 // |
| 10 | 10 |
| (...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 328 EXPECT_EQ(net::ERR_FILE_NOT_FOUND, request_->status().error()); | 328 EXPECT_EQ(net::ERR_FILE_NOT_FOUND, request_->status().error()); |
| 329 } | 329 } |
| 330 | 330 |
| 331 TEST_F(FileSystemURLRequestJobTest, NoSuchFile) { | 331 TEST_F(FileSystemURLRequestJobTest, NoSuchFile) { |
| 332 TestRequest(CreateFileSystemURL("somefile")); | 332 TestRequest(CreateFileSystemURL("somefile")); |
| 333 ASSERT_FALSE(request_->is_pending()); | 333 ASSERT_FALSE(request_->is_pending()); |
| 334 EXPECT_TRUE(delegate_->request_failed()); | 334 EXPECT_TRUE(delegate_->request_failed()); |
| 335 EXPECT_EQ(net::ERR_FILE_NOT_FOUND, request_->status().error()); | 335 EXPECT_EQ(net::ERR_FILE_NOT_FOUND, request_->status().error()); |
| 336 } | 336 } |
| 337 | 337 |
| 338 class QuitNowTask : public Task { | |
| 339 public: | |
| 340 virtual void Run() { | |
| 341 MessageLoop::current()->QuitNow(); | |
| 342 } | |
| 343 }; | |
| 344 | |
| 345 TEST_F(FileSystemURLRequestJobTest, Cancel) { | 338 TEST_F(FileSystemURLRequestJobTest, Cancel) { |
| 346 WriteFile("file1.dat", kTestFileData, arraysize(kTestFileData) - 1); | 339 WriteFile("file1.dat", kTestFileData, arraysize(kTestFileData) - 1); |
| 347 TestRequestNoRun(CreateFileSystemURL("file1.dat")); | 340 TestRequestNoRun(CreateFileSystemURL("file1.dat")); |
| 348 | 341 |
| 349 // Run StartAsync() and only StartAsync(). | 342 // Run StartAsync() and only StartAsync(). |
| 350 MessageLoop::current()->PostTask(FROM_HERE, new QuitNowTask); | 343 MessageLoop::current()->DeleteSoon(FROM_HERE, request_.release()); |
| 351 MessageLoop::current()->Run(); | |
| 352 | |
| 353 request_.reset(); | |
| 354 MessageLoop::current()->RunAllPending(); | 344 MessageLoop::current()->RunAllPending(); |
| 355 // If we get here, success! we didn't crash! | 345 // If we get here, success! we didn't crash! |
| 356 } | 346 } |
| 357 | 347 |
| 358 TEST_F(FileSystemURLRequestJobTest, GetMimeType) { | 348 TEST_F(FileSystemURLRequestJobTest, GetMimeType) { |
| 359 const char kFilename[] = "hoge.html"; | 349 const char kFilename[] = "hoge.html"; |
| 360 | 350 |
| 361 std::string mime_type_direct; | 351 std::string mime_type_direct; |
| 362 FilePath::StringType extension = | 352 FilePath::StringType extension = |
| 363 FilePath().AppendASCII(kFilename).Extension(); | 353 FilePath().AppendASCII(kFilename).Extension(); |
| 364 if (!extension.empty()) | 354 if (!extension.empty()) |
| 365 extension = extension.substr(1); | 355 extension = extension.substr(1); |
| 366 EXPECT_TRUE(net::GetWellKnownMimeTypeFromExtension( | 356 EXPECT_TRUE(net::GetWellKnownMimeTypeFromExtension( |
| 367 extension, &mime_type_direct)); | 357 extension, &mime_type_direct)); |
| 368 | 358 |
| 369 TestRequest(CreateFileSystemURL(kFilename)); | 359 TestRequest(CreateFileSystemURL(kFilename)); |
| 370 | 360 |
| 371 std::string mime_type_from_job; | 361 std::string mime_type_from_job; |
| 372 request_->GetMimeType(&mime_type_from_job); | 362 request_->GetMimeType(&mime_type_from_job); |
| 373 EXPECT_EQ(mime_type_direct, mime_type_from_job); | 363 EXPECT_EQ(mime_type_direct, mime_type_from_job); |
| 374 } | 364 } |
| 375 | 365 |
| 376 } // namespace (anonymous) | 366 } // namespace (anonymous) |
| 377 } // namespace fileapi | 367 } // namespace fileapi |
| OLD | NEW |