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 <set> | 5 #include <set> |
6 #include <string> | 6 #include <string> |
7 | 7 |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/files/scoped_temp_dir.h" | 9 #include "base/files/scoped_temp_dir.h" |
10 #include "base/format_macros.h" | 10 #include "base/format_macros.h" |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 void TearDown() { | 128 void TearDown() { |
129 isolated_context()->RemoveReference(filesystem_id_); | 129 isolated_context()->RemoveReference(filesystem_id_); |
130 file_system_context_ = NULL; | 130 file_system_context_ = NULL; |
131 } | 131 } |
132 | 132 |
133 protected: | 133 protected: |
134 FileSystemContext* file_system_context() { | 134 FileSystemContext* file_system_context() { |
135 return file_system_context_.get(); | 135 return file_system_context_.get(); |
136 } | 136 } |
137 | 137 |
| 138 FileSystemURL CreateURL(const FilePath::CharType* test_case_path) { |
| 139 return file_system_context_->CreateCrackedFileSystemURL( |
| 140 origin(), |
| 141 fileapi::kFileSystemTypeIsolated, |
| 142 GetVirtualPath(test_case_path)); |
| 143 } |
| 144 |
138 IsolatedContext* isolated_context() { | 145 IsolatedContext* isolated_context() { |
139 return IsolatedContext::GetInstance(); | 146 return IsolatedContext::GetInstance(); |
140 } | 147 } |
141 | 148 |
142 FilePath root_path() { | 149 FilePath root_path() { |
143 return data_dir_.path().Append(FPL("Media Directory")); | 150 return data_dir_.path().Append(FPL("Media Directory")); |
144 } | 151 } |
145 | 152 |
| 153 FilePath GetVirtualPath(const FilePath::CharType* test_case_path) { |
| 154 return FilePath::FromUTF8Unsafe(filesystem_id_). |
| 155 Append(FPL("Media Directory")). |
| 156 Append(FilePath(test_case_path)); |
| 157 } |
| 158 |
146 FileSystemFileUtil* file_util() { | 159 FileSystemFileUtil* file_util() { |
147 return file_util_; | 160 return file_util_; |
148 } | 161 } |
149 | 162 |
150 GURL origin() { | 163 GURL origin() { |
151 return GURL("http://example.com"); | 164 return GURL("http://example.com"); |
152 } | 165 } |
153 | 166 |
154 fileapi::FileSystemType type() { | 167 fileapi::FileSystemType type() { |
155 return kFileSystemTypeNativeMedia; | 168 return kFileSystemTypeNativeMedia; |
(...skipping 14 matching lines...) Expand all Loading... |
170 | 183 |
171 DISALLOW_COPY_AND_ASSIGN(NativeMediaFileUtilTest); | 184 DISALLOW_COPY_AND_ASSIGN(NativeMediaFileUtilTest); |
172 }; | 185 }; |
173 | 186 |
174 TEST_F(NativeMediaFileUtilTest, DirectoryExistsAndFileExistsFiltering) { | 187 TEST_F(NativeMediaFileUtilTest, DirectoryExistsAndFileExistsFiltering) { |
175 PopulateDirectoryWithTestCases(root_path(), | 188 PopulateDirectoryWithTestCases(root_path(), |
176 kFilteringTestCases, | 189 kFilteringTestCases, |
177 arraysize(kFilteringTestCases)); | 190 arraysize(kFilteringTestCases)); |
178 | 191 |
179 for (size_t i = 0; i < arraysize(kFilteringTestCases); ++i) { | 192 for (size_t i = 0; i < arraysize(kFilteringTestCases); ++i) { |
180 FilePath path = root_path().Append(kFilteringTestCases[i].path); | 193 FileSystemURL url = CreateURL(kFilteringTestCases[i].path); |
181 FileSystemURL url(origin(), type(), path); | |
182 FileSystemOperation* operation = NewOperation(url); | 194 FileSystemOperation* operation = NewOperation(url); |
183 | 195 |
184 base::PlatformFileError expectation = | 196 base::PlatformFileError expectation = |
185 kFilteringTestCases[i].visible ? | 197 kFilteringTestCases[i].visible ? |
186 base::PLATFORM_FILE_OK : | 198 base::PLATFORM_FILE_OK : |
187 base::PLATFORM_FILE_ERROR_NOT_FOUND; | 199 base::PLATFORM_FILE_ERROR_NOT_FOUND; |
188 | 200 |
189 std::string test_name = | 201 std::string test_name = |
190 base::StringPrintf("DirectoryExistsAndFileExistsFiltering %" PRIuS, i); | 202 base::StringPrintf("DirectoryExistsAndFileExistsFiltering %" PRIuS, i); |
191 if (kFilteringTestCases[i].is_directory) { | 203 if (kFilteringTestCases[i].is_directory) { |
192 operation->DirectoryExists( | 204 operation->DirectoryExists( |
193 url, base::Bind(&ExpectEqHelper, test_name, expectation)); | 205 url, base::Bind(&ExpectEqHelper, test_name, expectation)); |
194 } else { | 206 } else { |
195 operation->FileExists( | 207 operation->FileExists( |
196 url, base::Bind(&ExpectEqHelper, test_name, expectation)); | 208 url, base::Bind(&ExpectEqHelper, test_name, expectation)); |
197 } | 209 } |
198 MessageLoop::current()->RunUntilIdle(); | 210 MessageLoop::current()->RunUntilIdle(); |
199 } | 211 } |
200 } | 212 } |
201 | 213 |
202 TEST_F(NativeMediaFileUtilTest, ReadDirectoryFiltering) { | 214 TEST_F(NativeMediaFileUtilTest, ReadDirectoryFiltering) { |
203 PopulateDirectoryWithTestCases(root_path(), | 215 PopulateDirectoryWithTestCases(root_path(), |
204 kFilteringTestCases, | 216 kFilteringTestCases, |
205 arraysize(kFilteringTestCases)); | 217 arraysize(kFilteringTestCases)); |
206 | 218 |
207 std::set<FilePath::StringType> content; | 219 std::set<FilePath::StringType> content; |
208 FileSystemURL url(origin(), type(), root_path()); | 220 FileSystemURL url = CreateURL(FPL("")); |
209 bool completed = false; | 221 bool completed = false; |
210 NewOperation(url)->ReadDirectory( | 222 NewOperation(url)->ReadDirectory( |
211 url, base::Bind(&DidReadDirectory, &content, &completed)); | 223 url, base::Bind(&DidReadDirectory, &content, &completed)); |
212 MessageLoop::current()->RunUntilIdle(); | 224 MessageLoop::current()->RunUntilIdle(); |
213 EXPECT_TRUE(completed); | 225 EXPECT_TRUE(completed); |
214 EXPECT_EQ(5u, content.size()); | 226 EXPECT_EQ(5u, content.size()); |
215 | 227 |
216 for (size_t i = 0; i < arraysize(kFilteringTestCases); ++i) { | 228 for (size_t i = 0; i < arraysize(kFilteringTestCases); ++i) { |
217 FilePath::StringType name = | 229 FilePath::StringType name = |
218 FilePath(kFilteringTestCases[i].path).BaseName().value(); | 230 FilePath(kFilteringTestCases[i].path).BaseName().value(); |
219 std::set<FilePath::StringType>::const_iterator found = content.find(name); | 231 std::set<FilePath::StringType>::const_iterator found = content.find(name); |
220 EXPECT_EQ(kFilteringTestCases[i].visible, found != content.end()); | 232 EXPECT_EQ(kFilteringTestCases[i].visible, found != content.end()); |
221 } | 233 } |
222 } | 234 } |
223 | 235 |
224 TEST_F(NativeMediaFileUtilTest, CreateFileAndCreateDirectoryFiltering) { | 236 TEST_F(NativeMediaFileUtilTest, CreateFileAndCreateDirectoryFiltering) { |
225 // Run the loop twice. The second loop attempts to create files that are | 237 // Run the loop twice. The second loop attempts to create files that are |
226 // pre-existing. Though the result should be the same. | 238 // pre-existing. Though the result should be the same. |
227 for (int loop_count = 0; loop_count < 2; ++loop_count) { | 239 for (int loop_count = 0; loop_count < 2; ++loop_count) { |
228 for (size_t i = 0; i < arraysize(kFilteringTestCases); ++i) { | 240 for (size_t i = 0; i < arraysize(kFilteringTestCases); ++i) { |
229 FileSystemURL root_url(origin(), type(), root_path()); | 241 FileSystemURL root_url = CreateURL(FPL("")); |
230 FileSystemOperation* operation = NewOperation(root_url); | 242 FileSystemOperation* operation = NewOperation(root_url); |
231 | 243 |
232 FilePath path = root_path().Append(kFilteringTestCases[i].path); | 244 FileSystemURL url = CreateURL(kFilteringTestCases[i].path); |
233 FileSystemURL url(origin(), type(), path); | |
234 | 245 |
235 std::string test_name = base::StringPrintf( | 246 std::string test_name = base::StringPrintf( |
236 "CreateFileAndCreateDirectoryFiltering run %d, test %" PRIuS, | 247 "CreateFileAndCreateDirectoryFiltering run %d, test %" PRIuS, |
237 loop_count, i); | 248 loop_count, i); |
238 base::PlatformFileError expectation = | 249 base::PlatformFileError expectation = |
239 kFilteringTestCases[i].visible ? | 250 kFilteringTestCases[i].visible ? |
240 base::PLATFORM_FILE_OK : | 251 base::PLATFORM_FILE_OK : |
241 base::PLATFORM_FILE_ERROR_SECURITY; | 252 base::PLATFORM_FILE_ERROR_SECURITY; |
242 if (kFilteringTestCases[i].is_directory) { | 253 if (kFilteringTestCases[i].is_directory) { |
243 operation->CreateDirectory( | 254 operation->CreateDirectory( |
244 url, false, false, | 255 url, false, false, |
245 base::Bind(&ExpectEqHelper, test_name, expectation)); | 256 base::Bind(&ExpectEqHelper, test_name, expectation)); |
246 } else { | 257 } else { |
247 operation->CreateFile( | 258 operation->CreateFile( |
248 url, false, base::Bind(&ExpectEqHelper, test_name, expectation)); | 259 url, false, base::Bind(&ExpectEqHelper, test_name, expectation)); |
249 } | 260 } |
250 MessageLoop::current()->RunUntilIdle(); | 261 MessageLoop::current()->RunUntilIdle(); |
251 } | 262 } |
252 } | 263 } |
253 } | 264 } |
254 | 265 |
255 TEST_F(NativeMediaFileUtilTest, CopySourceFiltering) { | 266 TEST_F(NativeMediaFileUtilTest, CopySourceFiltering) { |
256 FilePath dest_path = root_path().AppendASCII("dest"); | 267 FilePath dest_path = root_path().AppendASCII("dest"); |
257 FileSystemURL dest_url(origin(), type(), dest_path); | 268 FileSystemURL dest_url = CreateURL(FPL("dest")); |
258 | 269 |
259 // Run the loop twice. The first run has no source files. The second run does. | 270 // Run the loop twice. The first run has no source files. The second run does. |
260 for (int loop_count = 0; loop_count < 2; ++loop_count) { | 271 for (int loop_count = 0; loop_count < 2; ++loop_count) { |
261 if (loop_count == 1) { | 272 if (loop_count == 1) { |
262 PopulateDirectoryWithTestCases(root_path(), | 273 PopulateDirectoryWithTestCases(root_path(), |
263 kFilteringTestCases, | 274 kFilteringTestCases, |
264 arraysize(kFilteringTestCases)); | 275 arraysize(kFilteringTestCases)); |
265 } | 276 } |
266 for (size_t i = 0; i < arraysize(kFilteringTestCases); ++i) { | 277 for (size_t i = 0; i < arraysize(kFilteringTestCases); ++i) { |
267 // Always start with an empty destination directory. | 278 // Always start with an empty destination directory. |
268 // Copying to a non-empty destination directory is an invalid operation. | 279 // Copying to a non-empty destination directory is an invalid operation. |
269 ASSERT_TRUE(file_util::Delete(dest_path, true)); | 280 ASSERT_TRUE(file_util::Delete(dest_path, true)); |
270 ASSERT_TRUE(file_util::CreateDirectory(dest_path)); | 281 ASSERT_TRUE(file_util::CreateDirectory(dest_path)); |
271 | 282 |
272 FileSystemURL root_url(origin(), type(), root_path()); | 283 FileSystemURL root_url = CreateURL(FPL("")); |
273 FileSystemOperation* operation = NewOperation(root_url); | 284 FileSystemOperation* operation = NewOperation(root_url); |
274 | 285 |
275 FilePath path = root_path().Append(kFilteringTestCases[i].path); | 286 FileSystemURL url = CreateURL(kFilteringTestCases[i].path); |
276 FileSystemURL url(origin(), type(), path); | |
277 | 287 |
278 std::string test_name = base::StringPrintf( | 288 std::string test_name = base::StringPrintf( |
279 "CopySourceFiltering run %d test %" PRIuS, loop_count, i); | 289 "CopySourceFiltering run %d test %" PRIuS, loop_count, i); |
280 base::PlatformFileError expectation = base::PLATFORM_FILE_OK; | 290 base::PlatformFileError expectation = base::PLATFORM_FILE_OK; |
281 if (loop_count == 0 || !kFilteringTestCases[i].visible) { | 291 if (loop_count == 0 || !kFilteringTestCases[i].visible) { |
282 // If the source does not exist or is not visible. | 292 // If the source does not exist or is not visible. |
283 expectation = base::PLATFORM_FILE_ERROR_NOT_FOUND; | 293 expectation = base::PLATFORM_FILE_ERROR_NOT_FOUND; |
284 } else if (!kFilteringTestCases[i].is_directory) { | 294 } else if (!kFilteringTestCases[i].is_directory) { |
285 // Cannot copy a visible file to a directory. | 295 // Cannot copy a visible file to a directory. |
286 expectation = base::PLATFORM_FILE_ERROR_INVALID_OPERATION; | 296 expectation = base::PLATFORM_FILE_ERROR_INVALID_OPERATION; |
(...skipping 14 matching lines...) Expand all Loading... |
301 // directories and create new ones that should pre-exist. | 311 // directories and create new ones that should pre-exist. |
302 ASSERT_TRUE(file_util::Delete(root_path(), true)); | 312 ASSERT_TRUE(file_util::Delete(root_path(), true)); |
303 ASSERT_TRUE(file_util::CreateDirectory(root_path())); | 313 ASSERT_TRUE(file_util::CreateDirectory(root_path())); |
304 PopulateDirectoryWithTestCases(root_path(), | 314 PopulateDirectoryWithTestCases(root_path(), |
305 kFilteringTestCases, | 315 kFilteringTestCases, |
306 arraysize(kFilteringTestCases)); | 316 arraysize(kFilteringTestCases)); |
307 } | 317 } |
308 | 318 |
309 // Always create a dummy source data file. | 319 // Always create a dummy source data file. |
310 FilePath src_path = root_path().AppendASCII("foo.jpg"); | 320 FilePath src_path = root_path().AppendASCII("foo.jpg"); |
311 FileSystemURL src_url(origin(), type(), src_path); | 321 FileSystemURL src_url = CreateURL(FPL("foo.jpg")); |
312 static const char kDummyData[] = "dummy"; | 322 static const char kDummyData[] = "dummy"; |
313 ASSERT_TRUE(file_util::WriteFile(src_path, kDummyData, strlen(kDummyData))); | 323 ASSERT_TRUE(file_util::WriteFile(src_path, kDummyData, strlen(kDummyData))); |
314 | 324 |
315 for (size_t i = 0; i < arraysize(kFilteringTestCases); ++i) { | 325 for (size_t i = 0; i < arraysize(kFilteringTestCases); ++i) { |
316 FileSystemURL root_url(origin(), type(), root_path()); | 326 FileSystemURL root_url = CreateURL(FPL("")); |
317 FileSystemOperation* operation = NewOperation(root_url); | 327 FileSystemOperation* operation = NewOperation(root_url); |
318 | 328 |
319 FilePath path = root_path().Append(kFilteringTestCases[i].path); | 329 FileSystemURL url = CreateURL(kFilteringTestCases[i].path); |
320 FileSystemURL url(origin(), type(), path); | |
321 | 330 |
322 std::string test_name = base::StringPrintf( | 331 std::string test_name = base::StringPrintf( |
323 "CopyDestFiltering run %d test %" PRIuS, loop_count, i); | 332 "CopyDestFiltering run %d test %" PRIuS, loop_count, i); |
324 base::PlatformFileError expectation; | 333 base::PlatformFileError expectation; |
325 if (loop_count == 0) { | 334 if (loop_count == 0) { |
326 // These directories do not exist in this case, so Copy() will not | 335 // These directories do not exist in this case, so Copy() will not |
327 // treat them as directories. Thus invalidating these test cases. | 336 // treat them as directories. Thus invalidating these test cases. |
328 if (kFilteringTestCases[i].is_directory) | 337 if (kFilteringTestCases[i].is_directory) |
329 continue; | 338 continue; |
330 // If the destination path does not exist and is not visible, then | 339 // If the destination path does not exist and is not visible, then |
(...skipping 18 matching lines...) Expand all Loading... |
349 } | 358 } |
350 operation->Copy( | 359 operation->Copy( |
351 src_url, url, base::Bind(&ExpectEqHelper, test_name, expectation)); | 360 src_url, url, base::Bind(&ExpectEqHelper, test_name, expectation)); |
352 MessageLoop::current()->RunUntilIdle(); | 361 MessageLoop::current()->RunUntilIdle(); |
353 } | 362 } |
354 } | 363 } |
355 } | 364 } |
356 | 365 |
357 TEST_F(NativeMediaFileUtilTest, MoveSourceFiltering) { | 366 TEST_F(NativeMediaFileUtilTest, MoveSourceFiltering) { |
358 FilePath dest_path = root_path().AppendASCII("dest"); | 367 FilePath dest_path = root_path().AppendASCII("dest"); |
359 FileSystemURL dest_url(origin(), type(), dest_path); | 368 FileSystemURL dest_url = CreateURL(FPL("dest")); |
360 | 369 |
361 // Run the loop twice. The first run has no source files. The second run does. | 370 // Run the loop twice. The first run has no source files. The second run does. |
362 for (int loop_count = 0; loop_count < 2; ++loop_count) { | 371 for (int loop_count = 0; loop_count < 2; ++loop_count) { |
363 if (loop_count == 1) { | 372 if (loop_count == 1) { |
364 PopulateDirectoryWithTestCases(root_path(), | 373 PopulateDirectoryWithTestCases(root_path(), |
365 kFilteringTestCases, | 374 kFilteringTestCases, |
366 arraysize(kFilteringTestCases)); | 375 arraysize(kFilteringTestCases)); |
367 } | 376 } |
368 for (size_t i = 0; i < arraysize(kFilteringTestCases); ++i) { | 377 for (size_t i = 0; i < arraysize(kFilteringTestCases); ++i) { |
369 // Always start with an empty destination directory. | 378 // Always start with an empty destination directory. |
370 // Moving to a non-empty destination directory is an invalid operation. | 379 // Moving to a non-empty destination directory is an invalid operation. |
371 ASSERT_TRUE(file_util::Delete(dest_path, true)); | 380 ASSERT_TRUE(file_util::Delete(dest_path, true)); |
372 ASSERT_TRUE(file_util::CreateDirectory(dest_path)); | 381 ASSERT_TRUE(file_util::CreateDirectory(dest_path)); |
373 | 382 |
374 FileSystemURL root_url(origin(), type(), root_path()); | 383 FileSystemURL root_url = CreateURL(FPL("")); |
375 FileSystemOperation* operation = NewOperation(root_url); | 384 FileSystemOperation* operation = NewOperation(root_url); |
376 | 385 |
377 FilePath path = root_path().Append(kFilteringTestCases[i].path); | 386 FileSystemURL url = CreateURL(kFilteringTestCases[i].path); |
378 FileSystemURL url(origin(), type(), path); | |
379 | 387 |
380 std::string test_name = base::StringPrintf( | 388 std::string test_name = base::StringPrintf( |
381 "MoveSourceFiltering run %d test %" PRIuS, loop_count, i); | 389 "MoveSourceFiltering run %d test %" PRIuS, loop_count, i); |
382 base::PlatformFileError expectation = base::PLATFORM_FILE_OK; | 390 base::PlatformFileError expectation = base::PLATFORM_FILE_OK; |
383 if (loop_count == 0 || !kFilteringTestCases[i].visible) { | 391 if (loop_count == 0 || !kFilteringTestCases[i].visible) { |
384 // If the source does not exist or is not visible. | 392 // If the source does not exist or is not visible. |
385 expectation = base::PLATFORM_FILE_ERROR_NOT_FOUND; | 393 expectation = base::PLATFORM_FILE_ERROR_NOT_FOUND; |
386 } else if (!kFilteringTestCases[i].is_directory) { | 394 } else if (!kFilteringTestCases[i].is_directory) { |
387 // Cannot move a visible file to a directory. | 395 // Cannot move a visible file to a directory. |
388 expectation = base::PLATFORM_FILE_ERROR_INVALID_OPERATION; | 396 expectation = base::PLATFORM_FILE_ERROR_INVALID_OPERATION; |
(...skipping 15 matching lines...) Expand all Loading... |
404 ASSERT_TRUE(file_util::Delete(root_path(), true)); | 412 ASSERT_TRUE(file_util::Delete(root_path(), true)); |
405 ASSERT_TRUE(file_util::CreateDirectory(root_path())); | 413 ASSERT_TRUE(file_util::CreateDirectory(root_path())); |
406 PopulateDirectoryWithTestCases(root_path(), | 414 PopulateDirectoryWithTestCases(root_path(), |
407 kFilteringTestCases, | 415 kFilteringTestCases, |
408 arraysize(kFilteringTestCases)); | 416 arraysize(kFilteringTestCases)); |
409 } | 417 } |
410 | 418 |
411 for (size_t i = 0; i < arraysize(kFilteringTestCases); ++i) { | 419 for (size_t i = 0; i < arraysize(kFilteringTestCases); ++i) { |
412 // Create the source file for every test case because it might get moved. | 420 // Create the source file for every test case because it might get moved. |
413 FilePath src_path = root_path().AppendASCII("foo.jpg"); | 421 FilePath src_path = root_path().AppendASCII("foo.jpg"); |
414 FileSystemURL src_url(origin(), type(), src_path); | 422 FileSystemURL src_url = CreateURL(FPL("foo.jpg")); |
415 static const char kDummyData[] = "dummy"; | 423 static const char kDummyData[] = "dummy"; |
416 ASSERT_TRUE( | 424 ASSERT_TRUE( |
417 file_util::WriteFile(src_path, kDummyData, strlen(kDummyData))); | 425 file_util::WriteFile(src_path, kDummyData, strlen(kDummyData))); |
418 | 426 |
419 FileSystemURL root_url(origin(), type(), root_path()); | 427 FileSystemURL root_url = CreateURL(FPL("")); |
420 FileSystemOperation* operation = NewOperation(root_url); | 428 FileSystemOperation* operation = NewOperation(root_url); |
421 | 429 |
422 FilePath path = root_path().Append(kFilteringTestCases[i].path); | 430 FileSystemURL url = CreateURL(kFilteringTestCases[i].path); |
423 FileSystemURL url(origin(), type(), path); | |
424 | 431 |
425 std::string test_name = base::StringPrintf( | 432 std::string test_name = base::StringPrintf( |
426 "MoveDestFiltering run %d test %" PRIuS, loop_count, i); | 433 "MoveDestFiltering run %d test %" PRIuS, loop_count, i); |
427 base::PlatformFileError expectation; | 434 base::PlatformFileError expectation; |
428 if (loop_count == 0) { | 435 if (loop_count == 0) { |
429 // These directories do not exist in this case, so Move() will not | 436 // These directories do not exist in this case, so Move() will not |
430 // treat them as directories. Thus invalidating these test cases. | 437 // treat them as directories. Thus invalidating these test cases. |
431 if (kFilteringTestCases[i].is_directory) | 438 if (kFilteringTestCases[i].is_directory) |
432 continue; | 439 continue; |
433 // If the destination path does not exist and is not visible, then | 440 // If the destination path does not exist and is not visible, then |
(...skipping 25 matching lines...) Expand all Loading... |
459 | 466 |
460 TEST_F(NativeMediaFileUtilTest, GetMetadataFiltering) { | 467 TEST_F(NativeMediaFileUtilTest, GetMetadataFiltering) { |
461 // Run the loop twice. The first run has no files. The second run does. | 468 // Run the loop twice. The first run has no files. The second run does. |
462 for (int loop_count = 0; loop_count < 2; ++loop_count) { | 469 for (int loop_count = 0; loop_count < 2; ++loop_count) { |
463 if (loop_count == 1) { | 470 if (loop_count == 1) { |
464 PopulateDirectoryWithTestCases(root_path(), | 471 PopulateDirectoryWithTestCases(root_path(), |
465 kFilteringTestCases, | 472 kFilteringTestCases, |
466 arraysize(kFilteringTestCases)); | 473 arraysize(kFilteringTestCases)); |
467 } | 474 } |
468 for (size_t i = 0; i < arraysize(kFilteringTestCases); ++i) { | 475 for (size_t i = 0; i < arraysize(kFilteringTestCases); ++i) { |
469 FileSystemURL root_url(origin(), type(), root_path()); | 476 FileSystemURL root_url = CreateURL(FPL("")); |
470 FileSystemOperation* operation = NewOperation(root_url); | 477 FileSystemOperation* operation = NewOperation(root_url); |
471 | 478 |
472 FilePath path = root_path().Append(kFilteringTestCases[i].path); | 479 FileSystemURL url = CreateURL(kFilteringTestCases[i].path); |
473 FileSystemURL url(origin(), type(), path); | |
474 | 480 |
475 std::string test_name = base::StringPrintf( | 481 std::string test_name = base::StringPrintf( |
476 "GetMetadataFiltering run %d test %" PRIuS, loop_count, i); | 482 "GetMetadataFiltering run %d test %" PRIuS, loop_count, i); |
477 base::PlatformFileError expectation = base::PLATFORM_FILE_OK; | 483 base::PlatformFileError expectation = base::PLATFORM_FILE_OK; |
478 if (loop_count == 0 || !kFilteringTestCases[i].visible) { | 484 if (loop_count == 0 || !kFilteringTestCases[i].visible) { |
479 // Cannot get metadata from files that do not exist or are not visible. | 485 // Cannot get metadata from files that do not exist or are not visible. |
480 expectation = base::PLATFORM_FILE_ERROR_NOT_FOUND; | 486 expectation = base::PLATFORM_FILE_ERROR_NOT_FOUND; |
481 } | 487 } |
482 operation->GetMetadata(url, | 488 operation->GetMetadata(url, |
483 base::Bind(&ExpectMetadataEqHelper, | 489 base::Bind(&ExpectMetadataEqHelper, |
484 test_name, | 490 test_name, |
485 expectation, | 491 expectation, |
486 kFilteringTestCases[i].is_directory)); | 492 kFilteringTestCases[i].is_directory)); |
487 MessageLoop::current()->RunUntilIdle(); | 493 MessageLoop::current()->RunUntilIdle(); |
488 } | 494 } |
489 } | 495 } |
490 } | 496 } |
491 | 497 |
492 TEST_F(NativeMediaFileUtilTest, RemoveFiltering) { | 498 TEST_F(NativeMediaFileUtilTest, RemoveFiltering) { |
493 // Run the loop twice. The first run has no files. The second run does. | 499 // Run the loop twice. The first run has no files. The second run does. |
494 for (int loop_count = 0; loop_count < 2; ++loop_count) { | 500 for (int loop_count = 0; loop_count < 2; ++loop_count) { |
495 if (loop_count == 1) { | 501 if (loop_count == 1) { |
496 PopulateDirectoryWithTestCases(root_path(), | 502 PopulateDirectoryWithTestCases(root_path(), |
497 kFilteringTestCases, | 503 kFilteringTestCases, |
498 arraysize(kFilteringTestCases)); | 504 arraysize(kFilteringTestCases)); |
499 } | 505 } |
500 for (size_t i = 0; i < arraysize(kFilteringTestCases); ++i) { | 506 for (size_t i = 0; i < arraysize(kFilteringTestCases); ++i) { |
501 FileSystemURL root_url(origin(), type(), root_path()); | 507 FileSystemURL root_url = CreateURL(FPL("")); |
502 FileSystemOperation* operation = NewOperation(root_url); | 508 FileSystemOperation* operation = NewOperation(root_url); |
503 | 509 |
504 FilePath path = root_path().Append(kFilteringTestCases[i].path); | 510 FileSystemURL url = CreateURL(kFilteringTestCases[i].path); |
505 FileSystemURL url(origin(), type(), path); | |
506 | 511 |
507 std::string test_name = base::StringPrintf( | 512 std::string test_name = base::StringPrintf( |
508 "RemoveFiltering run %d test %" PRIuS, loop_count, i); | 513 "RemoveFiltering run %d test %" PRIuS, loop_count, i); |
509 base::PlatformFileError expectation = base::PLATFORM_FILE_OK; | 514 base::PlatformFileError expectation = base::PLATFORM_FILE_OK; |
510 if (loop_count == 0 || !kFilteringTestCases[i].visible) { | 515 if (loop_count == 0 || !kFilteringTestCases[i].visible) { |
511 // Cannot remove files that do not exist or are not visible. | 516 // Cannot remove files that do not exist or are not visible. |
512 expectation = base::PLATFORM_FILE_ERROR_NOT_FOUND; | 517 expectation = base::PLATFORM_FILE_ERROR_NOT_FOUND; |
513 } | 518 } |
514 operation->Remove( | 519 operation->Remove( |
515 url, false, base::Bind(&ExpectEqHelper, test_name, expectation)); | 520 url, false, base::Bind(&ExpectEqHelper, test_name, expectation)); |
516 MessageLoop::current()->RunUntilIdle(); | 521 MessageLoop::current()->RunUntilIdle(); |
517 } | 522 } |
518 } | 523 } |
519 } | 524 } |
520 | 525 |
521 TEST_F(NativeMediaFileUtilTest, TruncateFiltering) { | 526 TEST_F(NativeMediaFileUtilTest, TruncateFiltering) { |
522 // Run the loop twice. The first run has no files. The second run does. | 527 // Run the loop twice. The first run has no files. The second run does. |
523 for (int loop_count = 0; loop_count < 2; ++loop_count) { | 528 for (int loop_count = 0; loop_count < 2; ++loop_count) { |
524 if (loop_count == 1) { | 529 if (loop_count == 1) { |
525 PopulateDirectoryWithTestCases(root_path(), | 530 PopulateDirectoryWithTestCases(root_path(), |
526 kFilteringTestCases, | 531 kFilteringTestCases, |
527 arraysize(kFilteringTestCases)); | 532 arraysize(kFilteringTestCases)); |
528 } | 533 } |
529 for (size_t i = 0; i < arraysize(kFilteringTestCases); ++i) { | 534 for (size_t i = 0; i < arraysize(kFilteringTestCases); ++i) { |
530 FileSystemURL root_url(origin(), type(), root_path()); | 535 FileSystemURL root_url = CreateURL(FPL("")); |
531 FileSystemOperation* operation = NewOperation(root_url); | 536 FileSystemOperation* operation = NewOperation(root_url); |
532 | 537 |
533 FilePath path = root_path().Append(kFilteringTestCases[i].path); | 538 FileSystemURL url = CreateURL(kFilteringTestCases[i].path); |
534 FileSystemURL url(origin(), type(), path); | |
535 | 539 |
536 std::string test_name = base::StringPrintf( | 540 std::string test_name = base::StringPrintf( |
537 "TruncateFiltering run %d test %" PRIuS, loop_count, i); | 541 "TruncateFiltering run %d test %" PRIuS, loop_count, i); |
538 base::PlatformFileError expectation = base::PLATFORM_FILE_OK; | 542 base::PlatformFileError expectation = base::PLATFORM_FILE_OK; |
539 if (loop_count == 0 || !kFilteringTestCases[i].visible) { | 543 if (loop_count == 0 || !kFilteringTestCases[i].visible) { |
540 // Cannot truncate files that do not exist or are not visible. | 544 // Cannot truncate files that do not exist or are not visible. |
541 expectation = base::PLATFORM_FILE_ERROR_NOT_FOUND; | 545 expectation = base::PLATFORM_FILE_ERROR_NOT_FOUND; |
542 } else if (kFilteringTestCases[i].is_directory) { | 546 } else if (kFilteringTestCases[i].is_directory) { |
543 // Cannot truncate directories. | 547 // Cannot truncate directories. |
544 expectation = base::PLATFORM_FILE_ERROR_ACCESS_DENIED; | 548 expectation = base::PLATFORM_FILE_ERROR_ACCESS_DENIED; |
545 } | 549 } |
546 operation->Truncate( | 550 operation->Truncate( |
547 url, 0, base::Bind(&ExpectEqHelper, test_name, expectation)); | 551 url, 0, base::Bind(&ExpectEqHelper, test_name, expectation)); |
548 MessageLoop::current()->RunUntilIdle(); | 552 MessageLoop::current()->RunUntilIdle(); |
549 } | 553 } |
550 } | 554 } |
551 } | 555 } |
552 | 556 |
553 TEST_F(NativeMediaFileUtilTest, TouchFileFiltering) { | 557 TEST_F(NativeMediaFileUtilTest, TouchFileFiltering) { |
554 base::Time time = base::Time::Now(); | 558 base::Time time = base::Time::Now(); |
555 | 559 |
556 // Run the loop twice. The first run has no files. The second run does. | 560 // Run the loop twice. The first run has no files. The second run does. |
557 for (int loop_count = 0; loop_count < 2; ++loop_count) { | 561 for (int loop_count = 0; loop_count < 2; ++loop_count) { |
558 if (loop_count == 1) { | 562 if (loop_count == 1) { |
559 PopulateDirectoryWithTestCases(root_path(), | 563 PopulateDirectoryWithTestCases(root_path(), |
560 kFilteringTestCases, | 564 kFilteringTestCases, |
561 arraysize(kFilteringTestCases)); | 565 arraysize(kFilteringTestCases)); |
562 } | 566 } |
563 for (size_t i = 0; i < arraysize(kFilteringTestCases); ++i) { | 567 for (size_t i = 0; i < arraysize(kFilteringTestCases); ++i) { |
564 FileSystemURL root_url(origin(), type(), root_path()); | 568 FileSystemURL root_url = CreateURL(FPL("")); |
565 FileSystemOperation* operation = NewOperation(root_url); | 569 FileSystemOperation* operation = NewOperation(root_url); |
566 | 570 |
567 FilePath path = root_path().Append(kFilteringTestCases[i].path); | 571 FileSystemURL url = CreateURL(kFilteringTestCases[i].path); |
568 FileSystemURL url(origin(), type(), path); | |
569 | 572 |
570 std::string test_name = base::StringPrintf( | 573 std::string test_name = base::StringPrintf( |
571 "TouchFileFiltering run %d test %" PRIuS, loop_count, i); | 574 "TouchFileFiltering run %d test %" PRIuS, loop_count, i); |
572 base::PlatformFileError expectation = base::PLATFORM_FILE_OK; | 575 base::PlatformFileError expectation = base::PLATFORM_FILE_OK; |
573 if (loop_count == 0 || !kFilteringTestCases[i].visible) { | 576 if (loop_count == 0 || !kFilteringTestCases[i].visible) { |
574 // Files do not exists. Touch fails. | 577 // Files do not exists. Touch fails. |
575 expectation = base::PLATFORM_FILE_ERROR_FAILED; | 578 expectation = base::PLATFORM_FILE_ERROR_FAILED; |
576 } | 579 } |
577 operation->TouchFile( | 580 operation->TouchFile( |
578 url, time, time, base::Bind(&ExpectEqHelper, test_name, expectation)); | 581 url, time, time, base::Bind(&ExpectEqHelper, test_name, expectation)); |
579 MessageLoop::current()->RunUntilIdle(); | 582 MessageLoop::current()->RunUntilIdle(); |
580 } | 583 } |
581 } | 584 } |
582 } | 585 } |
OLD | NEW |