OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "webkit/browser/fileapi/file_system_url_request_job.h" | 5 #include "webkit/browser/fileapi/file_system_url_request_job.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 } | 55 } |
56 | 56 |
57 virtual void SetUp() OVERRIDE { | 57 virtual void SetUp() OVERRIDE { |
58 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 58 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
59 | 59 |
60 // We use the main thread so that we can get the root path synchronously. | 60 // We use the main thread so that we can get the root path synchronously. |
61 // TODO(adamk): Run this on the FILE thread we've created as well. | 61 // TODO(adamk): Run this on the FILE thread we've created as well. |
62 file_system_context_ = | 62 file_system_context_ = |
63 CreateFileSystemContextForTesting(NULL, temp_dir_.path()); | 63 CreateFileSystemContextForTesting(NULL, temp_dir_.path()); |
64 | 64 |
65 file_system_context_->sandbox_provider()->ValidateFileSystemRoot( | 65 file_system_context_->sandbox_provider()->OpenFileSystem( |
66 GURL("http://remote/"), kFileSystemTypeTemporary, true, // create | 66 GURL("http://remote/"), kFileSystemTypeTemporary, |
67 base::Bind(&FileSystemURLRequestJobTest::OnValidateFileSystem, | 67 OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT, |
| 68 base::Bind(&FileSystemURLRequestJobTest::OnOpenFileSystem, |
68 weak_factory_.GetWeakPtr())); | 69 weak_factory_.GetWeakPtr())); |
69 base::MessageLoop::current()->RunUntilIdle(); | 70 base::MessageLoop::current()->RunUntilIdle(); |
70 | 71 |
71 net::URLRequest::Deprecated::RegisterProtocolFactory( | 72 net::URLRequest::Deprecated::RegisterProtocolFactory( |
72 "filesystem", &FileSystemURLRequestJobFactory); | 73 "filesystem", &FileSystemURLRequestJobFactory); |
73 } | 74 } |
74 | 75 |
75 virtual void TearDown() OVERRIDE { | 76 virtual void TearDown() OVERRIDE { |
76 net::URLRequest::Deprecated::RegisterProtocolFactory("filesystem", NULL); | 77 net::URLRequest::Deprecated::RegisterProtocolFactory("filesystem", NULL); |
77 ClearUnusedJob(); | 78 ClearUnusedJob(); |
78 if (pending_job_) { | 79 if (pending_job_) { |
79 pending_job_->Kill(); | 80 pending_job_->Kill(); |
80 pending_job_ = NULL; | 81 pending_job_ = NULL; |
81 } | 82 } |
82 // FileReader posts a task to close the file in destructor. | 83 // FileReader posts a task to close the file in destructor. |
83 base::MessageLoop::current()->RunUntilIdle(); | 84 base::MessageLoop::current()->RunUntilIdle(); |
84 } | 85 } |
85 | 86 |
86 void OnValidateFileSystem(base::PlatformFileError result) { | 87 void OnOpenFileSystem(base::PlatformFileError result) { |
87 ASSERT_EQ(base::PLATFORM_FILE_OK, result); | 88 ASSERT_EQ(base::PLATFORM_FILE_OK, result); |
88 } | 89 } |
89 | 90 |
90 void TestRequestHelper(const GURL& url, | 91 void TestRequestHelper(const GURL& url, |
91 const net::HttpRequestHeaders* headers, | 92 const net::HttpRequestHeaders* headers, |
92 bool run_to_completion) { | 93 bool run_to_completion) { |
93 delegate_.reset(new net::TestDelegate()); | 94 delegate_.reset(new net::TestDelegate()); |
94 // Make delegate_ exit the MessageLoop when the request is done. | 95 // Make delegate_ exit the MessageLoop when the request is done. |
95 delegate_->set_quit_on_complete(true); | 96 delegate_->set_quit_on_complete(true); |
96 delegate_->set_quit_on_redirect(true); | 97 delegate_->set_quit_on_redirect(true); |
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
350 | 351 |
351 TestRequest(CreateFileSystemURL(kFilename)); | 352 TestRequest(CreateFileSystemURL(kFilename)); |
352 | 353 |
353 std::string mime_type_from_job; | 354 std::string mime_type_from_job; |
354 request_->GetMimeType(&mime_type_from_job); | 355 request_->GetMimeType(&mime_type_from_job); |
355 EXPECT_EQ(mime_type_direct, mime_type_from_job); | 356 EXPECT_EQ(mime_type_direct, mime_type_from_job); |
356 } | 357 } |
357 | 358 |
358 } // namespace | 359 } // namespace |
359 } // namespace fileapi | 360 } // namespace fileapi |
OLD | NEW |