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/files/file_path.h" | 5 #include "base/files/file_path.h" |
6 #include "base/memory/ref_counted.h" | 6 #include "base/memory/ref_counted.h" |
7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
8 #include "base/memory/weak_ptr.h" | 8 #include "base/memory/weak_ptr.h" |
9 #include "chrome/browser/download/download_ui_controller.h" | 9 #include "chrome/browser/download/download_ui_controller.h" |
10 #include "content/public/test/mock_download_item.h" | 10 #include "content/public/test/mock_download_item.h" |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 scoped_ptr<DownloadUIController::Delegate> GetTestDelegate(); | 62 scoped_ptr<DownloadUIController::Delegate> GetTestDelegate(); |
63 | 63 |
64 MockDownloadManager* manager() { return manager_.get(); } | 64 MockDownloadManager* manager() { return manager_.get(); } |
65 content::DownloadManager::Observer* manager_observer() { | 65 content::DownloadManager::Observer* manager_observer() { |
66 return manager_observer_; | 66 return manager_observer_; |
67 } | 67 } |
68 content::DownloadItem::Observer* item_observer() { return item_observer_; } | 68 content::DownloadItem::Observer* item_observer() { return item_observer_; } |
69 content::DownloadItem* received_item() { return received_item_; } | 69 content::DownloadItem* received_item() { return received_item_; } |
70 | 70 |
71 private: | 71 private: |
72 scoped_refptr<MockDownloadManager> manager_; | 72 scoped_ptr<MockDownloadManager> manager_; |
73 content::DownloadManager::Observer* manager_observer_; | 73 content::DownloadManager::Observer* manager_observer_; |
74 content::DownloadItem::Observer* item_observer_; | 74 content::DownloadItem::Observer* item_observer_; |
75 content::DownloadItem* received_item_; | 75 content::DownloadItem* received_item_; |
76 | 76 |
77 base::WeakPtrFactory<content::DownloadItem*> receiver_factory_; | 77 base::WeakPtrFactory<content::DownloadItem*> receiver_factory_; |
78 }; | 78 }; |
79 | 79 |
80 DownloadUIControllerTest::DownloadUIControllerTest() | 80 DownloadUIControllerTest::DownloadUIControllerTest() |
81 : manager_observer_(NULL), | 81 : manager_observer_(NULL), |
82 item_observer_(NULL), | 82 item_observer_(NULL), |
83 received_item_(NULL), | 83 received_item_(NULL), |
84 receiver_factory_(&received_item_) { | 84 receiver_factory_(&received_item_) { |
85 } | 85 } |
86 | 86 |
87 void DownloadUIControllerTest::SetUp() { | 87 void DownloadUIControllerTest::SetUp() { |
88 manager_ = new testing::StrictMock<MockDownloadManager>(); | 88 manager_.reset(new testing::StrictMock<MockDownloadManager>()); |
89 EXPECT_CALL(*manager_, AddObserver(_)) | 89 EXPECT_CALL(*manager_, AddObserver(_)) |
90 .WillOnce(SaveArg<0>(&manager_observer_)); | 90 .WillOnce(SaveArg<0>(&manager_observer_)); |
91 EXPECT_CALL(*manager_, RemoveObserver(_)) | 91 EXPECT_CALL(*manager_, RemoveObserver(_)) |
92 .WillOnce(Assign(&manager_observer_, | 92 .WillOnce(Assign(&manager_observer_, |
93 static_cast<content::DownloadManager::Observer*>(NULL))); | 93 static_cast<content::DownloadManager::Observer*>(NULL))); |
94 EXPECT_CALL(*manager_, GetAllDownloads(_)); | 94 EXPECT_CALL(*manager_, GetAllDownloads(_)); |
95 } | 95 } |
96 | 96 |
97 scoped_ptr<MockDownloadItem> DownloadUIControllerTest::GetMockDownload() { | 97 scoped_ptr<MockDownloadItem> DownloadUIControllerTest::GetMockDownload() { |
98 scoped_ptr<MockDownloadItem> item( | 98 scoped_ptr<MockDownloadItem> item( |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 | 174 |
175 ASSERT_TRUE(manager_observer()); | 175 ASSERT_TRUE(manager_observer()); |
176 manager_observer()->OnDownloadCreated(manager(), item.get()); | 176 manager_observer()->OnDownloadCreated(manager(), item.get()); |
177 EXPECT_FALSE(received_item()); | 177 EXPECT_FALSE(received_item()); |
178 | 178 |
179 item_observer()->OnDownloadUpdated(item.get()); | 179 item_observer()->OnDownloadUpdated(item.get()); |
180 EXPECT_FALSE(received_item()); | 180 EXPECT_FALSE(received_item()); |
181 } | 181 } |
182 | 182 |
183 } // namespace | 183 } // namespace |
OLD | NEW |