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 "chrome/browser/download/download_history.h" | 5 #include "chrome/browser/download/download_history.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 #include <utility> | 9 #include <utility> |
10 #include <vector> | 10 #include <vector> |
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
228 const history::DownloadRow& row = infos->at(index); | 228 const history::DownloadRow& row = infos->at(index); |
229 content::MockDownloadManager::CreateDownloadItemAdapter adapter( | 229 content::MockDownloadManager::CreateDownloadItemAdapter adapter( |
230 row.guid, history::ToContentDownloadId(row.id), row.current_path, | 230 row.guid, history::ToContentDownloadId(row.id), row.current_path, |
231 row.target_path, row.url_chain, row.referrer_url, row.site_url, | 231 row.target_path, row.url_chain, row.referrer_url, row.site_url, |
232 row.tab_url, row.tab_referrer_url, row.mime_type, | 232 row.tab_url, row.tab_referrer_url, row.mime_type, |
233 row.original_mime_type, row.start_time, row.end_time, row.etag, | 233 row.original_mime_type, row.start_time, row.end_time, row.etag, |
234 row.last_modified, row.received_bytes, row.total_bytes, std::string(), | 234 row.last_modified, row.received_bytes, row.total_bytes, std::string(), |
235 history::ToContentDownloadState(row.state), | 235 history::ToContentDownloadState(row.state), |
236 history::ToContentDownloadDangerType(row.danger_type), | 236 history::ToContentDownloadDangerType(row.danger_type), |
237 history::ToContentDownloadInterruptReason(row.interrupt_reason), | 237 history::ToContentDownloadInterruptReason(row.interrupt_reason), |
238 row.opened, row.last_access_time, | 238 row.opened, row.last_access_time, row.visible, |
239 history::ToContentReceivedSlices(row.download_slice_info)); | 239 history::ToContentReceivedSlices(row.download_slice_info)); |
240 EXPECT_CALL(manager(), MockCreateDownloadItem(adapter)) | 240 EXPECT_CALL(manager(), MockCreateDownloadItem(adapter)) |
241 .WillOnce(DoAll( | 241 .WillOnce(DoAll( |
242 InvokeWithoutArgs( | 242 InvokeWithoutArgs( |
243 this, &DownloadHistoryTest::CallOnDownloadCreatedInOrder), | 243 this, &DownloadHistoryTest::CallOnDownloadCreatedInOrder), |
244 Return(&item(index)))); | 244 Return(&item(index)))); |
245 } | 245 } |
246 EXPECT_CALL(manager(), CheckForHistoryFilesRemoval()); | 246 EXPECT_CALL(manager(), CheckForHistoryFilesRemoval()); |
247 history_ = new FakeHistoryAdapter(); | 247 history_ = new FakeHistoryAdapter(); |
248 history_->ExpectWillQueryDownloads(std::move(infos)); | 248 history_->ExpectWillQueryDownloads(std::move(infos)); |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
341 InitItem(base::GenerateGUID(), static_cast<uint32_t>(items_.size() + 1), | 341 InitItem(base::GenerateGUID(), static_cast<uint32_t>(items_.size() + 1), |
342 base::FilePath(path), base::FilePath(path), url_chain, referrer, | 342 base::FilePath(path), base::FilePath(path), url_chain, referrer, |
343 GURL("http://example.com"), GURL("http://example.com/tab-url"), | 343 GURL("http://example.com"), GURL("http://example.com/tab-url"), |
344 GURL("http://example.com/tab-referrer-url"), | 344 GURL("http://example.com/tab-referrer-url"), |
345 "application/octet-stream", "application/octet-stream", | 345 "application/octet-stream", "application/octet-stream", |
346 (base::Time::Now() - base::TimeDelta::FromMinutes(10)), | 346 (base::Time::Now() - base::TimeDelta::FromMinutes(10)), |
347 (base::Time::Now() - base::TimeDelta::FromMinutes(1)), "Etag", | 347 (base::Time::Now() - base::TimeDelta::FromMinutes(1)), "Etag", |
348 "abc", 100, 100, state, | 348 "abc", 100, 100, state, |
349 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, | 349 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, |
350 content::DOWNLOAD_INTERRUPT_REASON_NONE, false, base::Time::Now(), | 350 content::DOWNLOAD_INTERRUPT_REASON_NONE, false, base::Time::Now(), |
351 std::string(), std::string(), | 351 true, std::string(), std::string(), |
352 std::vector<content::DownloadItem::ReceivedSlice>(), info); | 352 std::vector<content::DownloadItem::ReceivedSlice>(), info); |
353 } | 353 } |
354 | 354 |
355 void InitItem( | 355 void InitItem( |
356 const std::string& guid, | 356 const std::string& guid, |
357 uint32_t id, | 357 uint32_t id, |
358 const base::FilePath& current_path, | 358 const base::FilePath& current_path, |
359 const base::FilePath& target_path, | 359 const base::FilePath& target_path, |
360 const std::vector<GURL>& url_chain, | 360 const std::vector<GURL>& url_chain, |
361 const GURL& referrer, | 361 const GURL& referrer, |
362 const GURL& site_url, | 362 const GURL& site_url, |
363 const GURL& tab_url, | 363 const GURL& tab_url, |
364 const GURL& tab_referrer_url, | 364 const GURL& tab_referrer_url, |
365 const std::string& mime_type, | 365 const std::string& mime_type, |
366 const std::string& original_mime_type, | 366 const std::string& original_mime_type, |
367 const base::Time& start_time, | 367 const base::Time& start_time, |
368 const base::Time& end_time, | 368 const base::Time& end_time, |
369 const std::string& etag, | 369 const std::string& etag, |
370 const std::string& last_modified, | 370 const std::string& last_modified, |
371 int64_t received_bytes, | 371 int64_t received_bytes, |
372 int64_t total_bytes, | 372 int64_t total_bytes, |
373 content::DownloadItem::DownloadState state, | 373 content::DownloadItem::DownloadState state, |
374 content::DownloadDangerType danger_type, | 374 content::DownloadDangerType danger_type, |
375 content::DownloadInterruptReason interrupt_reason, | 375 content::DownloadInterruptReason interrupt_reason, |
376 bool opened, | 376 bool opened, |
377 const base::Time& last_access_time, | 377 const base::Time& last_access_time, |
| 378 bool visible, |
378 const std::string& by_extension_id, | 379 const std::string& by_extension_id, |
379 const std::string& by_extension_name, | 380 const std::string& by_extension_name, |
380 const std::vector<content::DownloadItem::ReceivedSlice>& received_slices, | 381 const std::vector<content::DownloadItem::ReceivedSlice>& received_slices, |
381 history::DownloadRow* info) { | 382 history::DownloadRow* info) { |
382 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 383 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
383 | 384 |
384 size_t index = items_.size(); | 385 size_t index = items_.size(); |
385 items_.push_back(base::MakeUnique<StrictMockDownloadItem>()); | 386 items_.push_back(base::MakeUnique<StrictMockDownloadItem>()); |
386 | 387 |
387 info->current_path = current_path; | 388 info->current_path = current_path; |
(...skipping 12 matching lines...) Expand all Loading... |
400 info->received_bytes = received_bytes; | 401 info->received_bytes = received_bytes; |
401 info->total_bytes = total_bytes; | 402 info->total_bytes = total_bytes; |
402 info->state = history::ToHistoryDownloadState(state); | 403 info->state = history::ToHistoryDownloadState(state); |
403 info->danger_type = history::ToHistoryDownloadDangerType(danger_type); | 404 info->danger_type = history::ToHistoryDownloadDangerType(danger_type); |
404 info->interrupt_reason = | 405 info->interrupt_reason = |
405 history::ToHistoryDownloadInterruptReason(interrupt_reason); | 406 history::ToHistoryDownloadInterruptReason(interrupt_reason); |
406 info->id = history::ToHistoryDownloadId(id); | 407 info->id = history::ToHistoryDownloadId(id); |
407 info->guid = guid; | 408 info->guid = guid; |
408 info->opened = opened; | 409 info->opened = opened; |
409 info->last_access_time = last_access_time; | 410 info->last_access_time = last_access_time; |
| 411 info->visible = visible; |
410 info->by_ext_id = by_extension_id; | 412 info->by_ext_id = by_extension_id; |
411 info->by_ext_name = by_extension_name; | 413 info->by_ext_name = by_extension_name; |
412 | 414 |
413 EXPECT_CALL(item(index), GetId()).WillRepeatedly(Return(id)); | 415 EXPECT_CALL(item(index), GetId()).WillRepeatedly(Return(id)); |
414 EXPECT_CALL(item(index), GetGuid()).WillRepeatedly(ReturnRefOfCopy(guid)); | 416 EXPECT_CALL(item(index), GetGuid()).WillRepeatedly(ReturnRefOfCopy(guid)); |
415 EXPECT_CALL(item(index), GetFullPath()) | 417 EXPECT_CALL(item(index), GetFullPath()) |
416 .WillRepeatedly(ReturnRefOfCopy(current_path)); | 418 .WillRepeatedly(ReturnRefOfCopy(current_path)); |
417 EXPECT_CALL(item(index), GetTargetFilePath()) | 419 EXPECT_CALL(item(index), GetTargetFilePath()) |
418 .WillRepeatedly(ReturnRefOfCopy(target_path)); | 420 .WillRepeatedly(ReturnRefOfCopy(target_path)); |
419 DCHECK_LE(1u, url_chain.size()); | 421 DCHECK_LE(1u, url_chain.size()); |
(...skipping 24 matching lines...) Expand all Loading... |
444 EXPECT_CALL(item(index), GetTotalBytes()) | 446 EXPECT_CALL(item(index), GetTotalBytes()) |
445 .WillRepeatedly(Return(total_bytes)); | 447 .WillRepeatedly(Return(total_bytes)); |
446 EXPECT_CALL(item(index), GetState()).WillRepeatedly(Return(state)); | 448 EXPECT_CALL(item(index), GetState()).WillRepeatedly(Return(state)); |
447 EXPECT_CALL(item(index), GetDangerType()) | 449 EXPECT_CALL(item(index), GetDangerType()) |
448 .WillRepeatedly(Return(danger_type)); | 450 .WillRepeatedly(Return(danger_type)); |
449 EXPECT_CALL(item(index), GetLastReason()) | 451 EXPECT_CALL(item(index), GetLastReason()) |
450 .WillRepeatedly(Return(interrupt_reason)); | 452 .WillRepeatedly(Return(interrupt_reason)); |
451 EXPECT_CALL(item(index), GetOpened()).WillRepeatedly(Return(opened)); | 453 EXPECT_CALL(item(index), GetOpened()).WillRepeatedly(Return(opened)); |
452 EXPECT_CALL(item(index), GetLastAccessTime()) | 454 EXPECT_CALL(item(index), GetLastAccessTime()) |
453 .WillRepeatedly(Return(last_access_time)); | 455 .WillRepeatedly(Return(last_access_time)); |
| 456 EXPECT_CALL(item(index), IsVisible()).WillRepeatedly(Return(visible)); |
454 EXPECT_CALL(item(index), GetTargetDisposition()) | 457 EXPECT_CALL(item(index), GetTargetDisposition()) |
455 .WillRepeatedly( | 458 .WillRepeatedly( |
456 Return(content::DownloadItem::TARGET_DISPOSITION_OVERWRITE)); | 459 Return(content::DownloadItem::TARGET_DISPOSITION_OVERWRITE)); |
457 EXPECT_CALL(manager(), GetDownload(id)) | 460 EXPECT_CALL(manager(), GetDownload(id)) |
458 .WillRepeatedly(Return(&item(index))); | 461 .WillRepeatedly(Return(&item(index))); |
459 EXPECT_CALL(item(index), IsTemporary()).WillRepeatedly(Return(false)); | 462 EXPECT_CALL(item(index), IsTemporary()).WillRepeatedly(Return(false)); |
460 #if BUILDFLAG(ENABLE_EXTENSIONS) | 463 #if BUILDFLAG(ENABLE_EXTENSIONS) |
461 new extensions::DownloadedByExtension( | 464 new extensions::DownloadedByExtension( |
462 &item(index), by_extension_id, by_extension_name); | 465 &item(index), by_extension_id, by_extension_name); |
463 #endif | 466 #endif |
(...skipping 484 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
948 FinishCreateDownload(); | 951 FinishCreateDownload(); |
949 EXPECT_TRUE(DownloadHistory::IsPersisted(&item(0))); | 952 EXPECT_TRUE(DownloadHistory::IsPersisted(&item(0))); |
950 | 953 |
951 // ItemAdded should call OnDownloadUpdated, which should detect that the item | 954 // ItemAdded should call OnDownloadUpdated, which should detect that the item |
952 // changed while it was being added and call UpdateDownload immediately. | 955 // changed while it was being added and call UpdateDownload immediately. |
953 info.opened = true; | 956 info.opened = true; |
954 ExpectDownloadUpdated(info, false); | 957 ExpectDownloadUpdated(info, false); |
955 } | 958 } |
956 | 959 |
957 } // anonymous namespace | 960 } // anonymous namespace |
OLD | NEW |