Chromium Code Reviews| 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::COMPLETE, | |
| 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::COMPLETE, | |
| 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); |
|
asanka
2016/11/21 20:17:57
There's currently no test for the case where Shoul
qinmin
2016/11/21 23:14:54
Actually, we set the state INTERRUPTED in this tes
| |
| 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 |
| 700 EXPECT_CALL(item(0), GetState()) | 715 EXPECT_CALL(item(0), GetState()) |
| 701 .WillRepeatedly(Return(content::DownloadItem::INTERRUPTED)); | 716 .WillRepeatedly(Return(content::DownloadItem::INTERRUPTED)); |
| 702 info.state = history::DownloadState::INTERRUPTED; | 717 info.state = history::DownloadState::INTERRUPTED; |
| 703 item(0).NotifyObserversDownloadUpdated(); | 718 item(0).NotifyObserversDownloadUpdated(); |
| 704 ExpectDownloadUpdated(info); | 719 ExpectDownloadUpdated(info, false); |
| 705 | 720 |
| 706 // danger_type | 721 // danger_type |
| 707 EXPECT_CALL(item(0), GetDangerType()) | 722 EXPECT_CALL(item(0), GetDangerType()) |
| 708 .WillRepeatedly(Return(content::DOWNLOAD_DANGER_TYPE_DANGEROUS_CONTENT)); | 723 .WillRepeatedly(Return(content::DOWNLOAD_DANGER_TYPE_DANGEROUS_CONTENT)); |
| 709 info.danger_type = history::DownloadDangerType::DANGEROUS_CONTENT; | 724 info.danger_type = history::DownloadDangerType::DANGEROUS_CONTENT; |
| 710 item(0).NotifyObserversDownloadUpdated(); | 725 item(0).NotifyObserversDownloadUpdated(); |
| 711 ExpectDownloadUpdated(info); | 726 ExpectDownloadUpdated(info, false); |
| 712 | 727 |
| 713 // interrupt_reason | 728 // interrupt_reason |
| 714 EXPECT_CALL(item(0), GetLastReason()) | 729 EXPECT_CALL(item(0), GetLastReason()) |
| 715 .WillRepeatedly(Return(content::DOWNLOAD_INTERRUPT_REASON_SERVER_FAILED)); | 730 .WillRepeatedly(Return(content::DOWNLOAD_INTERRUPT_REASON_SERVER_FAILED)); |
| 716 info.interrupt_reason = history::ToHistoryDownloadInterruptReason( | 731 info.interrupt_reason = history::ToHistoryDownloadInterruptReason( |
| 717 content::DOWNLOAD_INTERRUPT_REASON_SERVER_FAILED); | 732 content::DOWNLOAD_INTERRUPT_REASON_SERVER_FAILED); |
| 718 item(0).NotifyObserversDownloadUpdated(); | 733 item(0).NotifyObserversDownloadUpdated(); |
| 719 ExpectDownloadUpdated(info); | 734 ExpectDownloadUpdated(info, false); |
| 720 | 735 |
| 721 // opened | 736 // opened |
| 722 EXPECT_CALL(item(0), GetOpened()).WillRepeatedly(Return(true)); | 737 EXPECT_CALL(item(0), GetOpened()).WillRepeatedly(Return(true)); |
| 723 info.opened = true; | 738 info.opened = true; |
| 724 item(0).NotifyObserversDownloadUpdated(); | 739 item(0).NotifyObserversDownloadUpdated(); |
| 725 ExpectDownloadUpdated(info); | 740 ExpectDownloadUpdated(info, false); |
| 726 } | 741 } |
| 727 | 742 |
| 728 // Test creating a new item, saving it, removing it by setting it Temporary, | 743 // 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 | 744 // 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 | 745 // IsTemporary, saving it back, changing it, saving it back because it isn't |
| 731 // Temporary anymore. | 746 // Temporary anymore. |
| 732 TEST_F(DownloadHistoryTest, DownloadHistoryTest_Temporary) { | 747 TEST_F(DownloadHistoryTest, DownloadHistoryTest_Temporary) { |
| 733 // Create a fresh item not from history, OnDownloadCreated, OnDownloadUpdated, | 748 // Create a fresh item not from history, OnDownloadCreated, OnDownloadUpdated, |
| 734 // OnDownloadRemoved. | 749 // OnDownloadRemoved. |
| 735 CreateDownloadHistory(std::unique_ptr<InfoVector>(new InfoVector())); | 750 CreateDownloadHistory(std::unique_ptr<InfoVector>(new InfoVector())); |
| 736 | 751 |
| 737 history::DownloadRow info; | 752 history::DownloadRow info; |
| 738 InitBasicItem(FILE_PATH_LITERAL("/foo/bar.pdf"), | 753 InitBasicItem(FILE_PATH_LITERAL("/foo/bar.pdf"), |
| 739 "http://example.com/bar.pdf", | 754 "http://example.com/bar.pdf", |
| 740 "http://example.com/referrer.html", | 755 "http://example.com/referrer.html", |
| 756 content::DownloadItem::COMPLETE, | |
| 741 &info); | 757 &info); |
| 742 | 758 |
| 743 // Pretend the manager just created |item|. | 759 // Pretend the manager just created |item|. |
| 744 CallOnDownloadCreated(0); | 760 CallOnDownloadCreated(0); |
| 745 ExpectDownloadCreated(info); | 761 ExpectDownloadCreated(info); |
| 746 EXPECT_TRUE(DownloadHistory::IsPersisted(&item(0))); | 762 EXPECT_TRUE(DownloadHistory::IsPersisted(&item(0))); |
| 747 | 763 |
| 748 // Pretend the item was marked temporary. DownloadHistory should remove it | 764 // Pretend the item was marked temporary. DownloadHistory should remove it |
| 749 // from history and start ignoring it. | 765 // from history and start ignoring it. |
| 750 EXPECT_CALL(item(0), IsTemporary()).WillRepeatedly(Return(true)); | 766 EXPECT_CALL(item(0), IsTemporary()).WillRepeatedly(Return(true)); |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 763 // DownloadHistory call CreateDownload. | 779 // DownloadHistory call CreateDownload. |
| 764 EXPECT_CALL(item(0), IsTemporary()).WillRepeatedly(Return(false)); | 780 EXPECT_CALL(item(0), IsTemporary()).WillRepeatedly(Return(false)); |
| 765 item(0).NotifyObserversDownloadUpdated(); | 781 item(0).NotifyObserversDownloadUpdated(); |
| 766 info.received_bytes = 4200; | 782 info.received_bytes = 4200; |
| 767 ExpectDownloadCreated(info); | 783 ExpectDownloadCreated(info); |
| 768 EXPECT_TRUE(DownloadHistory::IsPersisted(&item(0))); | 784 EXPECT_TRUE(DownloadHistory::IsPersisted(&item(0))); |
| 769 | 785 |
| 770 EXPECT_CALL(item(0), GetReceivedBytes()).WillRepeatedly(Return(100)); | 786 EXPECT_CALL(item(0), GetReceivedBytes()).WillRepeatedly(Return(100)); |
| 771 item(0).NotifyObserversDownloadUpdated(); | 787 item(0).NotifyObserversDownloadUpdated(); |
| 772 info.received_bytes = 100; | 788 info.received_bytes = 100; |
| 773 ExpectDownloadUpdated(info); | 789 ExpectDownloadUpdated(info, false); |
| 774 } | 790 } |
| 775 | 791 |
| 776 // Test removing downloads while they're still being added. | 792 // Test removing downloads while they're still being added. |
| 777 TEST_F(DownloadHistoryTest, DownloadHistoryTest_RemoveWhileAdding) { | 793 TEST_F(DownloadHistoryTest, DownloadHistoryTest_RemoveWhileAdding) { |
| 778 CreateDownloadHistory(std::unique_ptr<InfoVector>(new InfoVector())); | 794 CreateDownloadHistory(std::unique_ptr<InfoVector>(new InfoVector())); |
| 779 | 795 |
| 780 history::DownloadRow info; | 796 history::DownloadRow info; |
| 781 InitBasicItem(FILE_PATH_LITERAL("/foo/bar.pdf"), | 797 InitBasicItem(FILE_PATH_LITERAL("/foo/bar.pdf"), |
| 782 "http://example.com/bar.pdf", | 798 "http://example.com/bar.pdf", |
| 783 "http://example.com/referrer.html", | 799 "http://example.com/referrer.html", |
| 800 content::DownloadItem::COMPLETE, | |
| 784 &info); | 801 &info); |
| 785 | 802 |
| 786 // Instruct CreateDownload() to not callback to DownloadHistory immediately, | 803 // Instruct CreateDownload() to not callback to DownloadHistory immediately, |
| 787 // but to wait for FinishCreateDownload(). | 804 // but to wait for FinishCreateDownload(). |
| 788 set_slow_create_download(true); | 805 set_slow_create_download(true); |
| 789 | 806 |
| 790 // Pretend the manager just created |item|. | 807 // Pretend the manager just created |item|. |
| 791 CallOnDownloadCreated(0); | 808 CallOnDownloadCreated(0); |
| 792 ExpectDownloadCreated(info); | 809 ExpectDownloadCreated(info); |
| 793 EXPECT_FALSE(DownloadHistory::IsPersisted(&item(0))); | 810 EXPECT_FALSE(DownloadHistory::IsPersisted(&item(0))); |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 812 } | 829 } |
| 813 | 830 |
| 814 // Test loading multiple items from the database and removing them all. | 831 // Test loading multiple items from the database and removing them all. |
| 815 TEST_F(DownloadHistoryTest, DownloadHistoryTest_Multiple) { | 832 TEST_F(DownloadHistoryTest, DownloadHistoryTest_Multiple) { |
| 816 // Load a download from history, create the item, OnDownloadCreated, | 833 // Load a download from history, create the item, OnDownloadCreated, |
| 817 // OnDownloadUpdated, OnDownloadRemoved. | 834 // OnDownloadUpdated, OnDownloadRemoved. |
| 818 history::DownloadRow info0, info1; | 835 history::DownloadRow info0, info1; |
| 819 InitBasicItem(FILE_PATH_LITERAL("/foo/bar.pdf"), | 836 InitBasicItem(FILE_PATH_LITERAL("/foo/bar.pdf"), |
| 820 "http://example.com/bar.pdf", | 837 "http://example.com/bar.pdf", |
| 821 "http://example.com/referrer.html", | 838 "http://example.com/referrer.html", |
| 839 content::DownloadItem::COMPLETE, | |
| 822 &info0); | 840 &info0); |
| 823 InitBasicItem(FILE_PATH_LITERAL("/foo/qux.pdf"), | 841 InitBasicItem(FILE_PATH_LITERAL("/foo/qux.pdf"), |
| 824 "http://example.com/qux.pdf", | 842 "http://example.com/qux.pdf", |
| 825 "http://example.com/referrer1.html", | 843 "http://example.com/referrer1.html", |
| 844 content::DownloadItem::COMPLETE, | |
| 826 &info1); | 845 &info1); |
| 827 { | 846 { |
| 828 std::unique_ptr<InfoVector> infos(new InfoVector()); | 847 std::unique_ptr<InfoVector> infos(new InfoVector()); |
| 829 infos->push_back(info0); | 848 infos->push_back(info0); |
| 830 infos->push_back(info1); | 849 infos->push_back(info1); |
| 831 CreateDownloadHistory(std::move(infos)); | 850 CreateDownloadHistory(std::move(infos)); |
| 832 ExpectNoDownloadCreated(); | 851 ExpectNoDownloadCreated(); |
| 833 } | 852 } |
| 834 | 853 |
| 835 EXPECT_TRUE(DownloadHistory::IsPersisted(&item(0))); | 854 EXPECT_TRUE(DownloadHistory::IsPersisted(&item(0))); |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 847 // Test what happens when HistoryService/CreateDownload::CreateDownload() fails. | 866 // Test what happens when HistoryService/CreateDownload::CreateDownload() fails. |
| 848 TEST_F(DownloadHistoryTest, DownloadHistoryTest_CreateFailed) { | 867 TEST_F(DownloadHistoryTest, DownloadHistoryTest_CreateFailed) { |
| 849 // Create a fresh item not from history, OnDownloadCreated, OnDownloadUpdated, | 868 // Create a fresh item not from history, OnDownloadCreated, OnDownloadUpdated, |
| 850 // OnDownloadRemoved. | 869 // OnDownloadRemoved. |
| 851 CreateDownloadHistory(std::unique_ptr<InfoVector>(new InfoVector())); | 870 CreateDownloadHistory(std::unique_ptr<InfoVector>(new InfoVector())); |
| 852 | 871 |
| 853 history::DownloadRow info; | 872 history::DownloadRow info; |
| 854 InitBasicItem(FILE_PATH_LITERAL("/foo/bar.pdf"), | 873 InitBasicItem(FILE_PATH_LITERAL("/foo/bar.pdf"), |
| 855 "http://example.com/bar.pdf", | 874 "http://example.com/bar.pdf", |
| 856 "http://example.com/referrer.html", | 875 "http://example.com/referrer.html", |
| 876 content::DownloadItem::COMPLETE, | |
| 857 &info); | 877 &info); |
| 858 | 878 |
| 859 FailCreateDownload(); | 879 FailCreateDownload(); |
| 860 // Pretend the manager just created |item|. | 880 // Pretend the manager just created |item|. |
| 861 CallOnDownloadCreated(0); | 881 CallOnDownloadCreated(0); |
| 862 ExpectDownloadCreated(info); | 882 ExpectDownloadCreated(info); |
| 863 EXPECT_FALSE(DownloadHistory::IsPersisted(&item(0))); | 883 EXPECT_FALSE(DownloadHistory::IsPersisted(&item(0))); |
| 864 | 884 |
| 865 EXPECT_CALL(item(0), GetReceivedBytes()).WillRepeatedly(Return(100)); | 885 EXPECT_CALL(item(0), GetReceivedBytes()).WillRepeatedly(Return(100)); |
| 866 item(0).NotifyObserversDownloadUpdated(); | 886 item(0).NotifyObserversDownloadUpdated(); |
| 867 info.received_bytes = 100; | 887 info.received_bytes = 100; |
| 868 ExpectDownloadCreated(info); | 888 ExpectDownloadCreated(info); |
| 869 EXPECT_TRUE(DownloadHistory::IsPersisted(&item(0))); | 889 EXPECT_TRUE(DownloadHistory::IsPersisted(&item(0))); |
| 870 } | 890 } |
| 871 | 891 |
| 872 TEST_F(DownloadHistoryTest, DownloadHistoryTest_UpdateWhileAdding) { | 892 TEST_F(DownloadHistoryTest, DownloadHistoryTest_UpdateWhileAdding) { |
| 873 // Create a fresh item not from history, OnDownloadCreated, OnDownloadUpdated, | 893 // Create a fresh item not from history, OnDownloadCreated, OnDownloadUpdated, |
| 874 // OnDownloadRemoved. | 894 // OnDownloadRemoved. |
| 875 CreateDownloadHistory(std::unique_ptr<InfoVector>(new InfoVector())); | 895 CreateDownloadHistory(std::unique_ptr<InfoVector>(new InfoVector())); |
| 876 | 896 |
| 877 history::DownloadRow info; | 897 history::DownloadRow info; |
| 878 InitBasicItem(FILE_PATH_LITERAL("/foo/bar.pdf"), | 898 InitBasicItem(FILE_PATH_LITERAL("/foo/bar.pdf"), |
| 879 "http://example.com/bar.pdf", | 899 "http://example.com/bar.pdf", |
| 880 "http://example.com/referrer.html", | 900 "http://example.com/referrer.html", |
| 901 content::DownloadItem::COMPLETE, | |
| 881 &info); | 902 &info); |
| 882 | 903 |
| 883 // Instruct CreateDownload() to not callback to DownloadHistory immediately, | 904 // Instruct CreateDownload() to not callback to DownloadHistory immediately, |
| 884 // but to wait for FinishCreateDownload(). | 905 // but to wait for FinishCreateDownload(). |
| 885 set_slow_create_download(true); | 906 set_slow_create_download(true); |
| 886 | 907 |
| 887 // Pretend the manager just created |item|. | 908 // Pretend the manager just created |item|. |
| 888 CallOnDownloadCreated(0); | 909 CallOnDownloadCreated(0); |
| 889 ExpectDownloadCreated(info); | 910 ExpectDownloadCreated(info); |
| 890 EXPECT_FALSE(DownloadHistory::IsPersisted(&item(0))); | 911 EXPECT_FALSE(DownloadHistory::IsPersisted(&item(0))); |
| 891 | 912 |
| 892 // Pretend that something changed on the item. | 913 // Pretend that something changed on the item. |
| 893 EXPECT_CALL(item(0), GetOpened()).WillRepeatedly(Return(true)); | 914 EXPECT_CALL(item(0), GetOpened()).WillRepeatedly(Return(true)); |
| 894 item(0).NotifyObserversDownloadUpdated(); | 915 item(0).NotifyObserversDownloadUpdated(); |
| 895 | 916 |
| 896 FinishCreateDownload(); | 917 FinishCreateDownload(); |
| 897 EXPECT_TRUE(DownloadHistory::IsPersisted(&item(0))); | 918 EXPECT_TRUE(DownloadHistory::IsPersisted(&item(0))); |
| 898 | 919 |
| 899 // ItemAdded should call OnDownloadUpdated, which should detect that the item | 920 // ItemAdded should call OnDownloadUpdated, which should detect that the item |
| 900 // changed while it was being added and call UpdateDownload immediately. | 921 // changed while it was being added and call UpdateDownload immediately. |
| 901 info.opened = true; | 922 info.opened = true; |
| 902 ExpectDownloadUpdated(info); | 923 ExpectDownloadUpdated(info, false); |
| 903 } | 924 } |
| 904 | 925 |
| 905 } // anonymous namespace | 926 } // anonymous namespace |
| OLD | NEW |