OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 <string.h> | 5 #include <string.h> |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <string> | 8 #include <string> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
11 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
12 #include "base/memory/ptr_util.h" | 12 #include "base/memory/ptr_util.h" |
13 #include "base/run_loop.h" | 13 #include "base/run_loop.h" |
14 #include "chrome/browser/chromeos/arc/fileapi/arc_documents_provider_root.h" | 14 #include "chrome/browser/chromeos/arc/fileapi/arc_documents_provider_root.h" |
15 #include "chrome/browser/chromeos/arc/fileapi/arc_documents_provider_util.h" | 15 #include "chrome/browser/chromeos/arc/fileapi/arc_documents_provider_util.h" |
16 #include "components/arc/arc_bridge_service.h" | 16 #include "components/arc/arc_bridge_service.h" |
17 #include "components/arc/arc_service_manager.h" | 17 #include "components/arc/arc_service_manager.h" |
18 #include "components/arc/test/fake_file_system_instance.h" | 18 #include "components/arc/test/fake_file_system_instance.h" |
19 #include "content/public/test/test_browser_thread_bundle.h" | 19 #include "content/public/test/test_browser_thread_bundle.h" |
20 #include "storage/common/fileapi/directory_entry.h" | 20 #include "storage/common/fileapi/directory_entry.h" |
21 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
| 22 #include "url/gurl.h" |
22 | 23 |
23 using storage::DirectoryEntry; | 24 using storage::DirectoryEntry; |
24 using EntryList = storage::AsyncFileUtil::EntryList; | 25 using EntryList = storage::AsyncFileUtil::EntryList; |
25 | 26 |
26 namespace arc { | 27 namespace arc { |
27 | 28 |
28 namespace { | 29 namespace { |
29 | 30 |
30 struct DocumentSpec { | 31 struct DocumentSpec { |
31 const char* document_id; | 32 const char* document_id; |
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
308 EXPECT_FALSE(file_list[2].is_directory); | 309 EXPECT_FALSE(file_list[2].is_directory); |
309 EXPECT_EQ(FILE_PATH_LITERAL("dup.mp4"), file_list[3].name); | 310 EXPECT_EQ(FILE_PATH_LITERAL("dup.mp4"), file_list[3].name); |
310 EXPECT_FALSE(file_list[3].is_directory); | 311 EXPECT_FALSE(file_list[3].is_directory); |
311 EXPECT_FALSE(has_more); | 312 EXPECT_FALSE(has_more); |
312 run_loop->Quit(); | 313 run_loop->Quit(); |
313 }, | 314 }, |
314 &run_loop)); | 315 &run_loop)); |
315 run_loop.Run(); | 316 run_loop.Run(); |
316 } | 317 } |
317 | 318 |
| 319 TEST_F(ArcDocumentsProviderRootTest, ResolveToContentUrl) { |
| 320 base::RunLoop run_loop; |
| 321 root_->ResolveToContentUrl( |
| 322 base::FilePath(FILE_PATH_LITERAL("dir/photo.jpg")), |
| 323 base::Bind( |
| 324 [](base::RunLoop* run_loop, const GURL& url) { |
| 325 EXPECT_EQ(GURL("content://org.chromium.test/document/photo-id"), |
| 326 url); |
| 327 run_loop->Quit(); |
| 328 }, |
| 329 &run_loop)); |
| 330 run_loop.Run(); |
| 331 } |
| 332 |
| 333 TEST_F(ArcDocumentsProviderRootTest, ResolveToContentUrlRoot) { |
| 334 base::RunLoop run_loop; |
| 335 root_->ResolveToContentUrl( |
| 336 base::FilePath(FILE_PATH_LITERAL("")), |
| 337 base::Bind( |
| 338 [](base::RunLoop* run_loop, const GURL& url) { |
| 339 EXPECT_EQ(GURL("content://org.chromium.test/document/root-id"), |
| 340 url); |
| 341 run_loop->Quit(); |
| 342 }, |
| 343 &run_loop)); |
| 344 run_loop.Run(); |
| 345 } |
| 346 |
| 347 TEST_F(ArcDocumentsProviderRootTest, ResolveToContentUrlNoSuchFile) { |
| 348 base::RunLoop run_loop; |
| 349 root_->ResolveToContentUrl(base::FilePath(FILE_PATH_LITERAL("missing")), |
| 350 base::Bind( |
| 351 [](base::RunLoop* run_loop, const GURL& url) { |
| 352 EXPECT_EQ(GURL(), url); |
| 353 run_loop->Quit(); |
| 354 }, |
| 355 &run_loop)); |
| 356 run_loop.Run(); |
| 357 } |
| 358 |
| 359 TEST_F(ArcDocumentsProviderRootTest, ResolveToContentUrlDups) { |
| 360 base::RunLoop run_loop; |
| 361 // "dup 2.mp4" should map to the 3rd instance of "dup.mp4" regardless of the |
| 362 // order returned from FileSystemInstance. |
| 363 root_->ResolveToContentUrl( |
| 364 base::FilePath(FILE_PATH_LITERAL("dups/dup 2.mp4")), |
| 365 base::Bind( |
| 366 [](base::RunLoop* run_loop, const GURL& url) { |
| 367 EXPECT_EQ(GURL("content://org.chromium.test/document/dup3-id"), |
| 368 url); |
| 369 run_loop->Quit(); |
| 370 }, |
| 371 &run_loop)); |
| 372 run_loop.Run(); |
| 373 } |
| 374 |
318 } // namespace arc | 375 } // namespace arc |
OLD | NEW |