| 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 EXPECT_CALL(manager(), MockCreateDownloadItem(adapter)) | 239 EXPECT_CALL(manager(), MockCreateDownloadItem(adapter)) |
| 240 .WillOnce(DoAll( | 240 .WillOnce(DoAll( |
| 241 InvokeWithoutArgs( | 241 InvokeWithoutArgs( |
| 242 this, &DownloadHistoryTest::CallOnDownloadCreatedInOrder), | 242 this, &DownloadHistoryTest::CallOnDownloadCreatedInOrder), |
| 243 Return(&item(index)))); | 243 Return(&item(index)))); |
| 244 } | 244 } |
| 245 EXPECT_CALL(manager(), CheckForHistoryFilesRemoval()); | 245 EXPECT_CALL(manager(), CheckForHistoryFilesRemoval()); |
| 246 history_ = new FakeHistoryAdapter(); | 246 history_ = new FakeHistoryAdapter(); |
| 247 history_->ExpectWillQueryDownloads(std::move(infos)); | 247 history_->ExpectWillQueryDownloads(std::move(infos)); |
| 248 EXPECT_CALL(*manager_.get(), GetAllDownloads(_)).WillRepeatedly(Return()); | 248 EXPECT_CALL(*manager_.get(), GetAllDownloads(_)).WillRepeatedly(Return()); |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 339 url_chain.push_back(url); | 339 url_chain.push_back(url); |
| 340 InitItem(base::GenerateGUID(), static_cast<uint32_t>(items_.size() + 1), | 340 InitItem(base::GenerateGUID(), static_cast<uint32_t>(items_.size() + 1), |
| 341 base::FilePath(path), base::FilePath(path), url_chain, referrer, | 341 base::FilePath(path), base::FilePath(path), url_chain, referrer, |
| 342 GURL("http://example.com"), GURL("http://example.com/tab-url"), | 342 GURL("http://example.com"), GURL("http://example.com/tab-url"), |
| 343 GURL("http://example.com/tab-referrer-url"), | 343 GURL("http://example.com/tab-referrer-url"), |
| 344 "application/octet-stream", "application/octet-stream", | 344 "application/octet-stream", "application/octet-stream", |
| 345 (base::Time::Now() - base::TimeDelta::FromMinutes(10)), | 345 (base::Time::Now() - base::TimeDelta::FromMinutes(10)), |
| 346 (base::Time::Now() - base::TimeDelta::FromMinutes(1)), "Etag", | 346 (base::Time::Now() - base::TimeDelta::FromMinutes(1)), "Etag", |
| 347 "abc", 100, 100, state, | 347 "abc", 100, 100, state, |
| 348 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, | 348 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, |
| 349 content::DOWNLOAD_INTERRUPT_REASON_NONE, false, std::string(), | 349 content::DOWNLOAD_INTERRUPT_REASON_NONE, false, base::Time::Now(), |
| 350 std::string(), info); | 350 std::string(), std::string(), info); |
| 351 } | 351 } |
| 352 | 352 |
| 353 void InitItem(const std::string& guid, | 353 void InitItem(const std::string& guid, |
| 354 uint32_t id, | 354 uint32_t id, |
| 355 const base::FilePath& current_path, | 355 const base::FilePath& current_path, |
| 356 const base::FilePath& target_path, | 356 const base::FilePath& target_path, |
| 357 const std::vector<GURL>& url_chain, | 357 const std::vector<GURL>& url_chain, |
| 358 const GURL& referrer, | 358 const GURL& referrer, |
| 359 const GURL& site_url, | 359 const GURL& site_url, |
| 360 const GURL& tab_url, | 360 const GURL& tab_url, |
| 361 const GURL& tab_referrer_url, | 361 const GURL& tab_referrer_url, |
| 362 const std::string& mime_type, | 362 const std::string& mime_type, |
| 363 const std::string& original_mime_type, | 363 const std::string& original_mime_type, |
| 364 const base::Time& start_time, | 364 const base::Time& start_time, |
| 365 const base::Time& end_time, | 365 const base::Time& end_time, |
| 366 const std::string& etag, | 366 const std::string& etag, |
| 367 const std::string& last_modified, | 367 const std::string& last_modified, |
| 368 int64_t received_bytes, | 368 int64_t received_bytes, |
| 369 int64_t total_bytes, | 369 int64_t total_bytes, |
| 370 content::DownloadItem::DownloadState state, | 370 content::DownloadItem::DownloadState state, |
| 371 content::DownloadDangerType danger_type, | 371 content::DownloadDangerType danger_type, |
| 372 content::DownloadInterruptReason interrupt_reason, | 372 content::DownloadInterruptReason interrupt_reason, |
| 373 bool opened, | 373 bool opened, |
| 374 const base::Time& last_access_time, |
| 374 const std::string& by_extension_id, | 375 const std::string& by_extension_id, |
| 375 const std::string& by_extension_name, | 376 const std::string& by_extension_name, |
| 376 history::DownloadRow* info) { | 377 history::DownloadRow* info) { |
| 377 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 378 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 378 | 379 |
| 379 size_t index = items_.size(); | 380 size_t index = items_.size(); |
| 380 items_.push_back(base::MakeUnique<StrictMockDownloadItem>()); | 381 items_.push_back(base::MakeUnique<StrictMockDownloadItem>()); |
| 381 | 382 |
| 382 info->current_path = current_path; | 383 info->current_path = current_path; |
| 383 info->target_path = target_path; | 384 info->target_path = target_path; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 394 info->last_modified = last_modified; | 395 info->last_modified = last_modified; |
| 395 info->received_bytes = received_bytes; | 396 info->received_bytes = received_bytes; |
| 396 info->total_bytes = total_bytes; | 397 info->total_bytes = total_bytes; |
| 397 info->state = history::ToHistoryDownloadState(state); | 398 info->state = history::ToHistoryDownloadState(state); |
| 398 info->danger_type = history::ToHistoryDownloadDangerType(danger_type); | 399 info->danger_type = history::ToHistoryDownloadDangerType(danger_type); |
| 399 info->interrupt_reason = | 400 info->interrupt_reason = |
| 400 history::ToHistoryDownloadInterruptReason(interrupt_reason); | 401 history::ToHistoryDownloadInterruptReason(interrupt_reason); |
| 401 info->id = history::ToHistoryDownloadId(id); | 402 info->id = history::ToHistoryDownloadId(id); |
| 402 info->guid = guid; | 403 info->guid = guid; |
| 403 info->opened = opened; | 404 info->opened = opened; |
| 405 info->last_access_time = last_access_time; |
| 404 info->by_ext_id = by_extension_id; | 406 info->by_ext_id = by_extension_id; |
| 405 info->by_ext_name = by_extension_name; | 407 info->by_ext_name = by_extension_name; |
| 406 | 408 |
| 407 EXPECT_CALL(item(index), GetId()).WillRepeatedly(Return(id)); | 409 EXPECT_CALL(item(index), GetId()).WillRepeatedly(Return(id)); |
| 408 EXPECT_CALL(item(index), GetGuid()).WillRepeatedly(ReturnRefOfCopy(guid)); | 410 EXPECT_CALL(item(index), GetGuid()).WillRepeatedly(ReturnRefOfCopy(guid)); |
| 409 EXPECT_CALL(item(index), GetFullPath()) | 411 EXPECT_CALL(item(index), GetFullPath()) |
| 410 .WillRepeatedly(ReturnRefOfCopy(current_path)); | 412 .WillRepeatedly(ReturnRefOfCopy(current_path)); |
| 411 EXPECT_CALL(item(index), GetTargetFilePath()) | 413 EXPECT_CALL(item(index), GetTargetFilePath()) |
| 412 .WillRepeatedly(ReturnRefOfCopy(target_path)); | 414 .WillRepeatedly(ReturnRefOfCopy(target_path)); |
| 413 DCHECK_LE(1u, url_chain.size()); | 415 DCHECK_LE(1u, url_chain.size()); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 434 EXPECT_CALL(item(index), GetReceivedBytes()) | 436 EXPECT_CALL(item(index), GetReceivedBytes()) |
| 435 .WillRepeatedly(Return(received_bytes)); | 437 .WillRepeatedly(Return(received_bytes)); |
| 436 EXPECT_CALL(item(index), GetTotalBytes()) | 438 EXPECT_CALL(item(index), GetTotalBytes()) |
| 437 .WillRepeatedly(Return(total_bytes)); | 439 .WillRepeatedly(Return(total_bytes)); |
| 438 EXPECT_CALL(item(index), GetState()).WillRepeatedly(Return(state)); | 440 EXPECT_CALL(item(index), GetState()).WillRepeatedly(Return(state)); |
| 439 EXPECT_CALL(item(index), GetDangerType()) | 441 EXPECT_CALL(item(index), GetDangerType()) |
| 440 .WillRepeatedly(Return(danger_type)); | 442 .WillRepeatedly(Return(danger_type)); |
| 441 EXPECT_CALL(item(index), GetLastReason()) | 443 EXPECT_CALL(item(index), GetLastReason()) |
| 442 .WillRepeatedly(Return(interrupt_reason)); | 444 .WillRepeatedly(Return(interrupt_reason)); |
| 443 EXPECT_CALL(item(index), GetOpened()).WillRepeatedly(Return(opened)); | 445 EXPECT_CALL(item(index), GetOpened()).WillRepeatedly(Return(opened)); |
| 446 EXPECT_CALL(item(index), GetLastAccessTime()) |
| 447 .WillRepeatedly(Return(last_access_time)); |
| 444 EXPECT_CALL(item(index), GetTargetDisposition()) | 448 EXPECT_CALL(item(index), GetTargetDisposition()) |
| 445 .WillRepeatedly( | 449 .WillRepeatedly( |
| 446 Return(content::DownloadItem::TARGET_DISPOSITION_OVERWRITE)); | 450 Return(content::DownloadItem::TARGET_DISPOSITION_OVERWRITE)); |
| 447 EXPECT_CALL(manager(), GetDownload(id)) | 451 EXPECT_CALL(manager(), GetDownload(id)) |
| 448 .WillRepeatedly(Return(&item(index))); | 452 .WillRepeatedly(Return(&item(index))); |
| 449 EXPECT_CALL(item(index), IsTemporary()).WillRepeatedly(Return(false)); | 453 EXPECT_CALL(item(index), IsTemporary()).WillRepeatedly(Return(false)); |
| 450 #if BUILDFLAG(ENABLE_EXTENSIONS) | 454 #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 451 new extensions::DownloadedByExtension( | 455 new extensions::DownloadedByExtension( |
| 452 &item(index), by_extension_id, by_extension_name); | 456 &item(index), by_extension_id, by_extension_name); |
| 453 #endif | 457 #endif |
| (...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 925 FinishCreateDownload(); | 929 FinishCreateDownload(); |
| 926 EXPECT_TRUE(DownloadHistory::IsPersisted(&item(0))); | 930 EXPECT_TRUE(DownloadHistory::IsPersisted(&item(0))); |
| 927 | 931 |
| 928 // ItemAdded should call OnDownloadUpdated, which should detect that the item | 932 // ItemAdded should call OnDownloadUpdated, which should detect that the item |
| 929 // changed while it was being added and call UpdateDownload immediately. | 933 // changed while it was being added and call UpdateDownload immediately. |
| 930 info.opened = true; | 934 info.opened = true; |
| 931 ExpectDownloadUpdated(info, false); | 935 ExpectDownloadUpdated(info, false); |
| 932 } | 936 } |
| 933 | 937 |
| 934 } // anonymous namespace | 938 } // anonymous namespace |
| OLD | NEW |