| 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" | 10 #include "chrome/browser/download/download_extension_api.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 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" |
| 25 #include "content/public/browser/download_persistent_store_info.h" | 25 #include "content/public/browser/download_persistent_store_info.h" |
| 26 #include "content/test/net/url_request_slow_download_job.h" | 26 #include "content/test/net/url_request_slow_download_job.h" |
| 27 #include "net/base/data_url.h" | 27 #include "net/base/data_url.h" |
| 28 #include "net/base/net_util.h" | 28 #include "net/base/net_util.h" |
| 29 #include "ui/gfx/codec/png_codec.h" | 29 #include "ui/gfx/codec/png_codec.h" |
| 30 | 30 |
| 31 using content::BrowserContext; |
| 31 using content::BrowserThread; | 32 using content::BrowserThread; |
| 32 using content::DownloadItem; | 33 using content::DownloadItem; |
| 33 using content::DownloadManager; | 34 using content::DownloadManager; |
| 34 using content::DownloadPersistentStoreInfo; | 35 using content::DownloadPersistentStoreInfo; |
| 35 | 36 |
| 36 namespace { | 37 namespace { |
| 37 | 38 |
| 38 // Comparator that orders download items by their ID. Can be used with | 39 // Comparator that orders download items by their ID. Can be used with |
| 39 // std::sort. | 40 // std::sort. |
| 40 struct DownloadIdComparator { | 41 struct DownloadIdComparator { |
| (...skipping 27 matching lines...) Expand all Loading... |
| 68 BrowserThread::IO, FROM_HERE, | 69 BrowserThread::IO, FROM_HERE, |
| 69 base::Bind(&chrome_browser_net::SetUrlRequestMocksEnabled, true)); | 70 base::Bind(&chrome_browser_net::SetUrlRequestMocksEnabled, true)); |
| 70 InProcessBrowserTest::SetUpOnMainThread(); | 71 InProcessBrowserTest::SetUpOnMainThread(); |
| 71 CreateAndSetDownloadsDirectory(); | 72 CreateAndSetDownloadsDirectory(); |
| 72 current_browser()->profile()->GetPrefs()->SetBoolean( | 73 current_browser()->profile()->GetPrefs()->SetBoolean( |
| 73 prefs::kPromptForDownload, false); | 74 prefs::kPromptForDownload, false); |
| 74 GetDownloadManager()->RemoveAllDownloads(); | 75 GetDownloadManager()->RemoveAllDownloads(); |
| 75 } | 76 } |
| 76 | 77 |
| 77 virtual DownloadManager* GetDownloadManager() { | 78 virtual DownloadManager* GetDownloadManager() { |
| 78 DownloadService* download_service = | 79 return BrowserContext::GetDownloadManager(current_browser()->profile()); |
| 79 DownloadServiceFactory::GetForProfile(current_browser()->profile()); | |
| 80 return download_service->GetDownloadManager(); | |
| 81 } | 80 } |
| 82 | 81 |
| 83 // Creates a set of history downloads based on the provided |history_info| | 82 // Creates a set of history downloads based on the provided |history_info| |
| 84 // array. |count| is the number of elements in |history_info|. On success, | 83 // array. |count| is the number of elements in |history_info|. On success, |
| 85 // |items| will contain |count| DownloadItems in the order that they were | 84 // |items| will contain |count| DownloadItems in the order that they were |
| 86 // specified in |history_info|. Returns true on success and false otherwise. | 85 // specified in |history_info|. Returns true on success and false otherwise. |
| 87 bool CreateHistoryDownloads(const HistoryDownloadInfo* history_info, | 86 bool CreateHistoryDownloads(const HistoryDownloadInfo* history_info, |
| 88 size_t count, | 87 size_t count, |
| 89 DownloadManager::DownloadVector* items) { | 88 DownloadManager::DownloadVector* items) { |
| 90 DownloadIdComparator download_id_comparator; | 89 DownloadIdComparator download_id_comparator; |
| (...skipping 856 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 947 EXPECT_TRUE(off_item->IsCancelled()); | 946 EXPECT_TRUE(off_item->IsCancelled()); |
| 948 error = RunFunctionAndReturnError(new DownloadsPauseFunction(), | 947 error = RunFunctionAndReturnError(new DownloadsPauseFunction(), |
| 949 off_item_arg); | 948 off_item_arg); |
| 950 EXPECT_STREQ(download_extension_errors::kInvalidOperationError, | 949 EXPECT_STREQ(download_extension_errors::kInvalidOperationError, |
| 951 error.c_str()); | 950 error.c_str()); |
| 952 error = RunFunctionAndReturnError(new DownloadsResumeFunction(), | 951 error = RunFunctionAndReturnError(new DownloadsResumeFunction(), |
| 953 off_item_arg); | 952 off_item_arg); |
| 954 EXPECT_STREQ(download_extension_errors::kInvalidOperationError, | 953 EXPECT_STREQ(download_extension_errors::kInvalidOperationError, |
| 955 error.c_str()); | 954 error.c_str()); |
| 956 } | 955 } |
| OLD | NEW |