| 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 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
| 10 #include "base/files/scoped_temp_dir.h" | 10 #include "base/files/scoped_temp_dir.h" |
| (...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 261 | 261 |
| 262 #endif | 262 #endif |
| 263 | 263 |
| 264 } // namespace | 264 } // namespace |
| 265 | 265 |
| 266 IN_PROC_BROWSER_TEST_F(PPAPIFileChooserTest, FileChooser_Open_Success) { | 266 IN_PROC_BROWSER_TEST_F(PPAPIFileChooserTest, FileChooser_Open_Success) { |
| 267 const char kContents[] = "Hello from browser"; | 267 const char kContents[] = "Hello from browser"; |
| 268 base::ScopedTempDir temp_dir; | 268 base::ScopedTempDir temp_dir; |
| 269 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 269 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 270 | 270 |
| 271 base::FilePath existing_filename = temp_dir.path().AppendASCII("foo"); | 271 base::FilePath existing_filename = temp_dir.GetPath().AppendASCII("foo"); |
| 272 ASSERT_EQ( | 272 ASSERT_EQ( |
| 273 static_cast<int>(sizeof(kContents) - 1), | 273 static_cast<int>(sizeof(kContents) - 1), |
| 274 base::WriteFile(existing_filename, kContents, sizeof(kContents) - 1)); | 274 base::WriteFile(existing_filename, kContents, sizeof(kContents) - 1)); |
| 275 | 275 |
| 276 TestSelectFileDialogFactory::SelectedFileInfoList file_info_list; | 276 TestSelectFileDialogFactory::SelectedFileInfoList file_info_list; |
| 277 file_info_list.push_back( | 277 file_info_list.push_back( |
| 278 ui::SelectedFileInfo(existing_filename, existing_filename)); | 278 ui::SelectedFileInfo(existing_filename, existing_filename)); |
| 279 TestSelectFileDialogFactory test_dialog_factory( | 279 TestSelectFileDialogFactory test_dialog_factory( |
| 280 TestSelectFileDialogFactory::RESPOND_WITH_FILE_LIST, file_info_list); | 280 TestSelectFileDialogFactory::RESPOND_WITH_FILE_LIST, file_info_list); |
| 281 RunTestViaHTTP("FileChooser_OpenSimple"); | 281 RunTestViaHTTP("FileChooser_OpenSimple"); |
| 282 } | 282 } |
| 283 | 283 |
| 284 IN_PROC_BROWSER_TEST_F(PPAPIFileChooserTest, FileChooser_Open_Cancel) { | 284 IN_PROC_BROWSER_TEST_F(PPAPIFileChooserTest, FileChooser_Open_Cancel) { |
| 285 TestSelectFileDialogFactory test_dialog_factory( | 285 TestSelectFileDialogFactory test_dialog_factory( |
| 286 TestSelectFileDialogFactory::CANCEL, | 286 TestSelectFileDialogFactory::CANCEL, |
| 287 TestSelectFileDialogFactory::SelectedFileInfoList()); | 287 TestSelectFileDialogFactory::SelectedFileInfoList()); |
| 288 RunTestViaHTTP("FileChooser_OpenCancel"); | 288 RunTestViaHTTP("FileChooser_OpenCancel"); |
| 289 } | 289 } |
| 290 | 290 |
| 291 IN_PROC_BROWSER_TEST_F(PPAPIFileChooserTest, FileChooser_SaveAs_Success) { | 291 IN_PROC_BROWSER_TEST_F(PPAPIFileChooserTest, FileChooser_SaveAs_Success) { |
| 292 base::ScopedTempDir temp_dir; | 292 base::ScopedTempDir temp_dir; |
| 293 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 293 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 294 base::FilePath suggested_filename = temp_dir.path().AppendASCII("foo"); | 294 base::FilePath suggested_filename = temp_dir.GetPath().AppendASCII("foo"); |
| 295 | 295 |
| 296 TestSelectFileDialogFactory::SelectedFileInfoList file_info_list; | 296 TestSelectFileDialogFactory::SelectedFileInfoList file_info_list; |
| 297 file_info_list.push_back( | 297 file_info_list.push_back( |
| 298 ui::SelectedFileInfo(suggested_filename, suggested_filename)); | 298 ui::SelectedFileInfo(suggested_filename, suggested_filename)); |
| 299 TestSelectFileDialogFactory test_dialog_factory( | 299 TestSelectFileDialogFactory test_dialog_factory( |
| 300 TestSelectFileDialogFactory::RESPOND_WITH_FILE_LIST, file_info_list); | 300 TestSelectFileDialogFactory::RESPOND_WITH_FILE_LIST, file_info_list); |
| 301 | 301 |
| 302 RunTestViaHTTP("FileChooser_SaveAsSafeDefaultName"); | 302 RunTestViaHTTP("FileChooser_SaveAsSafeDefaultName"); |
| 303 ASSERT_TRUE(base::PathExists(suggested_filename)); | 303 ASSERT_TRUE(base::PathExists(suggested_filename)); |
| 304 } | 304 } |
| 305 | 305 |
| 306 IN_PROC_BROWSER_TEST_F(PPAPIFileChooserTest, | 306 IN_PROC_BROWSER_TEST_F(PPAPIFileChooserTest, |
| 307 FileChooser_SaveAs_SafeDefaultName) { | 307 FileChooser_SaveAs_SafeDefaultName) { |
| 308 base::ScopedTempDir temp_dir; | 308 base::ScopedTempDir temp_dir; |
| 309 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 309 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 310 base::FilePath suggested_filename = temp_dir.path().AppendASCII("foo"); | 310 base::FilePath suggested_filename = temp_dir.GetPath().AppendASCII("foo"); |
| 311 | 311 |
| 312 TestSelectFileDialogFactory::SelectedFileInfoList file_info_list; | 312 TestSelectFileDialogFactory::SelectedFileInfoList file_info_list; |
| 313 file_info_list.push_back( | 313 file_info_list.push_back( |
| 314 ui::SelectedFileInfo(suggested_filename, suggested_filename)); | 314 ui::SelectedFileInfo(suggested_filename, suggested_filename)); |
| 315 TestSelectFileDialogFactory test_dialog_factory( | 315 TestSelectFileDialogFactory test_dialog_factory( |
| 316 TestSelectFileDialogFactory::REPLACE_BASENAME, file_info_list); | 316 TestSelectFileDialogFactory::REPLACE_BASENAME, file_info_list); |
| 317 | 317 |
| 318 RunTestViaHTTP("FileChooser_SaveAsSafeDefaultName"); | 318 RunTestViaHTTP("FileChooser_SaveAsSafeDefaultName"); |
| 319 base::FilePath actual_filename = temp_dir.path().AppendASCII("innocuous.txt"); | 319 base::FilePath actual_filename = |
| 320 temp_dir.GetPath().AppendASCII("innocuous.txt"); |
| 320 | 321 |
| 321 ASSERT_TRUE(base::PathExists(actual_filename)); | 322 ASSERT_TRUE(base::PathExists(actual_filename)); |
| 322 std::string file_contents; | 323 std::string file_contents; |
| 323 ASSERT_TRUE(base::ReadFileToString(actual_filename, &file_contents)); | 324 ASSERT_TRUE(base::ReadFileToString(actual_filename, &file_contents)); |
| 324 EXPECT_EQ("Hello from PPAPI", file_contents); | 325 EXPECT_EQ("Hello from PPAPI", file_contents); |
| 325 } | 326 } |
| 326 | 327 |
| 327 IN_PROC_BROWSER_TEST_F(PPAPIFileChooserTest, | 328 IN_PROC_BROWSER_TEST_F(PPAPIFileChooserTest, |
| 328 FileChooser_SaveAs_UnsafeDefaultName) { | 329 FileChooser_SaveAs_UnsafeDefaultName) { |
| 329 base::ScopedTempDir temp_dir; | 330 base::ScopedTempDir temp_dir; |
| 330 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 331 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 331 base::FilePath suggested_filename = temp_dir.path().AppendASCII("foo"); | 332 base::FilePath suggested_filename = temp_dir.GetPath().AppendASCII("foo"); |
| 332 | 333 |
| 333 TestSelectFileDialogFactory::SelectedFileInfoList file_info_list; | 334 TestSelectFileDialogFactory::SelectedFileInfoList file_info_list; |
| 334 file_info_list.push_back( | 335 file_info_list.push_back( |
| 335 ui::SelectedFileInfo(suggested_filename, suggested_filename)); | 336 ui::SelectedFileInfo(suggested_filename, suggested_filename)); |
| 336 TestSelectFileDialogFactory test_dialog_factory( | 337 TestSelectFileDialogFactory test_dialog_factory( |
| 337 TestSelectFileDialogFactory::REPLACE_BASENAME, file_info_list); | 338 TestSelectFileDialogFactory::REPLACE_BASENAME, file_info_list); |
| 338 | 339 |
| 339 RunTestViaHTTP("FileChooser_SaveAsUnsafeDefaultName"); | 340 RunTestViaHTTP("FileChooser_SaveAsUnsafeDefaultName"); |
| 340 base::FilePath actual_filename = temp_dir.path().AppendASCII("unsafe.txt-"); | 341 base::FilePath actual_filename = |
| 342 temp_dir.GetPath().AppendASCII("unsafe.txt-"); |
| 341 | 343 |
| 342 ASSERT_TRUE(base::PathExists(actual_filename)); | 344 ASSERT_TRUE(base::PathExists(actual_filename)); |
| 343 std::string file_contents; | 345 std::string file_contents; |
| 344 ASSERT_TRUE(base::ReadFileToString(actual_filename, &file_contents)); | 346 ASSERT_TRUE(base::ReadFileToString(actual_filename, &file_contents)); |
| 345 EXPECT_EQ("Hello from PPAPI", file_contents); | 347 EXPECT_EQ("Hello from PPAPI", file_contents); |
| 346 } | 348 } |
| 347 | 349 |
| 348 IN_PROC_BROWSER_TEST_F(PPAPIFileChooserTest, FileChooser_SaveAs_Cancel) { | 350 IN_PROC_BROWSER_TEST_F(PPAPIFileChooserTest, FileChooser_SaveAs_Cancel) { |
| 349 TestSelectFileDialogFactory test_dialog_factory( | 351 TestSelectFileDialogFactory test_dialog_factory( |
| 350 TestSelectFileDialogFactory::CANCEL, | 352 TestSelectFileDialogFactory::CANCEL, |
| 351 TestSelectFileDialogFactory::SelectedFileInfoList()); | 353 TestSelectFileDialogFactory::SelectedFileInfoList()); |
| 352 RunTestViaHTTP("FileChooser_SaveAsCancel"); | 354 RunTestViaHTTP("FileChooser_SaveAsCancel"); |
| 353 } | 355 } |
| 354 | 356 |
| 355 #if defined(FULL_SAFE_BROWSING) | 357 #if defined(FULL_SAFE_BROWSING) |
| 356 // These tests only make sense when SafeBrowsing is enabled. They verify | 358 // These tests only make sense when SafeBrowsing is enabled. They verify |
| 357 // that files written via the FileChooser_Trusted API are properly passed | 359 // that files written via the FileChooser_Trusted API are properly passed |
| 358 // through Safe Browsing. | 360 // through Safe Browsing. |
| 359 | 361 |
| 360 IN_PROC_BROWSER_TEST_F(PPAPIFileChooserTestWithSBService, | 362 IN_PROC_BROWSER_TEST_F(PPAPIFileChooserTestWithSBService, |
| 361 FileChooser_SaveAs_DangerousExecutable_Allowed) { | 363 FileChooser_SaveAs_DangerousExecutable_Allowed) { |
| 362 safe_browsing_test_configuration_.default_result = | 364 safe_browsing_test_configuration_.default_result = |
| 363 DownloadProtectionService::DANGEROUS; | 365 DownloadProtectionService::DANGEROUS; |
| 364 safe_browsing_test_configuration_.result_map.insert( | 366 safe_browsing_test_configuration_.result_map.insert( |
| 365 std::make_pair(base::FilePath::StringType(FILE_PATH_LITERAL(".exe")), | 367 std::make_pair(base::FilePath::StringType(FILE_PATH_LITERAL(".exe")), |
| 366 DownloadProtectionService::SAFE)); | 368 DownloadProtectionService::SAFE)); |
| 367 | 369 |
| 368 base::ScopedTempDir temp_dir; | 370 base::ScopedTempDir temp_dir; |
| 369 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 371 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 370 base::FilePath suggested_filename = temp_dir.path().AppendASCII("foo"); | 372 base::FilePath suggested_filename = temp_dir.GetPath().AppendASCII("foo"); |
| 371 | 373 |
| 372 TestSelectFileDialogFactory::SelectedFileInfoList file_info_list; | 374 TestSelectFileDialogFactory::SelectedFileInfoList file_info_list; |
| 373 file_info_list.push_back( | 375 file_info_list.push_back( |
| 374 ui::SelectedFileInfo(suggested_filename, suggested_filename)); | 376 ui::SelectedFileInfo(suggested_filename, suggested_filename)); |
| 375 TestSelectFileDialogFactory test_dialog_factory( | 377 TestSelectFileDialogFactory test_dialog_factory( |
| 376 TestSelectFileDialogFactory::REPLACE_BASENAME, file_info_list); | 378 TestSelectFileDialogFactory::REPLACE_BASENAME, file_info_list); |
| 377 | 379 |
| 378 RunTestViaHTTP("FileChooser_SaveAsDangerousExecutableAllowed"); | 380 RunTestViaHTTP("FileChooser_SaveAsDangerousExecutableAllowed"); |
| 379 base::FilePath actual_filename = temp_dir.path().AppendASCII("dangerous.exe"); | 381 base::FilePath actual_filename = |
| 382 temp_dir.GetPath().AppendASCII("dangerous.exe"); |
| 380 | 383 |
| 381 ASSERT_TRUE(base::PathExists(actual_filename)); | 384 ASSERT_TRUE(base::PathExists(actual_filename)); |
| 382 std::string file_contents; | 385 std::string file_contents; |
| 383 ASSERT_TRUE(base::ReadFileToString(actual_filename, &file_contents)); | 386 ASSERT_TRUE(base::ReadFileToString(actual_filename, &file_contents)); |
| 384 EXPECT_EQ("Hello from PPAPI", file_contents); | 387 EXPECT_EQ("Hello from PPAPI", file_contents); |
| 385 } | 388 } |
| 386 | 389 |
| 387 IN_PROC_BROWSER_TEST_F(PPAPIFileChooserTestWithSBService, | 390 IN_PROC_BROWSER_TEST_F(PPAPIFileChooserTestWithSBService, |
| 388 FileChooser_SaveAs_DangerousExecutable_Disallowed) { | 391 FileChooser_SaveAs_DangerousExecutable_Disallowed) { |
| 389 safe_browsing_test_configuration_.default_result = | 392 safe_browsing_test_configuration_.default_result = |
| (...skipping 16 matching lines...) Expand all Loading... |
| 406 std::make_pair(base::FilePath::StringType(FILE_PATH_LITERAL(".exe")), | 409 std::make_pair(base::FilePath::StringType(FILE_PATH_LITERAL(".exe")), |
| 407 DownloadProtectionService::DANGEROUS)); | 410 DownloadProtectionService::DANGEROUS)); |
| 408 | 411 |
| 409 TestSelectFileDialogFactory test_dialog_factory( | 412 TestSelectFileDialogFactory test_dialog_factory( |
| 410 TestSelectFileDialogFactory::NOT_REACHED, | 413 TestSelectFileDialogFactory::NOT_REACHED, |
| 411 TestSelectFileDialogFactory::SelectedFileInfoList()); | 414 TestSelectFileDialogFactory::SelectedFileInfoList()); |
| 412 RunTestViaHTTP("FileChooser_SaveAsDangerousExtensionListDisallowed"); | 415 RunTestViaHTTP("FileChooser_SaveAsDangerousExtensionListDisallowed"); |
| 413 } | 416 } |
| 414 | 417 |
| 415 #endif // FULL_SAFE_BROWSING | 418 #endif // FULL_SAFE_BROWSING |
| OLD | NEW |