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 "base/bind.h" | 5 #include "base/bind.h" |
6 #include "base/command_line.h" | 6 #include "base/command_line.h" |
7 #include "base/files/file_util.h" | 7 #include "base/files/file_util.h" |
8 #include "base/files/scoped_temp_dir.h" | 8 #include "base/files/scoped_temp_dir.h" |
9 #include "base/thread_task_runner_handle.h" | 9 #include "base/thread_task_runner_handle.h" |
10 #include "chrome/common/chrome_switches.h" | 10 #include "chrome/common/chrome_switches.h" |
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
232 file_info_list.push_back( | 232 file_info_list.push_back( |
233 ui::SelectedFileInfo(suggested_filename, suggested_filename)); | 233 ui::SelectedFileInfo(suggested_filename, suggested_filename)); |
234 TestSelectFileDialogFactory test_dialog_factory( | 234 TestSelectFileDialogFactory test_dialog_factory( |
235 TestSelectFileDialogFactory::REPLACE_BASENAME, file_info_list); | 235 TestSelectFileDialogFactory::REPLACE_BASENAME, file_info_list); |
236 | 236 |
237 RunTestViaHTTP("FileChooser_SaveAsSafeDefaultName"); | 237 RunTestViaHTTP("FileChooser_SaveAsSafeDefaultName"); |
238 base::FilePath actual_filename = temp_dir.path().AppendASCII("innocuous.txt"); | 238 base::FilePath actual_filename = temp_dir.path().AppendASCII("innocuous.txt"); |
239 | 239 |
240 ASSERT_TRUE(base::PathExists(actual_filename)); | 240 ASSERT_TRUE(base::PathExists(actual_filename)); |
241 std::string file_contents; | 241 std::string file_contents; |
242 ASSERT_TRUE(base::ReadFileToString(actual_filename, &file_contents, 100)); | 242 ASSERT_TRUE(base::ReadFileToString(actual_filename, &file_contents)); |
243 EXPECT_EQ("Hello from PPAPI", file_contents); | 243 EXPECT_EQ("Hello from PPAPI", file_contents); |
244 } | 244 } |
245 | 245 |
246 IN_PROC_BROWSER_TEST_F(PPAPIFileChooserTest, | 246 IN_PROC_BROWSER_TEST_F(PPAPIFileChooserTest, |
247 FileChooser_SaveAs_UnsafeDefaultName) { | 247 FileChooser_SaveAs_UnsafeDefaultName) { |
248 base::ScopedTempDir temp_dir; | 248 base::ScopedTempDir temp_dir; |
249 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 249 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
250 base::FilePath suggested_filename = temp_dir.path().AppendASCII("foo"); | 250 base::FilePath suggested_filename = temp_dir.path().AppendASCII("foo"); |
251 | 251 |
252 TestSelectFileDialogFactory::SelectedFileInfoList file_info_list; | 252 TestSelectFileDialogFactory::SelectedFileInfoList file_info_list; |
253 file_info_list.push_back( | 253 file_info_list.push_back( |
254 ui::SelectedFileInfo(suggested_filename, suggested_filename)); | 254 ui::SelectedFileInfo(suggested_filename, suggested_filename)); |
255 TestSelectFileDialogFactory test_dialog_factory( | 255 TestSelectFileDialogFactory test_dialog_factory( |
256 TestSelectFileDialogFactory::REPLACE_BASENAME, file_info_list); | 256 TestSelectFileDialogFactory::REPLACE_BASENAME, file_info_list); |
257 | 257 |
258 RunTestViaHTTP("FileChooser_SaveAsUnsafeDefaultName"); | 258 RunTestViaHTTP("FileChooser_SaveAsUnsafeDefaultName"); |
259 base::FilePath actual_filename = temp_dir.path().AppendASCII("unsafe.txt-"); | 259 base::FilePath actual_filename = temp_dir.path().AppendASCII("unsafe.txt-"); |
260 | 260 |
261 ASSERT_TRUE(base::PathExists(actual_filename)); | 261 ASSERT_TRUE(base::PathExists(actual_filename)); |
262 std::string file_contents; | 262 std::string file_contents; |
263 ASSERT_TRUE(base::ReadFileToString(actual_filename, &file_contents, 100)); | 263 ASSERT_TRUE(base::ReadFileToString(actual_filename, &file_contents)); |
264 EXPECT_EQ("Hello from PPAPI", file_contents); | 264 EXPECT_EQ("Hello from PPAPI", file_contents); |
265 } | 265 } |
266 | 266 |
267 IN_PROC_BROWSER_TEST_F(PPAPIFileChooserTest, FileChooser_SaveAs_Cancel) { | 267 IN_PROC_BROWSER_TEST_F(PPAPIFileChooserTest, FileChooser_SaveAs_Cancel) { |
268 TestSelectFileDialogFactory test_dialog_factory( | 268 TestSelectFileDialogFactory test_dialog_factory( |
269 TestSelectFileDialogFactory::CANCEL, | 269 TestSelectFileDialogFactory::CANCEL, |
270 TestSelectFileDialogFactory::SelectedFileInfoList()); | 270 TestSelectFileDialogFactory::SelectedFileInfoList()); |
271 RunTestViaHTTP("FileChooser_SaveAsCancel"); | 271 RunTestViaHTTP("FileChooser_SaveAsCancel"); |
272 } | 272 } |
273 | 273 |
(...skipping 14 matching lines...) Expand all Loading... |
288 file_info_list.push_back( | 288 file_info_list.push_back( |
289 ui::SelectedFileInfo(suggested_filename, suggested_filename)); | 289 ui::SelectedFileInfo(suggested_filename, suggested_filename)); |
290 TestSelectFileDialogFactory test_dialog_factory( | 290 TestSelectFileDialogFactory test_dialog_factory( |
291 TestSelectFileDialogFactory::REPLACE_BASENAME, file_info_list); | 291 TestSelectFileDialogFactory::REPLACE_BASENAME, file_info_list); |
292 | 292 |
293 RunTestViaHTTP("FileChooser_SaveAsDangerousExecutableAllowed"); | 293 RunTestViaHTTP("FileChooser_SaveAsDangerousExecutableAllowed"); |
294 base::FilePath actual_filename = temp_dir.path().AppendASCII("dangerous.exe"); | 294 base::FilePath actual_filename = temp_dir.path().AppendASCII("dangerous.exe"); |
295 | 295 |
296 ASSERT_TRUE(base::PathExists(actual_filename)); | 296 ASSERT_TRUE(base::PathExists(actual_filename)); |
297 std::string file_contents; | 297 std::string file_contents; |
298 ASSERT_TRUE(base::ReadFileToString(actual_filename, &file_contents, 100)); | 298 ASSERT_TRUE(base::ReadFileToString(actual_filename, &file_contents)); |
299 EXPECT_EQ("Hello from PPAPI", file_contents); | 299 EXPECT_EQ("Hello from PPAPI", file_contents); |
300 } | 300 } |
301 | 301 |
302 IN_PROC_BROWSER_TEST_F(PPAPIFileChooserTest, | 302 IN_PROC_BROWSER_TEST_F(PPAPIFileChooserTest, |
303 FileChooser_SaveAs_DangerousExecutable_Disallowed) { | 303 FileChooser_SaveAs_DangerousExecutable_Disallowed) { |
304 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 304 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
305 switches::kDisallowUncheckedDangerousDownloads); | 305 switches::kDisallowUncheckedDangerousDownloads); |
306 TestSelectFileDialogFactory test_dialog_factory( | 306 TestSelectFileDialogFactory test_dialog_factory( |
307 TestSelectFileDialogFactory::NOT_REACHED, | 307 TestSelectFileDialogFactory::NOT_REACHED, |
308 TestSelectFileDialogFactory::SelectedFileInfoList()); | 308 TestSelectFileDialogFactory::SelectedFileInfoList()); |
(...skipping 27 matching lines...) Expand all Loading... |
336 file_info_list.push_back( | 336 file_info_list.push_back( |
337 ui::SelectedFileInfo(suggested_filename, suggested_filename)); | 337 ui::SelectedFileInfo(suggested_filename, suggested_filename)); |
338 TestSelectFileDialogFactory test_dialog_factory( | 338 TestSelectFileDialogFactory test_dialog_factory( |
339 TestSelectFileDialogFactory::REPLACE_BASENAME, file_info_list); | 339 TestSelectFileDialogFactory::REPLACE_BASENAME, file_info_list); |
340 | 340 |
341 RunTestViaHTTP("FileChooser_SaveAsDangerousExecutableAllowed"); | 341 RunTestViaHTTP("FileChooser_SaveAsDangerousExecutableAllowed"); |
342 base::FilePath actual_filename = temp_dir.path().AppendASCII("dangerous.exe"); | 342 base::FilePath actual_filename = temp_dir.path().AppendASCII("dangerous.exe"); |
343 | 343 |
344 ASSERT_TRUE(base::PathExists(actual_filename)); | 344 ASSERT_TRUE(base::PathExists(actual_filename)); |
345 std::string file_contents; | 345 std::string file_contents; |
346 ASSERT_TRUE(base::ReadFileToString(actual_filename, &file_contents, 100)); | 346 ASSERT_TRUE(base::ReadFileToString(actual_filename, &file_contents)); |
347 EXPECT_EQ("Hello from PPAPI", file_contents); | 347 EXPECT_EQ("Hello from PPAPI", file_contents); |
348 } | 348 } |
349 | 349 |
350 #endif // FULL_SAFE_BROWSING | 350 #endif // FULL_SAFE_BROWSING |
OLD | NEW |