| 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, | 238 row.opened, row.last_access_time, |
| 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 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 340 url_chain.push_back(url); | 340 url_chain.push_back(url); |
| 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, std::string(), | 350 content::DOWNLOAD_INTERRUPT_REASON_NONE, false, base::Time::Now(), |
| 351 std::string(), std::vector<content::DownloadItem::ReceivedSlice>(), | 351 std::string(), std::string(), |
| 352 info); | 352 std::vector<content::DownloadItem::ReceivedSlice>(), info); |
| 353 } | 353 } |
| 354 | 354 |
| 355 void InitItem(const std::string& guid, | 355 void InitItem( |
| 356 uint32_t id, | 356 const std::string& guid, |
| 357 const base::FilePath& current_path, | 357 uint32_t id, |
| 358 const base::FilePath& target_path, | 358 const base::FilePath& current_path, |
| 359 const std::vector<GURL>& url_chain, | 359 const base::FilePath& target_path, |
| 360 const GURL& referrer, | 360 const std::vector<GURL>& url_chain, |
| 361 const GURL& site_url, | 361 const GURL& referrer, |
| 362 const GURL& tab_url, | 362 const GURL& site_url, |
| 363 const GURL& tab_referrer_url, | 363 const GURL& tab_url, |
| 364 const std::string& mime_type, | 364 const GURL& tab_referrer_url, |
| 365 const std::string& original_mime_type, | 365 const std::string& mime_type, |
| 366 const base::Time& start_time, | 366 const std::string& original_mime_type, |
| 367 const base::Time& end_time, | 367 const base::Time& start_time, |
| 368 const std::string& etag, | 368 const base::Time& end_time, |
| 369 const std::string& last_modified, | 369 const std::string& etag, |
| 370 int64_t received_bytes, | 370 const std::string& last_modified, |
| 371 int64_t total_bytes, | 371 int64_t received_bytes, |
| 372 content::DownloadItem::DownloadState state, | 372 int64_t total_bytes, |
| 373 content::DownloadDangerType danger_type, | 373 content::DownloadItem::DownloadState state, |
| 374 content::DownloadInterruptReason interrupt_reason, | 374 content::DownloadDangerType danger_type, |
| 375 bool opened, | 375 content::DownloadInterruptReason interrupt_reason, |
| 376 const std::string& by_extension_id, | 376 bool opened, |
| 377 const std::string& by_extension_name, | 377 const base::Time& last_access_time, |
| 378 const std::vector<content::DownloadItem::ReceivedSlice>& | 378 const std::string& by_extension_id, |
| 379 received_slices, | 379 const std::string& by_extension_name, |
| 380 history::DownloadRow* info) { | 380 const std::vector<content::DownloadItem::ReceivedSlice>& received_slices, |
| 381 history::DownloadRow* info) { |
| 381 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 382 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 382 | 383 |
| 383 size_t index = items_.size(); | 384 size_t index = items_.size(); |
| 384 items_.push_back(base::MakeUnique<StrictMockDownloadItem>()); | 385 items_.push_back(base::MakeUnique<StrictMockDownloadItem>()); |
| 385 | 386 |
| 386 info->current_path = current_path; | 387 info->current_path = current_path; |
| 387 info->target_path = target_path; | 388 info->target_path = target_path; |
| 388 info->url_chain = url_chain; | 389 info->url_chain = url_chain; |
| 389 info->referrer_url = referrer; | 390 info->referrer_url = referrer; |
| 390 info->site_url = site_url; | 391 info->site_url = site_url; |
| 391 info->tab_url = tab_url; | 392 info->tab_url = tab_url; |
| 392 info->tab_referrer_url = tab_referrer_url; | 393 info->tab_referrer_url = tab_referrer_url; |
| 393 info->mime_type = mime_type; | 394 info->mime_type = mime_type; |
| 394 info->original_mime_type = original_mime_type; | 395 info->original_mime_type = original_mime_type; |
| 395 info->start_time = start_time; | 396 info->start_time = start_time; |
| 396 info->end_time = end_time; | 397 info->end_time = end_time; |
| 397 info->etag = etag; | 398 info->etag = etag; |
| 398 info->last_modified = last_modified; | 399 info->last_modified = last_modified; |
| 399 info->received_bytes = received_bytes; | 400 info->received_bytes = received_bytes; |
| 400 info->total_bytes = total_bytes; | 401 info->total_bytes = total_bytes; |
| 401 info->state = history::ToHistoryDownloadState(state); | 402 info->state = history::ToHistoryDownloadState(state); |
| 402 info->danger_type = history::ToHistoryDownloadDangerType(danger_type); | 403 info->danger_type = history::ToHistoryDownloadDangerType(danger_type); |
| 403 info->interrupt_reason = | 404 info->interrupt_reason = |
| 404 history::ToHistoryDownloadInterruptReason(interrupt_reason); | 405 history::ToHistoryDownloadInterruptReason(interrupt_reason); |
| 405 info->id = history::ToHistoryDownloadId(id); | 406 info->id = history::ToHistoryDownloadId(id); |
| 406 info->guid = guid; | 407 info->guid = guid; |
| 407 info->opened = opened; | 408 info->opened = opened; |
| 409 info->last_access_time = last_access_time; |
| 408 info->by_ext_id = by_extension_id; | 410 info->by_ext_id = by_extension_id; |
| 409 info->by_ext_name = by_extension_name; | 411 info->by_ext_name = by_extension_name; |
| 410 | 412 |
| 411 EXPECT_CALL(item(index), GetId()).WillRepeatedly(Return(id)); | 413 EXPECT_CALL(item(index), GetId()).WillRepeatedly(Return(id)); |
| 412 EXPECT_CALL(item(index), GetGuid()).WillRepeatedly(ReturnRefOfCopy(guid)); | 414 EXPECT_CALL(item(index), GetGuid()).WillRepeatedly(ReturnRefOfCopy(guid)); |
| 413 EXPECT_CALL(item(index), GetFullPath()) | 415 EXPECT_CALL(item(index), GetFullPath()) |
| 414 .WillRepeatedly(ReturnRefOfCopy(current_path)); | 416 .WillRepeatedly(ReturnRefOfCopy(current_path)); |
| 415 EXPECT_CALL(item(index), GetTargetFilePath()) | 417 EXPECT_CALL(item(index), GetTargetFilePath()) |
| 416 .WillRepeatedly(ReturnRefOfCopy(target_path)); | 418 .WillRepeatedly(ReturnRefOfCopy(target_path)); |
| 417 DCHECK_LE(1u, url_chain.size()); | 419 DCHECK_LE(1u, url_chain.size()); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 440 EXPECT_CALL(item(index), GetReceivedSlices()) | 442 EXPECT_CALL(item(index), GetReceivedSlices()) |
| 441 .WillRepeatedly(ReturnRefOfCopy(received_slices)); | 443 .WillRepeatedly(ReturnRefOfCopy(received_slices)); |
| 442 EXPECT_CALL(item(index), GetTotalBytes()) | 444 EXPECT_CALL(item(index), GetTotalBytes()) |
| 443 .WillRepeatedly(Return(total_bytes)); | 445 .WillRepeatedly(Return(total_bytes)); |
| 444 EXPECT_CALL(item(index), GetState()).WillRepeatedly(Return(state)); | 446 EXPECT_CALL(item(index), GetState()).WillRepeatedly(Return(state)); |
| 445 EXPECT_CALL(item(index), GetDangerType()) | 447 EXPECT_CALL(item(index), GetDangerType()) |
| 446 .WillRepeatedly(Return(danger_type)); | 448 .WillRepeatedly(Return(danger_type)); |
| 447 EXPECT_CALL(item(index), GetLastReason()) | 449 EXPECT_CALL(item(index), GetLastReason()) |
| 448 .WillRepeatedly(Return(interrupt_reason)); | 450 .WillRepeatedly(Return(interrupt_reason)); |
| 449 EXPECT_CALL(item(index), GetOpened()).WillRepeatedly(Return(opened)); | 451 EXPECT_CALL(item(index), GetOpened()).WillRepeatedly(Return(opened)); |
| 452 EXPECT_CALL(item(index), GetLastAccessTime()) |
| 453 .WillRepeatedly(Return(last_access_time)); |
| 450 EXPECT_CALL(item(index), GetTargetDisposition()) | 454 EXPECT_CALL(item(index), GetTargetDisposition()) |
| 451 .WillRepeatedly( | 455 .WillRepeatedly( |
| 452 Return(content::DownloadItem::TARGET_DISPOSITION_OVERWRITE)); | 456 Return(content::DownloadItem::TARGET_DISPOSITION_OVERWRITE)); |
| 453 EXPECT_CALL(manager(), GetDownload(id)) | 457 EXPECT_CALL(manager(), GetDownload(id)) |
| 454 .WillRepeatedly(Return(&item(index))); | 458 .WillRepeatedly(Return(&item(index))); |
| 455 EXPECT_CALL(item(index), IsTemporary()).WillRepeatedly(Return(false)); | 459 EXPECT_CALL(item(index), IsTemporary()).WillRepeatedly(Return(false)); |
| 456 #if BUILDFLAG(ENABLE_EXTENSIONS) | 460 #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 457 new extensions::DownloadedByExtension( | 461 new extensions::DownloadedByExtension( |
| 458 &item(index), by_extension_id, by_extension_name); | 462 &item(index), by_extension_id, by_extension_name); |
| 459 #endif | 463 #endif |
| (...skipping 484 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 944 FinishCreateDownload(); | 948 FinishCreateDownload(); |
| 945 EXPECT_TRUE(DownloadHistory::IsPersisted(&item(0))); | 949 EXPECT_TRUE(DownloadHistory::IsPersisted(&item(0))); |
| 946 | 950 |
| 947 // ItemAdded should call OnDownloadUpdated, which should detect that the item | 951 // ItemAdded should call OnDownloadUpdated, which should detect that the item |
| 948 // changed while it was being added and call UpdateDownload immediately. | 952 // changed while it was being added and call UpdateDownload immediately. |
| 949 info.opened = true; | 953 info.opened = true; |
| 950 ExpectDownloadUpdated(info, false); | 954 ExpectDownloadUpdated(info, false); |
| 951 } | 955 } |
| 952 | 956 |
| 953 } // anonymous namespace | 957 } // anonymous namespace |
| OLD | NEW |