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 "base/memory/scoped_ptr.h" | 5 #include "base/memory/scoped_ptr.h" |
| 6 #include "base/memory/weak_ptr.h" | 6 #include "base/memory/weak_ptr.h" |
| 7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
| 8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
| 9 #include "chrome/browser/download/download_status_updater.h" | 9 #include "chrome/browser/download/download_status_updater.h" |
| 10 #include "content/public/test/mock_download_item.h" | 10 #include "content/public/test/mock_download_item.h" |
| 11 #include "content/public/test/mock_download_manager.h" | 11 #include "content/public/test/mock_download_manager.h" |
| 12 #include "content/public/test/test_browser_thread.h" | 12 #include "content/public/test/test_browser_thread.h" |
| 13 #include "testing/gmock/include/gmock/gmock.h" | 13 #include "testing/gmock/include/gmock/gmock.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 15 | 15 |
| 16 | 16 |
| 17 using ::testing::AtLeast; | 17 using ::testing::AtLeast; |
| 18 using ::testing::Mock; | 18 using ::testing::Mock; |
| 19 using ::testing::Return; | 19 using ::testing::Return; |
| 20 using ::testing::SetArgPointee; | 20 using ::testing::SetArgPointee; |
| 21 using ::testing::StrictMock; | 21 using ::testing::StrictMock; |
| 22 using ::testing::_; | 22 using ::testing::_; |
| 23 | 23 |
| 24 class TestDownloadStatusUpdater : public DownloadStatusUpdater { | 24 class TestDownloadStatusUpdater : public DownloadStatusUpdater { |
| 25 protected: | 25 protected: |
| 26 virtual void UpdateAppIconDownloadProgress() OVERRIDE { | 26 virtual void UpdateAppIconDownloadProgress( |
| 27 content::DownloadItem* download) OVERRIDE { | |
|
Randy Smith (Not in Mondays)
2012/08/10 18:38:44
Shouldn't you add a test to make sure the right do
| |
| 27 return; | 28 return; |
| 28 } | 29 } |
| 29 }; | 30 }; |
| 30 | 31 |
| 31 class DownloadStatusUpdaterTest : public testing::Test { | 32 class DownloadStatusUpdaterTest : public testing::Test { |
| 32 public: | 33 public: |
| 33 DownloadStatusUpdaterTest() | 34 DownloadStatusUpdaterTest() |
| 34 : updater_(new TestDownloadStatusUpdater()), | 35 : updater_(new TestDownloadStatusUpdater()), |
| 35 ui_thread_(content::BrowserThread::UI, &loop_) {} | 36 ui_thread_(content::BrowserThread::UI, &loop_) {} |
| 36 | 37 |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 113 content::MockDownloadItem* Item(int manager_index, int item_index) { | 114 content::MockDownloadItem* Item(int manager_index, int item_index) { |
| 114 DCHECK_GT(manager_items_.size(), static_cast<size_t>(manager_index)); | 115 DCHECK_GT(manager_items_.size(), static_cast<size_t>(manager_index)); |
| 115 DCHECK_GT(manager_items_[manager_index].size(), | 116 DCHECK_GT(manager_items_[manager_index].size(), |
| 116 static_cast<size_t>(item_index)); | 117 static_cast<size_t>(item_index)); |
| 117 // All DownloadItems in manager_items_ are MockDownloadItems. | 118 // All DownloadItems in manager_items_ are MockDownloadItems. |
| 118 return static_cast<content::MockDownloadItem*>( | 119 return static_cast<content::MockDownloadItem*>( |
| 119 manager_items_[manager_index][item_index]); | 120 manager_items_[manager_index][item_index]); |
| 120 } | 121 } |
| 121 | 122 |
| 122 // Set return values relevant to |DownloadStatusUpdater::GetProgress()| | 123 // Set return values relevant to |DownloadStatusUpdater::GetProgress()| |
| 123 // for the specified item | 124 // for the specified item. |
| 124 void SetItemValues(int manager_index, int item_index, | 125 void SetItemValues(int manager_index, int item_index, |
| 125 int received_bytes, int total_bytes) { | 126 int received_bytes, int total_bytes) { |
| 126 EXPECT_CALL(*Item(manager_index, item_index), GetReceivedBytes()) | 127 EXPECT_CALL(*Item(manager_index, item_index), GetReceivedBytes()) |
| 127 .WillRepeatedly(Return(received_bytes)); | 128 .WillRepeatedly(Return(received_bytes)); |
| 128 EXPECT_CALL(*Item(manager_index, item_index), GetTotalBytes()) | 129 EXPECT_CALL(*Item(manager_index, item_index), GetTotalBytes()) |
| 129 .WillRepeatedly(Return(total_bytes)); | 130 .WillRepeatedly(Return(total_bytes)); |
| 130 } | 131 } |
| 131 | 132 |
| 132 // Transition specified item to completed. | 133 // Transition specified item to completed. |
| 133 void CompleteItem(int manager_index, int item_index) { | 134 void CompleteItem(int manager_index, int item_index) { |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 279 SetItemValues(0, 0, 10, 20); | 280 SetItemValues(0, 0, 10, 20); |
| 280 SetItemValues(0, 1, 50, 60); | 281 SetItemValues(0, 1, 50, 60); |
| 281 SetItemValues(1, 0, 80, 90); | 282 SetItemValues(1, 0, 80, 90); |
| 282 | 283 |
| 283 float progress = -1; | 284 float progress = -1; |
| 284 int download_count = -1; | 285 int download_count = -1; |
| 285 EXPECT_TRUE(updater_->GetProgress(&progress, &download_count)); | 286 EXPECT_TRUE(updater_->GetProgress(&progress, &download_count)); |
| 286 EXPECT_FLOAT_EQ((10+50+80)/(20.0f+60+90), progress); | 287 EXPECT_FLOAT_EQ((10+50+80)/(20.0f+60+90), progress); |
| 287 EXPECT_EQ(3, download_count); | 288 EXPECT_EQ(3, download_count); |
| 288 } | 289 } |
| OLD | NEW |