| 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 "base/bind.h" |
| 6 #include "base/command_line.h" |
| 7 #include "base/files/file_util.h" |
| 8 #include "base/files/scoped_temp_dir.h" |
| 5 #include "base/path_service.h" | 9 #include "base/path_service.h" |
| 10 #include "base/task_runner.h" |
| 6 #include "base/test/test_timeouts.h" | 11 #include "base/test/test_timeouts.h" |
| 12 #include "base/thread_task_runner_handle.h" |
| 7 #include "base/win/windows_version.h" | 13 #include "base/win/windows_version.h" |
| 8 #include "build/build_config.h" | 14 #include "build/build_config.h" |
| 9 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" | 15 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" |
| 10 #include "chrome/browser/extensions/extension_browsertest.h" | 16 #include "chrome/browser/extensions/extension_browsertest.h" |
| 11 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
| 12 #include "chrome/browser/ui/browser.h" | 18 #include "chrome/browser/ui/browser.h" |
| 13 #include "chrome/browser/ui/browser_navigator_params.h" | 19 #include "chrome/browser/ui/browser_navigator_params.h" |
| 14 #include "chrome/browser/ui/extensions/app_launch_params.h" | 20 #include "chrome/browser/ui/extensions/app_launch_params.h" |
| 15 #include "chrome/browser/ui/extensions/application_launch.h" | 21 #include "chrome/browser/ui/extensions/application_launch.h" |
| 16 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 22 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 17 #include "chrome/common/chrome_paths.h" | 23 #include "chrome/common/chrome_paths.h" |
| 24 #include "chrome/common/chrome_switches.h" |
| 18 #include "chrome/test/base/ui_test_utils.h" | 25 #include "chrome/test/base/ui_test_utils.h" |
| 19 #include "chrome/test/nacl/nacl_browsertest_util.h" | 26 #include "chrome/test/nacl/nacl_browsertest_util.h" |
| 20 #include "chrome/test/ppapi/ppapi_test.h" | 27 #include "chrome/test/ppapi/ppapi_test.h" |
| 21 #include "components/content_settings/core/browser/host_content_settings_map.h" | 28 #include "components/content_settings/core/browser/host_content_settings_map.h" |
| 22 #include "components/nacl/common/nacl_switches.h" | 29 #include "components/nacl/common/nacl_switches.h" |
| 23 #include "content/public/browser/web_contents.h" | 30 #include "content/public/browser/web_contents.h" |
| 24 #include "content/public/common/content_switches.h" | 31 #include "content/public/common/content_switches.h" |
| 25 #include "content/public/common/url_constants.h" | 32 #include "content/public/common/url_constants.h" |
| 26 #include "content/public/test/javascript_test_observer.h" | 33 #include "content/public/test/javascript_test_observer.h" |
| 27 #include "content/public/test/test_renderer_host.h" | 34 #include "content/public/test/test_renderer_host.h" |
| 28 #include "extensions/common/constants.h" | 35 #include "extensions/common/constants.h" |
| 29 #include "extensions/test/extension_test_message_listener.h" | 36 #include "extensions/test/extension_test_message_listener.h" |
| 30 #include "ppapi/shared_impl/test_utils.h" | 37 #include "ppapi/shared_impl/test_utils.h" |
| 38 #include "ui/shell_dialogs/select_file_dialog.h" |
| 39 #include "ui/shell_dialogs/select_file_dialog_factory.h" |
| 40 #include "ui/shell_dialogs/selected_file_info.h" |
| 31 | 41 |
| 32 using content::RenderViewHost; | 42 using content::RenderViewHost; |
| 33 | 43 |
| 34 // This macro finesses macro expansion to do what we want. | 44 // This macro finesses macro expansion to do what we want. |
| 35 #define STRIP_PREFIXES(test_name) ppapi::StripTestPrefixes(#test_name) | 45 #define STRIP_PREFIXES(test_name) ppapi::StripTestPrefixes(#test_name) |
| 36 // Turn the given token into a string. This allows us to use precompiler stuff | 46 // Turn the given token into a string. This allows us to use precompiler stuff |
| 37 // to turn names into DISABLED_Foo, but still pass a string to RunTest. | 47 // to turn names into DISABLED_Foo, but still pass a string to RunTest. |
| 38 #define STRINGIFY(test_name) #test_name | 48 #define STRINGIFY(test_name) #test_name |
| 39 #define LIST_TEST(test_name) STRINGIFY(test_name) "," | 49 #define LIST_TEST(test_name) STRINGIFY(test_name) "," |
| 40 | 50 |
| (...skipping 673 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 714 } | 724 } |
| 715 IN_PROC_BROWSER_TEST_F(PPAPINaClPNaClNonSfiTest, | 725 IN_PROC_BROWSER_TEST_F(PPAPINaClPNaClNonSfiTest, |
| 716 MAYBE_PNACL_NONSFI(FileRef1)) { | 726 MAYBE_PNACL_NONSFI(FileRef1)) { |
| 717 RUN_FILEREF_SUBTESTS_1; | 727 RUN_FILEREF_SUBTESTS_1; |
| 718 } | 728 } |
| 719 IN_PROC_BROWSER_TEST_F(PPAPINaClPNaClNonSfiTest, | 729 IN_PROC_BROWSER_TEST_F(PPAPINaClPNaClNonSfiTest, |
| 720 MAYBE_PNACL_NONSFI(FileRef2)) { | 730 MAYBE_PNACL_NONSFI(FileRef2)) { |
| 721 RUN_FILEREF_SUBTESTS_2; | 731 RUN_FILEREF_SUBTESTS_2; |
| 722 } | 732 } |
| 723 | 733 |
| 734 // FileChooser tests. |
| 735 namespace { |
| 736 |
| 737 class TestSelectFileDialogFactory final : public ui::SelectFileDialogFactory { |
| 738 public: |
| 739 using SelectedFileInfoList = std::vector<ui::SelectedFileInfo>; |
| 740 |
| 741 enum Mode { |
| 742 RESPOND_WITH_FILE_LIST, |
| 743 CANCEL, |
| 744 REPLACE_BASENAME, |
| 745 NOT_REACHED, |
| 746 }; |
| 747 |
| 748 TestSelectFileDialogFactory(Mode mode, |
| 749 const SelectedFileInfoList& selected_file_info) |
| 750 : selected_file_info_(selected_file_info), mode_(mode) { |
| 751 // Only safe because this class is 'final' |
| 752 ui::SelectFileDialog::SetFactory(this); |
| 753 } |
| 754 |
| 755 // SelectFileDialogFactory |
| 756 ui::SelectFileDialog* Create(ui::SelectFileDialog::Listener* listener, |
| 757 ui::SelectFilePolicy* policy) override { |
| 758 return new SelectFileDialog(listener, policy, selected_file_info_, mode_); |
| 759 } |
| 760 |
| 761 private: |
| 762 class SelectFileDialog : public ui::SelectFileDialog { |
| 763 public: |
| 764 SelectFileDialog(Listener* listener, |
| 765 ui::SelectFilePolicy* policy, |
| 766 const SelectedFileInfoList& selected_file_info, |
| 767 Mode mode) |
| 768 : ui::SelectFileDialog(listener, policy), |
| 769 selected_file_info_(selected_file_info), |
| 770 mode_(mode) {} |
| 771 |
| 772 protected: |
| 773 // ui::SelectFileDialog |
| 774 void SelectFileImpl(Type type, |
| 775 const base::string16& title, |
| 776 const base::FilePath& default_path, |
| 777 const FileTypeInfo* file_types, |
| 778 int file_type_index, |
| 779 const base::FilePath::StringType& default_extension, |
| 780 gfx::NativeWindow owning_window, |
| 781 void* params) override { |
| 782 switch (mode_) { |
| 783 case RESPOND_WITH_FILE_LIST: |
| 784 break; |
| 785 |
| 786 case CANCEL: |
| 787 EXPECT_EQ(0u, selected_file_info_.size()); |
| 788 break; |
| 789 |
| 790 case REPLACE_BASENAME: |
| 791 EXPECT_EQ(1u, selected_file_info_.size()); |
| 792 for (auto& selected_file : selected_file_info_) { |
| 793 selected_file = |
| 794 ui::SelectedFileInfo(selected_file.file_path.DirName().Append( |
| 795 default_path.BaseName()), |
| 796 selected_file.local_path.DirName().Append( |
| 797 default_path.BaseName())); |
| 798 } |
| 799 break; |
| 800 |
| 801 case NOT_REACHED: |
| 802 NOTREACHED(); |
| 803 break; |
| 804 } |
| 805 |
| 806 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 807 FROM_HERE, |
| 808 base::Bind(&SelectFileDialog::RespondToFileSelectionRequest, this, |
| 809 params)); |
| 810 } |
| 811 bool HasMultipleFileTypeChoicesImpl() override { return false; } |
| 812 |
| 813 // BaseShellDialog |
| 814 bool IsRunning(gfx::NativeWindow owning_window) const override { |
| 815 return false; |
| 816 } |
| 817 void ListenerDestroyed() override {} |
| 818 |
| 819 private: |
| 820 void RespondToFileSelectionRequest(void* params) { |
| 821 if (selected_file_info_.size() == 0) |
| 822 listener_->FileSelectionCanceled(params); |
| 823 else if (selected_file_info_.size() == 1) |
| 824 listener_->FileSelectedWithExtraInfo(selected_file_info_.front(), 0, |
| 825 params); |
| 826 else |
| 827 listener_->MultiFilesSelectedWithExtraInfo(selected_file_info_, params); |
| 828 } |
| 829 |
| 830 SelectedFileInfoList selected_file_info_; |
| 831 Mode mode_; |
| 832 }; |
| 833 |
| 834 std::vector<ui::SelectedFileInfo> selected_file_info_; |
| 835 Mode mode_; |
| 836 }; |
| 837 |
| 838 } // namespace |
| 839 |
| 840 IN_PROC_BROWSER_TEST_F(OutOfProcessPPAPITest, FileChooser_Open_Success) { |
| 841 const char kContents[] = "Hello from browser"; |
| 842 base::ScopedTempDir temp_dir; |
| 843 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 844 |
| 845 base::FilePath suggested_filename = temp_dir.path().AppendASCII("foo"); |
| 846 ASSERT_EQ( |
| 847 static_cast<int>(sizeof(kContents) - 1), |
| 848 base::WriteFile(suggested_filename, kContents, sizeof(kContents) - 1)); |
| 849 |
| 850 TestSelectFileDialogFactory::SelectedFileInfoList file_info_list; |
| 851 file_info_list.push_back( |
| 852 ui::SelectedFileInfo(suggested_filename, suggested_filename)); |
| 853 TestSelectFileDialogFactory test_dialog_factory( |
| 854 TestSelectFileDialogFactory::RESPOND_WITH_FILE_LIST, file_info_list); |
| 855 RunTest("FileChooser_OpenSimple"); |
| 856 } |
| 857 |
| 858 IN_PROC_BROWSER_TEST_F(OutOfProcessPPAPITest, FileChooser_Open_Cancel) { |
| 859 TestSelectFileDialogFactory test_dialog_factory( |
| 860 TestSelectFileDialogFactory::CANCEL, |
| 861 TestSelectFileDialogFactory::SelectedFileInfoList()); |
| 862 RunTest("FileChooser_OpenCancel"); |
| 863 } |
| 864 |
| 865 IN_PROC_BROWSER_TEST_F(OutOfProcessPPAPITest, FileChooser_SaveAs_Success) { |
| 866 base::ScopedTempDir temp_dir; |
| 867 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 868 base::FilePath suggested_filename = temp_dir.path().AppendASCII("foo"); |
| 869 |
| 870 TestSelectFileDialogFactory::SelectedFileInfoList file_info_list; |
| 871 file_info_list.push_back( |
| 872 ui::SelectedFileInfo(suggested_filename, suggested_filename)); |
| 873 TestSelectFileDialogFactory test_dialog_factory( |
| 874 TestSelectFileDialogFactory::RESPOND_WITH_FILE_LIST, file_info_list); |
| 875 |
| 876 RunTest("FileChooser_SaveAsSafeDefaultName"); |
| 877 ASSERT_TRUE(base::PathExists(suggested_filename)); |
| 878 } |
| 879 |
| 880 IN_PROC_BROWSER_TEST_F(OutOfProcessPPAPITest, |
| 881 FileChooser_SaveAs_SafeDefaultName) { |
| 882 base::ScopedTempDir temp_dir; |
| 883 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 884 base::FilePath suggested_filename = temp_dir.path().AppendASCII("foo"); |
| 885 |
| 886 TestSelectFileDialogFactory::SelectedFileInfoList file_info_list; |
| 887 file_info_list.push_back( |
| 888 ui::SelectedFileInfo(suggested_filename, suggested_filename)); |
| 889 TestSelectFileDialogFactory test_dialog_factory( |
| 890 TestSelectFileDialogFactory::REPLACE_BASENAME, file_info_list); |
| 891 |
| 892 RunTest("FileChooser_SaveAsSafeDefaultName"); |
| 893 base::FilePath actual_filename = temp_dir.path().AppendASCII("innocuous.txt"); |
| 894 |
| 895 ASSERT_TRUE(base::PathExists(actual_filename)); |
| 896 std::string file_contents; |
| 897 ASSERT_TRUE(base::ReadFileToString(actual_filename, &file_contents, 100)); |
| 898 EXPECT_EQ("Hello from PPAPI", file_contents); |
| 899 } |
| 900 |
| 901 IN_PROC_BROWSER_TEST_F(OutOfProcessPPAPITest, |
| 902 FileChooser_SaveAs_UnsafeDefaultName) { |
| 903 base::ScopedTempDir temp_dir; |
| 904 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 905 base::FilePath suggested_filename = temp_dir.path().AppendASCII("foo"); |
| 906 |
| 907 TestSelectFileDialogFactory::SelectedFileInfoList file_info_list; |
| 908 file_info_list.push_back( |
| 909 ui::SelectedFileInfo(suggested_filename, suggested_filename)); |
| 910 TestSelectFileDialogFactory test_dialog_factory( |
| 911 TestSelectFileDialogFactory::REPLACE_BASENAME, file_info_list); |
| 912 |
| 913 RunTest("FileChooser_SaveAsUnsafeDefaultName"); |
| 914 base::FilePath actual_filename = temp_dir.path().AppendASCII("unsafe.txt-"); |
| 915 |
| 916 ASSERT_TRUE(base::PathExists(actual_filename)); |
| 917 std::string file_contents; |
| 918 ASSERT_TRUE(base::ReadFileToString(actual_filename, &file_contents, 100)); |
| 919 EXPECT_EQ("Hello from PPAPI", file_contents); |
| 920 } |
| 921 |
| 922 #if defined(FULL_SAFE_BROWSING) |
| 923 // These two tests only make sense when SafeBrowsing is enabled. They verify |
| 924 // that files written via the FileChooser_Trusted API are properly threaded |
| 925 // through Safe Browsing. |
| 926 |
| 927 IN_PROC_BROWSER_TEST_F(OutOfProcessPPAPITest, |
| 928 FileChooser_SaveAs_DangerousExecutable_Allowed) { |
| 929 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 930 switches::kAllowUncheckedDangerousDownloads); |
| 931 base::ScopedTempDir temp_dir; |
| 932 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 933 base::FilePath suggested_filename = temp_dir.path().AppendASCII("foo"); |
| 934 |
| 935 TestSelectFileDialogFactory::SelectedFileInfoList file_info_list; |
| 936 file_info_list.push_back( |
| 937 ui::SelectedFileInfo(suggested_filename, suggested_filename)); |
| 938 TestSelectFileDialogFactory test_dialog_factory( |
| 939 TestSelectFileDialogFactory::REPLACE_BASENAME, file_info_list); |
| 940 |
| 941 RunTest("FileChooser_SaveAsDangerousExecutableAllowed"); |
| 942 base::FilePath actual_filename = temp_dir.path().AppendASCII("dangerous.exe"); |
| 943 |
| 944 ASSERT_TRUE(base::PathExists(actual_filename)); |
| 945 std::string file_contents; |
| 946 ASSERT_TRUE(base::ReadFileToString(actual_filename, &file_contents, 100)); |
| 947 EXPECT_EQ("Hello from PPAPI", file_contents); |
| 948 } |
| 949 |
| 950 IN_PROC_BROWSER_TEST_F(OutOfProcessPPAPITest, |
| 951 FileChooser_SaveAs_DangerousExecutable_Disallowed) { |
| 952 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 953 switches::kDisallowUncheckedDangerousDownloads); |
| 954 TestSelectFileDialogFactory test_dialog_factory( |
| 955 TestSelectFileDialogFactory::NOT_REACHED, |
| 956 TestSelectFileDialogFactory::SelectedFileInfoList()); |
| 957 RunTest("FileChooser_SaveAsDangerousExecutableDisallowed"); |
| 958 } |
| 959 |
| 960 #endif // FULL_SAFE_BROWSING |
| 961 |
| 962 // FileSystem tests. |
| 963 |
| 724 TEST_PPAPI_OUT_OF_PROCESS_VIA_HTTP(FileSystem) | 964 TEST_PPAPI_OUT_OF_PROCESS_VIA_HTTP(FileSystem) |
| 725 | 965 |
| 726 // PPAPINaClTest.FileSystem times out consistently on Windows and Mac. | 966 // PPAPINaClTest.FileSystem times out consistently on Windows and Mac. |
| 727 // http://crbug.com/130372 | 967 // http://crbug.com/130372 |
| 728 #if defined(OS_MACOSX) || defined(OS_WIN) | 968 #if defined(OS_MACOSX) || defined(OS_WIN) |
| 729 #define MAYBE_FileSystem DISABLED_FileSystem | 969 #define MAYBE_FileSystem DISABLED_FileSystem |
| 730 #else | 970 #else |
| 731 #define MAYBE_FileSystem FileSystem | 971 #define MAYBE_FileSystem FileSystem |
| 732 #endif | 972 #endif |
| 733 | 973 |
| (...skipping 565 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1299 MAYBE_PPAPI_NACL(NoSocketPermissions)) { | 1539 MAYBE_PPAPI_NACL(NoSocketPermissions)) { |
| 1300 RunTests("no_socket_permissions"); | 1540 RunTests("no_socket_permissions"); |
| 1301 } | 1541 } |
| 1302 | 1542 |
| 1303 IN_PROC_BROWSER_TEST_F(NewlibPackagedAppTest, | 1543 IN_PROC_BROWSER_TEST_F(NewlibPackagedAppTest, |
| 1304 MAYBE_PPAPI_NACL(SocketPermissions)) { | 1544 MAYBE_PPAPI_NACL(SocketPermissions)) { |
| 1305 RunTests("socket_permissions"); | 1545 RunTests("socket_permissions"); |
| 1306 } | 1546 } |
| 1307 | 1547 |
| 1308 #endif | 1548 #endif |
| OLD | NEW |