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