| 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" |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 DCHECK_GT(managers_.size(), static_cast<size_t>(manager_index)); | 96 DCHECK_GT(managers_.size(), static_cast<size_t>(manager_index)); |
| 97 content::MockDownloadManager* manager = managers_[manager_index].get(); | 97 content::MockDownloadManager* manager = managers_[manager_index].get(); |
| 98 | 98 |
| 99 if (manager_items_.size() <= static_cast<size_t>(manager_index)) | 99 if (manager_items_.size() <= static_cast<size_t>(manager_index)) |
| 100 manager_items_.resize(manager_index+1); | 100 manager_items_.resize(manager_index+1); |
| 101 | 101 |
| 102 std::vector<content::DownloadItem*> item_list; | 102 std::vector<content::DownloadItem*> item_list; |
| 103 for (int i = 0; i < item_count; ++i) { | 103 for (int i = 0; i < item_count; ++i) { |
| 104 content::MockDownloadItem* item = | 104 content::MockDownloadItem* item = |
| 105 new StrictMock<content::MockDownloadItem>; | 105 new StrictMock<content::MockDownloadItem>; |
| 106 EXPECT_CALL(*item, IsTemporary()) | |
| 107 .WillRepeatedly(Return(false)); | |
| 108 if (i < in_progress_count) { | 106 if (i < in_progress_count) { |
| 109 EXPECT_CALL(*item, GetState()) | 107 EXPECT_CALL(*item, GetState()) |
| 110 .WillRepeatedly(Return(content::DownloadItem::IN_PROGRESS)); | 108 .WillRepeatedly(Return(content::DownloadItem::IN_PROGRESS)); |
| 111 EXPECT_CALL(*item, AddObserver(updater_)) | 109 EXPECT_CALL(*item, AddObserver(updater_)) |
| 112 .WillOnce(Return()); | 110 .WillOnce(Return()); |
| 113 } else { | 111 } else { |
| 114 EXPECT_CALL(*item, GetState()) | 112 EXPECT_CALL(*item, GetState()) |
| 115 .WillRepeatedly(Return(content::DownloadItem::COMPLETE)); | 113 .WillRepeatedly(Return(content::DownloadItem::COMPLETE)); |
| 116 } | 114 } |
| 117 manager_items_[manager_index].push_back(item); | 115 manager_items_[manager_index].push_back(item); |
| 118 } | 116 } |
| 119 EXPECT_CALL(*manager, GetAllDownloads(_)) | 117 EXPECT_CALL(*manager, SearchDownloads(string16(), _)) |
| 120 .WillOnce(SetArgPointee<0>(manager_items_[manager_index])); | 118 .WillOnce(SetArgPointee<1>(manager_items_[manager_index])); |
| 121 } | 119 } |
| 122 | 120 |
| 123 // Return the specified manager. | 121 // Return the specified manager. |
| 124 content::MockDownloadManager* Manager(int manager_index) { | 122 content::MockDownloadManager* Manager(int manager_index) { |
| 125 DCHECK_GT(managers_.size(), static_cast<size_t>(manager_index)); | 123 DCHECK_GT(managers_.size(), static_cast<size_t>(manager_index)); |
| 126 return managers_[manager_index].get(); | 124 return managers_[manager_index].get(); |
| 127 } | 125 } |
| 128 | 126 |
| 129 // Return the specified item. | 127 // Return the specified item. |
| 130 content::MockDownloadItem* Item(int manager_index, int item_index) { | 128 content::MockDownloadItem* Item(int manager_index, int item_index) { |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 332 SetItemValues(0, 0, 10, 20, false); | 330 SetItemValues(0, 0, 10, 20, false); |
| 333 SetItemValues(0, 1, 50, 60, false); | 331 SetItemValues(0, 1, 50, 60, false); |
| 334 SetItemValues(1, 0, 80, 90, false); | 332 SetItemValues(1, 0, 80, 90, false); |
| 335 | 333 |
| 336 float progress = -1; | 334 float progress = -1; |
| 337 int download_count = -1; | 335 int download_count = -1; |
| 338 EXPECT_TRUE(updater_->GetProgress(&progress, &download_count)); | 336 EXPECT_TRUE(updater_->GetProgress(&progress, &download_count)); |
| 339 EXPECT_FLOAT_EQ((10+50+80)/(20.0f+60+90), progress); | 337 EXPECT_FLOAT_EQ((10+50+80)/(20.0f+60+90), progress); |
| 340 EXPECT_EQ(3, download_count); | 338 EXPECT_EQ(3, download_count); |
| 341 } | 339 } |
| OLD | NEW |