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_vector.h" | 5 #include "base/memory/scoped_vector.h" |
6 #include "base/memory/weak_ptr.h" | 6 #include "base/memory/weak_ptr.h" |
7 #include "base/message_loop/message_loop.h" | 7 #include "base/message_loop/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" |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 | 47 |
48 class DownloadStatusUpdaterTest : public testing::Test { | 48 class DownloadStatusUpdaterTest : public testing::Test { |
49 public: | 49 public: |
50 DownloadStatusUpdaterTest() | 50 DownloadStatusUpdaterTest() |
51 : updater_(new TestDownloadStatusUpdater()), | 51 : updater_(new TestDownloadStatusUpdater()), |
52 ui_thread_(content::BrowserThread::UI, &loop_) {} | 52 ui_thread_(content::BrowserThread::UI, &loop_) {} |
53 | 53 |
54 virtual ~DownloadStatusUpdaterTest() { | 54 virtual ~DownloadStatusUpdaterTest() { |
55 for (size_t mgr_idx = 0; mgr_idx < managers_.size(); ++mgr_idx) { | 55 for (size_t mgr_idx = 0; mgr_idx < managers_.size(); ++mgr_idx) { |
56 EXPECT_CALL(*Manager(mgr_idx), RemoveObserver(_)); | 56 EXPECT_CALL(*Manager(mgr_idx), RemoveObserver(_)); |
57 for (size_t item_idx = 0; item_idx < manager_items_[mgr_idx].size(); | |
58 ++item_idx) { | |
59 EXPECT_CALL(*Item(mgr_idx, item_idx), RemoveObserver(_)); | |
60 } | |
61 } | 57 } |
62 | 58 |
63 delete updater_; | 59 delete updater_; |
64 updater_ = NULL; | 60 updater_ = NULL; |
65 VerifyAndClearExpectations(); | 61 VerifyAndClearExpectations(); |
66 | 62 |
67 managers_.clear(); | 63 managers_.clear(); |
68 for (std::vector<Items>::iterator it = manager_items_.begin(); | 64 for (std::vector<Items>::iterator it = manager_items_.begin(); |
69 it != manager_items_.end(); ++it) | 65 it != manager_items_.end(); ++it) |
70 STLDeleteContainerPointers(it->begin(), it->end()); | 66 STLDeleteContainerPointers(it->begin(), it->end()); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 manager_items_.resize(manager_index+1); | 105 manager_items_.resize(manager_index+1); |
110 | 106 |
111 std::vector<content::DownloadItem*> item_list; | 107 std::vector<content::DownloadItem*> item_list; |
112 for (int i = 0; i < item_count; ++i) { | 108 for (int i = 0; i < item_count; ++i) { |
113 content::MockDownloadItem* item = | 109 content::MockDownloadItem* item = |
114 new StrictMock<content::MockDownloadItem>; | 110 new StrictMock<content::MockDownloadItem>; |
115 content::DownloadItem::DownloadState state = | 111 content::DownloadItem::DownloadState state = |
116 i < in_progress_count ? content::DownloadItem::IN_PROGRESS | 112 i < in_progress_count ? content::DownloadItem::IN_PROGRESS |
117 : content::DownloadItem::CANCELLED; | 113 : content::DownloadItem::CANCELLED; |
118 EXPECT_CALL(*item, GetState()).WillRepeatedly(Return(state)); | 114 EXPECT_CALL(*item, GetState()).WillRepeatedly(Return(state)); |
119 EXPECT_CALL(*item, AddObserver(_)) | |
120 .WillOnce(Return()); | |
121 manager_items_[manager_index].push_back(item); | 115 manager_items_[manager_index].push_back(item); |
122 } | 116 } |
123 EXPECT_CALL(*manager, GetAllDownloads(_)) | 117 EXPECT_CALL(*manager, GetAllDownloads(_)) |
124 .WillRepeatedly(SetArgPointee<0>(manager_items_[manager_index])); | 118 .WillRepeatedly(SetArgPointee<0>(manager_items_[manager_index])); |
125 } | 119 } |
126 | 120 |
127 // Return the specified manager. | 121 // Return the specified manager. |
128 content::MockDownloadManager* Manager(int manager_index) { | 122 content::MockDownloadManager* Manager(int manager_index) { |
129 DCHECK_GT(managers_.size(), static_cast<size_t>(manager_index)); | 123 DCHECK_GT(managers_.size(), static_cast<size_t>(manager_index)); |
130 return managers_[manager_index]; | 124 return managers_[manager_index]; |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
340 SetItemValues(0, 0, 10, 20, false); | 334 SetItemValues(0, 0, 10, 20, false); |
341 SetItemValues(0, 1, 50, 60, false); | 335 SetItemValues(0, 1, 50, 60, false); |
342 SetItemValues(1, 0, 80, 90, false); | 336 SetItemValues(1, 0, 80, 90, false); |
343 | 337 |
344 float progress = -1; | 338 float progress = -1; |
345 int download_count = -1; | 339 int download_count = -1; |
346 EXPECT_TRUE(updater_->GetProgress(&progress, &download_count)); | 340 EXPECT_TRUE(updater_->GetProgress(&progress, &download_count)); |
347 EXPECT_FLOAT_EQ((10+50+80)/(20.0f+60+90), progress); | 341 EXPECT_FLOAT_EQ((10+50+80)/(20.0f+60+90), progress); |
348 EXPECT_EQ(3, download_count); | 342 EXPECT_EQ(3, download_count); |
349 } | 343 } |
OLD | NEW |