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> |
11 | 11 |
12 #include "base/guid.h" | 12 #include "base/guid.h" |
13 #include "base/macros.h" | 13 #include "base/macros.h" |
14 #include "base/memory/ptr_util.h" | 14 #include "base/memory/ptr_util.h" |
15 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
16 #include "base/rand_util.h" | 16 #include "base/rand_util.h" |
17 #include "base/stl_util.h" | 17 #include "base/stl_util.h" |
18 #include "components/history/content/browser/download_conversions.h" | 18 #include "components/history/content/browser/download_conversions.h" |
19 #include "components/history/core/browser/download_constants.h" | 19 #include "components/history/core/browser/download_constants.h" |
20 #include "components/history/core/browser/download_row.h" | 20 #include "components/history/core/browser/download_row.h" |
21 #include "components/history/core/browser/history_service.h" | 21 #include "components/history/core/browser/history_service.h" |
22 #include "content/public/test/mock_download_item.h" | 22 #include "content/public/test/mock_download_item.h" |
23 #include "content/public/test/mock_download_manager.h" | 23 #include "content/public/test/mock_download_manager.h" |
24 #include "content/public/test/test_browser_thread.h" | 24 #include "content/public/test/test_browser_thread_bundle.h" |
25 #include "content/public/test/test_utils.h" | 25 #include "content/public/test/test_utils.h" |
26 #include "extensions/features/features.h" | 26 #include "extensions/features/features.h" |
27 #include "testing/gtest/include/gtest/gtest.h" | 27 #include "testing/gtest/include/gtest/gtest.h" |
28 | 28 |
29 #if BUILDFLAG(ENABLE_EXTENSIONS) | 29 #if BUILDFLAG(ENABLE_EXTENSIONS) |
30 #include "chrome/browser/extensions/api/downloads/downloads_api.h" | 30 #include "chrome/browser/extensions/api/downloads/downloads_api.h" |
31 #endif | 31 #endif |
32 | 32 |
33 using testing::DoAll; | 33 using testing::DoAll; |
34 using testing::Invoke; | 34 using testing::Invoke; |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 } | 189 } |
190 bool on_history_query_complete_called_ = false; | 190 bool on_history_query_complete_called_ = false; |
191 }; | 191 }; |
192 | 192 |
193 class DownloadHistoryTest : public testing::Test { | 193 class DownloadHistoryTest : public testing::Test { |
194 public: | 194 public: |
195 // Generic callback that receives a pointer to a StrictMockDownloadItem. | 195 // Generic callback that receives a pointer to a StrictMockDownloadItem. |
196 typedef base::Callback<void(content::MockDownloadItem*)> DownloadItemCallback; | 196 typedef base::Callback<void(content::MockDownloadItem*)> DownloadItemCallback; |
197 | 197 |
198 DownloadHistoryTest() | 198 DownloadHistoryTest() |
199 : ui_thread_(content::BrowserThread::UI, &loop_), | 199 : manager_(new content::MockDownloadManager()), |
200 manager_(new content::MockDownloadManager()), | |
201 history_(NULL), | 200 history_(NULL), |
202 manager_observer_(NULL), | 201 manager_observer_(NULL), |
203 download_created_index_(0) {} | 202 download_created_index_(0) {} |
204 ~DownloadHistoryTest() override {} | 203 ~DownloadHistoryTest() override {} |
205 | 204 |
206 protected: | 205 protected: |
207 void TearDown() override { download_history_.reset(); } | 206 void TearDown() override { download_history_.reset(); } |
208 | 207 |
209 content::MockDownloadManager& manager() { return *manager_.get(); } | 208 content::MockDownloadManager& manager() { return *manager_.get(); } |
210 content::MockDownloadItem& item(size_t index) { return *items_[index]; } | 209 content::MockDownloadItem& item(size_t index) { return *items_[index]; } |
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
477 .WillRepeatedly(SetArgPointee<0>(items)); | 476 .WillRepeatedly(SetArgPointee<0>(items)); |
478 } | 477 } |
479 | 478 |
480 private: | 479 private: |
481 void CheckDownloadWasRestoredFromHistory(bool expected_value, | 480 void CheckDownloadWasRestoredFromHistory(bool expected_value, |
482 content::MockDownloadItem* item) { | 481 content::MockDownloadItem* item) { |
483 ASSERT_TRUE(download_history_.get()); | 482 ASSERT_TRUE(download_history_.get()); |
484 EXPECT_EQ(expected_value, download_history_->WasRestoredFromHistory(item)); | 483 EXPECT_EQ(expected_value, download_history_->WasRestoredFromHistory(item)); |
485 } | 484 } |
486 | 485 |
487 base::MessageLoopForUI loop_; | 486 content::TestBrowserThreadBundle test_browser_thread_bundle_; |
488 content::TestBrowserThread ui_thread_; | |
489 std::vector<std::unique_ptr<StrictMockDownloadItem>> items_; | 487 std::vector<std::unique_ptr<StrictMockDownloadItem>> items_; |
490 std::unique_ptr<content::MockDownloadManager> manager_; | 488 std::unique_ptr<content::MockDownloadManager> manager_; |
491 FakeHistoryAdapter* history_; | 489 FakeHistoryAdapter* history_; |
492 std::unique_ptr<DownloadHistory> download_history_; | 490 std::unique_ptr<DownloadHistory> download_history_; |
493 content::DownloadManager::Observer* manager_observer_; | 491 content::DownloadManager::Observer* manager_observer_; |
494 size_t download_created_index_; | 492 size_t download_created_index_; |
495 DownloadItemCallback pre_on_create_handler_; | 493 DownloadItemCallback pre_on_create_handler_; |
496 DownloadItemCallback post_on_create_handler_; | 494 DownloadItemCallback post_on_create_handler_; |
497 | 495 |
498 DISALLOW_COPY_AND_ASSIGN(DownloadHistoryTest); | 496 DISALLOW_COPY_AND_ASSIGN(DownloadHistoryTest); |
(...skipping 453 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
952 FinishCreateDownload(); | 950 FinishCreateDownload(); |
953 EXPECT_TRUE(DownloadHistory::IsPersisted(&item(0))); | 951 EXPECT_TRUE(DownloadHistory::IsPersisted(&item(0))); |
954 | 952 |
955 // ItemAdded should call OnDownloadUpdated, which should detect that the item | 953 // ItemAdded should call OnDownloadUpdated, which should detect that the item |
956 // changed while it was being added and call UpdateDownload immediately. | 954 // changed while it was being added and call UpdateDownload immediately. |
957 info.opened = true; | 955 info.opened = true; |
958 ExpectDownloadUpdated(info, false); | 956 ExpectDownloadUpdated(info, false); |
959 } | 957 } |
960 | 958 |
961 } // anonymous namespace | 959 } // anonymous namespace |
OLD | NEW |