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 <set> | 5 #include <set> |
6 #include <vector> | 6 #include <vector> |
7 | 7 |
8 #include "base/rand_util.h" | 8 #include "base/rand_util.h" |
9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
10 #include "chrome/browser/download/download_history.h" | 10 #include "chrome/browser/download/download_history.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 using testing::Return; | 22 using testing::Return; |
23 using testing::ReturnRef; | 23 using testing::ReturnRef; |
24 using testing::SetArgPointee; | 24 using testing::SetArgPointee; |
25 using testing::WithArg; | 25 using testing::WithArg; |
26 using testing::_; | 26 using testing::_; |
27 | 27 |
28 namespace { | 28 namespace { |
29 | 29 |
30 void CheckInfoEqual(const history::DownloadRow& left, | 30 void CheckInfoEqual(const history::DownloadRow& left, |
31 const history::DownloadRow& right) { | 31 const history::DownloadRow& right) { |
32 EXPECT_EQ(left.path.value(), right.path.value()); | 32 EXPECT_EQ(left.current_path.value(), right.current_path.value()); |
33 EXPECT_EQ(left.url.spec(), right.url.spec()); | 33 EXPECT_EQ(left.target_path.value(), right.target_path.value()); |
| 34 EXPECT_EQ(left.url_chain.size(), right.url_chain.size()); |
| 35 for (unsigned int i = 0; |
| 36 i < left.url_chain.size() && i < right.url_chain.size(); |
| 37 ++i) { |
| 38 EXPECT_EQ(left.url_chain[i].spec(), right.url_chain[i].spec()); |
| 39 } |
34 EXPECT_EQ(left.referrer_url.spec(), right.referrer_url.spec()); | 40 EXPECT_EQ(left.referrer_url.spec(), right.referrer_url.spec()); |
35 EXPECT_EQ(left.start_time.ToTimeT(), right.start_time.ToTimeT()); | 41 EXPECT_EQ(left.start_time.ToTimeT(), right.start_time.ToTimeT()); |
36 EXPECT_EQ(left.end_time.ToTimeT(), right.end_time.ToTimeT()); | 42 EXPECT_EQ(left.end_time.ToTimeT(), right.end_time.ToTimeT()); |
37 EXPECT_EQ(left.received_bytes, right.received_bytes); | 43 EXPECT_EQ(left.received_bytes, right.received_bytes); |
38 EXPECT_EQ(left.total_bytes, right.total_bytes); | 44 EXPECT_EQ(left.total_bytes, right.total_bytes); |
39 EXPECT_EQ(left.state, right.state); | 45 EXPECT_EQ(left.state, right.state); |
| 46 EXPECT_EQ(left.danger_type, right.danger_type); |
40 EXPECT_EQ(left.db_handle, right.db_handle); | 47 EXPECT_EQ(left.db_handle, right.db_handle); |
41 EXPECT_EQ(left.opened, right.opened); | 48 EXPECT_EQ(left.opened, right.opened); |
42 } | 49 } |
43 | 50 |
44 typedef std::set<int64> HandleSet; | 51 typedef std::set<int64> HandleSet; |
45 typedef std::vector<history::DownloadRow> InfoVector; | 52 typedef std::vector<history::DownloadRow> InfoVector; |
46 typedef testing::NiceMock<content::MockDownloadItem> NiceMockDownloadItem; | 53 typedef testing::NiceMock<content::MockDownloadItem> NiceMockDownloadItem; |
47 | 54 |
48 class FakeHistoryAdapter : public DownloadHistory::HistoryAdapter { | 55 class FakeHistoryAdapter : public DownloadHistory::HistoryAdapter { |
49 public: | 56 public: |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 content::MockDownloadManager& manager() { return *manager_.get(); } | 218 content::MockDownloadManager& manager() { return *manager_.get(); } |
212 content::MockDownloadItem& item(size_t index) { return *items_[index]; } | 219 content::MockDownloadItem& item(size_t index) { return *items_[index]; } |
213 | 220 |
214 void SetManagerObserver( | 221 void SetManagerObserver( |
215 content::DownloadManager::Observer* manager_observer) { | 222 content::DownloadManager::Observer* manager_observer) { |
216 manager_observer_ = manager_observer; | 223 manager_observer_ = manager_observer; |
217 } | 224 } |
218 content::DownloadManager::Observer* manager_observer() { | 225 content::DownloadManager::Observer* manager_observer() { |
219 return manager_observer_; | 226 return manager_observer_; |
220 } | 227 } |
| 228 |
| 229 // Relies on the same object observing all download items. |
221 void SetItemObserver( | 230 void SetItemObserver( |
222 content::DownloadItem::Observer* item_observer) { | 231 content::DownloadItem::Observer* item_observer) { |
223 item_observer_ = item_observer; | 232 item_observer_ = item_observer; |
224 } | 233 } |
225 content::DownloadItem::Observer* item_observer() { | 234 content::DownloadItem::Observer* item_observer() { |
226 return item_observer_; | 235 return item_observer_; |
227 } | 236 } |
228 | 237 |
229 void ExpectWillQueryDownloads(scoped_ptr<InfoVector> infos) { | 238 void ExpectWillQueryDownloads(scoped_ptr<InfoVector> infos) { |
230 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 239 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
231 CHECK(infos.get()); | 240 CHECK(infos.get()); |
232 EXPECT_CALL(manager(), AddObserver(_)).WillOnce(WithArg<0>(Invoke( | 241 EXPECT_CALL(manager(), AddObserver(_)).WillOnce(WithArg<0>(Invoke( |
233 this, &DownloadHistoryTest::SetManagerObserver))); | 242 this, &DownloadHistoryTest::SetManagerObserver))); |
234 EXPECT_CALL(manager(), RemoveObserver(_)); | 243 EXPECT_CALL(manager(), RemoveObserver(_)); |
235 download_created_index_ = 0; | 244 download_created_index_ = 0; |
236 for (size_t index = 0; index < infos->size(); ++index) { | 245 for (size_t index = 0; index < infos->size(); ++index) { |
237 EXPECT_CALL(manager(), CreateDownloadItem( | 246 content::MockDownloadManager::CreateDownloadItemAdapter adapter( |
238 infos->at(index).path, | 247 infos->at(index).current_path, |
239 infos->at(index).url, | 248 infos->at(index).target_path, |
| 249 infos->at(index).url_chain, |
240 infos->at(index).referrer_url, | 250 infos->at(index).referrer_url, |
241 infos->at(index).start_time, | 251 infos->at(index).start_time, |
242 infos->at(index).end_time, | 252 infos->at(index).end_time, |
243 infos->at(index).received_bytes, | 253 infos->at(index).received_bytes, |
244 infos->at(index).total_bytes, | 254 infos->at(index).total_bytes, |
245 infos->at(index).state, | 255 infos->at(index).state, |
246 infos->at(index).opened)) | 256 infos->at(index).danger_type, |
| 257 infos->at(index).interrupt_reason, |
| 258 infos->at(index).opened); |
| 259 EXPECT_CALL(manager(), MockCreateDownloadItem(adapter)) |
247 .WillOnce(DoAll( | 260 .WillOnce(DoAll( |
248 InvokeWithoutArgs( | 261 InvokeWithoutArgs( |
249 this, &DownloadHistoryTest::CallOnDownloadCreatedInOrder), | 262 this, &DownloadHistoryTest::CallOnDownloadCreatedInOrder), |
250 Return(&item(index)))); | 263 Return(&item(index)))); |
251 } | 264 } |
252 EXPECT_CALL(manager(), CheckForHistoryFilesRemoval()); | 265 EXPECT_CALL(manager(), CheckForHistoryFilesRemoval()); |
253 history_ = new FakeHistoryAdapter(); | 266 history_ = new FakeHistoryAdapter(); |
254 history_->ExpectWillQueryDownloads(infos.Pass()); | 267 history_->ExpectWillQueryDownloads(infos.Pass()); |
255 EXPECT_CALL(*manager_.get(), GetAllDownloads(_)).WillRepeatedly(Return()); | 268 EXPECT_CALL(*manager_.get(), GetAllDownloads(_)).WillRepeatedly(Return()); |
256 download_history_.reset(new DownloadHistory( | 269 download_history_.reset(new DownloadHistory( |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
310 void ExpectNoDownloadsRemoved() { | 323 void ExpectNoDownloadsRemoved() { |
311 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 324 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
312 history_->ExpectNoDownloadsRemoved(); | 325 history_->ExpectNoDownloadsRemoved(); |
313 } | 326 } |
314 | 327 |
315 void ExpectDownloadsRemoved(const HandleSet& handles) { | 328 void ExpectDownloadsRemoved(const HandleSet& handles) { |
316 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 329 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
317 history_->ExpectDownloadsRemoved(handles); | 330 history_->ExpectDownloadsRemoved(handles); |
318 } | 331 } |
319 | 332 |
| 333 // Caller is responsibile for making sure reference arguments lifetime is |
| 334 // greater than the lifetime of the NiceMockDownloadItem() created by this |
| 335 // routine. |
320 void InitItem( | 336 void InitItem( |
321 int32 id, | 337 int32 id, |
322 const FilePath& path, | 338 const FilePath& current_path, |
323 const GURL& url, | 339 const FilePath& target_path, |
| 340 const std::vector<GURL>& url_chain, |
324 const GURL& referrer, | 341 const GURL& referrer, |
325 const base::Time& start_time, | 342 const base::Time& start_time, |
326 const base::Time& end_time, | 343 const base::Time& end_time, |
327 int64 received_bytes, | 344 int64 received_bytes, |
328 int64 total_bytes, | 345 int64 total_bytes, |
329 content::DownloadItem::DownloadState state, | 346 content::DownloadItem::DownloadState state, |
| 347 content::DownloadDangerType danger_type, |
| 348 content::DownloadInterruptReason interrupt_reason, |
330 int64 db_handle, | 349 int64 db_handle, |
331 bool opened, | 350 bool opened, |
332 history::DownloadRow* info) { | 351 history::DownloadRow* info) { |
333 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 352 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
334 int32 index = items_.size(); | 353 int32 index = items_.size(); |
335 NiceMockDownloadItem* mock_item = new NiceMockDownloadItem(); | 354 NiceMockDownloadItem* mock_item = new NiceMockDownloadItem(); |
336 items_.push_back(mock_item); | 355 items_.push_back(mock_item); |
337 | 356 |
338 info->path = path; | 357 info->current_path = current_path; |
339 info->url = url; | 358 info->target_path = target_path; |
| 359 info->url_chain = url_chain; |
340 info->referrer_url = referrer; | 360 info->referrer_url = referrer; |
341 info->start_time = start_time; | 361 info->start_time = start_time; |
342 info->end_time = end_time; | 362 info->end_time = end_time; |
343 info->received_bytes = received_bytes; | 363 info->received_bytes = received_bytes; |
344 info->total_bytes = total_bytes; | 364 info->total_bytes = total_bytes; |
345 info->state = state; | 365 info->state = state; |
| 366 info->danger_type = danger_type; |
| 367 info->interrupt_reason = interrupt_reason; |
346 info->db_handle = db_handle; | 368 info->db_handle = db_handle; |
347 info->opened = opened; | 369 info->opened = opened; |
348 | 370 |
349 EXPECT_CALL(item(index), GetId()).WillRepeatedly(Return(id)); | 371 EXPECT_CALL(item(index), GetId()).WillRepeatedly(Return(id)); |
350 EXPECT_CALL(item(index), GetFullPath()).WillRepeatedly(ReturnRef(path)); | 372 EXPECT_CALL(item(index), |
351 EXPECT_CALL(item(index), GetURL()).WillRepeatedly(ReturnRef(url)); | 373 GetFullPath()).WillRepeatedly(ReturnRef(current_path)); |
| 374 EXPECT_CALL(item(index), |
| 375 GetTargetFilePath()).WillRepeatedly(ReturnRef(target_path)); |
| 376 DCHECK_LE(1u, url_chain.size()); |
| 377 EXPECT_CALL(item(index), GetURL()).WillRepeatedly(ReturnRef(url_chain[0])); |
| 378 EXPECT_CALL(item(index), |
| 379 GetUrlChain()).WillRepeatedly(ReturnRef(url_chain)); |
352 EXPECT_CALL(item(index), GetMimeType()).WillRepeatedly(Return( | 380 EXPECT_CALL(item(index), GetMimeType()).WillRepeatedly(Return( |
353 "application/octet-stream")); | 381 "application/octet-stream")); |
354 EXPECT_CALL(item(index), GetReferrerUrl()).WillRepeatedly(ReturnRef( | 382 EXPECT_CALL(item(index), GetReferrerUrl()).WillRepeatedly(ReturnRef( |
355 referrer)); | 383 referrer)); |
356 EXPECT_CALL(item(index), GetStartTime()).WillRepeatedly(Return(start_time)); | 384 EXPECT_CALL(item(index), GetStartTime()).WillRepeatedly(Return(start_time)); |
357 EXPECT_CALL(item(index), GetEndTime()).WillRepeatedly(Return(end_time)); | 385 EXPECT_CALL(item(index), GetEndTime()).WillRepeatedly(Return(end_time)); |
358 EXPECT_CALL(item(index), GetReceivedBytes()) | 386 EXPECT_CALL(item(index), GetReceivedBytes()) |
359 .WillRepeatedly(Return(received_bytes)); | 387 .WillRepeatedly(Return(received_bytes)); |
360 EXPECT_CALL(item(index), GetTotalBytes()).WillRepeatedly(Return( | 388 EXPECT_CALL(item(index), GetTotalBytes()).WillRepeatedly(Return( |
361 total_bytes)); | 389 total_bytes)); |
362 EXPECT_CALL(item(index), GetState()).WillRepeatedly(Return(state)); | 390 EXPECT_CALL(item(index), GetState()).WillRepeatedly(Return(state)); |
| 391 EXPECT_CALL(item(index), GetDangerType()) |
| 392 .WillRepeatedly(Return(danger_type)); |
| 393 EXPECT_CALL(item(index), GetLastReason()).WillRepeatedly( |
| 394 Return(interrupt_reason)); |
363 EXPECT_CALL(item(index), GetOpened()).WillRepeatedly(Return(opened)); | 395 EXPECT_CALL(item(index), GetOpened()).WillRepeatedly(Return(opened)); |
364 EXPECT_CALL(item(index), GetTargetDisposition()).WillRepeatedly(Return( | 396 EXPECT_CALL(item(index), GetTargetDisposition()).WillRepeatedly(Return( |
365 content::DownloadItem::TARGET_DISPOSITION_OVERWRITE)); | 397 content::DownloadItem::TARGET_DISPOSITION_OVERWRITE)); |
366 EXPECT_CALL(manager(), GetDownload(id)) | 398 EXPECT_CALL(manager(), GetDownload(id)) |
367 .WillRepeatedly(Return(&item(index))); | 399 .WillRepeatedly(Return(&item(index))); |
368 EXPECT_CALL(item(index), AddObserver(_)).WillOnce(WithArg<0>(Invoke( | 400 EXPECT_CALL(item(index), AddObserver(_)).WillOnce(WithArg<0>(Invoke( |
369 this, &DownloadHistoryTest::SetItemObserver))); | 401 this, &DownloadHistoryTest::SetItemObserver))); |
370 EXPECT_CALL(item(index), RemoveObserver(_)); | 402 EXPECT_CALL(item(index), RemoveObserver(_)); |
371 | 403 |
372 std::vector<content::DownloadItem*> items; | 404 std::vector<content::DownloadItem*> items; |
(...skipping 22 matching lines...) Expand all Loading... |
395 | 427 |
396 // Test loading an item from the database, changing it, saving it back, removing | 428 // Test loading an item from the database, changing it, saving it back, removing |
397 // it. | 429 // it. |
398 TEST_F(DownloadHistoryTest, DownloadHistoryTest_Load) { | 430 TEST_F(DownloadHistoryTest, DownloadHistoryTest_Load) { |
399 // Load a download from history, create the item, OnDownloadCreated, | 431 // Load a download from history, create the item, OnDownloadCreated, |
400 // OnDownloadUpdated, OnDownloadRemoved. | 432 // OnDownloadUpdated, OnDownloadRemoved. |
401 history::DownloadRow info; | 433 history::DownloadRow info; |
402 FilePath path(FILE_PATH_LITERAL("/foo/bar.pdf")); | 434 FilePath path(FILE_PATH_LITERAL("/foo/bar.pdf")); |
403 GURL url("http://example.com/bar.pdf"); | 435 GURL url("http://example.com/bar.pdf"); |
404 GURL referrer("http://example.com/referrer.html"); | 436 GURL referrer("http://example.com/referrer.html"); |
| 437 std::vector<GURL> url_chain; |
| 438 url_chain.push_back(url); |
405 InitItem(base::RandInt(0, 1 << 20), | 439 InitItem(base::RandInt(0, 1 << 20), |
406 path, | 440 path, |
407 url, | 441 path, |
| 442 url_chain, |
408 referrer, | 443 referrer, |
409 (base::Time::Now() - base::TimeDelta::FromMinutes(10)), | 444 (base::Time::Now() - base::TimeDelta::FromMinutes(10)), |
410 (base::Time::Now() - base::TimeDelta::FromMinutes(1)), | 445 (base::Time::Now() - base::TimeDelta::FromMinutes(1)), |
411 100, | 446 100, |
412 100, | 447 100, |
413 content::DownloadItem::COMPLETE, | 448 content::DownloadItem::COMPLETE, |
| 449 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, |
| 450 content::DOWNLOAD_INTERRUPT_REASON_NONE, |
414 base::RandInt(0, 1 << 20), | 451 base::RandInt(0, 1 << 20), |
415 false, | 452 false, |
416 &info); | 453 &info); |
417 { | 454 { |
418 scoped_ptr<InfoVector> infos(new InfoVector()); | 455 scoped_ptr<InfoVector> infos(new InfoVector()); |
419 infos->push_back(info); | 456 infos->push_back(info); |
420 ExpectWillQueryDownloads(infos.Pass()); | 457 ExpectWillQueryDownloads(infos.Pass()); |
421 ExpectNoDownloadCreated(); | 458 ExpectNoDownloadCreated(); |
422 } | 459 } |
423 EXPECT_TRUE(DownloadHistory::IsPersisted(&item(0))); | 460 EXPECT_TRUE(DownloadHistory::IsPersisted(&item(0))); |
(...skipping 16 matching lines...) Expand all Loading... |
440 TEST_F(DownloadHistoryTest, DownloadHistoryTest_Create) { | 477 TEST_F(DownloadHistoryTest, DownloadHistoryTest_Create) { |
441 // Create a fresh item not from history, OnDownloadCreated, OnDownloadUpdated, | 478 // Create a fresh item not from history, OnDownloadCreated, OnDownloadUpdated, |
442 // OnDownloadRemoved. | 479 // OnDownloadRemoved. |
443 ExpectWillQueryDownloads(scoped_ptr<InfoVector>(new InfoVector())); | 480 ExpectWillQueryDownloads(scoped_ptr<InfoVector>(new InfoVector())); |
444 | 481 |
445 // Note that db_handle must be -1 at first because it isn't in the db yet. | 482 // Note that db_handle must be -1 at first because it isn't in the db yet. |
446 history::DownloadRow info; | 483 history::DownloadRow info; |
447 FilePath path(FILE_PATH_LITERAL("/foo/bar.pdf")); | 484 FilePath path(FILE_PATH_LITERAL("/foo/bar.pdf")); |
448 GURL url("http://example.com/bar.pdf"); | 485 GURL url("http://example.com/bar.pdf"); |
449 GURL referrer("http://example.com/referrer.html"); | 486 GURL referrer("http://example.com/referrer.html"); |
| 487 std::vector<GURL> url_chain; |
| 488 url_chain.push_back(url); |
450 InitItem(base::RandInt(0, 1 << 20), | 489 InitItem(base::RandInt(0, 1 << 20), |
451 path, | 490 path, |
452 url, | 491 path, |
| 492 url_chain, |
453 referrer, | 493 referrer, |
454 (base::Time::Now() - base::TimeDelta::FromMinutes(10)), | 494 (base::Time::Now() - base::TimeDelta::FromMinutes(10)), |
455 (base::Time::Now() - base::TimeDelta::FromMinutes(1)), | 495 (base::Time::Now() - base::TimeDelta::FromMinutes(1)), |
456 100, | 496 100, |
457 100, | 497 100, |
458 content::DownloadItem::COMPLETE, | 498 content::DownloadItem::COMPLETE, |
| 499 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, |
| 500 content::DOWNLOAD_INTERRUPT_REASON_NONE, |
459 -1, | 501 -1, |
460 false, | 502 false, |
461 &info); | 503 &info); |
462 | 504 |
463 // Pretend the manager just created |item|. | 505 // Pretend the manager just created |item|. |
464 CallOnDownloadCreated(0); | 506 CallOnDownloadCreated(0); |
465 // CreateDownload() always gets db_handle=-1. | 507 // CreateDownload() always gets db_handle=-1. |
466 ExpectDownloadCreated(info); | 508 ExpectDownloadCreated(info); |
467 info.db_handle = 0; | 509 info.db_handle = 0; |
468 EXPECT_TRUE(DownloadHistory::IsPersisted(&item(0))); | 510 EXPECT_TRUE(DownloadHistory::IsPersisted(&item(0))); |
(...skipping 18 matching lines...) Expand all Loading... |
487 TEST_F(DownloadHistoryTest, DownloadHistoryTest_Temporary) { | 529 TEST_F(DownloadHistoryTest, DownloadHistoryTest_Temporary) { |
488 // Create a fresh item not from history, OnDownloadCreated, OnDownloadUpdated, | 530 // Create a fresh item not from history, OnDownloadCreated, OnDownloadUpdated, |
489 // OnDownloadRemoved. | 531 // OnDownloadRemoved. |
490 ExpectWillQueryDownloads(scoped_ptr<InfoVector>(new InfoVector())); | 532 ExpectWillQueryDownloads(scoped_ptr<InfoVector>(new InfoVector())); |
491 | 533 |
492 // Note that db_handle must be -1 at first because it isn't in the db yet. | 534 // Note that db_handle must be -1 at first because it isn't in the db yet. |
493 history::DownloadRow info; | 535 history::DownloadRow info; |
494 FilePath path(FILE_PATH_LITERAL("/foo/bar.pdf")); | 536 FilePath path(FILE_PATH_LITERAL("/foo/bar.pdf")); |
495 GURL url("http://example.com/bar.pdf"); | 537 GURL url("http://example.com/bar.pdf"); |
496 GURL referrer("http://example.com/referrer.html"); | 538 GURL referrer("http://example.com/referrer.html"); |
| 539 std::vector<GURL> url_chain; |
| 540 url_chain.push_back(url); |
497 InitItem(base::RandInt(0, 1 << 20), | 541 InitItem(base::RandInt(0, 1 << 20), |
498 path, | 542 path, |
499 url, | 543 path, |
| 544 url_chain, |
500 referrer, | 545 referrer, |
501 (base::Time::Now() - base::TimeDelta::FromMinutes(10)), | 546 (base::Time::Now() - base::TimeDelta::FromMinutes(10)), |
502 (base::Time::Now() - base::TimeDelta::FromMinutes(1)), | 547 (base::Time::Now() - base::TimeDelta::FromMinutes(1)), |
503 100, | 548 100, |
504 100, | 549 100, |
505 content::DownloadItem::COMPLETE, | 550 content::DownloadItem::COMPLETE, |
| 551 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, |
| 552 content::DOWNLOAD_INTERRUPT_REASON_NONE, |
506 -1, | 553 -1, |
507 false, | 554 false, |
508 &info); | 555 &info); |
509 | 556 |
510 // Pretend the manager just created |item|. | 557 // Pretend the manager just created |item|. |
511 CallOnDownloadCreated(0); | 558 CallOnDownloadCreated(0); |
512 // CreateDownload() always gets db_handle=-1. | 559 // CreateDownload() always gets db_handle=-1. |
513 ExpectDownloadCreated(info); | 560 ExpectDownloadCreated(info); |
514 info.db_handle = 0; | 561 info.db_handle = 0; |
515 EXPECT_TRUE(DownloadHistory::IsPersisted(&item(0))); | 562 EXPECT_TRUE(DownloadHistory::IsPersisted(&item(0))); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
548 // Test removing downloads while they're still being added. | 595 // Test removing downloads while they're still being added. |
549 TEST_F(DownloadHistoryTest, | 596 TEST_F(DownloadHistoryTest, |
550 DownloadHistoryTest_RemoveWhileAdding) { | 597 DownloadHistoryTest_RemoveWhileAdding) { |
551 ExpectWillQueryDownloads(scoped_ptr<InfoVector>(new InfoVector())); | 598 ExpectWillQueryDownloads(scoped_ptr<InfoVector>(new InfoVector())); |
552 | 599 |
553 // Note that db_handle must be -1 at first because it isn't in the db yet. | 600 // Note that db_handle must be -1 at first because it isn't in the db yet. |
554 history::DownloadRow info; | 601 history::DownloadRow info; |
555 FilePath path(FILE_PATH_LITERAL("/foo/bar.pdf")); | 602 FilePath path(FILE_PATH_LITERAL("/foo/bar.pdf")); |
556 GURL url("http://example.com/bar.pdf"); | 603 GURL url("http://example.com/bar.pdf"); |
557 GURL referrer("http://example.com/referrer.html"); | 604 GURL referrer("http://example.com/referrer.html"); |
| 605 std::vector<GURL> url_chain; |
| 606 url_chain.push_back(url); |
558 InitItem(base::RandInt(0, 1 << 20), | 607 InitItem(base::RandInt(0, 1 << 20), |
559 path, | 608 path, |
560 url, | 609 path, |
| 610 url_chain, |
561 referrer, | 611 referrer, |
562 (base::Time::Now() - base::TimeDelta::FromMinutes(10)), | 612 (base::Time::Now() - base::TimeDelta::FromMinutes(10)), |
563 (base::Time::Now() - base::TimeDelta::FromMinutes(1)), | 613 (base::Time::Now() - base::TimeDelta::FromMinutes(1)), |
564 100, | 614 100, |
565 100, | 615 100, |
566 content::DownloadItem::COMPLETE, | 616 content::DownloadItem::COMPLETE, |
| 617 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, |
| 618 content::DOWNLOAD_INTERRUPT_REASON_NONE, |
567 -1, | 619 -1, |
568 false, | 620 false, |
569 &info); | 621 &info); |
570 | 622 |
571 // Instruct CreateDownload() to not callback to DownloadHistory immediately, | 623 // Instruct CreateDownload() to not callback to DownloadHistory immediately, |
572 // but to wait for FinishCreateDownload(). | 624 // but to wait for FinishCreateDownload(). |
573 set_slow_create_download(true); | 625 set_slow_create_download(true); |
574 | 626 |
575 // Pretend the manager just created |item|. | 627 // Pretend the manager just created |item|. |
576 CallOnDownloadCreated(0); | 628 CallOnDownloadCreated(0); |
(...skipping 22 matching lines...) Expand all Loading... |
599 } | 651 } |
600 | 652 |
601 // Test loading multiple items from the database and removing them all. | 653 // Test loading multiple items from the database and removing them all. |
602 TEST_F(DownloadHistoryTest, DownloadHistoryTest_Multiple) { | 654 TEST_F(DownloadHistoryTest, DownloadHistoryTest_Multiple) { |
603 // Load a download from history, create the item, OnDownloadCreated, | 655 // Load a download from history, create the item, OnDownloadCreated, |
604 // OnDownloadUpdated, OnDownloadRemoved. | 656 // OnDownloadUpdated, OnDownloadRemoved. |
605 history::DownloadRow info0, info1; | 657 history::DownloadRow info0, info1; |
606 FilePath path0(FILE_PATH_LITERAL("/foo/bar.pdf")); | 658 FilePath path0(FILE_PATH_LITERAL("/foo/bar.pdf")); |
607 GURL url0("http://example.com/bar.pdf"); | 659 GURL url0("http://example.com/bar.pdf"); |
608 GURL referrer0("http://example.com/referrer.html"); | 660 GURL referrer0("http://example.com/referrer.html"); |
| 661 std::vector<GURL> url0_chain; |
| 662 url0_chain.push_back(url0); |
609 InitItem(base::RandInt(0, 1 << 10), | 663 InitItem(base::RandInt(0, 1 << 10), |
610 path0, | 664 path0, |
611 url0, | 665 path0, |
| 666 url0_chain, |
612 referrer0, | 667 referrer0, |
613 (base::Time::Now() - base::TimeDelta::FromMinutes(11)), | 668 (base::Time::Now() - base::TimeDelta::FromMinutes(11)), |
614 (base::Time::Now() - base::TimeDelta::FromMinutes(2)), | 669 (base::Time::Now() - base::TimeDelta::FromMinutes(2)), |
615 100, | 670 100, |
616 100, | 671 100, |
617 content::DownloadItem::COMPLETE, | 672 content::DownloadItem::COMPLETE, |
| 673 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, |
| 674 content::DOWNLOAD_INTERRUPT_REASON_NONE, |
618 base::RandInt(0, 1 << 10), | 675 base::RandInt(0, 1 << 10), |
619 false, | 676 false, |
620 &info0); | 677 &info0); |
621 FilePath path1(FILE_PATH_LITERAL("/foo/qux.pdf")); | 678 FilePath path1(FILE_PATH_LITERAL("/foo/qux.pdf")); |
622 GURL url1("http://example.com/qux.pdf"); | 679 GURL url1("http://example.com/qux.pdf"); |
623 GURL referrer1("http://example.com/referrer.html"); | 680 GURL referrer1("http://example.com/referrer.html"); |
| 681 std::vector<GURL> url1_chain; |
| 682 url1_chain.push_back(url0); |
624 InitItem(item(0).GetId() + base::RandInt(1, 1 << 10), | 683 InitItem(item(0).GetId() + base::RandInt(1, 1 << 10), |
625 path1, | 684 path1, |
626 url1, | 685 path1, |
| 686 url1_chain, |
627 referrer1, | 687 referrer1, |
628 (base::Time::Now() - base::TimeDelta::FromMinutes(10)), | 688 (base::Time::Now() - base::TimeDelta::FromMinutes(10)), |
629 (base::Time::Now() - base::TimeDelta::FromMinutes(1)), | 689 (base::Time::Now() - base::TimeDelta::FromMinutes(1)), |
630 200, | 690 200, |
631 200, | 691 200, |
632 content::DownloadItem::COMPLETE, | 692 content::DownloadItem::COMPLETE, |
| 693 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, |
| 694 content::DOWNLOAD_INTERRUPT_REASON_NONE, |
633 info0.db_handle + base::RandInt(1, 1 << 10), | 695 info0.db_handle + base::RandInt(1, 1 << 10), |
634 false, | 696 false, |
635 &info1); | 697 &info1); |
636 { | 698 { |
637 scoped_ptr<InfoVector> infos(new InfoVector()); | 699 scoped_ptr<InfoVector> infos(new InfoVector()); |
638 infos->push_back(info0); | 700 infos->push_back(info0); |
639 infos->push_back(info1); | 701 infos->push_back(info1); |
640 ExpectWillQueryDownloads(infos.Pass()); | 702 ExpectWillQueryDownloads(infos.Pass()); |
641 ExpectNoDownloadCreated(); | 703 ExpectNoDownloadCreated(); |
642 } | 704 } |
(...skipping 14 matching lines...) Expand all Loading... |
657 TEST_F(DownloadHistoryTest, DownloadHistoryTest_CreateFailed) { | 719 TEST_F(DownloadHistoryTest, DownloadHistoryTest_CreateFailed) { |
658 // Create a fresh item not from history, OnDownloadCreated, OnDownloadUpdated, | 720 // Create a fresh item not from history, OnDownloadCreated, OnDownloadUpdated, |
659 // OnDownloadRemoved. | 721 // OnDownloadRemoved. |
660 ExpectWillQueryDownloads(scoped_ptr<InfoVector>(new InfoVector())); | 722 ExpectWillQueryDownloads(scoped_ptr<InfoVector>(new InfoVector())); |
661 | 723 |
662 // Note that db_handle must be -1 at first because it isn't in the db yet. | 724 // Note that db_handle must be -1 at first because it isn't in the db yet. |
663 history::DownloadRow info; | 725 history::DownloadRow info; |
664 FilePath path(FILE_PATH_LITERAL("/foo/bar.pdf")); | 726 FilePath path(FILE_PATH_LITERAL("/foo/bar.pdf")); |
665 GURL url("http://example.com/bar.pdf"); | 727 GURL url("http://example.com/bar.pdf"); |
666 GURL referrer("http://example.com/referrer.html"); | 728 GURL referrer("http://example.com/referrer.html"); |
| 729 std::vector<GURL> url_chain; |
| 730 url_chain.push_back(url); |
667 InitItem(base::RandInt(0, 1 << 20), | 731 InitItem(base::RandInt(0, 1 << 20), |
668 path, | 732 path, |
669 url, | 733 path, |
| 734 url_chain, |
670 referrer, | 735 referrer, |
671 (base::Time::Now() - base::TimeDelta::FromMinutes(10)), | 736 (base::Time::Now() - base::TimeDelta::FromMinutes(10)), |
672 (base::Time::Now() - base::TimeDelta::FromMinutes(1)), | 737 (base::Time::Now() - base::TimeDelta::FromMinutes(1)), |
673 100, | 738 100, |
674 100, | 739 100, |
675 content::DownloadItem::COMPLETE, | 740 content::DownloadItem::COMPLETE, |
| 741 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, |
| 742 content::DOWNLOAD_INTERRUPT_REASON_NONE, |
676 -1, | 743 -1, |
677 false, | 744 false, |
678 &info); | 745 &info); |
679 | 746 |
680 FailCreateDownload(); | 747 FailCreateDownload(); |
681 // Pretend the manager just created |item|. | 748 // Pretend the manager just created |item|. |
682 CallOnDownloadCreated(0); | 749 CallOnDownloadCreated(0); |
683 // CreateDownload() always gets db_handle=-1. | 750 // CreateDownload() always gets db_handle=-1. |
684 ExpectDownloadCreated(info); | 751 ExpectDownloadCreated(info); |
685 EXPECT_FALSE(DownloadHistory::IsPersisted(&item(0))); | 752 EXPECT_FALSE(DownloadHistory::IsPersisted(&item(0))); |
686 | 753 |
687 EXPECT_CALL(item(0), GetReceivedBytes()).WillRepeatedly(Return(100)); | 754 EXPECT_CALL(item(0), GetReceivedBytes()).WillRepeatedly(Return(100)); |
688 item_observer()->OnDownloadUpdated(&item(0)); | 755 item_observer()->OnDownloadUpdated(&item(0)); |
689 info.received_bytes = 100; | 756 info.received_bytes = 100; |
690 ExpectDownloadCreated(info); | 757 ExpectDownloadCreated(info); |
691 EXPECT_TRUE(DownloadHistory::IsPersisted(&item(0))); | 758 EXPECT_TRUE(DownloadHistory::IsPersisted(&item(0))); |
692 } | 759 } |
693 | 760 |
694 TEST_F(DownloadHistoryTest, | 761 TEST_F(DownloadHistoryTest, |
695 DownloadHistoryTest_UpdateWhileAdding) { | 762 DownloadHistoryTest_UpdateWhileAdding) { |
696 // Create a fresh item not from history, OnDownloadCreated, OnDownloadUpdated, | 763 // Create a fresh item not from history, OnDownloadCreated, OnDownloadUpdated, |
697 // OnDownloadRemoved. | 764 // OnDownloadRemoved. |
698 ExpectWillQueryDownloads(scoped_ptr<InfoVector>(new InfoVector())); | 765 ExpectWillQueryDownloads(scoped_ptr<InfoVector>(new InfoVector())); |
699 | 766 |
700 // Note that db_handle must be -1 at first because it isn't in the db yet. | 767 // Note that db_handle must be -1 at first because it isn't in the db yet. |
701 history::DownloadRow info; | 768 history::DownloadRow info; |
702 FilePath path(FILE_PATH_LITERAL("/foo/bar.pdf")); | 769 FilePath path(FILE_PATH_LITERAL("/foo/bar.pdf")); |
703 GURL url("http://example.com/bar.pdf"); | 770 GURL url("http://example.com/bar.pdf"); |
704 GURL referrer("http://example.com/referrer.html"); | 771 GURL referrer("http://example.com/referrer.html"); |
| 772 std::vector<GURL> url_chain; |
| 773 url_chain.push_back(url); |
705 InitItem(base::RandInt(0, 1 << 20), | 774 InitItem(base::RandInt(0, 1 << 20), |
706 path, | 775 path, |
707 url, | 776 path, |
| 777 url_chain, |
708 referrer, | 778 referrer, |
709 (base::Time::Now() - base::TimeDelta::FromMinutes(10)), | 779 (base::Time::Now() - base::TimeDelta::FromMinutes(10)), |
710 (base::Time::Now() - base::TimeDelta::FromMinutes(1)), | 780 (base::Time::Now() - base::TimeDelta::FromMinutes(1)), |
711 100, | 781 100, |
712 100, | 782 100, |
713 content::DownloadItem::COMPLETE, | 783 content::DownloadItem::COMPLETE, |
| 784 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, |
| 785 content::DOWNLOAD_INTERRUPT_REASON_NONE, |
714 -1, | 786 -1, |
715 false, | 787 false, |
716 &info); | 788 &info); |
717 | 789 |
718 // Instruct CreateDownload() to not callback to DownloadHistory immediately, | 790 // Instruct CreateDownload() to not callback to DownloadHistory immediately, |
719 // but to wait for FinishCreateDownload(). | 791 // but to wait for FinishCreateDownload(). |
720 set_slow_create_download(true); | 792 set_slow_create_download(true); |
721 | 793 |
722 // Pretend the manager just created |item|. | 794 // Pretend the manager just created |item|. |
723 CallOnDownloadCreated(0); | 795 CallOnDownloadCreated(0); |
724 // CreateDownload() always gets db_handle=-1. | 796 // CreateDownload() always gets db_handle=-1. |
725 ExpectDownloadCreated(info); | 797 ExpectDownloadCreated(info); |
726 info.db_handle = 0; | 798 info.db_handle = 0; |
727 EXPECT_FALSE(DownloadHistory::IsPersisted(&item(0))); | 799 EXPECT_FALSE(DownloadHistory::IsPersisted(&item(0))); |
728 | 800 |
729 // Pretend that something changed on the item. | 801 // Pretend that something changed on the item. |
730 EXPECT_CALL(item(0), GetOpened()).WillRepeatedly(Return(true)); | 802 EXPECT_CALL(item(0), GetOpened()).WillRepeatedly(Return(true)); |
731 item_observer()->OnDownloadUpdated(&item(0)); | 803 item_observer()->OnDownloadUpdated(&item(0)); |
732 | 804 |
733 FinishCreateDownload(); | 805 FinishCreateDownload(); |
734 EXPECT_TRUE(DownloadHistory::IsPersisted(&item(0))); | 806 EXPECT_TRUE(DownloadHistory::IsPersisted(&item(0))); |
735 | 807 |
736 // ItemAdded should call OnDownloadUpdated, which should detect that the item | 808 // ItemAdded should call OnDownloadUpdated, which should detect that the item |
737 // changed while it was being added and call UpdateDownload immediately. | 809 // changed while it was being added and call UpdateDownload immediately. |
738 info.opened = true; | 810 info.opened = true; |
739 ExpectDownloadUpdated(info); | 811 ExpectDownloadUpdated(info); |
740 } | 812 } |
OLD | NEW |