| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "chrome/browser/chromeos/file_manager/file_tasks.h" | 5 #include "chrome/browser/chromeos/file_manager/file_tasks.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 554 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 565 // The basic logic is similar to a test case for FindDriveAppTasks above. | 565 // The basic logic is similar to a test case for FindDriveAppTasks above. |
| 566 TEST_F(FileManagerFileTasksComplexTest, FindFileBrowserHandlerTasks) { | 566 TEST_F(FileManagerFileTasksComplexTest, FindFileBrowserHandlerTasks) { |
| 567 // Copied from FindFileHandlerTasks test above. | 567 // Copied from FindFileHandlerTasks test above. |
| 568 const char kFooId[] = "hhgbjpmdppecanaaogonaigmmifgpaph"; | 568 const char kFooId[] = "hhgbjpmdppecanaaogonaigmmifgpaph"; |
| 569 const char kBarId[] = "odlhccgofgkadkkhcmhgnhgahonahoca"; | 569 const char kBarId[] = "odlhccgofgkadkkhcmhgnhgahonahoca"; |
| 570 const char kEphemeralId[] = "opoomfdlbjcbjinalcjdjfoiikdeaoel"; | 570 const char kEphemeralId[] = "opoomfdlbjcbjinalcjdjfoiikdeaoel"; |
| 571 | 571 |
| 572 // Foo.app can handle ".txt" and ".html". | 572 // Foo.app can handle ".txt" and ".html". |
| 573 // This one is an extension, and has "file_browser_handlers" | 573 // This one is an extension, and has "file_browser_handlers" |
| 574 extensions::ExtensionBuilder foo_app; | 574 extensions::ExtensionBuilder foo_app; |
| 575 foo_app.SetManifest(extensions::DictionaryBuilder() | 575 foo_app.SetManifest( |
| 576 .Set("name", "Foo") | 576 extensions::DictionaryBuilder() |
| 577 .Set("version", "1.0.0") | 577 .Set("name", "Foo") |
| 578 .Set("manifest_version", 2) | 578 .Set("version", "1.0.0") |
| 579 .Set("file_browser_handlers", | 579 .Set("manifest_version", 2) |
| 580 extensions::ListBuilder() | 580 .Set("permissions", |
| 581 .Append(extensions::DictionaryBuilder() | 581 extensions::ListBuilder().Append("fileBrowserHandler")) |
| 582 .Set("id", "open") | 582 .Set( |
| 583 .Set("default_title", "open") | 583 "file_browser_handlers", |
| 584 .Set("file_filters", | 584 extensions::ListBuilder().Append( |
| 585 extensions::ListBuilder() | 585 extensions::DictionaryBuilder() |
| 586 .Append("filesystem:*.txt") | 586 .Set("id", "open") |
| 587 .Append("filesystem:*.html"))))); | 587 .Set("default_title", "open") |
| 588 .Set("file_filters", extensions::ListBuilder() |
| 589 .Append("filesystem:*.txt") |
| 590 .Append("filesystem:*.html"))))); |
| 588 foo_app.SetID(kFooId); | 591 foo_app.SetID(kFooId); |
| 589 extension_service_->AddExtension(foo_app.Build().get()); | 592 extension_service_->AddExtension(foo_app.Build().get()); |
| 590 | 593 |
| 591 // Bar.app can only handle ".txt". | 594 // Bar.app can only handle ".txt". |
| 592 extensions::ExtensionBuilder bar_app; | 595 extensions::ExtensionBuilder bar_app; |
| 593 bar_app.SetManifest(extensions::DictionaryBuilder() | 596 bar_app.SetManifest( |
| 594 .Set("name", "Bar") | 597 extensions::DictionaryBuilder() |
| 595 .Set("version", "1.0.0") | 598 .Set("name", "Bar") |
| 596 .Set("manifest_version", 2) | 599 .Set("version", "1.0.0") |
| 597 .Set("file_browser_handlers", | 600 .Set("manifest_version", 2) |
| 598 extensions::ListBuilder() | 601 .Set("permissions", |
| 599 .Append(extensions::DictionaryBuilder() | 602 extensions::ListBuilder().Append("fileBrowserHandler")) |
| 600 .Set("id", "open") | 603 .Set("file_browser_handlers", |
| 601 .Set("default_title", "open") | 604 extensions::ListBuilder().Append( |
| 602 .Set("file_filters", | 605 extensions::DictionaryBuilder() |
| 603 extensions::ListBuilder() | 606 .Set("id", "open") |
| 604 .Append("filesystem:*.txt"))))); | 607 .Set("default_title", "open") |
| 608 .Set("file_filters", extensions::ListBuilder().Append( |
| 609 "filesystem:*.txt"))))); |
| 605 bar_app.SetID(kBarId); | 610 bar_app.SetID(kBarId); |
| 606 extension_service_->AddExtension(bar_app.Build().get()); | 611 extension_service_->AddExtension(bar_app.Build().get()); |
| 607 | 612 |
| 608 // Ephemeral.app is an ephemeral app that can handle ".txt". | 613 // Ephemeral.app is an ephemeral app that can handle ".txt". |
| 609 // It should not ever be found as ephemeral apps cannot be file browser | 614 // It should not ever be found as ephemeral apps cannot be file browser |
| 610 // handlers. | 615 // handlers. |
| 611 extensions::ExtensionBuilder ephemeral_app; | 616 extensions::ExtensionBuilder ephemeral_app; |
| 612 ephemeral_app.SetManifest( | 617 ephemeral_app.SetManifest( |
| 613 extensions::DictionaryBuilder() | 618 extensions::DictionaryBuilder() |
| 614 .Set("name", "Ephemeral") | 619 .Set("name", "Ephemeral") |
| 615 .Set("version", "1.0.0") | 620 .Set("version", "1.0.0") |
| 616 .Set("manifest_version", 2) | 621 .Set("manifest_version", 2) |
| 622 .Set("permissions", |
| 623 extensions::ListBuilder().Append("fileBrowserHandler")) |
| 617 .Set("file_browser_handlers", | 624 .Set("file_browser_handlers", |
| 618 extensions::ListBuilder().Append( | 625 extensions::ListBuilder().Append( |
| 619 extensions::DictionaryBuilder() | 626 extensions::DictionaryBuilder() |
| 620 .Set("id", "open") | 627 .Set("id", "open") |
| 621 .Set("default_title", "open") | 628 .Set("default_title", "open") |
| 622 .Set("file_filters", | 629 .Set("file_filters", extensions::ListBuilder().Append( |
| 623 extensions::ListBuilder().Append( | 630 "filesystem:*.txt"))))); |
| 624 "filesystem:*.txt"))))); | |
| 625 ephemeral_app.SetID(kEphemeralId); | 631 ephemeral_app.SetID(kEphemeralId); |
| 626 scoped_refptr<extensions::Extension> built_ephemeral_app( | 632 scoped_refptr<extensions::Extension> built_ephemeral_app( |
| 627 ephemeral_app.Build()); | 633 ephemeral_app.Build()); |
| 628 extension_service_->AddExtension(built_ephemeral_app.get()); | 634 extension_service_->AddExtension(built_ephemeral_app.get()); |
| 629 extensions::ExtensionPrefs* extension_prefs = | 635 extensions::ExtensionPrefs* extension_prefs = |
| 630 extensions::ExtensionPrefs::Get(&test_profile_); | 636 extensions::ExtensionPrefs::Get(&test_profile_); |
| 631 extension_prefs->OnExtensionInstalled(built_ephemeral_app.get(), | 637 extension_prefs->OnExtensionInstalled(built_ephemeral_app.get(), |
| 632 extensions::Extension::ENABLED, | 638 extensions::Extension::ENABLED, |
| 633 syncer::StringOrdinal(), | 639 syncer::StringOrdinal(), |
| 634 extensions::kInstallFlagIsEphemeral, | 640 extensions::kInstallFlagIsEphemeral, |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 697 .Set("title", "Text") | 703 .Set("title", "Text") |
| 698 .Set("types", | 704 .Set("types", |
| 699 extensions::ListBuilder() | 705 extensions::ListBuilder() |
| 700 .Append("text/plain"))))); | 706 .Append("text/plain"))))); |
| 701 foo_app.SetID(kFooId); | 707 foo_app.SetID(kFooId); |
| 702 extension_service_->AddExtension(foo_app.Build().get()); | 708 extension_service_->AddExtension(foo_app.Build().get()); |
| 703 | 709 |
| 704 // Bar.app can only handle ".txt". | 710 // Bar.app can only handle ".txt". |
| 705 // This is an extension (file browser handler). | 711 // This is an extension (file browser handler). |
| 706 extensions::ExtensionBuilder bar_app; | 712 extensions::ExtensionBuilder bar_app; |
| 707 bar_app.SetManifest(extensions::DictionaryBuilder() | 713 bar_app.SetManifest( |
| 708 .Set("name", "Bar") | 714 extensions::DictionaryBuilder() |
| 709 .Set("version", "1.0.0") | 715 .Set("name", "Bar") |
| 710 .Set("manifest_version", 2) | 716 .Set("version", "1.0.0") |
| 711 .Set("file_browser_handlers", | 717 .Set("manifest_version", 2) |
| 712 extensions::ListBuilder() | 718 .Set("permissions", |
| 713 .Append(extensions::DictionaryBuilder() | 719 extensions::ListBuilder().Append("fileBrowserHandler")) |
| 714 .Set("id", "open") | 720 .Set("file_browser_handlers", |
| 715 .Set("default_title", "open") | 721 extensions::ListBuilder().Append( |
| 716 .Set("file_filters", | 722 extensions::DictionaryBuilder() |
| 717 extensions::ListBuilder() | 723 .Set("id", "open") |
| 718 .Append("filesystem:*.txt"))))); | 724 .Set("default_title", "open") |
| 725 .Set("file_filters", extensions::ListBuilder().Append( |
| 726 "filesystem:*.txt"))))); |
| 719 bar_app.SetID(kBarId); | 727 bar_app.SetID(kBarId); |
| 720 extension_service_->AddExtension(bar_app.Build().get()); | 728 extension_service_->AddExtension(bar_app.Build().get()); |
| 721 | 729 |
| 722 // Baz.app can handle "text/plain". | 730 // Baz.app can handle "text/plain". |
| 723 // This is a Drive app. | 731 // This is a Drive app. |
| 724 scoped_ptr<google_apis::AppResource> baz_app(new google_apis::AppResource); | 732 scoped_ptr<google_apis::AppResource> baz_app(new google_apis::AppResource); |
| 725 baz_app->set_product_id("baz_app_id"); | 733 baz_app->set_product_id("baz_app_id"); |
| 726 baz_app->set_application_id(kBazId); | 734 baz_app->set_application_id(kBazId); |
| 727 baz_app->set_name("Baz"); | 735 baz_app->set_name("Baz"); |
| 728 baz_app->set_object_type("baz_object_type"); | 736 baz_app->set_object_type("baz_object_type"); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 786 ScopedVector<google_apis::AppResource> app_resources; | 794 ScopedVector<google_apis::AppResource> app_resources; |
| 787 app_resources.push_back(foo_app.release()); | 795 app_resources.push_back(foo_app.release()); |
| 788 google_apis::AppList app_list; | 796 google_apis::AppList app_list; |
| 789 app_list.set_items(app_resources.Pass()); | 797 app_list.set_items(app_resources.Pass()); |
| 790 drive::DriveAppRegistry drive_app_registry(NULL); | 798 drive::DriveAppRegistry drive_app_registry(NULL); |
| 791 drive_app_registry.UpdateFromAppList(app_list); | 799 drive_app_registry.UpdateFromAppList(app_list); |
| 792 | 800 |
| 793 // Bar.app can handle ".gdoc" files. | 801 // Bar.app can handle ".gdoc" files. |
| 794 // This is an extension (file browser handler). | 802 // This is an extension (file browser handler). |
| 795 extensions::ExtensionBuilder bar_app; | 803 extensions::ExtensionBuilder bar_app; |
| 796 bar_app.SetManifest(extensions::DictionaryBuilder() | 804 bar_app.SetManifest( |
| 797 .Set("name", "Bar") | 805 extensions::DictionaryBuilder() |
| 798 .Set("version", "1.0.0") | 806 .Set("name", "Bar") |
| 799 .Set("manifest_version", 2) | 807 .Set("version", "1.0.0") |
| 800 .Set("file_browser_handlers", | 808 .Set("manifest_version", 2) |
| 801 extensions::ListBuilder() | 809 .Set("permissions", |
| 802 .Append(extensions::DictionaryBuilder() | 810 extensions::ListBuilder().Append("fileBrowserHandler")) |
| 803 .Set("id", "open") | 811 .Set("file_browser_handlers", |
| 804 .Set("default_title", "open") | 812 extensions::ListBuilder().Append( |
| 805 .Set("file_filters", | 813 extensions::DictionaryBuilder() |
| 806 extensions::ListBuilder() | 814 .Set("id", "open") |
| 807 .Append("filesystem:*.gdoc"))))); | 815 .Set("default_title", "open") |
| 816 .Set("file_filters", extensions::ListBuilder().Append( |
| 817 "filesystem:*.gdoc"))))); |
| 808 bar_app.SetID(kBarId); | 818 bar_app.SetID(kBarId); |
| 809 extension_service_->AddExtension(bar_app.Build().get()); | 819 extension_service_->AddExtension(bar_app.Build().get()); |
| 810 | 820 |
| 811 // Files.app can handle ".gdoc" files. | 821 // Files.app can handle ".gdoc" files. |
| 812 // The ID "kFileManagerAppId" used here is precisely the one that identifies | 822 // The ID "kFileManagerAppId" used here is precisely the one that identifies |
| 813 // the Chrome OS Files.app application. | 823 // the Chrome OS Files.app application. |
| 814 extensions::ExtensionBuilder files_app; | 824 extensions::ExtensionBuilder files_app; |
| 815 files_app.SetManifest(extensions::DictionaryBuilder() | 825 files_app.SetManifest( |
| 816 .Set("name", "Files") | 826 extensions::DictionaryBuilder() |
| 817 .Set("version", "1.0.0") | 827 .Set("name", "Files") |
| 818 .Set("manifest_version", 2) | 828 .Set("version", "1.0.0") |
| 819 .Set("file_browser_handlers", | 829 .Set("manifest_version", 2) |
| 820 extensions::ListBuilder() | 830 .Set("permissions", |
| 821 .Append(extensions::DictionaryBuilder() | 831 extensions::ListBuilder().Append("fileBrowserHandler")) |
| 822 .Set("id", "open") | 832 .Set("file_browser_handlers", |
| 823 .Set("default_title", "open") | 833 extensions::ListBuilder().Append( |
| 824 .Set("file_filters", | 834 extensions::DictionaryBuilder() |
| 825 extensions::ListBuilder() | 835 .Set("id", "open") |
| 826 .Append("filesystem:*.gdoc"))))); | 836 .Set("default_title", "open") |
| 837 .Set("file_filters", extensions::ListBuilder().Append( |
| 838 "filesystem:*.gdoc"))))); |
| 827 files_app.SetID(kFileManagerAppId); | 839 files_app.SetID(kFileManagerAppId); |
| 828 extension_service_->AddExtension(files_app.Build().get()); | 840 extension_service_->AddExtension(files_app.Build().get()); |
| 829 | 841 |
| 830 // Find apps for a ".gdoc file". Only the built-in handler of Files.apps | 842 // Find apps for a ".gdoc file". Only the built-in handler of Files.apps |
| 831 // should be found. | 843 // should be found. |
| 832 PathAndMimeTypeSet path_mime_set; | 844 PathAndMimeTypeSet path_mime_set; |
| 833 std::vector<GURL> file_urls; | 845 std::vector<GURL> file_urls; |
| 834 path_mime_set.insert( | 846 path_mime_set.insert( |
| 835 std::make_pair( | 847 std::make_pair( |
| 836 drive::util::GetDriveMountPointPath(&test_profile_).AppendASCII( | 848 drive::util::GetDriveMountPointPath(&test_profile_).AppendASCII( |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 982 // treated as non-generic handler. | 994 // treated as non-generic handler. |
| 983 EXPECT_EQ("Baz", jpg_result[1].task_title()); | 995 EXPECT_EQ("Baz", jpg_result[1].task_title()); |
| 984 EXPECT_FALSE(jpg_result[1].is_generic_file_handler()); | 996 EXPECT_FALSE(jpg_result[1].is_generic_file_handler()); |
| 985 // Qux app provides a handler for all types. | 997 // Qux app provides a handler for all types. |
| 986 EXPECT_EQ("Qux", jpg_result[2].task_title()); | 998 EXPECT_EQ("Qux", jpg_result[2].task_title()); |
| 987 EXPECT_TRUE(jpg_result[2].is_generic_file_handler()); | 999 EXPECT_TRUE(jpg_result[2].is_generic_file_handler()); |
| 988 } | 1000 } |
| 989 | 1001 |
| 990 } // namespace file_tasks | 1002 } // namespace file_tasks |
| 991 } // namespace file_manager. | 1003 } // namespace file_manager. |
| OLD | NEW |