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/fileapi/file_system_url_request_job.h" | 5 #include "webkit/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_path.h" | 10 #include "base/file_path.h" |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 void TestRequestNoRun(const GURL& url) { | 131 void TestRequestNoRun(const GURL& url) { |
132 TestRequestHelper(url, NULL, false); | 132 TestRequestHelper(url, NULL, false); |
133 } | 133 } |
134 | 134 |
135 void CreateDirectory(const base::StringPiece& dir_name) { | 135 void CreateDirectory(const base::StringPiece& dir_name) { |
136 FileSystemFileUtil* file_util = file_system_context_-> | 136 FileSystemFileUtil* file_util = file_system_context_-> |
137 sandbox_provider()->GetFileUtil(kFileSystemTypeTemporary); | 137 sandbox_provider()->GetFileUtil(kFileSystemTypeTemporary); |
138 FileSystemURL url = file_system_context_->CreateCrackedFileSystemURL( | 138 FileSystemURL url = file_system_context_->CreateCrackedFileSystemURL( |
139 GURL("http://remote"), | 139 GURL("http://remote"), |
140 kFileSystemTypeTemporary, | 140 kFileSystemTypeTemporary, |
141 FilePath().AppendASCII(dir_name)); | 141 base::FilePath().AppendASCII(dir_name)); |
142 | 142 |
143 FileSystemOperationContext context(file_system_context_); | 143 FileSystemOperationContext context(file_system_context_); |
144 context.set_allowed_bytes_growth(1024); | 144 context.set_allowed_bytes_growth(1024); |
145 | 145 |
146 ASSERT_EQ(base::PLATFORM_FILE_OK, file_util->CreateDirectory( | 146 ASSERT_EQ(base::PLATFORM_FILE_OK, file_util->CreateDirectory( |
147 &context, | 147 &context, |
148 url, | 148 url, |
149 false /* exclusive */, | 149 false /* exclusive */, |
150 false /* recursive */)); | 150 false /* recursive */)); |
151 } | 151 } |
152 | 152 |
153 void WriteFile(const base::StringPiece& file_name, | 153 void WriteFile(const base::StringPiece& file_name, |
154 const char* buf, int buf_size) { | 154 const char* buf, int buf_size) { |
155 FileSystemFileUtil* file_util = file_system_context_-> | 155 FileSystemFileUtil* file_util = file_system_context_-> |
156 sandbox_provider()->GetFileUtil(kFileSystemTypeTemporary); | 156 sandbox_provider()->GetFileUtil(kFileSystemTypeTemporary); |
157 FileSystemURL url = file_system_context_->CreateCrackedFileSystemURL( | 157 FileSystemURL url = file_system_context_->CreateCrackedFileSystemURL( |
158 GURL("http://remote"), | 158 GURL("http://remote"), |
159 kFileSystemTypeTemporary, | 159 kFileSystemTypeTemporary, |
160 FilePath().AppendASCII(file_name)); | 160 base::FilePath().AppendASCII(file_name)); |
161 | 161 |
162 FileSystemOperationContext context(file_system_context_); | 162 FileSystemOperationContext context(file_system_context_); |
163 context.set_allowed_bytes_growth(1024); | 163 context.set_allowed_bytes_growth(1024); |
164 | 164 |
165 base::PlatformFile handle = base::kInvalidPlatformFileValue; | 165 base::PlatformFile handle = base::kInvalidPlatformFileValue; |
166 bool created = false; | 166 bool created = false; |
167 ASSERT_EQ(base::PLATFORM_FILE_OK, file_util->CreateOrOpen( | 167 ASSERT_EQ(base::PLATFORM_FILE_OK, file_util->CreateOrOpen( |
168 &context, | 168 &context, |
169 url, | 169 url, |
170 base::PLATFORM_FILE_CREATE | base::PLATFORM_FILE_WRITE, | 170 base::PLATFORM_FILE_CREATE | base::PLATFORM_FILE_WRITE, |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
346 // Run StartAsync() and only StartAsync(). | 346 // Run StartAsync() and only StartAsync(). |
347 MessageLoop::current()->DeleteSoon(FROM_HERE, request_.release()); | 347 MessageLoop::current()->DeleteSoon(FROM_HERE, request_.release()); |
348 MessageLoop::current()->RunUntilIdle(); | 348 MessageLoop::current()->RunUntilIdle(); |
349 // If we get here, success! we didn't crash! | 349 // If we get here, success! we didn't crash! |
350 } | 350 } |
351 | 351 |
352 TEST_F(FileSystemURLRequestJobTest, GetMimeType) { | 352 TEST_F(FileSystemURLRequestJobTest, GetMimeType) { |
353 const char kFilename[] = "hoge.html"; | 353 const char kFilename[] = "hoge.html"; |
354 | 354 |
355 std::string mime_type_direct; | 355 std::string mime_type_direct; |
356 FilePath::StringType extension = | 356 base::FilePath::StringType extension = |
357 FilePath().AppendASCII(kFilename).Extension(); | 357 base::FilePath().AppendASCII(kFilename).Extension(); |
358 if (!extension.empty()) | 358 if (!extension.empty()) |
359 extension = extension.substr(1); | 359 extension = extension.substr(1); |
360 EXPECT_TRUE(net::GetWellKnownMimeTypeFromExtension( | 360 EXPECT_TRUE(net::GetWellKnownMimeTypeFromExtension( |
361 extension, &mime_type_direct)); | 361 extension, &mime_type_direct)); |
362 | 362 |
363 TestRequest(CreateFileSystemURL(kFilename)); | 363 TestRequest(CreateFileSystemURL(kFilename)); |
364 | 364 |
365 std::string mime_type_from_job; | 365 std::string mime_type_from_job; |
366 request_->GetMimeType(&mime_type_from_job); | 366 request_->GetMimeType(&mime_type_from_job); |
367 EXPECT_EQ(mime_type_direct, mime_type_from_job); | 367 EXPECT_EQ(mime_type_direct, mime_type_from_job); |
368 } | 368 } |
369 | 369 |
370 } // namespace | 370 } // namespace |
371 } // namespace fileapi | 371 } // namespace fileapi |
OLD | NEW |