Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1004)

Side by Side Diff: content/browser/download/download_item_impl_unittest.cc

Issue 10912173: Replace the DownloadFileManager with direct ownership of DownloadFileImpl (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Sync to LKGR (r156083) Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/message_loop.h" 5 #include "base/message_loop.h"
6 #include "base/stl_util.h" 6 #include "base/stl_util.h"
7 #include "base/threading/thread.h" 7 #include "base/threading/thread.h"
8 #include "content/browser/download/byte_stream.h" 8 #include "content/browser/download/byte_stream.h"
9 #include "content/browser/download/download_create_info.h" 9 #include "content/browser/download/download_create_info.h"
10 #include "content/browser/download/download_file_manager.h" 10 #include "content/browser/download/download_file_factory.h"
11 #include "content/browser/download/download_item_impl.h" 11 #include "content/browser/download/download_item_impl.h"
12 #include "content/browser/download/download_item_impl_delegate.h" 12 #include "content/browser/download/download_item_impl_delegate.h"
13 #include "content/browser/download/download_request_handle.h" 13 #include "content/browser/download/download_request_handle.h"
14 #include "content/browser/download/mock_download_file.h"
14 #include "content/public/browser/download_id.h" 15 #include "content/public/browser/download_id.h"
16 #include "content/public/browser/download_destination_observer.h"
15 #include "content/public/browser/download_interrupt_reasons.h" 17 #include "content/public/browser/download_interrupt_reasons.h"
16 #include "content/public/test/mock_download_item.h" 18 #include "content/public/test/mock_download_item.h"
17 #include "content/public/test/test_browser_thread.h" 19 #include "content/public/test/test_browser_thread.h"
18 #include "testing/gmock/include/gmock/gmock.h" 20 #include "testing/gmock/include/gmock/gmock.h"
19 #include "testing/gtest/include/gtest/gtest.h" 21 #include "testing/gtest/include/gtest/gtest.h"
20 22
21 using content::BrowserThread; 23 using content::BrowserThread;
22 using content::DownloadId; 24 using content::DownloadId;
23 using content::DownloadItem; 25 using content::DownloadItem;
24 using content::DownloadManager; 26 using content::DownloadManager;
25 using content::MockDownloadItem; 27 using content::MockDownloadItem;
26 using content::WebContents; 28 using content::WebContents;
27 using ::testing::_; 29 using ::testing::_;
28 using ::testing::AllOf; 30 using ::testing::AllOf;
29 using ::testing::Property; 31 using ::testing::Property;
30 using ::testing::Return; 32 using ::testing::Return;
33 using ::testing::StrictMock;
31 34
32 DownloadId::Domain kValidDownloadItemIdDomain = "valid DownloadId::Domain"; 35 DownloadId::Domain kValidDownloadItemIdDomain = "valid DownloadId::Domain";
33 36
34 namespace { 37 namespace {
35 class MockDelegate : public DownloadItemImplDelegate { 38 class MockDelegate : public DownloadItemImplDelegate {
36 public: 39 public:
37 MockDelegate(DownloadFileManager* file_manager) 40 MOCK_METHOD1(DelegateStart, void(DownloadItemImpl* download));
38 : file_manager_(file_manager) { 41 MOCK_METHOD1(ShouldOpenDownload, bool(DownloadItemImpl* download));
39 }
40 MOCK_METHOD1(ShouldOpenFileBasedOnExtension, bool(const FilePath& path)); 42 MOCK_METHOD1(ShouldOpenFileBasedOnExtension, bool(const FilePath& path));
41 MOCK_METHOD1(ShouldOpenDownload, bool(DownloadItemImpl* download));
42 MOCK_METHOD1(CheckForFileRemoval, void(DownloadItemImpl* download)); 43 MOCK_METHOD1(CheckForFileRemoval, void(DownloadItemImpl* download));
43 MOCK_METHOD1(MaybeCompleteDownload, void(DownloadItemImpl* download)); 44 MOCK_METHOD1(MaybeCompleteDownload, void(DownloadItemImpl* download));
44 MOCK_CONST_METHOD0(GetBrowserContext, content::BrowserContext*()); 45 MOCK_CONST_METHOD0(GetBrowserContext, content::BrowserContext*());
45 MOCK_METHOD1(DownloadStopped, void(DownloadItemImpl* download)); 46 MOCK_METHOD1(DownloadStopped, void(DownloadItemImpl* download));
46 MOCK_METHOD1(DownloadCompleted, void(DownloadItemImpl* download)); 47 MOCK_METHOD1(DownloadCompleted, void(DownloadItemImpl* download));
47 MOCK_METHOD1(DownloadOpened, void(DownloadItemImpl* download)); 48 MOCK_METHOD1(DownloadOpened, void(DownloadItemImpl* download));
48 MOCK_METHOD1(DownloadRemoved, void(DownloadItemImpl* download)); 49 MOCK_METHOD1(DownloadRemoved, void(DownloadItemImpl* download));
49 MOCK_METHOD1(DownloadRenamedToIntermediateName, 50 MOCK_METHOD1(DownloadRenamedToIntermediateName,
50 void(DownloadItemImpl* download)); 51 void(DownloadItemImpl* download));
51 MOCK_METHOD1(DownloadRenamedToFinalName, void(DownloadItemImpl* download)); 52 MOCK_METHOD1(DownloadRenamedToFinalName, void(DownloadItemImpl* download));
52 MOCK_CONST_METHOD1(AssertStateConsistent, void(DownloadItemImpl* download)); 53 MOCK_CONST_METHOD1(AssertStateConsistent, void(DownloadItemImpl* download));
53 virtual DownloadFileManager* GetDownloadFileManager() OVERRIDE { 54 virtual DownloadFileManager* GetDownloadFileManager() OVERRIDE {
54 return file_manager_; 55 return file_manager_;
55 } 56 }
56 private: 57 private:
57 DownloadFileManager* file_manager_; 58 DownloadFileManager* file_manager_;
58 }; 59 };
59 60
60 class MockRequestHandle : public DownloadRequestHandleInterface { 61 class MockRequestHandle : public DownloadRequestHandleInterface {
61 public: 62 public:
62 MOCK_CONST_METHOD0(GetWebContents, WebContents*()); 63 MOCK_CONST_METHOD0(GetWebContents, WebContents*());
63 MOCK_CONST_METHOD0(GetDownloadManager, DownloadManager*()); 64 MOCK_CONST_METHOD0(GetDownloadManager, DownloadManager*());
64 MOCK_CONST_METHOD0(PauseRequest, void()); 65 MOCK_CONST_METHOD0(PauseRequest, void());
65 MOCK_CONST_METHOD0(ResumeRequest, void()); 66 MOCK_CONST_METHOD0(ResumeRequest, void());
66 MOCK_CONST_METHOD0(CancelRequest, void()); 67 MOCK_CONST_METHOD0(CancelRequest, void());
67 MOCK_CONST_METHOD0(DebugString, std::string()); 68 MOCK_CONST_METHOD0(DebugString, std::string());
68 }; 69 };
69 70
70 class MockDownloadFileFactory
71 : public DownloadFileManager::DownloadFileFactory {
72 public:
73 content::DownloadFile* CreateFile(
74 DownloadCreateInfo* info,
75 scoped_ptr<content::ByteStreamReader> stream_reader,
76 DownloadManager* mgr,
77 bool calculate_hash,
78 const net::BoundNetLog& bound_net_log) {
79 return MockCreateFile(
80 info, stream_reader.get(), info->request_handle, mgr, calculate_hash,
81 bound_net_log);
82 }
83
84 MOCK_METHOD6(MockCreateFile,
85 content::DownloadFile*(DownloadCreateInfo*,
86 content::ByteStreamReader*,
87 const DownloadRequestHandle&,
88 DownloadManager*,
89 bool,
90 const net::BoundNetLog&));
91 };
92
93 class MockDownloadFileManager : public DownloadFileManager {
94 public:
95 MockDownloadFileManager();
96 MOCK_METHOD0(Shutdown, void());
97 MOCK_METHOD1(CancelDownload, void(DownloadId));
98 MOCK_METHOD2(CompleteDownload, void(DownloadId, const base::Closure&));
99 MOCK_METHOD1(OnDownloadManagerShutdown, void(DownloadManager*));
100 MOCK_METHOD4(RenameDownloadFile, void(DownloadId, const FilePath&, bool,
101 const RenameCompletionCallback&));
102 MOCK_CONST_METHOD0(NumberOfActiveDownloads, int());
103 private:
104 ~MockDownloadFileManager() {}
105 };
106
107 // Schedules a task to invoke the RenameCompletionCallback with |new_path| on 71 // Schedules a task to invoke the RenameCompletionCallback with |new_path| on
108 // the UI thread. Should only be used as the action for 72 // the UI thread. Should only be used as the action for
109 // MockDownloadFileManager::Rename*DownloadFile as follows: 73 // MockDownloadFile::Rename as follows:
110 // EXPECT_CALL(mock_download_file_manager, 74 // EXPECT_CALL(download_file, Rename(_,_,_))
111 // RenameDownloadFile(_,_,_,_))
112 // .WillOnce(ScheduleRenameCallback(new_path)); 75 // .WillOnce(ScheduleRenameCallback(new_path));
113 ACTION_P(ScheduleRenameCallback, new_path) { 76 ACTION_P(ScheduleRenameCallback, new_path) {
114 BrowserThread::PostTask( 77 BrowserThread::PostTask(
115 BrowserThread::UI, FROM_HERE, 78 BrowserThread::UI, FROM_HERE,
116 base::Bind(arg3, content::DOWNLOAD_INTERRUPT_REASON_NONE, new_path)); 79 base::Bind(arg2, content::DOWNLOAD_INTERRUPT_REASON_NONE, new_path));
80 }
81
82 // Schedules a task to invoke the input closure on
83 // the UI thread. Should only be used as the action for
84 // MockDownloadFile::Detach/Cancel as follows:
85 // EXPECT_CALL(download_file, Detach(_))
86 // .WillOnce(ScheduleClosure()));
87 ACTION(ScheduleClosure) {
88 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, arg0);
117 } 89 }
118 90
119 // Similarly for scheduling a completion callback. 91 // Similarly for scheduling a completion callback.
120 ACTION(ScheduleCompleteCallback) { 92 ACTION(ScheduleCompleteCallback) {
121 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, base::Bind(arg1)); 93 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, base::Bind(arg1));
122 } 94 }
123 95
124 MockDownloadFileManager::MockDownloadFileManager()
125 : DownloadFileManager(new MockDownloadFileFactory) {
126 }
127
128 } // namespace 96 } // namespace
129 97
130 class DownloadItemTest : public testing::Test { 98 class DownloadItemTest : public testing::Test {
131 public: 99 public:
132 class MockObserver : public DownloadItem::Observer { 100 class MockObserver : public DownloadItem::Observer {
133 public: 101 public:
134 explicit MockObserver(DownloadItem* item) 102 explicit MockObserver(DownloadItem* item)
135 : item_(item), 103 : item_(item),
136 removed_(false), 104 removed_(false),
137 destroyed_(false), 105 destroyed_(false),
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 private: 145 private:
178 DownloadItem* item_; 146 DownloadItem* item_;
179 bool removed_; 147 bool removed_;
180 bool destroyed_; 148 bool destroyed_;
181 bool updated_; 149 bool updated_;
182 }; 150 };
183 151
184 DownloadItemTest() 152 DownloadItemTest()
185 : ui_thread_(BrowserThread::UI, &loop_), 153 : ui_thread_(BrowserThread::UI, &loop_),
186 file_thread_(BrowserThread::FILE, &loop_), 154 file_thread_(BrowserThread::FILE, &loop_),
187 file_manager_(new MockDownloadFileManager), 155 delegate_() {
188 delegate_(file_manager_.get()) {
189 } 156 }
190 157
191 ~DownloadItemTest() { 158 ~DownloadItemTest() {
192 } 159 }
193 160
194 virtual void SetUp() { 161 virtual void SetUp() {
195 } 162 }
196 163
197 virtual void TearDown() { 164 virtual void TearDown() {
198 ui_thread_.DeprecatedGetThreadObject()->message_loop()->RunAllPending(); 165 ui_thread_.DeprecatedGetThreadObject()->message_loop()->RunAllPending();
(...skipping 20 matching lines...) Expand all
219 186
220 scoped_ptr<DownloadRequestHandleInterface> request_handle( 187 scoped_ptr<DownloadRequestHandleInterface> request_handle(
221 new testing::NiceMock<MockRequestHandle>); 188 new testing::NiceMock<MockRequestHandle>);
222 DownloadItemImpl* download = 189 DownloadItemImpl* download =
223 new DownloadItemImpl(&delegate_, *(info_.get()), 190 new DownloadItemImpl(&delegate_, *(info_.get()),
224 request_handle.Pass(), net::BoundNetLog()); 191 request_handle.Pass(), net::BoundNetLog());
225 allocated_downloads_.insert(download); 192 allocated_downloads_.insert(download);
226 return download; 193 return download;
227 } 194 }
228 195
196 // Add DownloadFile to DownloadItem
197 MockDownloadFile* AddDownloadFileToDownloadItem(DownloadItemImpl* item) {
198 MockDownloadFile* mock_download_file(new StrictMock<MockDownloadFile>);
199 scoped_ptr<content::DownloadFile> download_file(mock_download_file);
200 EXPECT_CALL(*mock_download_file, Initialize(_));
201 item->Start(download_file.Pass());
202 loop_.RunAllPending();
203 return mock_download_file;
204 }
205
206 // Cleanup a download item (specifically get rid of the DownloadFile on it).
207 // The item must be in the IN_PROGRESS state.
208 void CleanupItem(DownloadItemImpl* item, MockDownloadFile* download_file) {
209 EXPECT_EQ(content::DownloadItem::IN_PROGRESS, item->GetState());
210
211 EXPECT_CALL(*download_file, Cancel());
212 EXPECT_CALL(delegate_, DownloadStopped(item));
213 item->Cancel(true);
214 loop_.RunAllPending();
215 }
216
229 // Destroy a previously created download item. 217 // Destroy a previously created download item.
230 void DestroyDownloadItem(DownloadItem* item) { 218 void DestroyDownloadItem(DownloadItem* item) {
231 allocated_downloads_.erase(item); 219 allocated_downloads_.erase(item);
232 delete item; 220 delete item;
233 } 221 }
234 222
235 void RunAllPendingInMessageLoops() { 223 void RunAllPendingInMessageLoops() {
236 loop_.RunAllPending(); 224 loop_.RunAllPending();
237 } 225 }
238 226
239 MockDelegate* mock_delegate() { 227 MockDelegate* mock_delegate() {
240 return &delegate_; 228 return &delegate_;
241 } 229 }
242 230
243 MockDownloadFileManager* mock_file_manager() {
244 return file_manager_.get();
245 }
246
247 private: 231 private:
248 MessageLoopForUI loop_; 232 MessageLoopForUI loop_;
249 content::TestBrowserThread ui_thread_; // UI thread 233 content::TestBrowserThread ui_thread_; // UI thread
250 content::TestBrowserThread file_thread_; // FILE thread 234 content::TestBrowserThread file_thread_; // FILE thread
251 scoped_refptr<MockDownloadFileManager> file_manager_;
252 testing::NiceMock<MockDelegate> delegate_; 235 testing::NiceMock<MockDelegate> delegate_;
253 std::set<DownloadItem*> allocated_downloads_; 236 std::set<DownloadItem*> allocated_downloads_;
254 }; 237 };
255 238
256 namespace { 239 namespace {
257 240
258 const int kDownloadChunkSize = 1000; 241 const int kDownloadChunkSize = 1000;
259 const int kDownloadSpeed = 1000; 242 const int kDownloadSpeed = 1000;
260 const int kDummyDBHandle = 10; 243 const int kDummyDBHandle = 10;
261 const FilePath::CharType kDummyPath[] = FILE_PATH_LITERAL("/testpath"); 244 const FilePath::CharType kDummyPath[] = FILE_PATH_LITERAL("/testpath");
(...skipping 13 matching lines...) Expand all
275 DownloadItemImpl* item = CreateDownloadItem(DownloadItem::IN_PROGRESS); 258 DownloadItemImpl* item = CreateDownloadItem(DownloadItem::IN_PROGRESS);
276 MockObserver observer(item); 259 MockObserver observer(item);
277 260
278 item->UpdateProgress(kDownloadChunkSize, kDownloadSpeed, ""); 261 item->UpdateProgress(kDownloadChunkSize, kDownloadSpeed, "");
279 ASSERT_TRUE(observer.CheckUpdated()); 262 ASSERT_TRUE(observer.CheckUpdated());
280 EXPECT_EQ(kDownloadSpeed, item->CurrentSpeed()); 263 EXPECT_EQ(kDownloadSpeed, item->CurrentSpeed());
281 } 264 }
282 265
283 TEST_F(DownloadItemTest, NotificationAfterCancel) { 266 TEST_F(DownloadItemTest, NotificationAfterCancel) {
284 DownloadItemImpl* user_cancel = CreateDownloadItem(DownloadItem::IN_PROGRESS); 267 DownloadItemImpl* user_cancel = CreateDownloadItem(DownloadItem::IN_PROGRESS);
268 MockDownloadFile* download_file = AddDownloadFileToDownloadItem(user_cancel);
269 EXPECT_CALL(*download_file, Cancel());
285 MockObserver observer1(user_cancel); 270 MockObserver observer1(user_cancel);
286 271
287 user_cancel->Cancel(true); 272 user_cancel->Cancel(true);
288 ASSERT_TRUE(observer1.CheckUpdated()); 273 ASSERT_TRUE(observer1.CheckUpdated());
274 RunAllPendingInMessageLoops();
289 275
290 DownloadItemImpl* system_cancel = 276 DownloadItemImpl* system_cancel =
291 CreateDownloadItem(DownloadItem::IN_PROGRESS); 277 CreateDownloadItem(DownloadItem::IN_PROGRESS);
278 download_file = AddDownloadFileToDownloadItem(system_cancel);
279 EXPECT_CALL(*download_file, Cancel());
292 MockObserver observer2(system_cancel); 280 MockObserver observer2(system_cancel);
293 281
294 system_cancel->Cancel(false); 282 system_cancel->Cancel(false);
295 ASSERT_TRUE(observer2.CheckUpdated()); 283 ASSERT_TRUE(observer2.CheckUpdated());
284 RunAllPendingInMessageLoops();
296 } 285 }
297 286
298 TEST_F(DownloadItemTest, NotificationAfterComplete) { 287 TEST_F(DownloadItemTest, NotificationAfterComplete) {
299 DownloadItemImpl* item = CreateDownloadItem(DownloadItem::IN_PROGRESS); 288 DownloadItemImpl* item = CreateDownloadItem(DownloadItem::IN_PROGRESS);
300 MockObserver observer(item); 289 MockObserver observer(item);
301 290
302 item->OnAllDataSaved(kDownloadChunkSize, DownloadItem::kEmptyFileHash); 291 item->OnAllDataSaved(DownloadItem::kEmptyFileHash);
303 ASSERT_TRUE(observer.CheckUpdated()); 292 ASSERT_TRUE(observer.CheckUpdated());
304 293
305 item->MarkAsComplete(); 294 item->MarkAsComplete();
306 ASSERT_TRUE(observer.CheckUpdated()); 295 ASSERT_TRUE(observer.CheckUpdated());
307 } 296 }
308 297
309 TEST_F(DownloadItemTest, NotificationAfterDownloadedFileRemoved) { 298 TEST_F(DownloadItemTest, NotificationAfterDownloadedFileRemoved) {
310 DownloadItemImpl* item = CreateDownloadItem(DownloadItem::IN_PROGRESS); 299 DownloadItemImpl* item = CreateDownloadItem(DownloadItem::IN_PROGRESS);
311 MockObserver observer(item); 300 MockObserver observer(item);
312 301
313 item->OnDownloadedFileRemoved(); 302 item->OnDownloadedFileRemoved();
314 ASSERT_TRUE(observer.CheckUpdated()); 303 ASSERT_TRUE(observer.CheckUpdated());
315 } 304 }
316 305
317 TEST_F(DownloadItemTest, NotificationAfterInterrupted) { 306 TEST_F(DownloadItemTest, NotificationAfterInterrupted) {
318 DownloadItemImpl* item = CreateDownloadItem(DownloadItem::IN_PROGRESS); 307 DownloadItemImpl* item = CreateDownloadItem(DownloadItem::IN_PROGRESS);
308 MockDownloadFile* download_file = AddDownloadFileToDownloadItem(item);
309 EXPECT_CALL(*download_file, Cancel());
319 MockObserver observer(item); 310 MockObserver observer(item);
320 311
321 item->Interrupt(content::DOWNLOAD_INTERRUPT_REASON_NONE); 312 item->Interrupt(content::DOWNLOAD_INTERRUPT_REASON_NONE);
322 ASSERT_TRUE(observer.CheckUpdated()); 313 ASSERT_TRUE(observer.CheckUpdated());
314 RunAllPendingInMessageLoops();
323 } 315 }
324 316
325 TEST_F(DownloadItemTest, NotificationAfterDelete) { 317 TEST_F(DownloadItemTest, NotificationAfterDelete) {
326 DownloadItemImpl* item = CreateDownloadItem(DownloadItem::IN_PROGRESS); 318 DownloadItemImpl* item = CreateDownloadItem(DownloadItem::IN_PROGRESS);
319 MockDownloadFile* download_file = AddDownloadFileToDownloadItem(item);
320 EXPECT_CALL(*download_file, Cancel());
327 MockObserver observer(item); 321 MockObserver observer(item);
328 322
329 item->Delete(DownloadItem::DELETE_DUE_TO_BROWSER_SHUTDOWN); 323 item->Delete(DownloadItem::DELETE_DUE_TO_BROWSER_SHUTDOWN);
330 ASSERT_TRUE(observer.CheckUpdated()); 324 ASSERT_TRUE(observer.CheckUpdated());
325 RunAllPendingInMessageLoops();
331 } 326 }
332 327
333 TEST_F(DownloadItemTest, NotificationAfterDestroyed) { 328 TEST_F(DownloadItemTest, NotificationAfterDestroyed) {
334 DownloadItemImpl* item = CreateDownloadItem(DownloadItem::IN_PROGRESS); 329 DownloadItemImpl* item = CreateDownloadItem(DownloadItem::IN_PROGRESS);
335 MockObserver observer(item); 330 MockObserver observer(item);
336 331
337 DestroyDownloadItem(item); 332 DestroyDownloadItem(item);
338 ASSERT_TRUE(observer.CheckDestroyed()); 333 ASSERT_TRUE(observer.CheckDestroyed());
339 } 334 }
340 335
341 TEST_F(DownloadItemTest, NotificationAfterRemove) { 336 TEST_F(DownloadItemTest, NotificationAfterRemove) {
342 DownloadItemImpl* item = CreateDownloadItem(DownloadItem::IN_PROGRESS); 337 DownloadItemImpl* item = CreateDownloadItem(DownloadItem::IN_PROGRESS);
338 MockDownloadFile* download_file = AddDownloadFileToDownloadItem(item);
339 EXPECT_CALL(*download_file, Cancel());
343 MockObserver observer(item); 340 MockObserver observer(item);
344 341
345 item->Remove(); 342 item->Remove();
346 ASSERT_TRUE(observer.CheckUpdated()); 343 ASSERT_TRUE(observer.CheckUpdated());
347 ASSERT_TRUE(observer.CheckRemoved()); 344 ASSERT_TRUE(observer.CheckRemoved());
348 } 345 }
349 346
350 TEST_F(DownloadItemTest, NotificationAfterOnContentCheckCompleted) { 347 TEST_F(DownloadItemTest, NotificationAfterOnContentCheckCompleted) {
351 // Setting to NOT_DANGEROUS does not trigger a notification. 348 // Setting to NOT_DANGEROUS does not trigger a notification.
352 DownloadItemImpl* safe_item = CreateDownloadItem(DownloadItem::IN_PROGRESS); 349 DownloadItemImpl* safe_item = CreateDownloadItem(DownloadItem::IN_PROGRESS);
353 MockObserver safe_observer(safe_item); 350 MockObserver safe_observer(safe_item);
354 351
355 safe_item->OnAllDataSaved(1, ""); 352 safe_item->OnAllDataSaved("");
356 EXPECT_TRUE(safe_observer.CheckUpdated()); 353 EXPECT_TRUE(safe_observer.CheckUpdated());
357 safe_item->OnContentCheckCompleted( 354 safe_item->OnContentCheckCompleted(
358 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS); 355 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS);
359 EXPECT_TRUE(safe_observer.CheckUpdated()); 356 EXPECT_TRUE(safe_observer.CheckUpdated());
360 357
361 // Setting to unsafe url or unsafe file should trigger a notification. 358 // Setting to unsafe url or unsafe file should trigger a notification.
362 DownloadItemImpl* unsafeurl_item = 359 DownloadItemImpl* unsafeurl_item =
363 CreateDownloadItem(DownloadItem::IN_PROGRESS); 360 CreateDownloadItem(DownloadItem::IN_PROGRESS);
364 MockObserver unsafeurl_observer(unsafeurl_item); 361 MockObserver unsafeurl_observer(unsafeurl_item);
365 362
366 unsafeurl_item->OnAllDataSaved(1, ""); 363 unsafeurl_item->OnAllDataSaved("");
367 EXPECT_TRUE(unsafeurl_observer.CheckUpdated()); 364 EXPECT_TRUE(unsafeurl_observer.CheckUpdated());
368 unsafeurl_item->OnContentCheckCompleted( 365 unsafeurl_item->OnContentCheckCompleted(
369 content::DOWNLOAD_DANGER_TYPE_DANGEROUS_URL); 366 content::DOWNLOAD_DANGER_TYPE_DANGEROUS_URL);
370 EXPECT_TRUE(unsafeurl_observer.CheckUpdated()); 367 EXPECT_TRUE(unsafeurl_observer.CheckUpdated());
371 368
372 unsafeurl_item->DangerousDownloadValidated(); 369 unsafeurl_item->DangerousDownloadValidated();
373 EXPECT_TRUE(unsafeurl_observer.CheckUpdated()); 370 EXPECT_TRUE(unsafeurl_observer.CheckUpdated());
374 371
375 DownloadItemImpl* unsafefile_item = 372 DownloadItemImpl* unsafefile_item =
376 CreateDownloadItem(DownloadItem::IN_PROGRESS); 373 CreateDownloadItem(DownloadItem::IN_PROGRESS);
377 MockObserver unsafefile_observer(unsafefile_item); 374 MockObserver unsafefile_observer(unsafefile_item);
378 375
379 unsafefile_item->OnAllDataSaved(1, ""); 376 unsafefile_item->OnAllDataSaved("");
380 EXPECT_TRUE(unsafefile_observer.CheckUpdated()); 377 EXPECT_TRUE(unsafefile_observer.CheckUpdated());
381 unsafefile_item->OnContentCheckCompleted( 378 unsafefile_item->OnContentCheckCompleted(
382 content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE); 379 content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE);
383 EXPECT_TRUE(unsafefile_observer.CheckUpdated()); 380 EXPECT_TRUE(unsafefile_observer.CheckUpdated());
384 381
385 unsafefile_item->DangerousDownloadValidated(); 382 unsafefile_item->DangerousDownloadValidated();
386 EXPECT_TRUE(unsafefile_observer.CheckUpdated()); 383 EXPECT_TRUE(unsafefile_observer.CheckUpdated());
387 } 384 }
388 385
389 // DownloadItemImpl::OnDownloadTargetDetermined will schedule a task to run 386 // DownloadItemImpl::OnDownloadTargetDetermined will schedule a task to run
390 // DownloadFileManager::RenameDownloadFile(). Once the rename 387 // DownloadFile::Rename(). Once the rename
391 // completes, DownloadItemImpl receives a notification with the new file 388 // completes, DownloadItemImpl receives a notification with the new file
392 // name. Check that observers are updated when the new filename is available and 389 // name. Check that observers are updated when the new filename is available and
393 // not before. 390 // not before.
394 TEST_F(DownloadItemTest, NotificationAfterOnDownloadTargetDetermined) { 391 TEST_F(DownloadItemTest, NotificationAfterOnDownloadTargetDetermined) {
395 DownloadItemImpl* item = CreateDownloadItem(DownloadItem::IN_PROGRESS); 392 DownloadItemImpl* item = CreateDownloadItem(DownloadItem::IN_PROGRESS);
393 MockDownloadFile* download_file = AddDownloadFileToDownloadItem(item);
396 MockObserver observer(item); 394 MockObserver observer(item);
397 FilePath target_path(kDummyPath); 395 FilePath target_path(kDummyPath);
398 FilePath intermediate_path(target_path.InsertBeforeExtensionASCII("x")); 396 FilePath intermediate_path(target_path.InsertBeforeExtensionASCII("x"));
399 FilePath new_intermediate_path(target_path.InsertBeforeExtensionASCII("y")); 397 FilePath new_intermediate_path(target_path.InsertBeforeExtensionASCII("y"));
400 EXPECT_CALL(*mock_file_manager(), 398 EXPECT_CALL(*download_file, Rename(intermediate_path, false, _))
401 RenameDownloadFile(_,intermediate_path,false,_))
402 .WillOnce(ScheduleRenameCallback(new_intermediate_path)); 399 .WillOnce(ScheduleRenameCallback(new_intermediate_path));
403 400
404 // Currently, a notification would be generated if the danger type is anything 401 // Currently, a notification would be generated if the danger type is anything
405 // other than NOT_DANGEROUS. 402 // other than NOT_DANGEROUS.
406 item->OnDownloadTargetDetermined(target_path, 403 item->OnDownloadTargetDetermined(target_path,
407 DownloadItem::TARGET_DISPOSITION_OVERWRITE, 404 DownloadItem::TARGET_DISPOSITION_OVERWRITE,
408 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, 405 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS,
409 intermediate_path); 406 intermediate_path);
410 EXPECT_FALSE(observer.CheckUpdated()); 407 EXPECT_FALSE(observer.CheckUpdated());
411 RunAllPendingInMessageLoops(); 408 RunAllPendingInMessageLoops();
412 EXPECT_TRUE(observer.CheckUpdated()); 409 EXPECT_TRUE(observer.CheckUpdated());
413 EXPECT_EQ(new_intermediate_path, item->GetFullPath()); 410 EXPECT_EQ(new_intermediate_path, item->GetFullPath());
411
412 CleanupItem(item, download_file);
414 } 413 }
415 414
416 TEST_F(DownloadItemTest, NotificationAfterTogglePause) { 415 TEST_F(DownloadItemTest, NotificationAfterTogglePause) {
417 DownloadItemImpl* item = CreateDownloadItem(DownloadItem::IN_PROGRESS); 416 DownloadItemImpl* item = CreateDownloadItem(DownloadItem::IN_PROGRESS);
418 MockObserver observer(item); 417 MockObserver observer(item);
419 418
420 item->TogglePause(); 419 item->TogglePause();
421 ASSERT_TRUE(observer.CheckUpdated()); 420 ASSERT_TRUE(observer.CheckUpdated());
422 421
423 item->TogglePause(); 422 item->TogglePause();
424 ASSERT_TRUE(observer.CheckUpdated()); 423 ASSERT_TRUE(observer.CheckUpdated());
425 } 424 }
426 425
427 TEST_F(DownloadItemTest, DisplayName) { 426 TEST_F(DownloadItemTest, DisplayName) {
428 DownloadItemImpl* item = CreateDownloadItem(DownloadItem::IN_PROGRESS); 427 DownloadItemImpl* item = CreateDownloadItem(DownloadItem::IN_PROGRESS);
428 MockDownloadFile* download_file = AddDownloadFileToDownloadItem(item);
429 FilePath target_path(FilePath(kDummyPath).AppendASCII("foo.bar")); 429 FilePath target_path(FilePath(kDummyPath).AppendASCII("foo.bar"));
430 FilePath intermediate_path(target_path.InsertBeforeExtensionASCII("x")); 430 FilePath intermediate_path(target_path.InsertBeforeExtensionASCII("x"));
431 EXPECT_EQ(FILE_PATH_LITERAL(""), 431 EXPECT_EQ(FILE_PATH_LITERAL(""),
432 item->GetFileNameToReportUser().value()); 432 item->GetFileNameToReportUser().value());
433 EXPECT_CALL(*mock_file_manager(), 433 EXPECT_CALL(*download_file, Rename(_, false, _))
434 RenameDownloadFile(_,_,false,_))
435 .WillOnce(ScheduleRenameCallback(intermediate_path)); 434 .WillOnce(ScheduleRenameCallback(intermediate_path));
436 item->OnDownloadTargetDetermined(target_path, 435 item->OnDownloadTargetDetermined(target_path,
437 DownloadItem::TARGET_DISPOSITION_OVERWRITE, 436 DownloadItem::TARGET_DISPOSITION_OVERWRITE,
438 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, 437 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS,
439 intermediate_path); 438 intermediate_path);
440 RunAllPendingInMessageLoops(); 439 RunAllPendingInMessageLoops();
441 EXPECT_EQ(FILE_PATH_LITERAL("foo.bar"), 440 EXPECT_EQ(FILE_PATH_LITERAL("foo.bar"),
442 item->GetFileNameToReportUser().value()); 441 item->GetFileNameToReportUser().value());
443 item->SetDisplayName(FilePath(FILE_PATH_LITERAL("new.name"))); 442 item->SetDisplayName(FilePath(FILE_PATH_LITERAL("new.name")));
444 EXPECT_EQ(FILE_PATH_LITERAL("new.name"), 443 EXPECT_EQ(FILE_PATH_LITERAL("new.name"),
445 item->GetFileNameToReportUser().value()); 444 item->GetFileNameToReportUser().value());
445 CleanupItem(item, download_file);
446 }
447
448 // Test to make sure that Start method calls DF initialize properly.
449 TEST_F(DownloadItemTest, Start) {
450 MockDownloadFile* mock_download_file(new MockDownloadFile);
451 scoped_ptr<content::DownloadFile> download_file(mock_download_file);
452 DownloadItemImpl* item = CreateDownloadItem(DownloadItem::IN_PROGRESS);
453 EXPECT_CALL(*mock_download_file, Initialize(_));
454 item->Start(download_file.Pass());
455
456 CleanupItem(item, mock_download_file);
446 } 457 }
447 458
448 // Test that the delegate is invoked after the download file is renamed. 459 // Test that the delegate is invoked after the download file is renamed.
449 // Delegate::DownloadRenamedToIntermediateName() should be invoked when the 460 // Delegate::DownloadRenamedToIntermediateName() should be invoked when the
450 // download is renamed to the intermediate name. 461 // download is renamed to the intermediate name.
451 // Delegate::DownloadRenamedToFinalName() should be invoked after the final 462 // Delegate::DownloadRenamedToFinalName() should be invoked after the final
452 // rename. 463 // rename.
453 TEST_F(DownloadItemTest, CallbackAfterRename) { 464 TEST_F(DownloadItemTest, CallbackAfterRename) {
454 DownloadItemImpl* item = CreateDownloadItem(DownloadItem::IN_PROGRESS); 465 DownloadItemImpl* item = CreateDownloadItem(DownloadItem::IN_PROGRESS);
466 MockDownloadFile* download_file = AddDownloadFileToDownloadItem(item);
455 FilePath final_path(FilePath(kDummyPath).AppendASCII("foo.bar")); 467 FilePath final_path(FilePath(kDummyPath).AppendASCII("foo.bar"));
456 FilePath intermediate_path(final_path.InsertBeforeExtensionASCII("x")); 468 FilePath intermediate_path(final_path.InsertBeforeExtensionASCII("x"));
457 FilePath new_intermediate_path(final_path.InsertBeforeExtensionASCII("y")); 469 FilePath new_intermediate_path(final_path.InsertBeforeExtensionASCII("y"));
458 EXPECT_CALL(*mock_file_manager(), 470 EXPECT_CALL(*download_file, Rename(intermediate_path, false, _))
459 RenameDownloadFile(item->GetGlobalId(),
460 intermediate_path, false, _))
461 .WillOnce(ScheduleRenameCallback(new_intermediate_path)); 471 .WillOnce(ScheduleRenameCallback(new_intermediate_path));
472
462 // DownloadItemImpl should invoke this callback on the delegate once the 473 // DownloadItemImpl should invoke this callback on the delegate once the
463 // download is renamed to the intermediate name. Also check that GetFullPath() 474 // download is renamed to the intermediate name. Also check that GetFullPath()
464 // returns the intermediate path at the time of the call. 475 // returns the intermediate path at the time of the call.
465 EXPECT_CALL(*mock_delegate(), 476 EXPECT_CALL(*mock_delegate(),
466 DownloadRenamedToIntermediateName( 477 DownloadRenamedToIntermediateName(
467 AllOf(item, 478 AllOf(item,
468 Property(&DownloadItem::GetFullPath, 479 Property(&DownloadItem::GetFullPath,
469 new_intermediate_path)))); 480 new_intermediate_path))));
470 item->OnDownloadTargetDetermined(final_path, 481 item->OnDownloadTargetDetermined(final_path,
471 DownloadItem::TARGET_DISPOSITION_OVERWRITE, 482 DownloadItem::TARGET_DISPOSITION_OVERWRITE,
472 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, 483 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS,
473 intermediate_path); 484 intermediate_path);
474 RunAllPendingInMessageLoops(); 485 RunAllPendingInMessageLoops();
475 // All the callbacks should have happened by now. 486 // All the callbacks should have happened by now.
476 ::testing::Mock::VerifyAndClearExpectations(mock_file_manager()); 487 ::testing::Mock::VerifyAndClearExpectations(download_file);
477 ::testing::Mock::VerifyAndClearExpectations(mock_delegate()); 488 ::testing::Mock::VerifyAndClearExpectations(mock_delegate());
478 489
479 item->OnAllDataSaved(10, ""); 490 item->OnAllDataSaved("");
480 EXPECT_CALL(*mock_file_manager(), 491 EXPECT_CALL(*download_file, Rename(final_path, true, _))
481 RenameDownloadFile(item->GetGlobalId(),
482 final_path, true, _))
483 .WillOnce(ScheduleRenameCallback(final_path)); 492 .WillOnce(ScheduleRenameCallback(final_path));
484 EXPECT_CALL(*mock_file_manager(),
485 CompleteDownload(item->GetGlobalId(), _))
486 .WillOnce(ScheduleCompleteCallback());
487 // DownloadItemImpl should invoke this callback on the delegate after the 493 // DownloadItemImpl should invoke this callback on the delegate after the
488 // final rename has completed. Also check that GetFullPath() and 494 // final rename has completed. Also check that GetFullPath() and
489 // GetTargetFilePath() return the final path at the time of the call. 495 // GetTargetFilePath() return the final path at the time of the call.
490 EXPECT_CALL(*mock_delegate(), 496 EXPECT_CALL(*mock_delegate(),
491 DownloadRenamedToFinalName( 497 DownloadRenamedToFinalName(
492 AllOf(item, 498 AllOf(item,
493 Property(&DownloadItem::GetFullPath, final_path), 499 Property(&DownloadItem::GetFullPath, final_path),
494 Property(&DownloadItem::GetTargetFilePath, 500 Property(&DownloadItem::GetTargetFilePath,
495 final_path)))); 501 final_path))));
496 EXPECT_CALL(*mock_delegate(), DownloadCompleted(item)); 502 EXPECT_CALL(*mock_delegate(), DownloadCompleted(item));
497 EXPECT_CALL(*mock_delegate(), ShouldOpenDownload(item)) 503 EXPECT_CALL(*mock_delegate(), ShouldOpenDownload(item))
498 .WillOnce(Return(true)); 504 .WillOnce(Return(true));
505 EXPECT_CALL(*download_file, Detach(_))
506 .WillOnce(ScheduleClosure());
499 item->OnDownloadCompleting(); 507 item->OnDownloadCompleting();
500 RunAllPendingInMessageLoops(); 508 RunAllPendingInMessageLoops();
501 ::testing::Mock::VerifyAndClearExpectations(mock_file_manager()); 509 ::testing::Mock::VerifyAndClearExpectations(download_file);
502 ::testing::Mock::VerifyAndClearExpectations(mock_delegate()); 510 ::testing::Mock::VerifyAndClearExpectations(mock_delegate());
503 } 511 }
504 512
505 TEST_F(DownloadItemTest, Interrupted) { 513 TEST_F(DownloadItemTest, Interrupted) {
506 DownloadItemImpl* item = CreateDownloadItem(DownloadItem::IN_PROGRESS); 514 DownloadItemImpl* item = CreateDownloadItem(DownloadItem::IN_PROGRESS);
515 MockDownloadFile* download_file = AddDownloadFileToDownloadItem(item);
507 516
508 const content::DownloadInterruptReason reason( 517 const content::DownloadInterruptReason reason(
509 content::DOWNLOAD_INTERRUPT_REASON_FILE_ACCESS_DENIED); 518 content::DOWNLOAD_INTERRUPT_REASON_FILE_ACCESS_DENIED);
510 519
511 // Confirm interrupt sets state properly. 520 // Confirm interrupt sets state properly.
521 EXPECT_CALL(*download_file, Cancel());
512 item->Interrupt(reason); 522 item->Interrupt(reason);
523 RunAllPendingInMessageLoops();
513 EXPECT_EQ(DownloadItem::INTERRUPTED, item->GetState()); 524 EXPECT_EQ(DownloadItem::INTERRUPTED, item->GetState());
514 EXPECT_EQ(reason, item->GetLastReason()); 525 EXPECT_EQ(reason, item->GetLastReason());
515 526
516 // Cancel should result in no change. 527 // Cancel should result in no change.
517 item->Cancel(true); 528 item->Cancel(true);
518 EXPECT_EQ(DownloadItem::INTERRUPTED, item->GetState()); 529 EXPECT_EQ(DownloadItem::INTERRUPTED, item->GetState());
519 EXPECT_EQ(content::DOWNLOAD_INTERRUPT_REASON_USER_CANCELED, 530 EXPECT_EQ(content::DOWNLOAD_INTERRUPT_REASON_USER_CANCELED,
520 item->GetLastReason()); 531 item->GetLastReason());
521 } 532 }
522 533
523 TEST_F(DownloadItemTest, Canceled) { 534 TEST_F(DownloadItemTest, Canceled) {
524 DownloadItemImpl* item = CreateDownloadItem(DownloadItem::IN_PROGRESS); 535 DownloadItemImpl* item = CreateDownloadItem(DownloadItem::IN_PROGRESS);
536 MockDownloadFile* download_file = AddDownloadFileToDownloadItem(item);
525 537
526 // Confirm cancel sets state properly. 538 // Confirm cancel sets state properly.
527 EXPECT_CALL(*mock_delegate(), DownloadStopped(item)); 539 EXPECT_CALL(*mock_delegate(), DownloadStopped(item));
540 EXPECT_CALL(*download_file, Cancel());
528 item->Cancel(true); 541 item->Cancel(true);
529 EXPECT_EQ(DownloadItem::CANCELLED, item->GetState()); 542 EXPECT_EQ(DownloadItem::CANCELLED, item->GetState());
543 RunAllPendingInMessageLoops();
530 } 544 }
531 545
532 TEST_F(DownloadItemTest, FileRemoved) { 546 TEST_F(DownloadItemTest, FileRemoved) {
533 DownloadItemImpl* item = CreateDownloadItem(DownloadItem::IN_PROGRESS); 547 DownloadItemImpl* item = CreateDownloadItem(DownloadItem::IN_PROGRESS);
534 548
535 EXPECT_FALSE(item->GetFileExternallyRemoved()); 549 EXPECT_FALSE(item->GetFileExternallyRemoved());
536 item->OnDownloadedFileRemoved(); 550 item->OnDownloadedFileRemoved();
537 EXPECT_TRUE(item->GetFileExternallyRemoved()); 551 EXPECT_TRUE(item->GetFileExternallyRemoved());
538 } 552 }
539 553
554 TEST_F(DownloadItemTest, DestinationUpdate) {
555 DownloadItemImpl* item = CreateDownloadItem(DownloadItem::IN_PROGRESS);
556 base::WeakPtr<content::DownloadDestinationObserver> as_observer(
557 item->DestinationObserverAsWeakPtr());
558 MockObserver observer(item);
559
560 EXPECT_EQ(0l, item->CurrentSpeed());
561 EXPECT_EQ("", item->GetHashState());
562 EXPECT_EQ(0l, item->GetReceivedBytes());
563 EXPECT_EQ(0l, item->GetTotalBytes());
564 EXPECT_FALSE(observer.CheckUpdated());
565 item->SetTotalBytes(100l);
566 EXPECT_EQ(100l, item->GetTotalBytes());
567
568 as_observer->DestinationUpdate(10, 20, "deadbeef");
569 EXPECT_EQ(20l, item->CurrentSpeed());
570 EXPECT_EQ("deadbeef", item->GetHashState());
571 EXPECT_EQ(10l, item->GetReceivedBytes());
572 EXPECT_EQ(100l, item->GetTotalBytes());
573 EXPECT_TRUE(observer.CheckUpdated());
574
575 as_observer->DestinationUpdate(200, 20, "livebeef");
576 EXPECT_EQ(20l, item->CurrentSpeed());
577 EXPECT_EQ("livebeef", item->GetHashState());
578 EXPECT_EQ(200l, item->GetReceivedBytes());
579 EXPECT_EQ(0l, item->GetTotalBytes());
580 EXPECT_TRUE(observer.CheckUpdated());
581 }
582
583 TEST_F(DownloadItemTest, DestinationError) {
584 DownloadItemImpl* item = CreateDownloadItem(DownloadItem::IN_PROGRESS);
585 MockDownloadFile* download_file = AddDownloadFileToDownloadItem(item);
586 base::WeakPtr<content::DownloadDestinationObserver> as_observer(
587 item->DestinationObserverAsWeakPtr());
588 MockObserver observer(item);
589
590 EXPECT_EQ(content::DownloadItem::IN_PROGRESS, item->GetState());
591 EXPECT_EQ(content::DOWNLOAD_INTERRUPT_REASON_NONE, item->GetLastReason());
592 EXPECT_FALSE(observer.CheckUpdated());
593
594 EXPECT_CALL(*mock_delegate(), DownloadStopped(item));
595 EXPECT_CALL(*download_file, Cancel());
596 as_observer->DestinationError(
597 content::DOWNLOAD_INTERRUPT_REASON_FILE_ACCESS_DENIED);
598 ::testing::Mock::VerifyAndClearExpectations(mock_delegate());
599 EXPECT_TRUE(observer.CheckUpdated());
600 EXPECT_EQ(content::DownloadItem::INTERRUPTED, item->GetState());
601 EXPECT_EQ(content::DOWNLOAD_INTERRUPT_REASON_FILE_ACCESS_DENIED,
602 item->GetLastReason());
603 RunAllPendingInMessageLoops();
604 }
605
606 TEST_F(DownloadItemTest, DestinationCompleted) {
607 DownloadItemImpl* item = CreateDownloadItem(DownloadItem::IN_PROGRESS);
608 base::WeakPtr<content::DownloadDestinationObserver> as_observer(
609 item->DestinationObserverAsWeakPtr());
610 MockObserver observer(item);
611
612 EXPECT_EQ(content::DownloadItem::IN_PROGRESS, item->GetState());
613 EXPECT_EQ("", item->GetHash());
614 EXPECT_EQ("", item->GetHashState());
615 EXPECT_FALSE(item->AllDataSaved());
616 EXPECT_FALSE(observer.CheckUpdated());
617
618 as_observer->DestinationUpdate(10, 20, "deadbeef");
619 EXPECT_TRUE(observer.CheckUpdated());
620 EXPECT_FALSE(observer.CheckUpdated()); // Confirm reset.
621 EXPECT_EQ(content::DownloadItem::IN_PROGRESS, item->GetState());
622 EXPECT_EQ("", item->GetHash());
623 EXPECT_EQ("deadbeef", item->GetHashState());
624 EXPECT_FALSE(item->AllDataSaved());
625
626 EXPECT_CALL(*mock_delegate(), MaybeCompleteDownload(item));
627 as_observer->DestinationCompleted("livebeef");
628 ::testing::Mock::VerifyAndClearExpectations(mock_delegate());
629 EXPECT_EQ(content::DownloadItem::IN_PROGRESS, item->GetState());
630 EXPECT_TRUE(observer.CheckUpdated());
631 EXPECT_EQ("livebeef", item->GetHash());
632 EXPECT_EQ("", item->GetHashState());
633 EXPECT_TRUE(item->AllDataSaved());
634 }
635
540 TEST(MockDownloadItem, Compiles) { 636 TEST(MockDownloadItem, Compiles) {
541 MockDownloadItem mock_item; 637 MockDownloadItem mock_item;
542 } 638 }
639
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698