| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "base/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/callback.h" | 6 #include "base/callback.h" |
| 7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
| 8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 namespace { | 33 namespace { |
| 34 | 34 |
| 35 // A DownloadUIController::Delegate that stores the DownloadItem* for the last | 35 // A DownloadUIController::Delegate that stores the DownloadItem* for the last |
| 36 // download that was sent to the UI. | 36 // download that was sent to the UI. |
| 37 class TestDelegate : public DownloadUIController::Delegate { | 37 class TestDelegate : public DownloadUIController::Delegate { |
| 38 public: | 38 public: |
| 39 explicit TestDelegate(base::WeakPtr<content::DownloadItem*> receiver); | 39 explicit TestDelegate(base::WeakPtr<content::DownloadItem*> receiver); |
| 40 virtual ~TestDelegate() {} | 40 virtual ~TestDelegate() {} |
| 41 | 41 |
| 42 private: | 42 private: |
| 43 virtual void OnNewDownloadReady(content::DownloadItem* item) OVERRIDE; | 43 virtual void OnNewDownloadReady(content::DownloadItem* item) override; |
| 44 | 44 |
| 45 base::WeakPtr<content::DownloadItem*> receiver_; | 45 base::WeakPtr<content::DownloadItem*> receiver_; |
| 46 }; | 46 }; |
| 47 | 47 |
| 48 TestDelegate::TestDelegate(base::WeakPtr<content::DownloadItem*> receiver) | 48 TestDelegate::TestDelegate(base::WeakPtr<content::DownloadItem*> receiver) |
| 49 : receiver_(receiver) { | 49 : receiver_(receiver) { |
| 50 } | 50 } |
| 51 | 51 |
| 52 void TestDelegate::OnNewDownloadReady(content::DownloadItem* item) { | 52 void TestDelegate::OnNewDownloadReady(content::DownloadItem* item) { |
| 53 if (receiver_.get()) | 53 if (receiver_.get()) |
| 54 *receiver_ = item; | 54 *receiver_ = item; |
| 55 } | 55 } |
| 56 | 56 |
| 57 // A DownloadService that returns a custom DownloadHistory. | 57 // A DownloadService that returns a custom DownloadHistory. |
| 58 class TestDownloadService : public DownloadService { | 58 class TestDownloadService : public DownloadService { |
| 59 public: | 59 public: |
| 60 explicit TestDownloadService(Profile* profile); | 60 explicit TestDownloadService(Profile* profile); |
| 61 virtual ~TestDownloadService(); | 61 virtual ~TestDownloadService(); |
| 62 | 62 |
| 63 void set_download_history(scoped_ptr<DownloadHistory> download_history) { | 63 void set_download_history(scoped_ptr<DownloadHistory> download_history) { |
| 64 download_history_.swap(download_history); | 64 download_history_.swap(download_history); |
| 65 } | 65 } |
| 66 virtual DownloadHistory* GetDownloadHistory() OVERRIDE; | 66 virtual DownloadHistory* GetDownloadHistory() override; |
| 67 | 67 |
| 68 private: | 68 private: |
| 69 scoped_ptr<DownloadHistory> download_history_; | 69 scoped_ptr<DownloadHistory> download_history_; |
| 70 }; | 70 }; |
| 71 | 71 |
| 72 TestDownloadService::TestDownloadService(Profile* profile) | 72 TestDownloadService::TestDownloadService(Profile* profile) |
| 73 : DownloadService(profile) { | 73 : DownloadService(profile) { |
| 74 } | 74 } |
| 75 | 75 |
| 76 TestDownloadService::~TestDownloadService() { | 76 TestDownloadService::~TestDownloadService() { |
| 77 } | 77 } |
| 78 | 78 |
| 79 DownloadHistory* TestDownloadService::GetDownloadHistory() { | 79 DownloadHistory* TestDownloadService::GetDownloadHistory() { |
| 80 return download_history_.get(); | 80 return download_history_.get(); |
| 81 } | 81 } |
| 82 | 82 |
| 83 // The test fixture: | 83 // The test fixture: |
| 84 class DownloadUIControllerTest : public ChromeRenderViewHostTestHarness { | 84 class DownloadUIControllerTest : public ChromeRenderViewHostTestHarness { |
| 85 public: | 85 public: |
| 86 DownloadUIControllerTest(); | 86 DownloadUIControllerTest(); |
| 87 | 87 |
| 88 protected: | 88 protected: |
| 89 // testing::Test | 89 // testing::Test |
| 90 virtual void SetUp() OVERRIDE; | 90 virtual void SetUp() override; |
| 91 | 91 |
| 92 // Returns a TestDelegate. Invoking OnNewDownloadReady on the returned | 92 // Returns a TestDelegate. Invoking OnNewDownloadReady on the returned |
| 93 // delegate results in the DownloadItem* being stored in |notified_item_|. | 93 // delegate results in the DownloadItem* being stored in |notified_item_|. |
| 94 scoped_ptr<DownloadUIController::Delegate> GetTestDelegate(); | 94 scoped_ptr<DownloadUIController::Delegate> GetTestDelegate(); |
| 95 | 95 |
| 96 MockDownloadManager* manager() { return manager_.get(); } | 96 MockDownloadManager* manager() { return manager_.get(); } |
| 97 | 97 |
| 98 // Returns the DownloadManager::Observer registered by a test case. This is | 98 // Returns the DownloadManager::Observer registered by a test case. This is |
| 99 // the DownloadUIController's observer for all current test cases. | 99 // the DownloadUIController's observer for all current test cases. |
| 100 content::DownloadManager::Observer* manager_observer() { | 100 content::DownloadManager::Observer* manager_observer() { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 121 private: | 121 private: |
| 122 // A private history adapter that stores the DownloadQueryCallback when | 122 // A private history adapter that stores the DownloadQueryCallback when |
| 123 // QueryDownloads is called. | 123 // QueryDownloads is called. |
| 124 class HistoryAdapter : public DownloadHistory::HistoryAdapter { | 124 class HistoryAdapter : public DownloadHistory::HistoryAdapter { |
| 125 public: | 125 public: |
| 126 HistoryAdapter() : DownloadHistory::HistoryAdapter(NULL) {} | 126 HistoryAdapter() : DownloadHistory::HistoryAdapter(NULL) {} |
| 127 HistoryService::DownloadQueryCallback download_query_callback_; | 127 HistoryService::DownloadQueryCallback download_query_callback_; |
| 128 | 128 |
| 129 private: | 129 private: |
| 130 virtual void QueryDownloads( | 130 virtual void QueryDownloads( |
| 131 const HistoryService::DownloadQueryCallback& callback) OVERRIDE { | 131 const HistoryService::DownloadQueryCallback& callback) override { |
| 132 download_query_callback_ = callback; | 132 download_query_callback_ = callback; |
| 133 } | 133 } |
| 134 }; | 134 }; |
| 135 | 135 |
| 136 // Constructs and returns a TestDownloadService. | 136 // Constructs and returns a TestDownloadService. |
| 137 static KeyedService* TestingDownloadServiceFactory( | 137 static KeyedService* TestingDownloadServiceFactory( |
| 138 content::BrowserContext* browser_context); | 138 content::BrowserContext* browser_context); |
| 139 | 139 |
| 140 scoped_ptr<MockDownloadManager> manager_; | 140 scoped_ptr<MockDownloadManager> manager_; |
| 141 content::DownloadManager::Observer* download_history_manager_observer_; | 141 content::DownloadManager::Observer* download_history_manager_observer_; |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 338 // DownloadUIController. It should ignore the download since it's marked as | 338 // DownloadUIController. It should ignore the download since it's marked as |
| 339 // being restored from history. | 339 // being restored from history. |
| 340 ASSERT_TRUE(manager_observer()); | 340 ASSERT_TRUE(manager_observer()); |
| 341 manager_observer()->OnDownloadCreated(manager(), item.get()); | 341 manager_observer()->OnDownloadCreated(manager(), item.get()); |
| 342 | 342 |
| 343 // Finally, the expectation we've been waiting for: | 343 // Finally, the expectation we've been waiting for: |
| 344 EXPECT_FALSE(notified_item()); | 344 EXPECT_FALSE(notified_item()); |
| 345 } | 345 } |
| 346 | 346 |
| 347 } // namespace | 347 } // namespace |
| OLD | NEW |