Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: chrome/browser/extensions/api/downloads/downloads_api_unittest.cc

Issue 10665049: Make DownloadHistory observe manager, items (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/json/json_reader.h" 8 #include "base/json/json_reader.h"
9 #include "base/json/json_writer.h" 9 #include "base/json/json_writer.h"
10 #include "base/message_loop.h" 10 #include "base/message_loop.h"
11 #include "base/scoped_temp_dir.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"
22 #include "chrome/browser/history/download_persistent_store_info.h"
22 #include "chrome/browser/net/url_request_mock_util.h" 23 #include "chrome/browser/net/url_request_mock_util.h"
23 #include "chrome/browser/prefs/pref_service.h" 24 #include "chrome/browser/prefs/pref_service.h"
24 #include "chrome/browser/profiles/profile.h" 25 #include "chrome/browser/profiles/profile.h"
25 #include "chrome/browser/ui/browser.h" 26 #include "chrome/browser/ui/browser.h"
26 #include "chrome/browser/ui/browser_tabstrip.h" 27 #include "chrome/browser/ui/browser_tabstrip.h"
27 #include "chrome/browser/ui/tab_contents/tab_contents.h" 28 #include "chrome/browser/ui/tab_contents/tab_contents.h"
28 #include "chrome/common/chrome_notification_types.h" 29 #include "chrome/common/chrome_notification_types.h"
29 #include "chrome/common/pref_names.h" 30 #include "chrome/common/pref_names.h"
30 #include "chrome/test/base/in_process_browser_test.h" 31 #include "chrome/test/base/in_process_browser_test.h"
31 #include "chrome/test/base/ui_test_utils.h" 32 #include "chrome/test/base/ui_test_utils.h"
32 #include "content/public/browser/browser_context.h" 33 #include "content/public/browser/browser_context.h"
33 #include "content/public/browser/browser_thread.h" 34 #include "content/public/browser/browser_thread.h"
34 #include "content/public/browser/download_item.h" 35 #include "content/public/browser/download_item.h"
35 #include "content/public/browser/download_manager.h" 36 #include "content/public/browser/download_manager.h"
36 #include "content/public/browser/download_persistent_store_info.h"
37 #include "content/public/browser/notification_service.h" 37 #include "content/public/browser/notification_service.h"
38 #include "content/public/browser/web_contents.h" 38 #include "content/public/browser/web_contents.h"
39 #include "content/public/common/page_transition_types.h" 39 #include "content/public/common/page_transition_types.h"
40 #include "content/public/test/download_test_observer.h" 40 #include "content/public/test/download_test_observer.h"
41 #include "content/test/net/url_request_slow_download_job.h" 41 #include "content/test/net/url_request_slow_download_job.h"
42 #include "net/base/data_url.h" 42 #include "net/base/data_url.h"
43 #include "net/base/net_util.h" 43 #include "net/base/net_util.h"
44 #include "net/url_request/url_request.h" 44 #include "net/url_request/url_request.h"
45 #include "net/url_request/url_request_context.h" 45 #include "net/url_request/url_request_context.h"
46 #include "net/url_request/url_request_job.h" 46 #include "net/url_request/url_request_job.h"
47 #include "net/url_request/url_request_job_factory.h"
47 #include "net/url_request/url_request_job_factory_impl.h" 48 #include "net/url_request/url_request_job_factory_impl.h"
48 #include "net/url_request/url_request_job_factory.h"
49 #include "webkit/blob/blob_data.h" 49 #include "webkit/blob/blob_data.h"
50 #include "webkit/blob/blob_storage_controller.h" 50 #include "webkit/blob/blob_storage_controller.h"
51 #include "webkit/blob/blob_url_request_job.h" 51 #include "webkit/blob/blob_url_request_job.h"
52 #include "webkit/fileapi/file_system_context.h" 52 #include "webkit/fileapi/file_system_context.h"
53 #include "webkit/fileapi/file_system_operation.h" 53 #include "webkit/fileapi/file_system_operation.h"
54 #include "webkit/fileapi/file_system_url.h" 54 #include "webkit/fileapi/file_system_url.h"
55 55
56 using content::BrowserContext; 56 using content::BrowserContext;
57 using content::BrowserThread; 57 using content::BrowserThread;
58 using content::DownloadItem; 58 using content::DownloadItem;
59 using content::DownloadManager; 59 using content::DownloadManager;
60 using content::DownloadPersistentStoreInfo;
61 60
62 namespace events = extensions::event_names; 61 namespace events = extensions::event_names;
63 62
64 namespace { 63 namespace {
65 64
66 // Comparator that orders download items by their ID. Can be used with 65 // Comparator that orders download items by their ID. Can be used with
67 // std::sort. 66 // std::sort.
68 struct DownloadIdComparator { 67 struct DownloadIdComparator {
69 bool operator() (DownloadItem* first, DownloadItem* second) { 68 bool operator() (DownloadItem* first, DownloadItem* second) {
70 return first->GetId() < second->GetId(); 69 return first->GetId() < second->GetId();
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after
348 347
349 // Creates a set of history downloads based on the provided |history_info| 348 // Creates a set of history downloads based on the provided |history_info|
350 // array. |count| is the number of elements in |history_info|. On success, 349 // array. |count| is the number of elements in |history_info|. On success,
351 // |items| will contain |count| DownloadItems in the order that they were 350 // |items| will contain |count| DownloadItems in the order that they were
352 // specified in |history_info|. Returns true on success and false otherwise. 351 // specified in |history_info|. Returns true on success and false otherwise.
353 bool CreateHistoryDownloads(const HistoryDownloadInfo* history_info, 352 bool CreateHistoryDownloads(const HistoryDownloadInfo* history_info,
354 size_t count, 353 size_t count,
355 DownloadManager::DownloadVector* items) { 354 DownloadManager::DownloadVector* items) {
356 DownloadIdComparator download_id_comparator; 355 DownloadIdComparator download_id_comparator;
357 base::Time current = base::Time::Now(); 356 base::Time current = base::Time::Now();
358 std::vector<DownloadPersistentStoreInfo> entries; 357 items->clear();
359 entries.reserve(count); 358 GetOnRecordManager()->GetAllDownloads(FilePath(), items);
359 CHECK_EQ(0, static_cast<int>(items->size()));
360 for (size_t i = 0; i < count; ++i) { 360 for (size_t i = 0; i < count; ++i) {
361 DownloadPersistentStoreInfo entry( 361 DownloadItem* item = GetOnRecordManager()->CreateDownloadItem(
362 downloads_directory().Append(history_info[i].filename), 362 downloads_directory().Append(history_info[i].filename),
363 GURL(), GURL(), // URL, referrer 363 GURL(), GURL(), // URL, referrer
364 current, current, // start_time, end_time 364 current, current, // start_time, end_time
365 1, 1, // received_bytes, total_bytes 365 1, 1, // received_bytes, total_bytes
366 history_info[i].state, // state 366 history_info[i].state, // state
367 i + 1, // db_handle
368 false); // opened 367 false); // opened
369 entries.push_back(entry); 368 items->push_back(item);
370 } 369 }
371 GetOnRecordManager()->OnPersistentStoreQueryComplete(&entries);
372 GetOnRecordManager()->GetAllDownloads(FilePath(), items);
373 EXPECT_EQ(count, items->size());
374 if (count != items->size())
375 return false;
376 370
377 // Order by ID so that they are in the order that we created them. 371 // Order by ID so that they are in the order that we created them.
378 std::sort(items->begin(), items->end(), download_id_comparator); 372 std::sort(items->begin(), items->end(), download_id_comparator);
379 // Set the danger type if necessary. 373 // Set the danger type if necessary.
380 for (size_t i = 0; i < count; ++i) { 374 for (size_t i = 0; i < count; ++i) {
381 if (history_info[i].danger_type != 375 if (history_info[i].danger_type !=
382 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS) { 376 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS) {
383 EXPECT_EQ(content::DOWNLOAD_DANGER_TYPE_DANGEROUS_CONTENT, 377 EXPECT_EQ(content::DOWNLOAD_DANGER_TYPE_DANGEROUS_CONTENT,
384 history_info[i].danger_type); 378 history_info[i].danger_type);
385 items->at(i)->OnContentCheckCompleted(history_info[i].danger_type); 379 items->at(i)->OnContentCheckCompleted(history_info[i].danger_type);
(...skipping 1699 matching lines...) Expand 10 before | Expand all | Expand 10 after
2085 " \"state\": {" 2079 " \"state\": {"
2086 " \"previous\": \"in_progress\"," 2080 " \"previous\": \"in_progress\","
2087 " \"current\": \"complete\"}}]", 2081 " \"current\": \"complete\"}}]",
2088 result_id, 2082 result_id,
2089 GetFilename("on_record.txt.crdownload").c_str(), 2083 GetFilename("on_record.txt.crdownload").c_str(),
2090 GetFilename("on_record.txt").c_str()))); 2084 GetFilename("on_record.txt").c_str())));
2091 std::string disk_data; 2085 std::string disk_data;
2092 EXPECT_TRUE(file_util::ReadFileToString(item->GetFullPath(), &disk_data)); 2086 EXPECT_TRUE(file_util::ReadFileToString(item->GetFullPath(), &disk_data));
2093 EXPECT_STREQ(kPayloadData, disk_data.c_str()); 2087 EXPECT_STREQ(kPayloadData, disk_data.c_str());
2094 } 2088 }
OLDNEW
« no previous file with comments | « chrome/browser/download/save_page_browsertest.cc ('k') | chrome/browser/history/download_database.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698