| 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 <stddef.h> | 5 #include <stddef.h> |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
| 10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
| 11 #include "base/message_loop/message_loop.h" | |
| 12 #include "base/run_loop.h" | 11 #include "base/run_loop.h" |
| 13 #include "chrome/browser/download/download_status_updater.h" | 12 #include "chrome/browser/download/download_status_updater.h" |
| 14 #include "content/public/test/mock_download_item.h" | 13 #include "content/public/test/mock_download_item.h" |
| 15 #include "content/public/test/mock_download_manager.h" | 14 #include "content/public/test/mock_download_manager.h" |
| 16 #include "content/public/test/test_browser_thread.h" | 15 #include "content/public/test/test_browser_thread_bundle.h" |
| 17 #include "testing/gmock/include/gmock/gmock.h" | 16 #include "testing/gmock/include/gmock/gmock.h" |
| 18 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 19 | 18 |
| 20 using testing::AtLeast; | 19 using testing::AtLeast; |
| 21 using testing::Invoke; | 20 using testing::Invoke; |
| 22 using testing::Mock; | 21 using testing::Mock; |
| 23 using testing::Return; | 22 using testing::Return; |
| 24 using testing::SetArgPointee; | 23 using testing::SetArgPointee; |
| 25 using testing::StrictMock; | 24 using testing::StrictMock; |
| 26 using testing::WithArg; | 25 using testing::WithArg; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 42 if (acceptable_notification_item_) | 41 if (acceptable_notification_item_) |
| 43 EXPECT_EQ(acceptable_notification_item_, download); | 42 EXPECT_EQ(acceptable_notification_item_, download); |
| 44 } | 43 } |
| 45 private: | 44 private: |
| 46 size_t notification_count_; | 45 size_t notification_count_; |
| 47 content::DownloadItem* acceptable_notification_item_; | 46 content::DownloadItem* acceptable_notification_item_; |
| 48 }; | 47 }; |
| 49 | 48 |
| 50 class DownloadStatusUpdaterTest : public testing::Test { | 49 class DownloadStatusUpdaterTest : public testing::Test { |
| 51 public: | 50 public: |
| 52 DownloadStatusUpdaterTest() | 51 DownloadStatusUpdaterTest() : updater_(new TestDownloadStatusUpdater()) {} |
| 53 : updater_(new TestDownloadStatusUpdater()), | |
| 54 ui_thread_(content::BrowserThread::UI, &loop_) {} | |
| 55 | 52 |
| 56 ~DownloadStatusUpdaterTest() override { | 53 ~DownloadStatusUpdaterTest() override { |
| 57 for (size_t mgr_idx = 0; mgr_idx < managers_.size(); ++mgr_idx) { | 54 for (size_t mgr_idx = 0; mgr_idx < managers_.size(); ++mgr_idx) { |
| 58 EXPECT_CALL(*Manager(mgr_idx), RemoveObserver(_)); | 55 EXPECT_CALL(*Manager(mgr_idx), RemoveObserver(_)); |
| 59 } | 56 } |
| 60 | 57 |
| 61 delete updater_; | 58 delete updater_; |
| 62 updater_ = nullptr; | 59 updater_ = nullptr; |
| 63 VerifyAndClearExpectations(); | 60 VerifyAndClearExpectations(); |
| 64 | 61 |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 std::vector<content::DownloadManager::Observer*> manager_observers_; | 176 std::vector<content::DownloadManager::Observer*> manager_observers_; |
| 180 | 177 |
| 181 // Pointer so we can verify that destruction triggers appropriate | 178 // Pointer so we can verify that destruction triggers appropriate |
| 182 // changes. | 179 // changes. |
| 183 TestDownloadStatusUpdater* updater_; | 180 TestDownloadStatusUpdater* updater_; |
| 184 | 181 |
| 185 // Thread so that the DownloadManager (which is a DeleteOnUIThread | 182 // Thread so that the DownloadManager (which is a DeleteOnUIThread |
| 186 // object) can be deleted. | 183 // object) can be deleted. |
| 187 // TODO(rdsmith): This can be removed when the DownloadManager | 184 // TODO(rdsmith): This can be removed when the DownloadManager |
| 188 // is no longer required to be deleted on the UI thread. | 185 // is no longer required to be deleted on the UI thread. |
| 189 base::MessageLoop loop_; | 186 content::TestBrowserThreadBundle test_browser_thread_bundle_; |
| 190 content::TestBrowserThread ui_thread_; | |
| 191 }; | 187 }; |
| 192 | 188 |
| 193 // Test null updater. | 189 // Test null updater. |
| 194 TEST_F(DownloadStatusUpdaterTest, Basic) { | 190 TEST_F(DownloadStatusUpdaterTest, Basic) { |
| 195 float progress = -1; | 191 float progress = -1; |
| 196 int download_count = -1; | 192 int download_count = -1; |
| 197 EXPECT_TRUE(updater_->GetProgress(&progress, &download_count)); | 193 EXPECT_TRUE(updater_->GetProgress(&progress, &download_count)); |
| 198 EXPECT_FLOAT_EQ(0.0f, progress); | 194 EXPECT_FLOAT_EQ(0.0f, progress); |
| 199 EXPECT_EQ(0, download_count); | 195 EXPECT_EQ(0, download_count); |
| 200 } | 196 } |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 338 SetItemValues(0, 0, 10, 20, false); | 334 SetItemValues(0, 0, 10, 20, false); |
| 339 SetItemValues(0, 1, 50, 60, false); | 335 SetItemValues(0, 1, 50, 60, false); |
| 340 SetItemValues(1, 0, 80, 90, false); | 336 SetItemValues(1, 0, 80, 90, false); |
| 341 | 337 |
| 342 float progress = -1; | 338 float progress = -1; |
| 343 int download_count = -1; | 339 int download_count = -1; |
| 344 EXPECT_TRUE(updater_->GetProgress(&progress, &download_count)); | 340 EXPECT_TRUE(updater_->GetProgress(&progress, &download_count)); |
| 345 EXPECT_FLOAT_EQ((10+50+80)/(20.0f+60+90), progress); | 341 EXPECT_FLOAT_EQ((10+50+80)/(20.0f+60+90), progress); |
| 346 EXPECT_EQ(3, download_count); | 342 EXPECT_EQ(3, download_count); |
| 347 } | 343 } |
| OLD | NEW |