| 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 <map> | 5 #include <map> |
| 6 #include <vector> | 6 #include <vector> |
| 7 | 7 |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
| 11 #include "base/files/scoped_temp_dir.h" | 11 #include "base/files/scoped_temp_dir.h" |
| 12 #include "base/strings/string_piece.h" | 12 #include "base/strings/string_piece.h" |
| 13 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
| 14 #include "base/threading/thread_restrictions.h" |
| 14 #include "base/threading/thread_task_runner_handle.h" | 15 #include "base/threading/thread_task_runner_handle.h" |
| 15 #include "chrome/common/chrome_switches.h" | 16 #include "chrome/common/chrome_switches.h" |
| 16 #include "chrome/test/ppapi/ppapi_test.h" | 17 #include "chrome/test/ppapi/ppapi_test.h" |
| 17 #include "content/public/common/quarantine.h" | 18 #include "content/public/common/quarantine.h" |
| 18 #include "ppapi/shared_impl/test_utils.h" | 19 #include "ppapi/shared_impl/test_utils.h" |
| 19 #include "ui/shell_dialogs/select_file_dialog.h" | 20 #include "ui/shell_dialogs/select_file_dialog.h" |
| 20 #include "ui/shell_dialogs/select_file_dialog_factory.h" | 21 #include "ui/shell_dialogs/select_file_dialog_factory.h" |
| 21 #include "ui/shell_dialogs/selected_file_info.h" | 22 #include "ui/shell_dialogs/selected_file_info.h" |
| 22 | 23 |
| 23 #if defined(FULL_SAFE_BROWSING) | 24 #if defined(FULL_SAFE_BROWSING) |
| (...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 private: | 264 private: |
| 264 TestSafeBrowsingServiceFactory safe_browsing_service_factory_; | 265 TestSafeBrowsingServiceFactory safe_browsing_service_factory_; |
| 265 }; | 266 }; |
| 266 | 267 |
| 267 #endif | 268 #endif |
| 268 | 269 |
| 269 } // namespace | 270 } // namespace |
| 270 | 271 |
| 271 IN_PROC_BROWSER_TEST_F(PPAPIFileChooserTest, FileChooser_Open_Success) { | 272 IN_PROC_BROWSER_TEST_F(PPAPIFileChooserTest, FileChooser_Open_Success) { |
| 272 const char kContents[] = "Hello from browser"; | 273 const char kContents[] = "Hello from browser"; |
| 274 base::ThreadRestrictions::ScopedAllowIO allow_io; |
| 273 base::ScopedTempDir temp_dir; | 275 base::ScopedTempDir temp_dir; |
| 274 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 276 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 275 | 277 |
| 276 base::FilePath existing_filename = temp_dir.GetPath().AppendASCII("foo"); | 278 base::FilePath existing_filename = temp_dir.GetPath().AppendASCII("foo"); |
| 277 ASSERT_EQ( | 279 ASSERT_EQ( |
| 278 static_cast<int>(sizeof(kContents) - 1), | 280 static_cast<int>(sizeof(kContents) - 1), |
| 279 base::WriteFile(existing_filename, kContents, sizeof(kContents) - 1)); | 281 base::WriteFile(existing_filename, kContents, sizeof(kContents) - 1)); |
| 280 | 282 |
| 281 TestSelectFileDialogFactory::SelectedFileInfoList file_info_list; | 283 TestSelectFileDialogFactory::SelectedFileInfoList file_info_list; |
| 282 file_info_list.push_back( | 284 file_info_list.push_back( |
| 283 ui::SelectedFileInfo(existing_filename, existing_filename)); | 285 ui::SelectedFileInfo(existing_filename, existing_filename)); |
| 284 TestSelectFileDialogFactory test_dialog_factory( | 286 TestSelectFileDialogFactory test_dialog_factory( |
| 285 TestSelectFileDialogFactory::RESPOND_WITH_FILE_LIST, file_info_list); | 287 TestSelectFileDialogFactory::RESPOND_WITH_FILE_LIST, file_info_list); |
| 286 RunTestViaHTTP("FileChooser_OpenSimple"); | 288 RunTestViaHTTP("FileChooser_OpenSimple"); |
| 287 } | 289 } |
| 288 | 290 |
| 289 IN_PROC_BROWSER_TEST_F(PPAPIFileChooserTest, FileChooser_Open_Cancel) { | 291 IN_PROC_BROWSER_TEST_F(PPAPIFileChooserTest, FileChooser_Open_Cancel) { |
| 290 TestSelectFileDialogFactory test_dialog_factory( | 292 TestSelectFileDialogFactory test_dialog_factory( |
| 291 TestSelectFileDialogFactory::CANCEL, | 293 TestSelectFileDialogFactory::CANCEL, |
| 292 TestSelectFileDialogFactory::SelectedFileInfoList()); | 294 TestSelectFileDialogFactory::SelectedFileInfoList()); |
| 293 RunTestViaHTTP("FileChooser_OpenCancel"); | 295 RunTestViaHTTP("FileChooser_OpenCancel"); |
| 294 } | 296 } |
| 295 | 297 |
| 296 IN_PROC_BROWSER_TEST_F(PPAPIFileChooserTest, FileChooser_SaveAs_Success) { | 298 IN_PROC_BROWSER_TEST_F(PPAPIFileChooserTest, FileChooser_SaveAs_Success) { |
| 299 base::ThreadRestrictions::ScopedAllowIO allow_io; |
| 297 base::ScopedTempDir temp_dir; | 300 base::ScopedTempDir temp_dir; |
| 298 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 301 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 299 base::FilePath suggested_filename = temp_dir.GetPath().AppendASCII("foo"); | 302 base::FilePath suggested_filename = temp_dir.GetPath().AppendASCII("foo"); |
| 300 | 303 |
| 301 TestSelectFileDialogFactory::SelectedFileInfoList file_info_list; | 304 TestSelectFileDialogFactory::SelectedFileInfoList file_info_list; |
| 302 file_info_list.push_back( | 305 file_info_list.push_back( |
| 303 ui::SelectedFileInfo(suggested_filename, suggested_filename)); | 306 ui::SelectedFileInfo(suggested_filename, suggested_filename)); |
| 304 TestSelectFileDialogFactory test_dialog_factory( | 307 TestSelectFileDialogFactory test_dialog_factory( |
| 305 TestSelectFileDialogFactory::RESPOND_WITH_FILE_LIST, file_info_list); | 308 TestSelectFileDialogFactory::RESPOND_WITH_FILE_LIST, file_info_list); |
| 306 | 309 |
| 307 RunTestViaHTTP("FileChooser_SaveAsSafeDefaultName"); | 310 RunTestViaHTTP("FileChooser_SaveAsSafeDefaultName"); |
| 308 ASSERT_TRUE(base::PathExists(suggested_filename)); | 311 ASSERT_TRUE(base::PathExists(suggested_filename)); |
| 309 } | 312 } |
| 310 | 313 |
| 311 IN_PROC_BROWSER_TEST_F(PPAPIFileChooserTest, | 314 IN_PROC_BROWSER_TEST_F(PPAPIFileChooserTest, |
| 312 FileChooser_SaveAs_SafeDefaultName) { | 315 FileChooser_SaveAs_SafeDefaultName) { |
| 316 base::ThreadRestrictions::ScopedAllowIO allow_io; |
| 313 base::ScopedTempDir temp_dir; | 317 base::ScopedTempDir temp_dir; |
| 314 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 318 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 315 base::FilePath suggested_filename = temp_dir.GetPath().AppendASCII("foo"); | 319 base::FilePath suggested_filename = temp_dir.GetPath().AppendASCII("foo"); |
| 316 | 320 |
| 317 TestSelectFileDialogFactory::SelectedFileInfoList file_info_list; | 321 TestSelectFileDialogFactory::SelectedFileInfoList file_info_list; |
| 318 file_info_list.push_back( | 322 file_info_list.push_back( |
| 319 ui::SelectedFileInfo(suggested_filename, suggested_filename)); | 323 ui::SelectedFileInfo(suggested_filename, suggested_filename)); |
| 320 TestSelectFileDialogFactory test_dialog_factory( | 324 TestSelectFileDialogFactory test_dialog_factory( |
| 321 TestSelectFileDialogFactory::REPLACE_BASENAME, file_info_list); | 325 TestSelectFileDialogFactory::REPLACE_BASENAME, file_info_list); |
| 322 | 326 |
| 323 RunTestViaHTTP("FileChooser_SaveAsSafeDefaultName"); | 327 RunTestViaHTTP("FileChooser_SaveAsSafeDefaultName"); |
| 324 base::FilePath actual_filename = | 328 base::FilePath actual_filename = |
| 325 temp_dir.GetPath().AppendASCII("innocuous.txt"); | 329 temp_dir.GetPath().AppendASCII("innocuous.txt"); |
| 326 | 330 |
| 327 ASSERT_TRUE(base::PathExists(actual_filename)); | 331 ASSERT_TRUE(base::PathExists(actual_filename)); |
| 328 std::string file_contents; | 332 std::string file_contents; |
| 329 ASSERT_TRUE(base::ReadFileToString(actual_filename, &file_contents)); | 333 ASSERT_TRUE(base::ReadFileToString(actual_filename, &file_contents)); |
| 330 EXPECT_EQ("Hello from PPAPI", file_contents); | 334 EXPECT_EQ("Hello from PPAPI", file_contents); |
| 331 } | 335 } |
| 332 | 336 |
| 333 IN_PROC_BROWSER_TEST_F(PPAPIFileChooserTest, | 337 IN_PROC_BROWSER_TEST_F(PPAPIFileChooserTest, |
| 334 FileChooser_SaveAs_UnsafeDefaultName) { | 338 FileChooser_SaveAs_UnsafeDefaultName) { |
| 339 base::ThreadRestrictions::ScopedAllowIO allow_io; |
| 335 base::ScopedTempDir temp_dir; | 340 base::ScopedTempDir temp_dir; |
| 336 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 341 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 337 base::FilePath suggested_filename = temp_dir.GetPath().AppendASCII("foo"); | 342 base::FilePath suggested_filename = temp_dir.GetPath().AppendASCII("foo"); |
| 338 | 343 |
| 339 TestSelectFileDialogFactory::SelectedFileInfoList file_info_list; | 344 TestSelectFileDialogFactory::SelectedFileInfoList file_info_list; |
| 340 file_info_list.push_back( | 345 file_info_list.push_back( |
| 341 ui::SelectedFileInfo(suggested_filename, suggested_filename)); | 346 ui::SelectedFileInfo(suggested_filename, suggested_filename)); |
| 342 TestSelectFileDialogFactory test_dialog_factory( | 347 TestSelectFileDialogFactory test_dialog_factory( |
| 343 TestSelectFileDialogFactory::REPLACE_BASENAME, file_info_list); | 348 TestSelectFileDialogFactory::REPLACE_BASENAME, file_info_list); |
| 344 | 349 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 359 RunTestViaHTTP("FileChooser_SaveAsCancel"); | 364 RunTestViaHTTP("FileChooser_SaveAsCancel"); |
| 360 } | 365 } |
| 361 | 366 |
| 362 #if defined(OS_WIN) || defined(OS_LINUX) | 367 #if defined(OS_WIN) || defined(OS_LINUX) |
| 363 // On Windows, tests that a file downloaded via PPAPI FileChooser API has the | 368 // On Windows, tests that a file downloaded via PPAPI FileChooser API has the |
| 364 // mark-of-the-web. The PPAPI FileChooser implementation invokes QuarantineFile | 369 // mark-of-the-web. The PPAPI FileChooser implementation invokes QuarantineFile |
| 365 // in order to mark the file as being downloaded from the web as soon as the | 370 // in order to mark the file as being downloaded from the web as soon as the |
| 366 // file is created. This MOTW prevents the file being opened without due | 371 // file is created. This MOTW prevents the file being opened without due |
| 367 // security warnings if the file is executable. | 372 // security warnings if the file is executable. |
| 368 IN_PROC_BROWSER_TEST_F(PPAPIFileChooserTest, FileChooser_Quarantine) { | 373 IN_PROC_BROWSER_TEST_F(PPAPIFileChooserTest, FileChooser_Quarantine) { |
| 374 base::ThreadRestrictions::ScopedAllowIO allow_io; |
| 369 base::ScopedTempDir temp_dir; | 375 base::ScopedTempDir temp_dir; |
| 370 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 376 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 371 base::FilePath suggested_filename = temp_dir.GetPath().AppendASCII("foo"); | 377 base::FilePath suggested_filename = temp_dir.GetPath().AppendASCII("foo"); |
| 372 | 378 |
| 373 TestSelectFileDialogFactory::SelectedFileInfoList file_info_list; | 379 TestSelectFileDialogFactory::SelectedFileInfoList file_info_list; |
| 374 file_info_list.push_back( | 380 file_info_list.push_back( |
| 375 ui::SelectedFileInfo(suggested_filename, suggested_filename)); | 381 ui::SelectedFileInfo(suggested_filename, suggested_filename)); |
| 376 TestSelectFileDialogFactory test_dialog_factory( | 382 TestSelectFileDialogFactory test_dialog_factory( |
| 377 TestSelectFileDialogFactory::REPLACE_BASENAME, file_info_list); | 383 TestSelectFileDialogFactory::REPLACE_BASENAME, file_info_list); |
| 378 | 384 |
| 379 RunTestViaHTTP("FileChooser_SaveAsDangerousExecutableAllowed"); | 385 RunTestViaHTTP("FileChooser_SaveAsDangerousExecutableAllowed"); |
| 380 base::FilePath actual_filename = | 386 base::FilePath actual_filename = |
| 381 temp_dir.GetPath().AppendASCII("dangerous.exe"); | 387 temp_dir.GetPath().AppendASCII("dangerous.exe"); |
| 382 | 388 |
| 383 ASSERT_TRUE(base::PathExists(actual_filename)); | 389 ASSERT_TRUE(base::PathExists(actual_filename)); |
| 384 EXPECT_TRUE(content::IsFileQuarantined(actual_filename, GURL(), GURL())); | 390 EXPECT_TRUE(content::IsFileQuarantined(actual_filename, GURL(), GURL())); |
| 385 } | 391 } |
| 386 #endif // defined(OS_WIN) || defined(OS_LINUX) | 392 #endif // defined(OS_WIN) || defined(OS_LINUX) |
| 387 | 393 |
| 388 #if defined(FULL_SAFE_BROWSING) | 394 #if defined(FULL_SAFE_BROWSING) |
| 389 // These tests only make sense when SafeBrowsing is enabled. They verify | 395 // These tests only make sense when SafeBrowsing is enabled. They verify |
| 390 // that files written via the FileChooser_Trusted API are properly passed | 396 // that files written via the FileChooser_Trusted API are properly passed |
| 391 // through Safe Browsing. | 397 // through Safe Browsing. |
| 392 | 398 |
| 393 IN_PROC_BROWSER_TEST_F(PPAPIFileChooserTestWithSBService, | 399 IN_PROC_BROWSER_TEST_F(PPAPIFileChooserTestWithSBService, |
| 394 FileChooser_SaveAs_DangerousExecutable_Allowed) { | 400 FileChooser_SaveAs_DangerousExecutable_Allowed) { |
| 401 base::ThreadRestrictions::ScopedAllowIO allow_io; |
| 395 safe_browsing_test_configuration_.default_result = | 402 safe_browsing_test_configuration_.default_result = |
| 396 DownloadProtectionService::DANGEROUS; | 403 DownloadProtectionService::DANGEROUS; |
| 397 safe_browsing_test_configuration_.result_map.insert( | 404 safe_browsing_test_configuration_.result_map.insert( |
| 398 std::make_pair(base::FilePath::StringType(FILE_PATH_LITERAL(".exe")), | 405 std::make_pair(base::FilePath::StringType(FILE_PATH_LITERAL(".exe")), |
| 399 DownloadProtectionService::SAFE)); | 406 DownloadProtectionService::SAFE)); |
| 400 | 407 |
| 401 base::ScopedTempDir temp_dir; | 408 base::ScopedTempDir temp_dir; |
| 402 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 409 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 403 base::FilePath suggested_filename = temp_dir.GetPath().AppendASCII("foo"); | 410 base::FilePath suggested_filename = temp_dir.GetPath().AppendASCII("foo"); |
| 404 | 411 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 440 std::make_pair(base::FilePath::StringType(FILE_PATH_LITERAL(".exe")), | 447 std::make_pair(base::FilePath::StringType(FILE_PATH_LITERAL(".exe")), |
| 441 DownloadProtectionService::DANGEROUS)); | 448 DownloadProtectionService::DANGEROUS)); |
| 442 | 449 |
| 443 TestSelectFileDialogFactory test_dialog_factory( | 450 TestSelectFileDialogFactory test_dialog_factory( |
| 444 TestSelectFileDialogFactory::NOT_REACHED, | 451 TestSelectFileDialogFactory::NOT_REACHED, |
| 445 TestSelectFileDialogFactory::SelectedFileInfoList()); | 452 TestSelectFileDialogFactory::SelectedFileInfoList()); |
| 446 RunTestViaHTTP("FileChooser_SaveAsDangerousExtensionListDisallowed"); | 453 RunTestViaHTTP("FileChooser_SaveAsDangerousExtensionListDisallowed"); |
| 447 } | 454 } |
| 448 | 455 |
| 449 #endif // FULL_SAFE_BROWSING | 456 #endif // FULL_SAFE_BROWSING |
| OLD | NEW |