| 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 <algorithm> | 5 #include <algorithm> |
| 6 | 6 |
| 7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
| 8 #include "base/scoped_temp_dir.h" | 8 #include "base/scoped_temp_dir.h" |
| 9 #include "base/stringprintf.h" | 9 #include "base/stringprintf.h" |
| 10 #include "chrome/browser/download/download_extension_api.h" | |
| 11 #include "chrome/browser/download/download_file_icon_extractor.h" | 10 #include "chrome/browser/download/download_file_icon_extractor.h" |
| 12 #include "chrome/browser/download/download_service.h" | 11 #include "chrome/browser/download/download_service.h" |
| 13 #include "chrome/browser/download/download_service_factory.h" | 12 #include "chrome/browser/download/download_service_factory.h" |
| 14 #include "chrome/browser/download/download_test_observer.h" | 13 #include "chrome/browser/download/download_test_observer.h" |
| 14 #include "chrome/browser/extensions/api/downloads/downloads_api.h" |
| 15 #include "chrome/browser/extensions/extension_function_test_utils.h" | 15 #include "chrome/browser/extensions/extension_function_test_utils.h" |
| 16 #include "chrome/browser/net/url_request_mock_util.h" | 16 #include "chrome/browser/net/url_request_mock_util.h" |
| 17 #include "chrome/browser/prefs/pref_service.h" | 17 #include "chrome/browser/prefs/pref_service.h" |
| 18 #include "chrome/browser/profiles/profile.h" | 18 #include "chrome/browser/profiles/profile.h" |
| 19 #include "chrome/browser/ui/browser.h" | 19 #include "chrome/browser/ui/browser.h" |
| 20 #include "chrome/common/pref_names.h" | 20 #include "chrome/common/pref_names.h" |
| 21 #include "chrome/test/base/in_process_browser_test.h" | 21 #include "chrome/test/base/in_process_browser_test.h" |
| 22 #include "chrome/test/base/ui_test_utils.h" | 22 #include "chrome/test/base/ui_test_utils.h" |
| 23 #include "content/public/browser/browser_thread.h" | 23 #include "content/public/browser/browser_thread.h" |
| 24 #include "content/public/browser/download_manager.h" | 24 #include "content/public/browser/download_manager.h" |
| (...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 371 } | 371 } |
| 372 } | 372 } |
| 373 | 373 |
| 374 private: | 374 private: |
| 375 DownloadManager::DownloadVector* items_; | 375 DownloadManager::DownloadVector* items_; |
| 376 DISALLOW_COPY_AND_ASSIGN(ScopedItemVectorCanceller); | 376 DISALLOW_COPY_AND_ASSIGN(ScopedItemVectorCanceller); |
| 377 }; | 377 }; |
| 378 | 378 |
| 379 } // namespace | 379 } // namespace |
| 380 | 380 |
| 381 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, DownloadsApi_PauseResumeCancel) { | 381 IN_PROC_BROWSER_TEST_F( |
| 382 DownloadExtensionTest, DownloadExtensionTest_PauseResumeCancel) { |
| 382 DownloadItem* download_item = CreateSlowTestDownload(); | 383 DownloadItem* download_item = CreateSlowTestDownload(); |
| 383 ASSERT_TRUE(download_item); | 384 ASSERT_TRUE(download_item); |
| 384 | 385 |
| 385 // Call pause(). It should succeed and the download should be paused on | 386 // Call pause(). It should succeed and the download should be paused on |
| 386 // return. | 387 // return. |
| 387 EXPECT_TRUE(RunFunction(new DownloadsPauseFunction(), | 388 EXPECT_TRUE(RunFunction(new DownloadsPauseFunction(), |
| 388 DownloadItemIdAsArgList(download_item))); | 389 DownloadItemIdAsArgList(download_item))); |
| 389 EXPECT_TRUE(download_item->IsPaused()); | 390 EXPECT_TRUE(download_item->IsPaused()); |
| 390 | 391 |
| 391 // Calling pause() twice shouldn't be an error. | 392 // Calling pause() twice shouldn't be an error. |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 429 new DownloadsResumeFunction(), DownloadItemIdAsArgList(download_item)); | 430 new DownloadsResumeFunction(), DownloadItemIdAsArgList(download_item)); |
| 430 EXPECT_STREQ(download_extension_errors::kInvalidOperationError, | 431 EXPECT_STREQ(download_extension_errors::kInvalidOperationError, |
| 431 error.c_str()); | 432 error.c_str()); |
| 432 | 433 |
| 433 // Calling pause()/resume()/cancel() with invalid download Ids is | 434 // Calling pause()/resume()/cancel() with invalid download Ids is |
| 434 // tested in the API test (DownloadsApiTest). | 435 // tested in the API test (DownloadsApiTest). |
| 435 } | 436 } |
| 436 | 437 |
| 437 // Test downloads.getFileIcon() on in-progress, finished, cancelled and deleted | 438 // Test downloads.getFileIcon() on in-progress, finished, cancelled and deleted |
| 438 // download items. | 439 // download items. |
| 439 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, DownloadsApi_FileIcon_Active) { | 440 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, |
| 441 DownloadExtensionTest_FileIcon_Active) { |
| 440 DownloadItem* download_item = CreateSlowTestDownload(); | 442 DownloadItem* download_item = CreateSlowTestDownload(); |
| 441 ASSERT_TRUE(download_item); | 443 ASSERT_TRUE(download_item); |
| 442 | 444 |
| 443 // Get the icon for the in-progress download. This call should succeed even | 445 // Get the icon for the in-progress download. This call should succeed even |
| 444 // if the file type isn't registered. | 446 // if the file type isn't registered. |
| 445 std::string args = base::StringPrintf("[%d, {}]", download_item->GetId()); | 447 std::string args = base::StringPrintf("[%d, {}]", download_item->GetId()); |
| 446 std::string result_string; | 448 std::string result_string; |
| 447 EXPECT_TRUE(RunFunctionAndReturnString(new DownloadsGetFileIconFunction(), | 449 EXPECT_TRUE(RunFunctionAndReturnString(new DownloadsGetFileIconFunction(), |
| 448 args, &result_string)); | 450 args, &result_string)); |
| 449 | 451 |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 528 error.c_str()); | 530 error.c_str()); |
| 529 | 531 |
| 530 // Asking for icons of other (invalid) sizes is tested in the API test | 532 // Asking for icons of other (invalid) sizes is tested in the API test |
| 531 // (DownloadsApiTest). | 533 // (DownloadsApiTest). |
| 532 } | 534 } |
| 533 | 535 |
| 534 // Test that we can acquire file icons for history downloads regardless of | 536 // Test that we can acquire file icons for history downloads regardless of |
| 535 // whether they exist or not. If the file doesn't exist we should receive a | 537 // whether they exist or not. If the file doesn't exist we should receive a |
| 536 // generic icon from the OS/toolkit that may or may not be specific to the file | 538 // generic icon from the OS/toolkit that may or may not be specific to the file |
| 537 // type. | 539 // type. |
| 538 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, DownloadsApi_FileIcon_History) { | 540 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, |
| 541 DownloadExtensionTest_FileIcon_History) { |
| 539 const HistoryDownloadInfo kHistoryInfo[] = { | 542 const HistoryDownloadInfo kHistoryInfo[] = { |
| 540 { FILE_PATH_LITERAL("real.txt"), | 543 { FILE_PATH_LITERAL("real.txt"), |
| 541 DownloadItem::COMPLETE, | 544 DownloadItem::COMPLETE, |
| 542 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS }, | 545 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS }, |
| 543 { FILE_PATH_LITERAL("fake.txt"), | 546 { FILE_PATH_LITERAL("fake.txt"), |
| 544 DownloadItem::COMPLETE, | 547 DownloadItem::COMPLETE, |
| 545 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS } | 548 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS } |
| 546 }; | 549 }; |
| 547 DownloadManager::DownloadVector all_downloads; | 550 DownloadManager::DownloadVector all_downloads; |
| 548 ASSERT_TRUE(CreateHistoryDownloads(kHistoryInfo, arraysize(kHistoryInfo), | 551 ASSERT_TRUE(CreateHistoryDownloads(kHistoryInfo, arraysize(kHistoryInfo), |
| (...skipping 27 matching lines...) Expand all Loading... |
| 576 function->SetIconExtractorForTesting(new MockIconExtractorImpl( | 579 function->SetIconExtractorForTesting(new MockIconExtractorImpl( |
| 577 (*iter)->GetFullPath(), IconLoader::NORMAL, "hello")); | 580 (*iter)->GetFullPath(), IconLoader::NORMAL, "hello")); |
| 578 EXPECT_TRUE(RunFunctionAndReturnString(function.release(), args, | 581 EXPECT_TRUE(RunFunctionAndReturnString(function.release(), args, |
| 579 &result_string)); | 582 &result_string)); |
| 580 EXPECT_STREQ("hello", result_string.c_str()); | 583 EXPECT_STREQ("hello", result_string.c_str()); |
| 581 } | 584 } |
| 582 | 585 |
| 583 // The temporary files should be cleaned up when the ScopedTempDir is removed. | 586 // The temporary files should be cleaned up when the ScopedTempDir is removed. |
| 584 } | 587 } |
| 585 | 588 |
| 586 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, DownloadsApi_SearchEmptyQuery) { | 589 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, |
| 590 DownloadExtensionTest_SearchEmptyQuery) { |
| 587 ScopedCancellingItem item(CreateSlowTestDownload()); | 591 ScopedCancellingItem item(CreateSlowTestDownload()); |
| 588 ASSERT_TRUE(item.get()); | 592 ASSERT_TRUE(item.get()); |
| 589 | 593 |
| 590 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( | 594 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( |
| 591 new DownloadsSearchFunction(), "[{}]")); | 595 new DownloadsSearchFunction(), "[{}]")); |
| 592 ASSERT_TRUE(result.get()); | 596 ASSERT_TRUE(result.get()); |
| 593 base::ListValue* result_list = NULL; | 597 base::ListValue* result_list = NULL; |
| 594 ASSERT_TRUE(result->GetAsList(&result_list)); | 598 ASSERT_TRUE(result->GetAsList(&result_list)); |
| 595 ASSERT_EQ(1UL, result_list->GetSize()); | 599 ASSERT_EQ(1UL, result_list->GetSize()); |
| 596 } | 600 } |
| 597 | 601 |
| 598 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, | 602 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, |
| 599 DownloadsApi_SearchFilenameRegex) { | 603 DownloadExtensionTest_SearchFilenameRegex) { |
| 600 const HistoryDownloadInfo kHistoryInfo[] = { | 604 const HistoryDownloadInfo kHistoryInfo[] = { |
| 601 { FILE_PATH_LITERAL("foobar"), | 605 { FILE_PATH_LITERAL("foobar"), |
| 602 DownloadItem::COMPLETE, | 606 DownloadItem::COMPLETE, |
| 603 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS }, | 607 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS }, |
| 604 { FILE_PATH_LITERAL("baz"), | 608 { FILE_PATH_LITERAL("baz"), |
| 605 DownloadItem::COMPLETE, | 609 DownloadItem::COMPLETE, |
| 606 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS } | 610 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS } |
| 607 }; | 611 }; |
| 608 DownloadManager::DownloadVector all_downloads; | 612 DownloadManager::DownloadVector all_downloads; |
| 609 ASSERT_TRUE(CreateHistoryDownloads(kHistoryInfo, arraysize(kHistoryInfo), | 613 ASSERT_TRUE(CreateHistoryDownloads(kHistoryInfo, arraysize(kHistoryInfo), |
| 610 &all_downloads)); | 614 &all_downloads)); |
| 611 | 615 |
| 612 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( | 616 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( |
| 613 new DownloadsSearchFunction(), "[{\"filenameRegex\": \"foobar\"}]")); | 617 new DownloadsSearchFunction(), "[{\"filenameRegex\": \"foobar\"}]")); |
| 614 ASSERT_TRUE(result.get()); | 618 ASSERT_TRUE(result.get()); |
| 615 base::ListValue* result_list = NULL; | 619 base::ListValue* result_list = NULL; |
| 616 ASSERT_TRUE(result->GetAsList(&result_list)); | 620 ASSERT_TRUE(result->GetAsList(&result_list)); |
| 617 ASSERT_EQ(1UL, result_list->GetSize()); | 621 ASSERT_EQ(1UL, result_list->GetSize()); |
| 618 base::DictionaryValue* item_value = NULL; | 622 base::DictionaryValue* item_value = NULL; |
| 619 ASSERT_TRUE(result_list->GetDictionary(0, &item_value)); | 623 ASSERT_TRUE(result_list->GetDictionary(0, &item_value)); |
| 620 int item_id = -1; | 624 int item_id = -1; |
| 621 ASSERT_TRUE(item_value->GetInteger("id", &item_id)); | 625 ASSERT_TRUE(item_value->GetInteger("id", &item_id)); |
| 622 ASSERT_EQ(0, item_id); | 626 ASSERT_EQ(0, item_id); |
| 623 } | 627 } |
| 624 | 628 |
| 625 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, DownloadsApi_SearchId) { | 629 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, DownloadExtensionTest_SearchId) { |
| 626 DownloadManager::DownloadVector items; | 630 DownloadManager::DownloadVector items; |
| 627 CreateSlowTestDownloads(2, &items); | 631 CreateSlowTestDownloads(2, &items); |
| 628 ScopedItemVectorCanceller delete_items(&items); | 632 ScopedItemVectorCanceller delete_items(&items); |
| 629 | 633 |
| 630 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( | 634 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( |
| 631 new DownloadsSearchFunction(), "[{\"id\": 0}]")); | 635 new DownloadsSearchFunction(), "[{\"id\": 0}]")); |
| 632 ASSERT_TRUE(result.get()); | 636 ASSERT_TRUE(result.get()); |
| 633 base::ListValue* result_list = NULL; | 637 base::ListValue* result_list = NULL; |
| 634 ASSERT_TRUE(result->GetAsList(&result_list)); | 638 ASSERT_TRUE(result->GetAsList(&result_list)); |
| 635 ASSERT_EQ(1UL, result_list->GetSize()); | 639 ASSERT_EQ(1UL, result_list->GetSize()); |
| 636 base::DictionaryValue* item_value = NULL; | 640 base::DictionaryValue* item_value = NULL; |
| 637 ASSERT_TRUE(result_list->GetDictionary(0, &item_value)); | 641 ASSERT_TRUE(result_list->GetDictionary(0, &item_value)); |
| 638 int item_id = -1; | 642 int item_id = -1; |
| 639 ASSERT_TRUE(item_value->GetInteger("id", &item_id)); | 643 ASSERT_TRUE(item_value->GetInteger("id", &item_id)); |
| 640 ASSERT_EQ(0, item_id); | 644 ASSERT_EQ(0, item_id); |
| 641 } | 645 } |
| 642 | 646 |
| 643 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, | 647 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, |
| 644 DownloadsApi_SearchIdAndFilename) { | 648 DownloadExtensionTest_SearchIdAndFilename) { |
| 645 DownloadManager::DownloadVector items; | 649 DownloadManager::DownloadVector items; |
| 646 CreateSlowTestDownloads(2, &items); | 650 CreateSlowTestDownloads(2, &items); |
| 647 ScopedItemVectorCanceller delete_items(&items); | 651 ScopedItemVectorCanceller delete_items(&items); |
| 648 | 652 |
| 649 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( | 653 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( |
| 650 new DownloadsSearchFunction(), "[{\"id\": 0,\"filename\": \"foobar\"}]")); | 654 new DownloadsSearchFunction(), "[{\"id\": 0,\"filename\": \"foobar\"}]")); |
| 651 ASSERT_TRUE(result.get()); | 655 ASSERT_TRUE(result.get()); |
| 652 base::ListValue* result_list = NULL; | 656 base::ListValue* result_list = NULL; |
| 653 ASSERT_TRUE(result->GetAsList(&result_list)); | 657 ASSERT_TRUE(result->GetAsList(&result_list)); |
| 654 ASSERT_EQ(0UL, result_list->GetSize()); | 658 ASSERT_EQ(0UL, result_list->GetSize()); |
| 655 } | 659 } |
| 656 | 660 |
| 657 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, DownloadsApi_SearchOrderBy) { | 661 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, |
| 662 DownloadExtensionTest_SearchOrderBy) { |
| 658 const HistoryDownloadInfo kHistoryInfo[] = { | 663 const HistoryDownloadInfo kHistoryInfo[] = { |
| 659 { FILE_PATH_LITERAL("zzz"), | 664 { FILE_PATH_LITERAL("zzz"), |
| 660 DownloadItem::COMPLETE, | 665 DownloadItem::COMPLETE, |
| 661 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS }, | 666 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS }, |
| 662 { FILE_PATH_LITERAL("baz"), | 667 { FILE_PATH_LITERAL("baz"), |
| 663 DownloadItem::COMPLETE, | 668 DownloadItem::COMPLETE, |
| 664 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS } | 669 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS } |
| 665 }; | 670 }; |
| 666 DownloadManager::DownloadVector items; | 671 DownloadManager::DownloadVector items; |
| 667 ASSERT_TRUE(CreateHistoryDownloads(kHistoryInfo, arraysize(kHistoryInfo), | 672 ASSERT_TRUE(CreateHistoryDownloads(kHistoryInfo, arraysize(kHistoryInfo), |
| 668 &items)); | 673 &items)); |
| 669 | 674 |
| 670 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( | 675 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( |
| 671 new DownloadsSearchFunction(), "[{\"orderBy\": \"filename\"}]")); | 676 new DownloadsSearchFunction(), "[{\"orderBy\": \"filename\"}]")); |
| 672 ASSERT_TRUE(result.get()); | 677 ASSERT_TRUE(result.get()); |
| 673 base::ListValue* result_list = NULL; | 678 base::ListValue* result_list = NULL; |
| 674 ASSERT_TRUE(result->GetAsList(&result_list)); | 679 ASSERT_TRUE(result->GetAsList(&result_list)); |
| 675 ASSERT_EQ(2UL, result_list->GetSize()); | 680 ASSERT_EQ(2UL, result_list->GetSize()); |
| 676 base::DictionaryValue* item0_value = NULL; | 681 base::DictionaryValue* item0_value = NULL; |
| 677 base::DictionaryValue* item1_value = NULL; | 682 base::DictionaryValue* item1_value = NULL; |
| 678 ASSERT_TRUE(result_list->GetDictionary(0, &item0_value)); | 683 ASSERT_TRUE(result_list->GetDictionary(0, &item0_value)); |
| 679 ASSERT_TRUE(result_list->GetDictionary(1, &item1_value)); | 684 ASSERT_TRUE(result_list->GetDictionary(1, &item1_value)); |
| 680 std::string item0_name, item1_name; | 685 std::string item0_name, item1_name; |
| 681 ASSERT_TRUE(item0_value->GetString("filename", &item0_name)); | 686 ASSERT_TRUE(item0_value->GetString("filename", &item0_name)); |
| 682 ASSERT_TRUE(item1_value->GetString("filename", &item1_name)); | 687 ASSERT_TRUE(item1_value->GetString("filename", &item1_name)); |
| 683 ASSERT_GT(items[0]->GetFullPath().value(), items[1]->GetFullPath().value()); | 688 ASSERT_GT(items[0]->GetFullPath().value(), items[1]->GetFullPath().value()); |
| 684 ASSERT_LT(item0_name, item1_name); | 689 ASSERT_LT(item0_name, item1_name); |
| 685 } | 690 } |
| 686 | 691 |
| 687 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, DownloadsApi_SearchOrderByEmpty) { | 692 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, |
| 693 DownloadExtensionTest_SearchOrderByEmpty) { |
| 688 const HistoryDownloadInfo kHistoryInfo[] = { | 694 const HistoryDownloadInfo kHistoryInfo[] = { |
| 689 { FILE_PATH_LITERAL("zzz"), | 695 { FILE_PATH_LITERAL("zzz"), |
| 690 DownloadItem::COMPLETE, | 696 DownloadItem::COMPLETE, |
| 691 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS }, | 697 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS }, |
| 692 { FILE_PATH_LITERAL("baz"), | 698 { FILE_PATH_LITERAL("baz"), |
| 693 DownloadItem::COMPLETE, | 699 DownloadItem::COMPLETE, |
| 694 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS } | 700 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS } |
| 695 }; | 701 }; |
| 696 DownloadManager::DownloadVector items; | 702 DownloadManager::DownloadVector items; |
| 697 ASSERT_TRUE(CreateHistoryDownloads(kHistoryInfo, arraysize(kHistoryInfo), | 703 ASSERT_TRUE(CreateHistoryDownloads(kHistoryInfo, arraysize(kHistoryInfo), |
| 698 &items)); | 704 &items)); |
| 699 | 705 |
| 700 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( | 706 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( |
| 701 new DownloadsSearchFunction(), "[{\"orderBy\": \"\"}]")); | 707 new DownloadsSearchFunction(), "[{\"orderBy\": \"\"}]")); |
| 702 ASSERT_TRUE(result.get()); | 708 ASSERT_TRUE(result.get()); |
| 703 base::ListValue* result_list = NULL; | 709 base::ListValue* result_list = NULL; |
| 704 ASSERT_TRUE(result->GetAsList(&result_list)); | 710 ASSERT_TRUE(result->GetAsList(&result_list)); |
| 705 ASSERT_EQ(2UL, result_list->GetSize()); | 711 ASSERT_EQ(2UL, result_list->GetSize()); |
| 706 base::DictionaryValue* item0_value = NULL; | 712 base::DictionaryValue* item0_value = NULL; |
| 707 base::DictionaryValue* item1_value = NULL; | 713 base::DictionaryValue* item1_value = NULL; |
| 708 ASSERT_TRUE(result_list->GetDictionary(0, &item0_value)); | 714 ASSERT_TRUE(result_list->GetDictionary(0, &item0_value)); |
| 709 ASSERT_TRUE(result_list->GetDictionary(1, &item1_value)); | 715 ASSERT_TRUE(result_list->GetDictionary(1, &item1_value)); |
| 710 std::string item0_name, item1_name; | 716 std::string item0_name, item1_name; |
| 711 ASSERT_TRUE(item0_value->GetString("filename", &item0_name)); | 717 ASSERT_TRUE(item0_value->GetString("filename", &item0_name)); |
| 712 ASSERT_TRUE(item1_value->GetString("filename", &item1_name)); | 718 ASSERT_TRUE(item1_value->GetString("filename", &item1_name)); |
| 713 ASSERT_GT(items[0]->GetFullPath().value(), items[1]->GetFullPath().value()); | 719 ASSERT_GT(items[0]->GetFullPath().value(), items[1]->GetFullPath().value()); |
| 714 ASSERT_GT(item0_name, item1_name); | 720 ASSERT_GT(item0_name, item1_name); |
| 715 } | 721 } |
| 716 | 722 |
| 717 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, DownloadsApi_SearchDanger) { | 723 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, |
| 724 DownloadExtensionTest_SearchDanger) { |
| 718 const HistoryDownloadInfo kHistoryInfo[] = { | 725 const HistoryDownloadInfo kHistoryInfo[] = { |
| 719 { FILE_PATH_LITERAL("zzz"), | 726 { FILE_PATH_LITERAL("zzz"), |
| 720 DownloadItem::COMPLETE, | 727 DownloadItem::COMPLETE, |
| 721 content::DOWNLOAD_DANGER_TYPE_DANGEROUS_CONTENT }, | 728 content::DOWNLOAD_DANGER_TYPE_DANGEROUS_CONTENT }, |
| 722 { FILE_PATH_LITERAL("baz"), | 729 { FILE_PATH_LITERAL("baz"), |
| 723 DownloadItem::COMPLETE, | 730 DownloadItem::COMPLETE, |
| 724 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS } | 731 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS } |
| 725 }; | 732 }; |
| 726 DownloadManager::DownloadVector items; | 733 DownloadManager::DownloadVector items; |
| 727 ASSERT_TRUE(CreateHistoryDownloads(kHistoryInfo, arraysize(kHistoryInfo), | 734 ASSERT_TRUE(CreateHistoryDownloads(kHistoryInfo, arraysize(kHistoryInfo), |
| 728 &items)); | 735 &items)); |
| 729 | 736 |
| 730 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( | 737 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( |
| 731 new DownloadsSearchFunction(), "[{\"danger\": \"content\"}]")); | 738 new DownloadsSearchFunction(), "[{\"danger\": \"content\"}]")); |
| 732 ASSERT_TRUE(result.get()); | 739 ASSERT_TRUE(result.get()); |
| 733 base::ListValue* result_list = NULL; | 740 base::ListValue* result_list = NULL; |
| 734 ASSERT_TRUE(result->GetAsList(&result_list)); | 741 ASSERT_TRUE(result->GetAsList(&result_list)); |
| 735 ASSERT_EQ(1UL, result_list->GetSize()); | 742 ASSERT_EQ(1UL, result_list->GetSize()); |
| 736 } | 743 } |
| 737 | 744 |
| 738 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, DownloadsApi_SearchState) { | 745 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, |
| 746 DownloadExtensionTest_SearchState) { |
| 739 DownloadManager::DownloadVector items; | 747 DownloadManager::DownloadVector items; |
| 740 CreateSlowTestDownloads(2, &items); | 748 CreateSlowTestDownloads(2, &items); |
| 741 ScopedItemVectorCanceller delete_items(&items); | 749 ScopedItemVectorCanceller delete_items(&items); |
| 742 | 750 |
| 743 items[0]->Cancel(true); | 751 items[0]->Cancel(true); |
| 744 | 752 |
| 745 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( | 753 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( |
| 746 new DownloadsSearchFunction(), "[{\"state\": \"in_progress\"}]")); | 754 new DownloadsSearchFunction(), "[{\"state\": \"in_progress\"}]")); |
| 747 ASSERT_TRUE(result.get()); | 755 ASSERT_TRUE(result.get()); |
| 748 base::ListValue* result_list = NULL; | 756 base::ListValue* result_list = NULL; |
| 749 ASSERT_TRUE(result->GetAsList(&result_list)); | 757 ASSERT_TRUE(result->GetAsList(&result_list)); |
| 750 ASSERT_EQ(1UL, result_list->GetSize()); | 758 ASSERT_EQ(1UL, result_list->GetSize()); |
| 751 } | 759 } |
| 752 | 760 |
| 753 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, DownloadsApi_SearchLimit) { | 761 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, |
| 762 DownloadExtensionTest_SearchLimit) { |
| 754 DownloadManager::DownloadVector items; | 763 DownloadManager::DownloadVector items; |
| 755 CreateSlowTestDownloads(2, &items); | 764 CreateSlowTestDownloads(2, &items); |
| 756 ScopedItemVectorCanceller delete_items(&items); | 765 ScopedItemVectorCanceller delete_items(&items); |
| 757 | 766 |
| 758 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( | 767 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( |
| 759 new DownloadsSearchFunction(), "[{\"limit\": 1}]")); | 768 new DownloadsSearchFunction(), "[{\"limit\": 1}]")); |
| 760 ASSERT_TRUE(result.get()); | 769 ASSERT_TRUE(result.get()); |
| 761 base::ListValue* result_list = NULL; | 770 base::ListValue* result_list = NULL; |
| 762 ASSERT_TRUE(result->GetAsList(&result_list)); | 771 ASSERT_TRUE(result->GetAsList(&result_list)); |
| 763 ASSERT_EQ(1UL, result_list->GetSize()); | 772 ASSERT_EQ(1UL, result_list->GetSize()); |
| 764 } | 773 } |
| 765 | 774 |
| 766 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, DownloadsApi_SearchInvalid) { | 775 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, |
| 776 DownloadExtensionTest_SearchInvalid) { |
| 767 std::string error = RunFunctionAndReturnError( | 777 std::string error = RunFunctionAndReturnError( |
| 768 new DownloadsSearchFunction(), "[{\"filenameRegex\": \"(\"}]"); | 778 new DownloadsSearchFunction(), "[{\"filenameRegex\": \"(\"}]"); |
| 769 EXPECT_STREQ(download_extension_errors::kInvalidFilterError, | 779 EXPECT_STREQ(download_extension_errors::kInvalidFilterError, |
| 770 error.c_str()); | 780 error.c_str()); |
| 771 error = RunFunctionAndReturnError( | 781 error = RunFunctionAndReturnError( |
| 772 new DownloadsSearchFunction(), "[{\"danger\": \"goat\"}]"); | 782 new DownloadsSearchFunction(), "[{\"danger\": \"goat\"}]"); |
| 773 EXPECT_STREQ(download_extension_errors::kInvalidDangerTypeError, | 783 EXPECT_STREQ(download_extension_errors::kInvalidDangerTypeError, |
| 774 error.c_str()); | 784 error.c_str()); |
| 775 error = RunFunctionAndReturnError( | 785 error = RunFunctionAndReturnError( |
| 776 new DownloadsSearchFunction(), "[{\"state\": \"goat\"}]"); | 786 new DownloadsSearchFunction(), "[{\"state\": \"goat\"}]"); |
| 777 EXPECT_STREQ(download_extension_errors::kInvalidStateError, | 787 EXPECT_STREQ(download_extension_errors::kInvalidStateError, |
| 778 error.c_str()); | 788 error.c_str()); |
| 779 error = RunFunctionAndReturnError( | 789 error = RunFunctionAndReturnError( |
| 780 new DownloadsSearchFunction(), "[{\"orderBy\": \"goat\"}]"); | 790 new DownloadsSearchFunction(), "[{\"orderBy\": \"goat\"}]"); |
| 781 EXPECT_STREQ(download_extension_errors::kInvalidOrderByError, | 791 EXPECT_STREQ(download_extension_errors::kInvalidOrderByError, |
| 782 error.c_str()); | 792 error.c_str()); |
| 783 error = RunFunctionAndReturnError( | 793 error = RunFunctionAndReturnError( |
| 784 new DownloadsSearchFunction(), "[{\"limit\": -1}]"); | 794 new DownloadsSearchFunction(), "[{\"limit\": -1}]"); |
| 785 EXPECT_STREQ(download_extension_errors::kInvalidQueryLimit, | 795 EXPECT_STREQ(download_extension_errors::kInvalidQueryLimit, |
| 786 error.c_str()); | 796 error.c_str()); |
| 787 } | 797 } |
| 788 | 798 |
| 789 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, DownloadsApi_SearchPlural) { | 799 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, |
| 800 DownloadExtensionTest_SearchPlural) { |
| 790 const HistoryDownloadInfo kHistoryInfo[] = { | 801 const HistoryDownloadInfo kHistoryInfo[] = { |
| 791 { FILE_PATH_LITERAL("aaa"), | 802 { FILE_PATH_LITERAL("aaa"), |
| 792 DownloadItem::CANCELLED, | 803 DownloadItem::CANCELLED, |
| 793 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS }, | 804 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS }, |
| 794 { FILE_PATH_LITERAL("zzz"), | 805 { FILE_PATH_LITERAL("zzz"), |
| 795 DownloadItem::COMPLETE, | 806 DownloadItem::COMPLETE, |
| 796 content::DOWNLOAD_DANGER_TYPE_DANGEROUS_CONTENT }, | 807 content::DOWNLOAD_DANGER_TYPE_DANGEROUS_CONTENT }, |
| 797 { FILE_PATH_LITERAL("baz"), | 808 { FILE_PATH_LITERAL("baz"), |
| 798 DownloadItem::COMPLETE, | 809 DownloadItem::COMPLETE, |
| 799 content::DOWNLOAD_DANGER_TYPE_DANGEROUS_CONTENT }, | 810 content::DOWNLOAD_DANGER_TYPE_DANGEROUS_CONTENT }, |
| (...skipping 13 matching lines...) Expand all Loading... |
| 813 ASSERT_TRUE(result->GetAsList(&result_list)); | 824 ASSERT_TRUE(result->GetAsList(&result_list)); |
| 814 ASSERT_EQ(1UL, result_list->GetSize()); | 825 ASSERT_EQ(1UL, result_list->GetSize()); |
| 815 base::DictionaryValue* item_value = NULL; | 826 base::DictionaryValue* item_value = NULL; |
| 816 ASSERT_TRUE(result_list->GetDictionary(0, &item_value)); | 827 ASSERT_TRUE(result_list->GetDictionary(0, &item_value)); |
| 817 FilePath::StringType item_name; | 828 FilePath::StringType item_name; |
| 818 ASSERT_TRUE(item_value->GetString("filename", &item_name)); | 829 ASSERT_TRUE(item_value->GetString("filename", &item_name)); |
| 819 ASSERT_EQ(items[2]->GetFullPath().value(), item_name); | 830 ASSERT_EQ(items[2]->GetFullPath().value(), item_name); |
| 820 } | 831 } |
| 821 | 832 |
| 822 IN_PROC_BROWSER_TEST_F(DownloadExtensionTestIncognito, | 833 IN_PROC_BROWSER_TEST_F(DownloadExtensionTestIncognito, |
| 823 DownloadsApi_SearchIncognito) { | 834 DownloadExtensionTest_SearchPauseResumeCancelGetFileIconIncognito) { |
| 824 scoped_ptr<base::Value> result_value; | 835 scoped_ptr<base::Value> result_value; |
| 825 base::ListValue* result_list = NULL; | 836 base::ListValue* result_list = NULL; |
| 826 base::DictionaryValue* result_dict = NULL; | 837 base::DictionaryValue* result_dict = NULL; |
| 827 FilePath::StringType filename; | 838 FilePath::StringType filename; |
| 828 bool is_incognito = false; | 839 bool is_incognito = false; |
| 829 std::string error; | 840 std::string error; |
| 830 std::string on_item_arg; | 841 std::string on_item_arg; |
| 831 std::string off_item_arg; | 842 std::string off_item_arg; |
| 832 std::string result_string; | 843 std::string result_string; |
| 833 | 844 |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 946 EXPECT_TRUE(off_item->IsCancelled()); | 957 EXPECT_TRUE(off_item->IsCancelled()); |
| 947 error = RunFunctionAndReturnError(new DownloadsPauseFunction(), | 958 error = RunFunctionAndReturnError(new DownloadsPauseFunction(), |
| 948 off_item_arg); | 959 off_item_arg); |
| 949 EXPECT_STREQ(download_extension_errors::kInvalidOperationError, | 960 EXPECT_STREQ(download_extension_errors::kInvalidOperationError, |
| 950 error.c_str()); | 961 error.c_str()); |
| 951 error = RunFunctionAndReturnError(new DownloadsResumeFunction(), | 962 error = RunFunctionAndReturnError(new DownloadsResumeFunction(), |
| 952 off_item_arg); | 963 off_item_arg); |
| 953 EXPECT_STREQ(download_extension_errors::kInvalidOperationError, | 964 EXPECT_STREQ(download_extension_errors::kInvalidOperationError, |
| 954 error.c_str()); | 965 error.c_str()); |
| 955 } | 966 } |
| OLD | NEW |