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 <stddef.h> |
| 6 #include <stdint.h> |
| 7 |
5 #include <vector> | 8 #include <vector> |
6 | 9 |
| 10 #include "base/macros.h" |
7 #include "base/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" |
8 #include "base/rand_util.h" | 12 #include "base/rand_util.h" |
9 #include "base/stl_util.h" | 13 #include "base/stl_util.h" |
10 #include "chrome/browser/download/download_history.h" | 14 #include "chrome/browser/download/download_history.h" |
11 #include "components/history/content/browser/download_constants_utils.h" | 15 #include "components/history/content/browser/download_constants_utils.h" |
12 #include "components/history/core/browser/download_constants.h" | 16 #include "components/history/core/browser/download_constants.h" |
13 #include "components/history/core/browser/download_row.h" | 17 #include "components/history/core/browser/download_row.h" |
14 #include "components/history/core/browser/history_service.h" | 18 #include "components/history/core/browser/history_service.h" |
15 #include "content/public/test/mock_download_item.h" | 19 #include "content/public/test/mock_download_item.h" |
16 #include "content/public/test/mock_download_manager.h" | 20 #include "content/public/test/mock_download_manager.h" |
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
339 } | 343 } |
340 | 344 |
341 void InitBasicItem(const base::FilePath::CharType* path, | 345 void InitBasicItem(const base::FilePath::CharType* path, |
342 const char* url_string, | 346 const char* url_string, |
343 const char* referrer_string, | 347 const char* referrer_string, |
344 history::DownloadRow* info) { | 348 history::DownloadRow* info) { |
345 GURL url(url_string); | 349 GURL url(url_string); |
346 GURL referrer(referrer_string); | 350 GURL referrer(referrer_string); |
347 std::vector<GURL> url_chain; | 351 std::vector<GURL> url_chain; |
348 url_chain.push_back(url); | 352 url_chain.push_back(url); |
349 InitItem(static_cast<uint32>(items_.size() + 1), | 353 InitItem(static_cast<uint32_t>(items_.size() + 1), base::FilePath(path), |
350 base::FilePath(path), | 354 base::FilePath(path), url_chain, referrer, |
351 base::FilePath(path), | 355 "application/octet-stream", "application/octet-stream", |
352 url_chain, | |
353 referrer, | |
354 "application/octet-stream", | |
355 "application/octet-stream", | |
356 (base::Time::Now() - base::TimeDelta::FromMinutes(10)), | 356 (base::Time::Now() - base::TimeDelta::FromMinutes(10)), |
357 (base::Time::Now() - base::TimeDelta::FromMinutes(1)), | 357 (base::Time::Now() - base::TimeDelta::FromMinutes(1)), "Etag", |
358 "Etag", | 358 "abc", 100, 100, content::DownloadItem::COMPLETE, |
359 "abc", | |
360 100, | |
361 100, | |
362 content::DownloadItem::COMPLETE, | |
363 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, | 359 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, |
364 content::DOWNLOAD_INTERRUPT_REASON_NONE, | 360 content::DOWNLOAD_INTERRUPT_REASON_NONE, false, std::string(), |
365 false, | 361 std::string(), info); |
366 std::string(), | |
367 std::string(), | |
368 info); | |
369 } | 362 } |
370 | 363 |
371 void InitItem( | 364 void InitItem(uint32_t id, |
372 uint32 id, | 365 const base::FilePath& current_path, |
373 const base::FilePath& current_path, | 366 const base::FilePath& target_path, |
374 const base::FilePath& target_path, | 367 const std::vector<GURL>& url_chain, |
375 const std::vector<GURL>& url_chain, | 368 const GURL& referrer, |
376 const GURL& referrer, | 369 const std::string& mime_type, |
377 const std::string& mime_type, | 370 const std::string& original_mime_type, |
378 const std::string& original_mime_type, | 371 const base::Time& start_time, |
379 const base::Time& start_time, | 372 const base::Time& end_time, |
380 const base::Time& end_time, | 373 const std::string& etag, |
381 const std::string& etag, | 374 const std::string& last_modified, |
382 const std::string& last_modified, | 375 int64_t received_bytes, |
383 int64 received_bytes, | 376 int64_t total_bytes, |
384 int64 total_bytes, | 377 content::DownloadItem::DownloadState state, |
385 content::DownloadItem::DownloadState state, | 378 content::DownloadDangerType danger_type, |
386 content::DownloadDangerType danger_type, | 379 content::DownloadInterruptReason interrupt_reason, |
387 content::DownloadInterruptReason interrupt_reason, | 380 bool opened, |
388 bool opened, | 381 const std::string& by_extension_id, |
389 const std::string& by_extension_id, | 382 const std::string& by_extension_name, |
390 const std::string& by_extension_name, | 383 history::DownloadRow* info) { |
391 history::DownloadRow* info) { | |
392 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 384 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
393 | 385 |
394 size_t index = items_.size(); | 386 size_t index = items_.size(); |
395 StrictMockDownloadItem* mock_item = new StrictMockDownloadItem(); | 387 StrictMockDownloadItem* mock_item = new StrictMockDownloadItem(); |
396 items_.push_back(mock_item); | 388 items_.push_back(mock_item); |
397 | 389 |
398 info->current_path = current_path; | 390 info->current_path = current_path; |
399 info->target_path = target_path; | 391 info->target_path = target_path; |
400 info->url_chain = url_chain; | 392 info->url_chain = url_chain; |
401 info->referrer_url = referrer; | 393 info->referrer_url = referrer; |
(...skipping 459 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
861 FinishCreateDownload(); | 853 FinishCreateDownload(); |
862 EXPECT_TRUE(DownloadHistory::IsPersisted(&item(0))); | 854 EXPECT_TRUE(DownloadHistory::IsPersisted(&item(0))); |
863 | 855 |
864 // ItemAdded should call OnDownloadUpdated, which should detect that the item | 856 // ItemAdded should call OnDownloadUpdated, which should detect that the item |
865 // changed while it was being added and call UpdateDownload immediately. | 857 // changed while it was being added and call UpdateDownload immediately. |
866 info.opened = true; | 858 info.opened = true; |
867 ExpectDownloadUpdated(info); | 859 ExpectDownloadUpdated(info); |
868 } | 860 } |
869 | 861 |
870 } // anonymous namespace | 862 } // anonymous namespace |
OLD | NEW |