| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "ppapi/tests/test_file_chooser.h" | 5 #include "ppapi/tests/test_file_chooser.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "ppapi/c/pp_errors.h" | 9 #include "ppapi/c/pp_errors.h" |
| 10 #include "ppapi/c/ppb_file_io.h" | 10 #include "ppapi/c/ppb_file_io.h" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 } | 28 } |
| 29 | 29 |
| 30 void TestFileChooser::RunTests(const std::string& filter) { | 30 void TestFileChooser::RunTests(const std::string& filter) { |
| 31 RUN_TEST(OpenSimple, filter); | 31 RUN_TEST(OpenSimple, filter); |
| 32 RUN_TEST(OpenCancel, filter); | 32 RUN_TEST(OpenCancel, filter); |
| 33 RUN_TEST(SaveAsSafeDefaultName, filter); | 33 RUN_TEST(SaveAsSafeDefaultName, filter); |
| 34 RUN_TEST(SaveAsUnsafeDefaultName, filter); | 34 RUN_TEST(SaveAsUnsafeDefaultName, filter); |
| 35 RUN_TEST(SaveAsCancel, filter); | 35 RUN_TEST(SaveAsCancel, filter); |
| 36 RUN_TEST(SaveAsDangerousExecutableAllowed, filter); | 36 RUN_TEST(SaveAsDangerousExecutableAllowed, filter); |
| 37 RUN_TEST(SaveAsDangerousExecutableDisallowed, filter); | 37 RUN_TEST(SaveAsDangerousExecutableDisallowed, filter); |
| 38 RUN_TEST(SaveAsDangerousExtensionListDisallowed, filter); |
| 38 } | 39 } |
| 39 | 40 |
| 40 bool TestFileChooser::WriteDefaultContentsToFile(const pp::FileRef& file_ref) { | 41 bool TestFileChooser::WriteDefaultContentsToFile(const pp::FileRef& file_ref) { |
| 41 TestCompletionCallback fileio_callback(instance_->pp_instance(), | 42 TestCompletionCallback fileio_callback(instance_->pp_instance(), |
| 42 callback_type()); | 43 callback_type()); |
| 43 pp::FileIO fileio(instance()); | 44 pp::FileIO fileio(instance()); |
| 44 | 45 |
| 45 fileio_callback.WaitForResult( | 46 fileio_callback.WaitForResult( |
| 46 fileio.Open(file_ref, PP_FILEOPENFLAG_WRITE | PP_FILEOPENFLAG_CREATE, | 47 fileio.Open(file_ref, PP_FILEOPENFLAG_WRITE | PP_FILEOPENFLAG_CREATE, |
| 47 fileio_callback.GetCallback())); | 48 fileio_callback.GetCallback())); |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 | 191 |
| 191 TestCompletionCallbackWithOutput<std::vector<pp::FileRef>> | 192 TestCompletionCallbackWithOutput<std::vector<pp::FileRef>> |
| 192 filechooser_callback(instance_->pp_instance(), callback_type()); | 193 filechooser_callback(instance_->pp_instance(), callback_type()); |
| 193 filechooser_callback.WaitForResult( | 194 filechooser_callback.WaitForResult( |
| 194 file_chooser.Show(filechooser_callback.GetCallback())); | 195 file_chooser.Show(filechooser_callback.GetCallback())); |
| 195 | 196 |
| 196 const std::vector<pp::FileRef>& output_ref = filechooser_callback.output(); | 197 const std::vector<pp::FileRef>& output_ref = filechooser_callback.output(); |
| 197 ASSERT_EQ(0u, output_ref.size()); | 198 ASSERT_EQ(0u, output_ref.size()); |
| 198 PASS(); | 199 PASS(); |
| 199 } | 200 } |
| 201 |
| 202 // Checks that a dangerous file is not allowed to be downloaded via the |
| 203 // FileChooser_Trusted API. Chrome should delegate the decision of which files |
| 204 // are allowed over to SafeBrowsing (if enabled), and the current SafeBrowsing |
| 205 // configuration should disallow downloading of dangerous files for this test to |
| 206 // work. |
| 207 std::string TestFileChooser::TestSaveAsDangerousExtensionListDisallowed() { |
| 208 pp::FileChooser_Trusted file_chooser(instance(), PP_FILECHOOSERMODE_OPEN, |
| 209 ".txt,.exe", true /* save_as */, |
| 210 "innocuous.txt"); |
| 211 ASSERT_FALSE(file_chooser.is_null()); |
| 212 |
| 213 TestCompletionCallbackWithOutput<std::vector<pp::FileRef>> |
| 214 filechooser_callback(instance_->pp_instance(), callback_type()); |
| 215 filechooser_callback.WaitForResult( |
| 216 file_chooser.Show(filechooser_callback.GetCallback())); |
| 217 |
| 218 const std::vector<pp::FileRef>& output_ref = filechooser_callback.output(); |
| 219 ASSERT_EQ(0u, output_ref.size()); |
| 220 PASS(); |
| 221 } |
| OLD | NEW |