| 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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 | 42 |
| 43 typedef DownloadHistory::IdSet IdSet; | 43 typedef DownloadHistory::IdSet IdSet; |
| 44 typedef std::vector<history::DownloadRow> InfoVector; | 44 typedef std::vector<history::DownloadRow> InfoVector; |
| 45 typedef testing::StrictMock<content::MockDownloadItem> StrictMockDownloadItem; | 45 typedef testing::StrictMock<content::MockDownloadItem> StrictMockDownloadItem; |
| 46 | 46 |
| 47 class FakeHistoryAdapter : public DownloadHistory::HistoryAdapter { | 47 class FakeHistoryAdapter : public DownloadHistory::HistoryAdapter { |
| 48 public: | 48 public: |
| 49 FakeHistoryAdapter() | 49 FakeHistoryAdapter() |
| 50 : DownloadHistory::HistoryAdapter(NULL), | 50 : DownloadHistory::HistoryAdapter(NULL), |
| 51 slow_create_download_(false), | 51 slow_create_download_(false), |
| 52 fail_create_download_(false) { | 52 fail_create_download_(false), |
| 53 should_commit_immediately_(false) { |
| 53 } | 54 } |
| 54 | 55 |
| 55 ~FakeHistoryAdapter() override {} | 56 ~FakeHistoryAdapter() override {} |
| 56 | 57 |
| 57 void QueryDownloads( | 58 void QueryDownloads( |
| 58 const history::HistoryService::DownloadQueryCallback& callback) override { | 59 const history::HistoryService::DownloadQueryCallback& callback) override { |
| 59 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 60 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 60 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, | 61 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, |
| 61 base::Bind(&FakeHistoryAdapter::QueryDownloadsDone, | 62 base::Bind(&FakeHistoryAdapter::QueryDownloadsDone, |
| 62 base::Unretained(this), callback)); | 63 base::Unretained(this), callback)); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 83 if (!slow_create_download_) | 84 if (!slow_create_download_) |
| 84 FinishCreateDownload(); | 85 FinishCreateDownload(); |
| 85 } | 86 } |
| 86 | 87 |
| 87 void FinishCreateDownload() { | 88 void FinishCreateDownload() { |
| 88 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 89 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 89 create_download_callback_.Run(); | 90 create_download_callback_.Run(); |
| 90 create_download_callback_.Reset(); | 91 create_download_callback_.Reset(); |
| 91 } | 92 } |
| 92 | 93 |
| 93 void UpdateDownload(const history::DownloadRow& info) override { | 94 void UpdateDownload(const history::DownloadRow& info, |
| 95 bool should_commit_immediately) override { |
| 94 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 96 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 95 update_download_ = info; | 97 update_download_ = info; |
| 98 should_commit_immediately_ = should_commit_immediately; |
| 96 } | 99 } |
| 97 | 100 |
| 98 void RemoveDownloads(const IdSet& ids) override { | 101 void RemoveDownloads(const IdSet& ids) override { |
| 99 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 102 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 100 for (IdSet::const_iterator it = ids.begin(); | 103 for (IdSet::const_iterator it = ids.begin(); |
| 101 it != ids.end(); ++it) { | 104 it != ids.end(); ++it) { |
| 102 remove_downloads_.insert(*it); | 105 remove_downloads_.insert(*it); |
| 103 } | 106 } |
| 104 } | 107 } |
| 105 | 108 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 125 EXPECT_EQ(info, create_download_info_); | 128 EXPECT_EQ(info, create_download_info_); |
| 126 create_download_info_ = history::DownloadRow(); | 129 create_download_info_ = history::DownloadRow(); |
| 127 } | 130 } |
| 128 | 131 |
| 129 void ExpectNoDownloadCreated() { | 132 void ExpectNoDownloadCreated() { |
| 130 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 133 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 131 content::RunAllPendingInMessageLoop(content::BrowserThread::UI); | 134 content::RunAllPendingInMessageLoop(content::BrowserThread::UI); |
| 132 EXPECT_EQ(history::DownloadRow(), create_download_info_); | 135 EXPECT_EQ(history::DownloadRow(), create_download_info_); |
| 133 } | 136 } |
| 134 | 137 |
| 135 void ExpectDownloadUpdated(const history::DownloadRow& info) { | 138 void ExpectDownloadUpdated(const history::DownloadRow& info, |
| 139 bool should_commit_immediately) { |
| 136 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 140 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 137 content::RunAllPendingInMessageLoop(content::BrowserThread::UI); | 141 content::RunAllPendingInMessageLoop(content::BrowserThread::UI); |
| 138 EXPECT_EQ(update_download_, info); | 142 EXPECT_EQ(update_download_, info); |
| 143 EXPECT_EQ(should_commit_immediately_, should_commit_immediately); |
| 139 update_download_ = history::DownloadRow(); | 144 update_download_ = history::DownloadRow(); |
| 145 should_commit_immediately_ = false; |
| 140 } | 146 } |
| 141 | 147 |
| 142 void ExpectNoDownloadUpdated() { | 148 void ExpectNoDownloadUpdated() { |
| 143 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 149 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 144 content::RunAllPendingInMessageLoop(content::BrowserThread::UI); | 150 content::RunAllPendingInMessageLoop(content::BrowserThread::UI); |
| 145 EXPECT_EQ(history::DownloadRow(), update_download_); | 151 EXPECT_EQ(history::DownloadRow(), update_download_); |
| 146 } | 152 } |
| 147 | 153 |
| 148 void ExpectNoDownloadsRemoved() { | 154 void ExpectNoDownloadsRemoved() { |
| 149 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 155 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 150 content::RunAllPendingInMessageLoop(content::BrowserThread::UI); | 156 content::RunAllPendingInMessageLoop(content::BrowserThread::UI); |
| 151 EXPECT_EQ(0, static_cast<int>(remove_downloads_.size())); | 157 EXPECT_EQ(0, static_cast<int>(remove_downloads_.size())); |
| 152 } | 158 } |
| 153 | 159 |
| 154 void ExpectDownloadsRemoved(const IdSet& ids) { | 160 void ExpectDownloadsRemoved(const IdSet& ids) { |
| 155 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 161 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 156 content::RunAllPendingInMessageLoop(content::BrowserThread::UI); | 162 content::RunAllPendingInMessageLoop(content::BrowserThread::UI); |
| 157 IdSet differences = base::STLSetDifference<IdSet>(ids, remove_downloads_); | 163 IdSet differences = base::STLSetDifference<IdSet>(ids, remove_downloads_); |
| 158 for (IdSet::const_iterator different = differences.begin(); | 164 for (IdSet::const_iterator different = differences.begin(); |
| 159 different != differences.end(); ++different) { | 165 different != differences.end(); ++different) { |
| 160 EXPECT_TRUE(false) << *different; | 166 EXPECT_TRUE(false) << *different; |
| 161 } | 167 } |
| 162 remove_downloads_.clear(); | 168 remove_downloads_.clear(); |
| 163 } | 169 } |
| 164 | 170 |
| 165 private: | 171 private: |
| 166 bool slow_create_download_; | 172 bool slow_create_download_; |
| 167 bool fail_create_download_; | 173 bool fail_create_download_; |
| 174 bool should_commit_immediately_; |
| 168 base::Closure create_download_callback_; | 175 base::Closure create_download_callback_; |
| 169 history::DownloadRow update_download_; | 176 history::DownloadRow update_download_; |
| 170 std::unique_ptr<InfoVector> expect_query_downloads_; | 177 std::unique_ptr<InfoVector> expect_query_downloads_; |
| 171 IdSet remove_downloads_; | 178 IdSet remove_downloads_; |
| 172 history::DownloadRow create_download_info_; | 179 history::DownloadRow create_download_info_; |
| 173 | 180 |
| 174 DISALLOW_COPY_AND_ASSIGN(FakeHistoryAdapter); | 181 DISALLOW_COPY_AND_ASSIGN(FakeHistoryAdapter); |
| 175 }; | 182 }; |
| 176 | 183 |
| 177 class TestDownloadHistoryObserver : public DownloadHistory::Observer { | 184 class TestDownloadHistoryObserver : public DownloadHistory::Observer { |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 281 const history::DownloadRow& info) { | 288 const history::DownloadRow& info) { |
| 282 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 289 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 283 history_->ExpectDownloadCreated(info); | 290 history_->ExpectDownloadCreated(info); |
| 284 } | 291 } |
| 285 | 292 |
| 286 void ExpectNoDownloadCreated() { | 293 void ExpectNoDownloadCreated() { |
| 287 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 294 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 288 history_->ExpectNoDownloadCreated(); | 295 history_->ExpectNoDownloadCreated(); |
| 289 } | 296 } |
| 290 | 297 |
| 291 void ExpectDownloadUpdated(const history::DownloadRow& info) { | 298 void ExpectDownloadUpdated(const history::DownloadRow& info, |
| 299 bool should_commit_immediately) { |
| 292 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 300 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 293 history_->ExpectDownloadUpdated(info); | 301 history_->ExpectDownloadUpdated(info, should_commit_immediately); |
| 294 } | 302 } |
| 295 | 303 |
| 296 void ExpectNoDownloadUpdated() { | 304 void ExpectNoDownloadUpdated() { |
| 297 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 305 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 298 history_->ExpectNoDownloadUpdated(); | 306 history_->ExpectNoDownloadUpdated(); |
| 299 } | 307 } |
| 300 | 308 |
| 301 void ExpectNoDownloadsRemoved() { | 309 void ExpectNoDownloadsRemoved() { |
| 302 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 310 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 303 history_->ExpectNoDownloadsRemoved(); | 311 history_->ExpectNoDownloadsRemoved(); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 316 expected_value); | 324 expected_value); |
| 317 post_on_create_handler_ = | 325 post_on_create_handler_ = |
| 318 base::Bind(&DownloadHistoryTest::CheckDownloadWasRestoredFromHistory, | 326 base::Bind(&DownloadHistoryTest::CheckDownloadWasRestoredFromHistory, |
| 319 base::Unretained(this), | 327 base::Unretained(this), |
| 320 expected_value); | 328 expected_value); |
| 321 } | 329 } |
| 322 | 330 |
| 323 void InitBasicItem(const base::FilePath::CharType* path, | 331 void InitBasicItem(const base::FilePath::CharType* path, |
| 324 const char* url_string, | 332 const char* url_string, |
| 325 const char* referrer_string, | 333 const char* referrer_string, |
| 334 content::DownloadItem::DownloadState state, |
| 326 history::DownloadRow* info) { | 335 history::DownloadRow* info) { |
| 327 GURL url(url_string); | 336 GURL url(url_string); |
| 328 GURL referrer(referrer_string); | 337 GURL referrer(referrer_string); |
| 329 std::vector<GURL> url_chain; | 338 std::vector<GURL> url_chain; |
| 330 url_chain.push_back(url); | 339 url_chain.push_back(url); |
| 331 InitItem(base::GenerateGUID(), static_cast<uint32_t>(items_.size() + 1), | 340 InitItem(base::GenerateGUID(), static_cast<uint32_t>(items_.size() + 1), |
| 332 base::FilePath(path), base::FilePath(path), url_chain, referrer, | 341 base::FilePath(path), base::FilePath(path), url_chain, referrer, |
| 333 GURL("http://example.com"), GURL("http://example.com/tab-url"), | 342 GURL("http://example.com"), GURL("http://example.com/tab-url"), |
| 334 GURL("http://example.com/tab-referrer-url"), | 343 GURL("http://example.com/tab-referrer-url"), |
| 335 "application/octet-stream", "application/octet-stream", | 344 "application/octet-stream", "application/octet-stream", |
| 336 (base::Time::Now() - base::TimeDelta::FromMinutes(10)), | 345 (base::Time::Now() - base::TimeDelta::FromMinutes(10)), |
| 337 (base::Time::Now() - base::TimeDelta::FromMinutes(1)), "Etag", | 346 (base::Time::Now() - base::TimeDelta::FromMinutes(1)), "Etag", |
| 338 "abc", 100, 100, content::DownloadItem::COMPLETE, | 347 "abc", 100, 100, state, |
| 339 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, | 348 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, |
| 340 content::DOWNLOAD_INTERRUPT_REASON_NONE, false, std::string(), | 349 content::DOWNLOAD_INTERRUPT_REASON_NONE, false, std::string(), |
| 341 std::string(), info); | 350 std::string(), info); |
| 342 } | 351 } |
| 343 | 352 |
| 344 void InitItem(const std::string& guid, | 353 void InitItem(const std::string& guid, |
| 345 uint32_t id, | 354 uint32_t id, |
| 346 const base::FilePath& current_path, | 355 const base::FilePath& current_path, |
| 347 const base::FilePath& target_path, | 356 const base::FilePath& target_path, |
| 348 const std::vector<GURL>& url_chain, | 357 const std::vector<GURL>& url_chain, |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 474 | 483 |
| 475 // Test loading an item from the database, changing it, saving it back, removing | 484 // Test loading an item from the database, changing it, saving it back, removing |
| 476 // it. | 485 // it. |
| 477 TEST_F(DownloadHistoryTest, DownloadHistoryTest_Load) { | 486 TEST_F(DownloadHistoryTest, DownloadHistoryTest_Load) { |
| 478 // Load a download from history, create the item, OnDownloadCreated, | 487 // Load a download from history, create the item, OnDownloadCreated, |
| 479 // OnDownloadUpdated, OnDownloadRemoved. | 488 // OnDownloadUpdated, OnDownloadRemoved. |
| 480 history::DownloadRow info; | 489 history::DownloadRow info; |
| 481 InitBasicItem(FILE_PATH_LITERAL("/foo/bar.pdf"), | 490 InitBasicItem(FILE_PATH_LITERAL("/foo/bar.pdf"), |
| 482 "http://example.com/bar.pdf", | 491 "http://example.com/bar.pdf", |
| 483 "http://example.com/referrer.html", | 492 "http://example.com/referrer.html", |
| 493 content::DownloadItem::IN_PROGRESS, |
| 484 &info); | 494 &info); |
| 485 { | 495 { |
| 486 std::unique_ptr<InfoVector> infos(new InfoVector()); | 496 std::unique_ptr<InfoVector> infos(new InfoVector()); |
| 487 infos->push_back(info); | 497 infos->push_back(info); |
| 488 CreateDownloadHistory(std::move(infos)); | 498 CreateDownloadHistory(std::move(infos)); |
| 489 ExpectNoDownloadCreated(); | 499 ExpectNoDownloadCreated(); |
| 490 } | 500 } |
| 491 EXPECT_TRUE(DownloadHistory::IsPersisted(&item(0))); | 501 EXPECT_TRUE(DownloadHistory::IsPersisted(&item(0))); |
| 492 | 502 |
| 493 // Pretend that something changed on the item. | 503 // Pretend that something changed on the item. |
| 494 EXPECT_CALL(item(0), GetOpened()).WillRepeatedly(Return(true)); | 504 EXPECT_CALL(item(0), GetOpened()).WillRepeatedly(Return(true)); |
| 495 item(0).NotifyObserversDownloadUpdated(); | 505 item(0).NotifyObserversDownloadUpdated(); |
| 496 info.opened = true; | 506 info.opened = true; |
| 497 ExpectDownloadUpdated(info); | 507 ExpectDownloadUpdated(info, false); |
| 498 | 508 |
| 499 // Pretend that the user removed the item. | 509 // Pretend that the user removed the item. |
| 500 IdSet ids; | 510 IdSet ids; |
| 501 ids.insert(info.id); | 511 ids.insert(info.id); |
| 502 item(0).NotifyObserversDownloadRemoved(); | 512 item(0).NotifyObserversDownloadRemoved(); |
| 503 ExpectDownloadsRemoved(ids); | 513 ExpectDownloadsRemoved(ids); |
| 504 } | 514 } |
| 505 | 515 |
| 506 // Test that the OnHistoryQueryComplete() observer method is invoked for an | 516 // Test that the OnHistoryQueryComplete() observer method is invoked for an |
| 507 // observer that was added before the initial history query completing. | 517 // observer that was added before the initial history query completing. |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 562 ExpectDownloadsRestoredFromHistory(true); | 572 ExpectDownloadsRestoredFromHistory(true); |
| 563 | 573 |
| 564 // Construct a DownloadHistory with a single history download. This results in | 574 // Construct a DownloadHistory with a single history download. This results in |
| 565 // DownloadManager::CreateDownload() being called for the restored download. | 575 // DownloadManager::CreateDownload() being called for the restored download. |
| 566 // The above test expectation should verify that the value of | 576 // The above test expectation should verify that the value of |
| 567 // WasRestoredFromHistory is correct for this download. | 577 // WasRestoredFromHistory is correct for this download. |
| 568 history::DownloadRow info; | 578 history::DownloadRow info; |
| 569 InitBasicItem(FILE_PATH_LITERAL("/foo/bar.pdf"), | 579 InitBasicItem(FILE_PATH_LITERAL("/foo/bar.pdf"), |
| 570 "http://example.com/bar.pdf", | 580 "http://example.com/bar.pdf", |
| 571 "http://example.com/referrer.html", | 581 "http://example.com/referrer.html", |
| 582 content::DownloadItem::COMPLETE, |
| 572 &info); | 583 &info); |
| 573 std::unique_ptr<InfoVector> infos(new InfoVector()); | 584 std::unique_ptr<InfoVector> infos(new InfoVector()); |
| 574 infos->push_back(info); | 585 infos->push_back(info); |
| 575 CreateDownloadHistory(std::move(infos)); | 586 CreateDownloadHistory(std::move(infos)); |
| 576 | 587 |
| 577 EXPECT_TRUE(DownloadHistory::IsPersisted(&item(0))); | 588 EXPECT_TRUE(DownloadHistory::IsPersisted(&item(0))); |
| 578 } | 589 } |
| 579 | 590 |
| 580 // Test that WasRestoredFromHistory accurately identifies downloads that were | 591 // Test that WasRestoredFromHistory accurately identifies downloads that were |
| 581 // not created from history. | 592 // not created from history. |
| 582 TEST_F(DownloadHistoryTest, DownloadHistoryTest_WasRestoredFromHistory_False) { | 593 TEST_F(DownloadHistoryTest, DownloadHistoryTest_WasRestoredFromHistory_False) { |
| 583 // This sets DownloadHistoryTest to call DH::WasRestoredFromHistory() both | 594 // This sets DownloadHistoryTest to call DH::WasRestoredFromHistory() both |
| 584 // before and after DH::OnDownloadCreated() is called. At each call, the | 595 // before and after DH::OnDownloadCreated() is called. At each call, the |
| 585 // expected return value is |true| since the download was restored from | 596 // expected return value is |true| since the download was restored from |
| 586 // history. | 597 // history. |
| 587 ExpectDownloadsRestoredFromHistory(false); | 598 ExpectDownloadsRestoredFromHistory(false); |
| 588 | 599 |
| 589 // Create a DownloadHistory with no history downloads. No | 600 // Create a DownloadHistory with no history downloads. No |
| 590 // DownloadManager::CreateDownload() calls are expected. | 601 // DownloadManager::CreateDownload() calls are expected. |
| 591 CreateDownloadHistory(std::unique_ptr<InfoVector>(new InfoVector())); | 602 CreateDownloadHistory(std::unique_ptr<InfoVector>(new InfoVector())); |
| 592 | 603 |
| 593 // Notify DownloadHistory that a new download was created. The above test | 604 // Notify DownloadHistory that a new download was created. The above test |
| 594 // expecation should verify that WasRestoredFromHistory is correct for this | 605 // expecation should verify that WasRestoredFromHistory is correct for this |
| 595 // download. | 606 // download. |
| 596 history::DownloadRow info; | 607 history::DownloadRow info; |
| 597 InitBasicItem(FILE_PATH_LITERAL("/foo/bar.pdf"), | 608 InitBasicItem(FILE_PATH_LITERAL("/foo/bar.pdf"), |
| 598 "http://example.com/bar.pdf", | 609 "http://example.com/bar.pdf", |
| 599 "http://example.com/referrer.html", | 610 "http://example.com/referrer.html", |
| 611 content::DownloadItem::COMPLETE, |
| 600 &info); | 612 &info); |
| 601 CallOnDownloadCreated(0); | 613 CallOnDownloadCreated(0); |
| 602 ExpectDownloadCreated(info); | 614 ExpectDownloadCreated(info); |
| 603 } | 615 } |
| 604 | 616 |
| 605 // Test creating an item, saving it to the database, changing it, saving it | 617 // Test creating an item, saving it to the database, changing it, saving it |
| 606 // back, removing it. | 618 // back, removing it. |
| 607 TEST_F(DownloadHistoryTest, DownloadHistoryTest_Create) { | 619 TEST_F(DownloadHistoryTest, DownloadHistoryTest_Create) { |
| 608 // Create a fresh item not from history, OnDownloadCreated, OnDownloadUpdated, | 620 // Create a fresh item not from history, OnDownloadCreated, OnDownloadUpdated, |
| 609 // OnDownloadRemoved. | 621 // OnDownloadRemoved. |
| 610 CreateDownloadHistory(std::unique_ptr<InfoVector>(new InfoVector())); | 622 CreateDownloadHistory(std::unique_ptr<InfoVector>(new InfoVector())); |
| 611 | 623 |
| 612 history::DownloadRow info; | 624 history::DownloadRow info; |
| 613 InitBasicItem(FILE_PATH_LITERAL("/foo/bar.pdf"), | 625 InitBasicItem(FILE_PATH_LITERAL("/foo/bar.pdf"), |
| 614 "http://example.com/bar.pdf", | 626 "http://example.com/bar.pdf", |
| 615 "http://example.com/referrer.html", | 627 "http://example.com/referrer.html", |
| 628 content::DownloadItem::IN_PROGRESS, |
| 616 &info); | 629 &info); |
| 617 | 630 |
| 618 // Pretend the manager just created |item|. | 631 // Pretend the manager just created |item|. |
| 619 CallOnDownloadCreated(0); | 632 CallOnDownloadCreated(0); |
| 620 ExpectDownloadCreated(info); | 633 ExpectDownloadCreated(info); |
| 621 EXPECT_TRUE(DownloadHistory::IsPersisted(&item(0))); | 634 EXPECT_TRUE(DownloadHistory::IsPersisted(&item(0))); |
| 622 | 635 |
| 623 // Pretend that something changed on the item. | 636 // Pretend that something changed on the item. |
| 624 EXPECT_CALL(item(0), GetOpened()).WillRepeatedly(Return(true)); | 637 EXPECT_CALL(item(0), GetOpened()).WillRepeatedly(Return(true)); |
| 625 item(0).NotifyObserversDownloadUpdated(); | 638 item(0).NotifyObserversDownloadUpdated(); |
| 626 info.opened = true; | 639 info.opened = true; |
| 627 ExpectDownloadUpdated(info); | 640 ExpectDownloadUpdated(info, false); |
| 628 | 641 |
| 629 // Pretend that the user removed the item. | 642 // Pretend that the user removed the item. |
| 630 IdSet ids; | 643 IdSet ids; |
| 631 ids.insert(info.id); | 644 ids.insert(info.id); |
| 632 item(0).NotifyObserversDownloadRemoved(); | 645 item(0).NotifyObserversDownloadRemoved(); |
| 633 ExpectDownloadsRemoved(ids); | 646 ExpectDownloadsRemoved(ids); |
| 634 } | 647 } |
| 635 | 648 |
| 636 // Test that changes to persisted fields in a DownloadItem triggers database | 649 // Test that changes to persisted fields in a DownloadItem triggers database |
| 637 // updates. | 650 // updates. |
| 638 TEST_F(DownloadHistoryTest, DownloadHistoryTest_Update) { | 651 TEST_F(DownloadHistoryTest, DownloadHistoryTest_Update) { |
| 639 CreateDownloadHistory(std::unique_ptr<InfoVector>(new InfoVector())); | 652 CreateDownloadHistory(std::unique_ptr<InfoVector>(new InfoVector())); |
| 640 | 653 |
| 641 history::DownloadRow info; | 654 history::DownloadRow info; |
| 642 InitBasicItem(FILE_PATH_LITERAL("/foo/bar.pdf"), | 655 InitBasicItem(FILE_PATH_LITERAL("/foo/bar.pdf"), |
| 643 "http://example.com/bar.pdf", | 656 "http://example.com/bar.pdf", |
| 644 "http://example.com/referrer.html", | 657 "http://example.com/referrer.html", |
| 658 content::DownloadItem::IN_PROGRESS, |
| 645 &info); | 659 &info); |
| 660 |
| 646 CallOnDownloadCreated(0); | 661 CallOnDownloadCreated(0); |
| 647 ExpectDownloadCreated(info); | 662 ExpectDownloadCreated(info); |
| 648 EXPECT_TRUE(DownloadHistory::IsPersisted(&item(0))); | 663 EXPECT_TRUE(DownloadHistory::IsPersisted(&item(0))); |
| 649 | 664 |
| 650 base::FilePath new_path(FILE_PATH_LITERAL("/foo/baz.txt")); | 665 base::FilePath new_path(FILE_PATH_LITERAL("/foo/baz.txt")); |
| 651 base::Time new_time(base::Time::Now()); | 666 base::Time new_time(base::Time::Now()); |
| 652 std::string new_etag("new etag"); | 667 std::string new_etag("new etag"); |
| 653 std::string new_last_modifed("new last modified"); | 668 std::string new_last_modifed("new last modified"); |
| 654 | 669 |
| 655 // current_path | 670 // current_path |
| 656 EXPECT_CALL(item(0), GetFullPath()).WillRepeatedly(ReturnRefOfCopy(new_path)); | 671 EXPECT_CALL(item(0), GetFullPath()).WillRepeatedly(ReturnRefOfCopy(new_path)); |
| 657 info.current_path = new_path; | 672 info.current_path = new_path; |
| 658 item(0).NotifyObserversDownloadUpdated(); | 673 item(0).NotifyObserversDownloadUpdated(); |
| 659 ExpectDownloadUpdated(info); | 674 ExpectDownloadUpdated(info, true); |
| 660 | 675 |
| 661 // target_path | 676 // target_path |
| 662 EXPECT_CALL(item(0), GetTargetFilePath()) | 677 EXPECT_CALL(item(0), GetTargetFilePath()) |
| 663 .WillRepeatedly(ReturnRefOfCopy(new_path)); | 678 .WillRepeatedly(ReturnRefOfCopy(new_path)); |
| 664 info.target_path = new_path; | 679 info.target_path = new_path; |
| 665 item(0).NotifyObserversDownloadUpdated(); | 680 item(0).NotifyObserversDownloadUpdated(); |
| 666 ExpectDownloadUpdated(info); | 681 ExpectDownloadUpdated(info, false); |
| 667 | 682 |
| 668 // end_time | 683 // end_time |
| 669 EXPECT_CALL(item(0), GetEndTime()).WillRepeatedly(Return(new_time)); | 684 EXPECT_CALL(item(0), GetEndTime()).WillRepeatedly(Return(new_time)); |
| 670 info.end_time = new_time; | 685 info.end_time = new_time; |
| 671 item(0).NotifyObserversDownloadUpdated(); | 686 item(0).NotifyObserversDownloadUpdated(); |
| 672 ExpectDownloadUpdated(info); | 687 ExpectDownloadUpdated(info, false); |
| 673 | 688 |
| 674 // received_bytes | 689 // received_bytes |
| 675 EXPECT_CALL(item(0), GetReceivedBytes()).WillRepeatedly(Return(101)); | 690 EXPECT_CALL(item(0), GetReceivedBytes()).WillRepeatedly(Return(101)); |
| 676 info.received_bytes = 101; | 691 info.received_bytes = 101; |
| 677 item(0).NotifyObserversDownloadUpdated(); | 692 item(0).NotifyObserversDownloadUpdated(); |
| 678 ExpectDownloadUpdated(info); | 693 ExpectDownloadUpdated(info, false); |
| 679 | 694 |
| 680 // total_bytes | 695 // total_bytes |
| 681 EXPECT_CALL(item(0), GetTotalBytes()).WillRepeatedly(Return(102)); | 696 EXPECT_CALL(item(0), GetTotalBytes()).WillRepeatedly(Return(102)); |
| 682 info.total_bytes = 102; | 697 info.total_bytes = 102; |
| 683 item(0).NotifyObserversDownloadUpdated(); | 698 item(0).NotifyObserversDownloadUpdated(); |
| 684 ExpectDownloadUpdated(info); | 699 ExpectDownloadUpdated(info, false); |
| 685 | 700 |
| 686 // etag | 701 // etag |
| 687 EXPECT_CALL(item(0), GetETag()).WillRepeatedly(ReturnRefOfCopy(new_etag)); | 702 EXPECT_CALL(item(0), GetETag()).WillRepeatedly(ReturnRefOfCopy(new_etag)); |
| 688 info.etag = new_etag; | 703 info.etag = new_etag; |
| 689 item(0).NotifyObserversDownloadUpdated(); | 704 item(0).NotifyObserversDownloadUpdated(); |
| 690 ExpectDownloadUpdated(info); | 705 ExpectDownloadUpdated(info, false); |
| 691 | 706 |
| 692 // last_modified | 707 // last_modified |
| 693 EXPECT_CALL(item(0), GetLastModifiedTime()) | 708 EXPECT_CALL(item(0), GetLastModifiedTime()) |
| 694 .WillRepeatedly(ReturnRefOfCopy(new_last_modifed)); | 709 .WillRepeatedly(ReturnRefOfCopy(new_last_modifed)); |
| 695 info.last_modified = new_last_modifed; | 710 info.last_modified = new_last_modifed; |
| 696 item(0).NotifyObserversDownloadUpdated(); | 711 item(0).NotifyObserversDownloadUpdated(); |
| 697 ExpectDownloadUpdated(info); | 712 ExpectDownloadUpdated(info, false); |
| 698 | 713 |
| 699 // state | 714 // state |
| 715 // Changing the state to INTERRUPTED will remove its stored state. |
| 700 EXPECT_CALL(item(0), GetState()) | 716 EXPECT_CALL(item(0), GetState()) |
| 701 .WillRepeatedly(Return(content::DownloadItem::INTERRUPTED)); | 717 .WillRepeatedly(Return(content::DownloadItem::INTERRUPTED)); |
| 702 info.state = history::DownloadState::INTERRUPTED; | 718 info.state = history::DownloadState::INTERRUPTED; |
| 703 item(0).NotifyObserversDownloadUpdated(); | 719 item(0).NotifyObserversDownloadUpdated(); |
| 704 ExpectDownloadUpdated(info); | 720 ExpectDownloadUpdated(info, false); |
| 721 |
| 722 // Changing the state back to IN_PROGRESS to reset its stored state. |
| 723 EXPECT_CALL(item(0), GetState()) |
| 724 .WillRepeatedly(Return(content::DownloadItem::IN_PROGRESS)); |
| 725 info.state = history::DownloadState::IN_PROGRESS; |
| 726 item(0).NotifyObserversDownloadUpdated(); |
| 727 ExpectDownloadUpdated(info, true); |
| 705 | 728 |
| 706 // danger_type | 729 // danger_type |
| 707 EXPECT_CALL(item(0), GetDangerType()) | 730 EXPECT_CALL(item(0), GetDangerType()) |
| 708 .WillRepeatedly(Return(content::DOWNLOAD_DANGER_TYPE_DANGEROUS_CONTENT)); | 731 .WillRepeatedly(Return(content::DOWNLOAD_DANGER_TYPE_DANGEROUS_CONTENT)); |
| 709 info.danger_type = history::DownloadDangerType::DANGEROUS_CONTENT; | 732 info.danger_type = history::DownloadDangerType::DANGEROUS_CONTENT; |
| 710 item(0).NotifyObserversDownloadUpdated(); | 733 item(0).NotifyObserversDownloadUpdated(); |
| 711 ExpectDownloadUpdated(info); | 734 ExpectDownloadUpdated(info, false); |
| 712 | 735 |
| 713 // interrupt_reason | 736 // interrupt_reason |
| 714 EXPECT_CALL(item(0), GetLastReason()) | 737 EXPECT_CALL(item(0), GetLastReason()) |
| 715 .WillRepeatedly(Return(content::DOWNLOAD_INTERRUPT_REASON_SERVER_FAILED)); | 738 .WillRepeatedly(Return(content::DOWNLOAD_INTERRUPT_REASON_SERVER_FAILED)); |
| 716 info.interrupt_reason = history::ToHistoryDownloadInterruptReason( | 739 info.interrupt_reason = history::ToHistoryDownloadInterruptReason( |
| 717 content::DOWNLOAD_INTERRUPT_REASON_SERVER_FAILED); | 740 content::DOWNLOAD_INTERRUPT_REASON_SERVER_FAILED); |
| 718 item(0).NotifyObserversDownloadUpdated(); | 741 item(0).NotifyObserversDownloadUpdated(); |
| 719 ExpectDownloadUpdated(info); | 742 ExpectDownloadUpdated(info, false); |
| 720 | 743 |
| 721 // opened | 744 // opened |
| 722 EXPECT_CALL(item(0), GetOpened()).WillRepeatedly(Return(true)); | 745 EXPECT_CALL(item(0), GetOpened()).WillRepeatedly(Return(true)); |
| 723 info.opened = true; | 746 info.opened = true; |
| 724 item(0).NotifyObserversDownloadUpdated(); | 747 item(0).NotifyObserversDownloadUpdated(); |
| 725 ExpectDownloadUpdated(info); | 748 ExpectDownloadUpdated(info, false); |
| 726 } | 749 } |
| 727 | 750 |
| 728 // Test creating a new item, saving it, removing it by setting it Temporary, | 751 // Test creating a new item, saving it, removing it by setting it Temporary, |
| 729 // changing it without saving it back because it's Temporary, clearing | 752 // changing it without saving it back because it's Temporary, clearing |
| 730 // IsTemporary, saving it back, changing it, saving it back because it isn't | 753 // IsTemporary, saving it back, changing it, saving it back because it isn't |
| 731 // Temporary anymore. | 754 // Temporary anymore. |
| 732 TEST_F(DownloadHistoryTest, DownloadHistoryTest_Temporary) { | 755 TEST_F(DownloadHistoryTest, DownloadHistoryTest_Temporary) { |
| 733 // Create a fresh item not from history, OnDownloadCreated, OnDownloadUpdated, | 756 // Create a fresh item not from history, OnDownloadCreated, OnDownloadUpdated, |
| 734 // OnDownloadRemoved. | 757 // OnDownloadRemoved. |
| 735 CreateDownloadHistory(std::unique_ptr<InfoVector>(new InfoVector())); | 758 CreateDownloadHistory(std::unique_ptr<InfoVector>(new InfoVector())); |
| 736 | 759 |
| 737 history::DownloadRow info; | 760 history::DownloadRow info; |
| 738 InitBasicItem(FILE_PATH_LITERAL("/foo/bar.pdf"), | 761 InitBasicItem(FILE_PATH_LITERAL("/foo/bar.pdf"), |
| 739 "http://example.com/bar.pdf", | 762 "http://example.com/bar.pdf", |
| 740 "http://example.com/referrer.html", | 763 "http://example.com/referrer.html", |
| 764 content::DownloadItem::COMPLETE, |
| 741 &info); | 765 &info); |
| 742 | 766 |
| 743 // Pretend the manager just created |item|. | 767 // Pretend the manager just created |item|. |
| 744 CallOnDownloadCreated(0); | 768 CallOnDownloadCreated(0); |
| 745 ExpectDownloadCreated(info); | 769 ExpectDownloadCreated(info); |
| 746 EXPECT_TRUE(DownloadHistory::IsPersisted(&item(0))); | 770 EXPECT_TRUE(DownloadHistory::IsPersisted(&item(0))); |
| 747 | 771 |
| 748 // Pretend the item was marked temporary. DownloadHistory should remove it | 772 // Pretend the item was marked temporary. DownloadHistory should remove it |
| 749 // from history and start ignoring it. | 773 // from history and start ignoring it. |
| 750 EXPECT_CALL(item(0), IsTemporary()).WillRepeatedly(Return(true)); | 774 EXPECT_CALL(item(0), IsTemporary()).WillRepeatedly(Return(true)); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 763 // DownloadHistory call CreateDownload. | 787 // DownloadHistory call CreateDownload. |
| 764 EXPECT_CALL(item(0), IsTemporary()).WillRepeatedly(Return(false)); | 788 EXPECT_CALL(item(0), IsTemporary()).WillRepeatedly(Return(false)); |
| 765 item(0).NotifyObserversDownloadUpdated(); | 789 item(0).NotifyObserversDownloadUpdated(); |
| 766 info.received_bytes = 4200; | 790 info.received_bytes = 4200; |
| 767 ExpectDownloadCreated(info); | 791 ExpectDownloadCreated(info); |
| 768 EXPECT_TRUE(DownloadHistory::IsPersisted(&item(0))); | 792 EXPECT_TRUE(DownloadHistory::IsPersisted(&item(0))); |
| 769 | 793 |
| 770 EXPECT_CALL(item(0), GetReceivedBytes()).WillRepeatedly(Return(100)); | 794 EXPECT_CALL(item(0), GetReceivedBytes()).WillRepeatedly(Return(100)); |
| 771 item(0).NotifyObserversDownloadUpdated(); | 795 item(0).NotifyObserversDownloadUpdated(); |
| 772 info.received_bytes = 100; | 796 info.received_bytes = 100; |
| 773 ExpectDownloadUpdated(info); | 797 ExpectDownloadUpdated(info, true); |
| 774 } | 798 } |
| 775 | 799 |
| 776 // Test removing downloads while they're still being added. | 800 // Test removing downloads while they're still being added. |
| 777 TEST_F(DownloadHistoryTest, DownloadHistoryTest_RemoveWhileAdding) { | 801 TEST_F(DownloadHistoryTest, DownloadHistoryTest_RemoveWhileAdding) { |
| 778 CreateDownloadHistory(std::unique_ptr<InfoVector>(new InfoVector())); | 802 CreateDownloadHistory(std::unique_ptr<InfoVector>(new InfoVector())); |
| 779 | 803 |
| 780 history::DownloadRow info; | 804 history::DownloadRow info; |
| 781 InitBasicItem(FILE_PATH_LITERAL("/foo/bar.pdf"), | 805 InitBasicItem(FILE_PATH_LITERAL("/foo/bar.pdf"), |
| 782 "http://example.com/bar.pdf", | 806 "http://example.com/bar.pdf", |
| 783 "http://example.com/referrer.html", | 807 "http://example.com/referrer.html", |
| 808 content::DownloadItem::COMPLETE, |
| 784 &info); | 809 &info); |
| 785 | 810 |
| 786 // Instruct CreateDownload() to not callback to DownloadHistory immediately, | 811 // Instruct CreateDownload() to not callback to DownloadHistory immediately, |
| 787 // but to wait for FinishCreateDownload(). | 812 // but to wait for FinishCreateDownload(). |
| 788 set_slow_create_download(true); | 813 set_slow_create_download(true); |
| 789 | 814 |
| 790 // Pretend the manager just created |item|. | 815 // Pretend the manager just created |item|. |
| 791 CallOnDownloadCreated(0); | 816 CallOnDownloadCreated(0); |
| 792 ExpectDownloadCreated(info); | 817 ExpectDownloadCreated(info); |
| 793 EXPECT_FALSE(DownloadHistory::IsPersisted(&item(0))); | 818 EXPECT_FALSE(DownloadHistory::IsPersisted(&item(0))); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 812 } | 837 } |
| 813 | 838 |
| 814 // Test loading multiple items from the database and removing them all. | 839 // Test loading multiple items from the database and removing them all. |
| 815 TEST_F(DownloadHistoryTest, DownloadHistoryTest_Multiple) { | 840 TEST_F(DownloadHistoryTest, DownloadHistoryTest_Multiple) { |
| 816 // Load a download from history, create the item, OnDownloadCreated, | 841 // Load a download from history, create the item, OnDownloadCreated, |
| 817 // OnDownloadUpdated, OnDownloadRemoved. | 842 // OnDownloadUpdated, OnDownloadRemoved. |
| 818 history::DownloadRow info0, info1; | 843 history::DownloadRow info0, info1; |
| 819 InitBasicItem(FILE_PATH_LITERAL("/foo/bar.pdf"), | 844 InitBasicItem(FILE_PATH_LITERAL("/foo/bar.pdf"), |
| 820 "http://example.com/bar.pdf", | 845 "http://example.com/bar.pdf", |
| 821 "http://example.com/referrer.html", | 846 "http://example.com/referrer.html", |
| 847 content::DownloadItem::COMPLETE, |
| 822 &info0); | 848 &info0); |
| 823 InitBasicItem(FILE_PATH_LITERAL("/foo/qux.pdf"), | 849 InitBasicItem(FILE_PATH_LITERAL("/foo/qux.pdf"), |
| 824 "http://example.com/qux.pdf", | 850 "http://example.com/qux.pdf", |
| 825 "http://example.com/referrer1.html", | 851 "http://example.com/referrer1.html", |
| 852 content::DownloadItem::COMPLETE, |
| 826 &info1); | 853 &info1); |
| 827 { | 854 { |
| 828 std::unique_ptr<InfoVector> infos(new InfoVector()); | 855 std::unique_ptr<InfoVector> infos(new InfoVector()); |
| 829 infos->push_back(info0); | 856 infos->push_back(info0); |
| 830 infos->push_back(info1); | 857 infos->push_back(info1); |
| 831 CreateDownloadHistory(std::move(infos)); | 858 CreateDownloadHistory(std::move(infos)); |
| 832 ExpectNoDownloadCreated(); | 859 ExpectNoDownloadCreated(); |
| 833 } | 860 } |
| 834 | 861 |
| 835 EXPECT_TRUE(DownloadHistory::IsPersisted(&item(0))); | 862 EXPECT_TRUE(DownloadHistory::IsPersisted(&item(0))); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 847 // Test what happens when HistoryService/CreateDownload::CreateDownload() fails. | 874 // Test what happens when HistoryService/CreateDownload::CreateDownload() fails. |
| 848 TEST_F(DownloadHistoryTest, DownloadHistoryTest_CreateFailed) { | 875 TEST_F(DownloadHistoryTest, DownloadHistoryTest_CreateFailed) { |
| 849 // Create a fresh item not from history, OnDownloadCreated, OnDownloadUpdated, | 876 // Create a fresh item not from history, OnDownloadCreated, OnDownloadUpdated, |
| 850 // OnDownloadRemoved. | 877 // OnDownloadRemoved. |
| 851 CreateDownloadHistory(std::unique_ptr<InfoVector>(new InfoVector())); | 878 CreateDownloadHistory(std::unique_ptr<InfoVector>(new InfoVector())); |
| 852 | 879 |
| 853 history::DownloadRow info; | 880 history::DownloadRow info; |
| 854 InitBasicItem(FILE_PATH_LITERAL("/foo/bar.pdf"), | 881 InitBasicItem(FILE_PATH_LITERAL("/foo/bar.pdf"), |
| 855 "http://example.com/bar.pdf", | 882 "http://example.com/bar.pdf", |
| 856 "http://example.com/referrer.html", | 883 "http://example.com/referrer.html", |
| 884 content::DownloadItem::COMPLETE, |
| 857 &info); | 885 &info); |
| 858 | 886 |
| 859 FailCreateDownload(); | 887 FailCreateDownload(); |
| 860 // Pretend the manager just created |item|. | 888 // Pretend the manager just created |item|. |
| 861 CallOnDownloadCreated(0); | 889 CallOnDownloadCreated(0); |
| 862 ExpectDownloadCreated(info); | 890 ExpectDownloadCreated(info); |
| 863 EXPECT_FALSE(DownloadHistory::IsPersisted(&item(0))); | 891 EXPECT_FALSE(DownloadHistory::IsPersisted(&item(0))); |
| 864 | 892 |
| 865 EXPECT_CALL(item(0), GetReceivedBytes()).WillRepeatedly(Return(100)); | 893 EXPECT_CALL(item(0), GetReceivedBytes()).WillRepeatedly(Return(100)); |
| 866 item(0).NotifyObserversDownloadUpdated(); | 894 item(0).NotifyObserversDownloadUpdated(); |
| 867 info.received_bytes = 100; | 895 info.received_bytes = 100; |
| 868 ExpectDownloadCreated(info); | 896 ExpectDownloadCreated(info); |
| 869 EXPECT_TRUE(DownloadHistory::IsPersisted(&item(0))); | 897 EXPECT_TRUE(DownloadHistory::IsPersisted(&item(0))); |
| 870 } | 898 } |
| 871 | 899 |
| 872 TEST_F(DownloadHistoryTest, DownloadHistoryTest_UpdateWhileAdding) { | 900 TEST_F(DownloadHistoryTest, DownloadHistoryTest_UpdateWhileAdding) { |
| 873 // Create a fresh item not from history, OnDownloadCreated, OnDownloadUpdated, | 901 // Create a fresh item not from history, OnDownloadCreated, OnDownloadUpdated, |
| 874 // OnDownloadRemoved. | 902 // OnDownloadRemoved. |
| 875 CreateDownloadHistory(std::unique_ptr<InfoVector>(new InfoVector())); | 903 CreateDownloadHistory(std::unique_ptr<InfoVector>(new InfoVector())); |
| 876 | 904 |
| 877 history::DownloadRow info; | 905 history::DownloadRow info; |
| 878 InitBasicItem(FILE_PATH_LITERAL("/foo/bar.pdf"), | 906 InitBasicItem(FILE_PATH_LITERAL("/foo/bar.pdf"), |
| 879 "http://example.com/bar.pdf", | 907 "http://example.com/bar.pdf", |
| 880 "http://example.com/referrer.html", | 908 "http://example.com/referrer.html", |
| 909 content::DownloadItem::IN_PROGRESS, |
| 881 &info); | 910 &info); |
| 882 | 911 |
| 883 // Instruct CreateDownload() to not callback to DownloadHistory immediately, | 912 // Instruct CreateDownload() to not callback to DownloadHistory immediately, |
| 884 // but to wait for FinishCreateDownload(). | 913 // but to wait for FinishCreateDownload(). |
| 885 set_slow_create_download(true); | 914 set_slow_create_download(true); |
| 886 | 915 |
| 887 // Pretend the manager just created |item|. | 916 // Pretend the manager just created |item|. |
| 888 CallOnDownloadCreated(0); | 917 CallOnDownloadCreated(0); |
| 889 ExpectDownloadCreated(info); | 918 ExpectDownloadCreated(info); |
| 890 EXPECT_FALSE(DownloadHistory::IsPersisted(&item(0))); | 919 EXPECT_FALSE(DownloadHistory::IsPersisted(&item(0))); |
| 891 | 920 |
| 892 // Pretend that something changed on the item. | 921 // Pretend that something changed on the item. |
| 893 EXPECT_CALL(item(0), GetOpened()).WillRepeatedly(Return(true)); | 922 EXPECT_CALL(item(0), GetOpened()).WillRepeatedly(Return(true)); |
| 894 item(0).NotifyObserversDownloadUpdated(); | 923 item(0).NotifyObserversDownloadUpdated(); |
| 895 | 924 |
| 896 FinishCreateDownload(); | 925 FinishCreateDownload(); |
| 897 EXPECT_TRUE(DownloadHistory::IsPersisted(&item(0))); | 926 EXPECT_TRUE(DownloadHistory::IsPersisted(&item(0))); |
| 898 | 927 |
| 899 // ItemAdded should call OnDownloadUpdated, which should detect that the item | 928 // ItemAdded should call OnDownloadUpdated, which should detect that the item |
| 900 // changed while it was being added and call UpdateDownload immediately. | 929 // changed while it was being added and call UpdateDownload immediately. |
| 901 info.opened = true; | 930 info.opened = true; |
| 902 ExpectDownloadUpdated(info); | 931 ExpectDownloadUpdated(info, false); |
| 903 } | 932 } |
| 904 | 933 |
| 905 } // anonymous namespace | 934 } // anonymous namespace |
| OLD | NEW |