| 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/files/scoped_temp_dir.h" |
| 8 #include "base/json/json_reader.h" | 9 #include "base/json/json_reader.h" |
| 9 #include "base/json/json_writer.h" | 10 #include "base/json/json_writer.h" |
| 10 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
| 11 #include "base/scoped_temp_dir.h" | |
| 12 #include "base/stl_util.h" | 12 #include "base/stl_util.h" |
| 13 #include "base/stringprintf.h" | 13 #include "base/stringprintf.h" |
| 14 #include "chrome/browser/download/download_file_icon_extractor.h" | 14 #include "chrome/browser/download/download_file_icon_extractor.h" |
| 15 #include "chrome/browser/download/download_service.h" | 15 #include "chrome/browser/download/download_service.h" |
| 16 #include "chrome/browser/download/download_service_factory.h" | 16 #include "chrome/browser/download/download_service_factory.h" |
| 17 #include "chrome/browser/download/download_test_file_chooser_observer.h" | 17 #include "chrome/browser/download/download_test_file_chooser_observer.h" |
| 18 #include "chrome/browser/extensions/api/downloads/downloads_api.h" | 18 #include "chrome/browser/extensions/api/downloads/downloads_api.h" |
| 19 #include "chrome/browser/extensions/event_names.h" | 19 #include "chrome/browser/extensions/event_names.h" |
| 20 #include "chrome/browser/extensions/extension_apitest.h" | 20 #include "chrome/browser/extensions/extension_apitest.h" |
| 21 #include "chrome/browser/extensions/extension_function_test_utils.h" | 21 #include "chrome/browser/extensions/extension_function_test_utils.h" |
| (...skipping 506 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 528 } | 528 } |
| 529 } | 529 } |
| 530 | 530 |
| 531 void CreateAndSetDownloadsDirectory() { | 531 void CreateAndSetDownloadsDirectory() { |
| 532 ASSERT_TRUE(downloads_directory_.CreateUniqueTempDir()); | 532 ASSERT_TRUE(downloads_directory_.CreateUniqueTempDir()); |
| 533 current_browser()->profile()->GetPrefs()->SetFilePath( | 533 current_browser()->profile()->GetPrefs()->SetFilePath( |
| 534 prefs::kDownloadDefaultDirectory, | 534 prefs::kDownloadDefaultDirectory, |
| 535 downloads_directory_.path()); | 535 downloads_directory_.path()); |
| 536 } | 536 } |
| 537 | 537 |
| 538 ScopedTempDir downloads_directory_; | 538 base::ScopedTempDir downloads_directory_; |
| 539 const extensions::Extension* extension_; | 539 const extensions::Extension* extension_; |
| 540 Browser* incognito_browser_; | 540 Browser* incognito_browser_; |
| 541 Browser* current_browser_; | 541 Browser* current_browser_; |
| 542 scoped_ptr<DownloadsEventsListener> events_listener_; | 542 scoped_ptr<DownloadsEventsListener> events_listener_; |
| 543 | 543 |
| 544 DISALLOW_COPY_AND_ASSIGN(DownloadExtensionTest); | 544 DISALLOW_COPY_AND_ASSIGN(DownloadExtensionTest); |
| 545 }; | 545 }; |
| 546 | 546 |
| 547 class MockIconExtractorImpl : public DownloadFileIconExtractor { | 547 class MockIconExtractorImpl : public DownloadFileIconExtractor { |
| 548 public: | 548 public: |
| (...skipping 462 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1011 std::string result_string; | 1011 std::string result_string; |
| 1012 // Use a MockIconExtractorImpl to test if the correct path is being passed | 1012 // Use a MockIconExtractorImpl to test if the correct path is being passed |
| 1013 // into the DownloadFileIconExtractor. | 1013 // into the DownloadFileIconExtractor. |
| 1014 EXPECT_TRUE(RunFunctionAndReturnString(MockedGetFileIconFunction( | 1014 EXPECT_TRUE(RunFunctionAndReturnString(MockedGetFileIconFunction( |
| 1015 (*iter)->GetFullPath(), IconLoader::NORMAL, "hello"), | 1015 (*iter)->GetFullPath(), IconLoader::NORMAL, "hello"), |
| 1016 base::StringPrintf("[%d, {\"size\": 32}]", (*iter)->GetId()), | 1016 base::StringPrintf("[%d, {\"size\": 32}]", (*iter)->GetId()), |
| 1017 &result_string)); | 1017 &result_string)); |
| 1018 EXPECT_STREQ("hello", result_string.c_str()); | 1018 EXPECT_STREQ("hello", result_string.c_str()); |
| 1019 } | 1019 } |
| 1020 | 1020 |
| 1021 // The temporary files should be cleaned up when the ScopedTempDir is removed. | 1021 // The temporary files should be cleaned up when the base::ScopedTempDir is re
moved. |
| 1022 } | 1022 } |
| 1023 | 1023 |
| 1024 // Test passing the empty query to search(). | 1024 // Test passing the empty query to search(). |
| 1025 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, | 1025 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, |
| 1026 DownloadExtensionTest_SearchEmptyQuery) { | 1026 DownloadExtensionTest_SearchEmptyQuery) { |
| 1027 ScopedCancellingItem item(CreateSlowTestDownload()); | 1027 ScopedCancellingItem item(CreateSlowTestDownload()); |
| 1028 ASSERT_TRUE(item.get()); | 1028 ASSERT_TRUE(item.get()); |
| 1029 | 1029 |
| 1030 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( | 1030 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( |
| 1031 new DownloadsSearchFunction(), "[{}]")); | 1031 new DownloadsSearchFunction(), "[{}]")); |
| (...skipping 1051 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2083 " \"state\": {" | 2083 " \"state\": {" |
| 2084 " \"previous\": \"in_progress\"," | 2084 " \"previous\": \"in_progress\"," |
| 2085 " \"current\": \"complete\"}}]", | 2085 " \"current\": \"complete\"}}]", |
| 2086 result_id, | 2086 result_id, |
| 2087 GetFilename("on_record.txt.crdownload").c_str(), | 2087 GetFilename("on_record.txt.crdownload").c_str(), |
| 2088 GetFilename("on_record.txt").c_str()))); | 2088 GetFilename("on_record.txt").c_str()))); |
| 2089 std::string disk_data; | 2089 std::string disk_data; |
| 2090 EXPECT_TRUE(file_util::ReadFileToString(item->GetFullPath(), &disk_data)); | 2090 EXPECT_TRUE(file_util::ReadFileToString(item->GetFullPath(), &disk_data)); |
| 2091 EXPECT_STREQ(kPayloadData, disk_data.c_str()); | 2091 EXPECT_STREQ(kPayloadData, disk_data.c_str()); |
| 2092 } | 2092 } |
| OLD | NEW |