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

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'd to LKGR. Created 8 years, 2 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 : public content::DownloadFileFactory {
71 public:
72 content::DownloadFile* CreateFile(
73 DownloadCreateInfo* info,
74 scoped_ptr<content::ByteStreamReader> stream_reader,
75 DownloadManager* mgr,
76 bool calculate_hash,
77 const net::BoundNetLog& bound_net_log) {
78 return MockCreateFile(
79 info, stream_reader.get(), info->request_handle, mgr, calculate_hash,
80 bound_net_log);
81 }
82
83 MOCK_METHOD6(MockCreateFile,
84 content::DownloadFile*(DownloadCreateInfo*,
85 content::ByteStreamReader*,
86 const DownloadRequestHandle&,
87 DownloadManager*,
88 bool,
89 const net::BoundNetLog&));
90 };
91
92 class MockDownloadFileManager : public DownloadFileManager {
93 public:
94 MockDownloadFileManager();
95 MOCK_METHOD0(Shutdown, void());
96 MOCK_METHOD1(CancelDownload, void(DownloadId));
97 MOCK_METHOD2(CompleteDownload, void(DownloadId, const base::Closure&));
98 MOCK_METHOD1(OnDownloadManagerShutdown, void(DownloadManager*));
99 MOCK_METHOD4(RenameDownloadFile, void(DownloadId, const FilePath&, bool,
100 const RenameCompletionCallback&));
101 MOCK_CONST_METHOD0(NumberOfActiveDownloads, int());
102 private:
103 ~MockDownloadFileManager() {}
104 };
105
106 // Schedules a task to invoke the RenameCompletionCallback with |new_path| on 71 // Schedules a task to invoke the RenameCompletionCallback with |new_path| on
107 // the UI thread. Should only be used as the action for 72 // the UI thread. Should only be used as the action for
108 // MockDownloadFileManager::Rename*DownloadFile as follows: 73 // MockDownloadFile::Rename as follows:
109 // EXPECT_CALL(mock_download_file_manager, 74 // EXPECT_CALL(download_file, Rename(_,_,_))
110 // RenameDownloadFile(_,_,_,_))
111 // .WillOnce(ScheduleRenameCallback(new_path)); 75 // .WillOnce(ScheduleRenameCallback(new_path));
112 ACTION_P(ScheduleRenameCallback, new_path) { 76 ACTION_P(ScheduleRenameCallback, new_path) {
113 BrowserThread::PostTask( 77 BrowserThread::PostTask(
114 BrowserThread::UI, FROM_HERE, 78 BrowserThread::UI, FROM_HERE,
115 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);
116 } 89 }
117 90
118 // Similarly for scheduling a completion callback. 91 // Similarly for scheduling a completion callback.
119 ACTION(ScheduleCompleteCallback) { 92 ACTION(ScheduleCompleteCallback) {
120 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, base::Bind(arg1)); 93 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, base::Bind(arg1));
121 } 94 }
122 95
123 MockDownloadFileManager::MockDownloadFileManager()
124 : DownloadFileManager(new MockDownloadFileFactory) {
125 }
126
127 } // namespace 96 } // namespace
128 97
129 class DownloadItemTest : public testing::Test { 98 class DownloadItemTest : public testing::Test {
130 public: 99 public:
131 class MockObserver : public DownloadItem::Observer { 100 class MockObserver : public DownloadItem::Observer {
132 public: 101 public:
133 explicit MockObserver(DownloadItem* item) 102 explicit MockObserver(DownloadItem* item)
134 : item_(item), 103 : item_(item),
135 removed_(false), 104 removed_(false),
136 destroyed_(false), 105 destroyed_(false),
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 private: 145 private:
177 DownloadItem* item_; 146 DownloadItem* item_;
178 bool removed_; 147 bool removed_;
179 bool destroyed_; 148 bool destroyed_;
180 bool updated_; 149 bool updated_;
181 }; 150 };
182 151
183 DownloadItemTest() 152 DownloadItemTest()
184 : ui_thread_(BrowserThread::UI, &loop_), 153 : ui_thread_(BrowserThread::UI, &loop_),
185 file_thread_(BrowserThread::FILE, &loop_), 154 file_thread_(BrowserThread::FILE, &loop_),
186 file_manager_(new MockDownloadFileManager), 155 delegate_() {
187 delegate_(file_manager_.get()) {
188 } 156 }
189 157
190 ~DownloadItemTest() { 158 ~DownloadItemTest() {
191 } 159 }
192 160
193 virtual void SetUp() { 161 virtual void SetUp() {
194 } 162 }
195 163
196 virtual void TearDown() { 164 virtual void TearDown() {
197 ui_thread_.DeprecatedGetThreadObject()->message_loop()->RunAllPending(); 165 ui_thread_.DeprecatedGetThreadObject()->message_loop()->RunAllPending();
(...skipping 20 matching lines...) Expand all
218 186
219 scoped_ptr<DownloadRequestHandleInterface> request_handle( 187 scoped_ptr<DownloadRequestHandleInterface> request_handle(
220 new testing::NiceMock<MockRequestHandle>); 188 new testing::NiceMock<MockRequestHandle>);
221 DownloadItemImpl* download = 189 DownloadItemImpl* download =
222 new DownloadItemImpl(&delegate_, *(info_.get()), 190 new DownloadItemImpl(&delegate_, *(info_.get()),
223 request_handle.Pass(), net::BoundNetLog()); 191 request_handle.Pass(), net::BoundNetLog());
224 allocated_downloads_.insert(download); 192 allocated_downloads_.insert(download);
225 return download; 193 return download;
226 } 194 }
227 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
228 // Destroy a previously created download item. 217 // Destroy a previously created download item.
229 void DestroyDownloadItem(DownloadItem* item) { 218 void DestroyDownloadItem(DownloadItem* item) {
230 allocated_downloads_.erase(item); 219 allocated_downloads_.erase(item);
231 delete item; 220 delete item;
232 } 221 }
233 222
234 void RunAllPendingInMessageLoops() { 223 void RunAllPendingInMessageLoops() {
235 loop_.RunAllPending(); 224 loop_.RunAllPending();
236 } 225 }
237 226
238 MockDelegate* mock_delegate() { 227 MockDelegate* mock_delegate() {
239 return &delegate_; 228 return &delegate_;
240 } 229 }
241 230
242 MockDownloadFileManager* mock_file_manager() {
243 return file_manager_.get();
244 }
245
246 private: 231 private:
247 MessageLoopForUI loop_; 232 MessageLoopForUI loop_;
248 content::TestBrowserThread ui_thread_; // UI thread 233 content::TestBrowserThread ui_thread_; // UI thread
249 content::TestBrowserThread file_thread_; // FILE thread 234 content::TestBrowserThread file_thread_; // FILE thread
250 scoped_refptr<MockDownloadFileManager> file_manager_;
251 testing::NiceMock<MockDelegate> delegate_; 235 testing::NiceMock<MockDelegate> delegate_;
252 std::set<DownloadItem*> allocated_downloads_; 236 std::set<DownloadItem*> allocated_downloads_;
253 }; 237 };
254 238
255 namespace { 239 namespace {
256 240
257 const int kDownloadChunkSize = 1000; 241 const int kDownloadChunkSize = 1000;
258 const int kDownloadSpeed = 1000; 242 const int kDownloadSpeed = 1000;
259 const int kDummyDBHandle = 10; 243 const int kDummyDBHandle = 10;
260 const FilePath::CharType kDummyPath[] = FILE_PATH_LITERAL("/testpath"); 244 const FilePath::CharType kDummyPath[] = FILE_PATH_LITERAL("/testpath");
(...skipping 13 matching lines...) Expand all
274 DownloadItemImpl* item = CreateDownloadItem(DownloadItem::IN_PROGRESS); 258 DownloadItemImpl* item = CreateDownloadItem(DownloadItem::IN_PROGRESS);
275 MockObserver observer(item); 259 MockObserver observer(item);
276 260
277 item->UpdateProgress(kDownloadChunkSize, kDownloadSpeed, ""); 261 item->UpdateProgress(kDownloadChunkSize, kDownloadSpeed, "");
278 ASSERT_TRUE(observer.CheckUpdated()); 262 ASSERT_TRUE(observer.CheckUpdated());
279 EXPECT_EQ(kDownloadSpeed, item->CurrentSpeed()); 263 EXPECT_EQ(kDownloadSpeed, item->CurrentSpeed());
280 } 264 }
281 265
282 TEST_F(DownloadItemTest, NotificationAfterCancel) { 266 TEST_F(DownloadItemTest, NotificationAfterCancel) {
283 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());
284 MockObserver observer1(user_cancel); 270 MockObserver observer1(user_cancel);
285 271
286 user_cancel->Cancel(true); 272 user_cancel->Cancel(true);
287 ASSERT_TRUE(observer1.CheckUpdated()); 273 ASSERT_TRUE(observer1.CheckUpdated());
274 RunAllPendingInMessageLoops();
288 275
289 DownloadItemImpl* system_cancel = 276 DownloadItemImpl* system_cancel =
290 CreateDownloadItem(DownloadItem::IN_PROGRESS); 277 CreateDownloadItem(DownloadItem::IN_PROGRESS);
278 download_file = AddDownloadFileToDownloadItem(system_cancel);
279 EXPECT_CALL(*download_file, Cancel());
291 MockObserver observer2(system_cancel); 280 MockObserver observer2(system_cancel);
292 281
293 system_cancel->Cancel(false); 282 system_cancel->Cancel(false);
294 ASSERT_TRUE(observer2.CheckUpdated()); 283 ASSERT_TRUE(observer2.CheckUpdated());
284 RunAllPendingInMessageLoops();
295 } 285 }
296 286
297 TEST_F(DownloadItemTest, NotificationAfterComplete) { 287 TEST_F(DownloadItemTest, NotificationAfterComplete) {
298 DownloadItemImpl* item = CreateDownloadItem(DownloadItem::IN_PROGRESS); 288 DownloadItemImpl* item = CreateDownloadItem(DownloadItem::IN_PROGRESS);
299 MockObserver observer(item); 289 MockObserver observer(item);
300 290
301 item->OnAllDataSaved(kDownloadChunkSize, DownloadItem::kEmptyFileHash); 291 item->OnAllDataSaved(DownloadItem::kEmptyFileHash);
302 ASSERT_TRUE(observer.CheckUpdated()); 292 ASSERT_TRUE(observer.CheckUpdated());
303 293
304 item->MarkAsComplete(); 294 item->MarkAsComplete();
305 ASSERT_TRUE(observer.CheckUpdated()); 295 ASSERT_TRUE(observer.CheckUpdated());
306 } 296 }
307 297
308 TEST_F(DownloadItemTest, NotificationAfterDownloadedFileRemoved) { 298 TEST_F(DownloadItemTest, NotificationAfterDownloadedFileRemoved) {
309 DownloadItemImpl* item = CreateDownloadItem(DownloadItem::IN_PROGRESS); 299 DownloadItemImpl* item = CreateDownloadItem(DownloadItem::IN_PROGRESS);
310 MockObserver observer(item); 300 MockObserver observer(item);
311 301
312 item->OnDownloadedFileRemoved(); 302 item->OnDownloadedFileRemoved();
313 ASSERT_TRUE(observer.CheckUpdated()); 303 ASSERT_TRUE(observer.CheckUpdated());
314 } 304 }
315 305
316 TEST_F(DownloadItemTest, NotificationAfterInterrupted) { 306 TEST_F(DownloadItemTest, NotificationAfterInterrupted) {
317 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());
318 MockObserver observer(item); 310 MockObserver observer(item);
319 311
320 item->Interrupt(content::DOWNLOAD_INTERRUPT_REASON_NONE); 312 item->Interrupt(content::DOWNLOAD_INTERRUPT_REASON_NONE);
321 ASSERT_TRUE(observer.CheckUpdated()); 313 ASSERT_TRUE(observer.CheckUpdated());
314 RunAllPendingInMessageLoops();
322 } 315 }
323 316
324 TEST_F(DownloadItemTest, NotificationAfterDelete) { 317 TEST_F(DownloadItemTest, NotificationAfterDelete) {
325 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());
326 MockObserver observer(item); 321 MockObserver observer(item);
327 322
328 item->Delete(DownloadItem::DELETE_DUE_TO_BROWSER_SHUTDOWN); 323 item->Delete(DownloadItem::DELETE_DUE_TO_BROWSER_SHUTDOWN);
329 ASSERT_TRUE(observer.CheckUpdated()); 324 ASSERT_TRUE(observer.CheckUpdated());
325 RunAllPendingInMessageLoops();
330 } 326 }
331 327
332 TEST_F(DownloadItemTest, NotificationAfterDestroyed) { 328 TEST_F(DownloadItemTest, NotificationAfterDestroyed) {
333 DownloadItemImpl* item = CreateDownloadItem(DownloadItem::IN_PROGRESS); 329 DownloadItemImpl* item = CreateDownloadItem(DownloadItem::IN_PROGRESS);
334 MockObserver observer(item); 330 MockObserver observer(item);
335 331
336 DestroyDownloadItem(item); 332 DestroyDownloadItem(item);
337 ASSERT_TRUE(observer.CheckDestroyed()); 333 ASSERT_TRUE(observer.CheckDestroyed());
338 } 334 }
339 335
340 TEST_F(DownloadItemTest, NotificationAfterRemove) { 336 TEST_F(DownloadItemTest, NotificationAfterRemove) {
341 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());
342 MockObserver observer(item); 340 MockObserver observer(item);
343 341
344 item->Remove(); 342 item->Remove();
345 ASSERT_TRUE(observer.CheckUpdated()); 343 ASSERT_TRUE(observer.CheckUpdated());
346 ASSERT_TRUE(observer.CheckRemoved()); 344 ASSERT_TRUE(observer.CheckRemoved());
347 } 345 }
348 346
349 TEST_F(DownloadItemTest, NotificationAfterOnContentCheckCompleted) { 347 TEST_F(DownloadItemTest, NotificationAfterOnContentCheckCompleted) {
350 // Setting to NOT_DANGEROUS does not trigger a notification. 348 // Setting to NOT_DANGEROUS does not trigger a notification.
351 DownloadItemImpl* safe_item = CreateDownloadItem(DownloadItem::IN_PROGRESS); 349 DownloadItemImpl* safe_item = CreateDownloadItem(DownloadItem::IN_PROGRESS);
352 MockObserver safe_observer(safe_item); 350 MockObserver safe_observer(safe_item);
353 351
354 safe_item->OnAllDataSaved(1, ""); 352 safe_item->OnAllDataSaved("");
355 EXPECT_TRUE(safe_observer.CheckUpdated()); 353 EXPECT_TRUE(safe_observer.CheckUpdated());
356 safe_item->OnContentCheckCompleted( 354 safe_item->OnContentCheckCompleted(
357 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS); 355 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS);
358 EXPECT_TRUE(safe_observer.CheckUpdated()); 356 EXPECT_TRUE(safe_observer.CheckUpdated());
359 357
360 // Setting to unsafe url or unsafe file should trigger a notification. 358 // Setting to unsafe url or unsafe file should trigger a notification.
361 DownloadItemImpl* unsafeurl_item = 359 DownloadItemImpl* unsafeurl_item =
362 CreateDownloadItem(DownloadItem::IN_PROGRESS); 360 CreateDownloadItem(DownloadItem::IN_PROGRESS);
363 MockObserver unsafeurl_observer(unsafeurl_item); 361 MockObserver unsafeurl_observer(unsafeurl_item);
364 362
365 unsafeurl_item->OnAllDataSaved(1, ""); 363 unsafeurl_item->OnAllDataSaved("");
366 EXPECT_TRUE(unsafeurl_observer.CheckUpdated()); 364 EXPECT_TRUE(unsafeurl_observer.CheckUpdated());
367 unsafeurl_item->OnContentCheckCompleted( 365 unsafeurl_item->OnContentCheckCompleted(
368 content::DOWNLOAD_DANGER_TYPE_DANGEROUS_URL); 366 content::DOWNLOAD_DANGER_TYPE_DANGEROUS_URL);
369 EXPECT_TRUE(unsafeurl_observer.CheckUpdated()); 367 EXPECT_TRUE(unsafeurl_observer.CheckUpdated());
370 368
371 unsafeurl_item->DangerousDownloadValidated(); 369 unsafeurl_item->DangerousDownloadValidated();
372 EXPECT_TRUE(unsafeurl_observer.CheckUpdated()); 370 EXPECT_TRUE(unsafeurl_observer.CheckUpdated());
373 371
374 DownloadItemImpl* unsafefile_item = 372 DownloadItemImpl* unsafefile_item =
375 CreateDownloadItem(DownloadItem::IN_PROGRESS); 373 CreateDownloadItem(DownloadItem::IN_PROGRESS);
376 MockObserver unsafefile_observer(unsafefile_item); 374 MockObserver unsafefile_observer(unsafefile_item);
377 375
378 unsafefile_item->OnAllDataSaved(1, ""); 376 unsafefile_item->OnAllDataSaved("");
379 EXPECT_TRUE(unsafefile_observer.CheckUpdated()); 377 EXPECT_TRUE(unsafefile_observer.CheckUpdated());
380 unsafefile_item->OnContentCheckCompleted( 378 unsafefile_item->OnContentCheckCompleted(
381 content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE); 379 content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE);
382 EXPECT_TRUE(unsafefile_observer.CheckUpdated()); 380 EXPECT_TRUE(unsafefile_observer.CheckUpdated());
383 381
384 unsafefile_item->DangerousDownloadValidated(); 382 unsafefile_item->DangerousDownloadValidated();
385 EXPECT_TRUE(unsafefile_observer.CheckUpdated()); 383 EXPECT_TRUE(unsafefile_observer.CheckUpdated());
386 } 384 }
387 385
388 // DownloadItemImpl::OnDownloadTargetDetermined will schedule a task to run 386 // DownloadItemImpl::OnDownloadTargetDetermined will schedule a task to run
389 // DownloadFileManager::RenameDownloadFile(). Once the rename 387 // DownloadFile::Rename(). Once the rename
390 // completes, DownloadItemImpl receives a notification with the new file 388 // completes, DownloadItemImpl receives a notification with the new file
391 // 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
392 // not before. 390 // not before.
393 TEST_F(DownloadItemTest, NotificationAfterOnDownloadTargetDetermined) { 391 TEST_F(DownloadItemTest, NotificationAfterOnDownloadTargetDetermined) {
394 DownloadItemImpl* item = CreateDownloadItem(DownloadItem::IN_PROGRESS); 392 DownloadItemImpl* item = CreateDownloadItem(DownloadItem::IN_PROGRESS);
393 MockDownloadFile* download_file = AddDownloadFileToDownloadItem(item);
395 MockObserver observer(item); 394 MockObserver observer(item);
396 FilePath target_path(kDummyPath); 395 FilePath target_path(kDummyPath);
397 FilePath intermediate_path(target_path.InsertBeforeExtensionASCII("x")); 396 FilePath intermediate_path(target_path.InsertBeforeExtensionASCII("x"));
398 FilePath new_intermediate_path(target_path.InsertBeforeExtensionASCII("y")); 397 FilePath new_intermediate_path(target_path.InsertBeforeExtensionASCII("y"));
399 EXPECT_CALL(*mock_file_manager(), 398 EXPECT_CALL(*download_file, Rename(intermediate_path, false, _))
400 RenameDownloadFile(_,intermediate_path,false,_))
401 .WillOnce(ScheduleRenameCallback(new_intermediate_path)); 399 .WillOnce(ScheduleRenameCallback(new_intermediate_path));
402 400
403 // 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
404 // other than NOT_DANGEROUS. 402 // other than NOT_DANGEROUS.
405 item->OnDownloadTargetDetermined(target_path, 403 item->OnDownloadTargetDetermined(target_path,
406 DownloadItem::TARGET_DISPOSITION_OVERWRITE, 404 DownloadItem::TARGET_DISPOSITION_OVERWRITE,
407 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, 405 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS,
408 intermediate_path); 406 intermediate_path);
409 EXPECT_FALSE(observer.CheckUpdated()); 407 EXPECT_FALSE(observer.CheckUpdated());
410 RunAllPendingInMessageLoops(); 408 RunAllPendingInMessageLoops();
411 EXPECT_TRUE(observer.CheckUpdated()); 409 EXPECT_TRUE(observer.CheckUpdated());
412 EXPECT_EQ(new_intermediate_path, item->GetFullPath()); 410 EXPECT_EQ(new_intermediate_path, item->GetFullPath());
411
412 CleanupItem(item, download_file);
413 } 413 }
414 414
415 TEST_F(DownloadItemTest, NotificationAfterTogglePause) { 415 TEST_F(DownloadItemTest, NotificationAfterTogglePause) {
416 DownloadItemImpl* item = CreateDownloadItem(DownloadItem::IN_PROGRESS); 416 DownloadItemImpl* item = CreateDownloadItem(DownloadItem::IN_PROGRESS);
417 MockObserver observer(item); 417 MockObserver observer(item);
418 418
419 item->TogglePause(); 419 item->TogglePause();
420 ASSERT_TRUE(observer.CheckUpdated()); 420 ASSERT_TRUE(observer.CheckUpdated());
421 421
422 item->TogglePause(); 422 item->TogglePause();
423 ASSERT_TRUE(observer.CheckUpdated()); 423 ASSERT_TRUE(observer.CheckUpdated());
424 } 424 }
425 425
426 TEST_F(DownloadItemTest, DisplayName) { 426 TEST_F(DownloadItemTest, DisplayName) {
427 DownloadItemImpl* item = CreateDownloadItem(DownloadItem::IN_PROGRESS); 427 DownloadItemImpl* item = CreateDownloadItem(DownloadItem::IN_PROGRESS);
428 MockDownloadFile* download_file = AddDownloadFileToDownloadItem(item);
428 FilePath target_path(FilePath(kDummyPath).AppendASCII("foo.bar")); 429 FilePath target_path(FilePath(kDummyPath).AppendASCII("foo.bar"));
429 FilePath intermediate_path(target_path.InsertBeforeExtensionASCII("x")); 430 FilePath intermediate_path(target_path.InsertBeforeExtensionASCII("x"));
430 EXPECT_EQ(FILE_PATH_LITERAL(""), 431 EXPECT_EQ(FILE_PATH_LITERAL(""),
431 item->GetFileNameToReportUser().value()); 432 item->GetFileNameToReportUser().value());
432 EXPECT_CALL(*mock_file_manager(), 433 EXPECT_CALL(*download_file, Rename(_, false, _))
433 RenameDownloadFile(_,_,false,_))
434 .WillOnce(ScheduleRenameCallback(intermediate_path)); 434 .WillOnce(ScheduleRenameCallback(intermediate_path));
435 item->OnDownloadTargetDetermined(target_path, 435 item->OnDownloadTargetDetermined(target_path,
436 DownloadItem::TARGET_DISPOSITION_OVERWRITE, 436 DownloadItem::TARGET_DISPOSITION_OVERWRITE,
437 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, 437 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS,
438 intermediate_path); 438 intermediate_path);
439 RunAllPendingInMessageLoops(); 439 RunAllPendingInMessageLoops();
440 EXPECT_EQ(FILE_PATH_LITERAL("foo.bar"), 440 EXPECT_EQ(FILE_PATH_LITERAL("foo.bar"),
441 item->GetFileNameToReportUser().value()); 441 item->GetFileNameToReportUser().value());
442 item->SetDisplayName(FilePath(FILE_PATH_LITERAL("new.name"))); 442 item->SetDisplayName(FilePath(FILE_PATH_LITERAL("new.name")));
443 EXPECT_EQ(FILE_PATH_LITERAL("new.name"), 443 EXPECT_EQ(FILE_PATH_LITERAL("new.name"),
444 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);
445 } 457 }
446 458
447 // 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.
448 // Delegate::DownloadRenamedToIntermediateName() should be invoked when the 460 // Delegate::DownloadRenamedToIntermediateName() should be invoked when the
449 // download is renamed to the intermediate name. 461 // download is renamed to the intermediate name.
450 // Delegate::DownloadRenamedToFinalName() should be invoked after the final 462 // Delegate::DownloadRenamedToFinalName() should be invoked after the final
451 // rename. 463 // rename.
452 TEST_F(DownloadItemTest, CallbackAfterRename) { 464 TEST_F(DownloadItemTest, CallbackAfterRename) {
453 DownloadItemImpl* item = CreateDownloadItem(DownloadItem::IN_PROGRESS); 465 DownloadItemImpl* item = CreateDownloadItem(DownloadItem::IN_PROGRESS);
466 MockDownloadFile* download_file = AddDownloadFileToDownloadItem(item);
454 FilePath final_path(FilePath(kDummyPath).AppendASCII("foo.bar")); 467 FilePath final_path(FilePath(kDummyPath).AppendASCII("foo.bar"));
455 FilePath intermediate_path(final_path.InsertBeforeExtensionASCII("x")); 468 FilePath intermediate_path(final_path.InsertBeforeExtensionASCII("x"));
456 FilePath new_intermediate_path(final_path.InsertBeforeExtensionASCII("y")); 469 FilePath new_intermediate_path(final_path.InsertBeforeExtensionASCII("y"));
457 EXPECT_CALL(*mock_file_manager(), 470 EXPECT_CALL(*download_file, Rename(intermediate_path, false, _))
458 RenameDownloadFile(item->GetGlobalId(),
459 intermediate_path, false, _))
460 .WillOnce(ScheduleRenameCallback(new_intermediate_path)); 471 .WillOnce(ScheduleRenameCallback(new_intermediate_path));
472
461 // DownloadItemImpl should invoke this callback on the delegate once the 473 // DownloadItemImpl should invoke this callback on the delegate once the
462 // download is renamed to the intermediate name. Also check that GetFullPath() 474 // download is renamed to the intermediate name. Also check that GetFullPath()
463 // returns the intermediate path at the time of the call. 475 // returns the intermediate path at the time of the call.
464 EXPECT_CALL(*mock_delegate(), 476 EXPECT_CALL(*mock_delegate(),
465 DownloadRenamedToIntermediateName( 477 DownloadRenamedToIntermediateName(
466 AllOf(item, 478 AllOf(item,
467 Property(&DownloadItem::GetFullPath, 479 Property(&DownloadItem::GetFullPath,
468 new_intermediate_path)))); 480 new_intermediate_path))));
469 item->OnDownloadTargetDetermined(final_path, 481 item->OnDownloadTargetDetermined(final_path,
470 DownloadItem::TARGET_DISPOSITION_OVERWRITE, 482 DownloadItem::TARGET_DISPOSITION_OVERWRITE,
471 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, 483 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS,
472 intermediate_path); 484 intermediate_path);
473 RunAllPendingInMessageLoops(); 485 RunAllPendingInMessageLoops();
474 // All the callbacks should have happened by now. 486 // All the callbacks should have happened by now.
475 ::testing::Mock::VerifyAndClearExpectations(mock_file_manager()); 487 ::testing::Mock::VerifyAndClearExpectations(download_file);
476 ::testing::Mock::VerifyAndClearExpectations(mock_delegate()); 488 ::testing::Mock::VerifyAndClearExpectations(mock_delegate());
477 489
478 item->OnAllDataSaved(10, ""); 490 item->OnAllDataSaved("");
479 EXPECT_CALL(*mock_file_manager(), 491 EXPECT_CALL(*download_file, Rename(final_path, true, _))
480 RenameDownloadFile(item->GetGlobalId(),
481 final_path, true, _))
482 .WillOnce(ScheduleRenameCallback(final_path)); 492 .WillOnce(ScheduleRenameCallback(final_path));
483 EXPECT_CALL(*mock_file_manager(),
484 CompleteDownload(item->GetGlobalId(), _))
485 .WillOnce(ScheduleCompleteCallback());
486 // DownloadItemImpl should invoke this callback on the delegate after the 493 // DownloadItemImpl should invoke this callback on the delegate after the
487 // final rename has completed. Also check that GetFullPath() and 494 // final rename has completed. Also check that GetFullPath() and
488 // GetTargetFilePath() return the final path at the time of the call. 495 // GetTargetFilePath() return the final path at the time of the call.
489 EXPECT_CALL(*mock_delegate(), 496 EXPECT_CALL(*mock_delegate(),
490 DownloadRenamedToFinalName( 497 DownloadRenamedToFinalName(
491 AllOf(item, 498 AllOf(item,
492 Property(&DownloadItem::GetFullPath, final_path), 499 Property(&DownloadItem::GetFullPath, final_path),
493 Property(&DownloadItem::GetTargetFilePath, 500 Property(&DownloadItem::GetTargetFilePath,
494 final_path)))); 501 final_path))));
495 EXPECT_CALL(*mock_delegate(), DownloadCompleted(item)); 502 EXPECT_CALL(*mock_delegate(), DownloadCompleted(item));
496 EXPECT_CALL(*mock_delegate(), ShouldOpenDownload(item)) 503 EXPECT_CALL(*mock_delegate(), ShouldOpenDownload(item))
497 .WillOnce(Return(true)); 504 .WillOnce(Return(true));
505 EXPECT_CALL(*download_file, Detach(_))
506 .WillOnce(ScheduleClosure());
498 item->OnDownloadCompleting(); 507 item->OnDownloadCompleting();
499 RunAllPendingInMessageLoops(); 508 RunAllPendingInMessageLoops();
500 ::testing::Mock::VerifyAndClearExpectations(mock_file_manager()); 509 ::testing::Mock::VerifyAndClearExpectations(download_file);
501 ::testing::Mock::VerifyAndClearExpectations(mock_delegate()); 510 ::testing::Mock::VerifyAndClearExpectations(mock_delegate());
502 } 511 }
503 512
504 TEST_F(DownloadItemTest, Interrupted) { 513 TEST_F(DownloadItemTest, Interrupted) {
505 DownloadItemImpl* item = CreateDownloadItem(DownloadItem::IN_PROGRESS); 514 DownloadItemImpl* item = CreateDownloadItem(DownloadItem::IN_PROGRESS);
515 MockDownloadFile* download_file = AddDownloadFileToDownloadItem(item);
506 516
507 const content::DownloadInterruptReason reason( 517 const content::DownloadInterruptReason reason(
508 content::DOWNLOAD_INTERRUPT_REASON_FILE_ACCESS_DENIED); 518 content::DOWNLOAD_INTERRUPT_REASON_FILE_ACCESS_DENIED);
509 519
510 // Confirm interrupt sets state properly. 520 // Confirm interrupt sets state properly.
521 EXPECT_CALL(*download_file, Cancel());
511 item->Interrupt(reason); 522 item->Interrupt(reason);
523 RunAllPendingInMessageLoops();
512 EXPECT_EQ(DownloadItem::INTERRUPTED, item->GetState()); 524 EXPECT_EQ(DownloadItem::INTERRUPTED, item->GetState());
513 EXPECT_EQ(reason, item->GetLastReason()); 525 EXPECT_EQ(reason, item->GetLastReason());
514 526
515 // Cancel should result in no change. 527 // Cancel should result in no change.
516 item->Cancel(true); 528 item->Cancel(true);
517 EXPECT_EQ(DownloadItem::INTERRUPTED, item->GetState()); 529 EXPECT_EQ(DownloadItem::INTERRUPTED, item->GetState());
518 EXPECT_EQ(content::DOWNLOAD_INTERRUPT_REASON_USER_CANCELED, 530 EXPECT_EQ(content::DOWNLOAD_INTERRUPT_REASON_USER_CANCELED,
519 item->GetLastReason()); 531 item->GetLastReason());
520 } 532 }
521 533
522 TEST_F(DownloadItemTest, Canceled) { 534 TEST_F(DownloadItemTest, Canceled) {
523 DownloadItemImpl* item = CreateDownloadItem(DownloadItem::IN_PROGRESS); 535 DownloadItemImpl* item = CreateDownloadItem(DownloadItem::IN_PROGRESS);
536 MockDownloadFile* download_file = AddDownloadFileToDownloadItem(item);
524 537
525 // Confirm cancel sets state properly. 538 // Confirm cancel sets state properly.
526 EXPECT_CALL(*mock_delegate(), DownloadStopped(item)); 539 EXPECT_CALL(*mock_delegate(), DownloadStopped(item));
540 EXPECT_CALL(*download_file, Cancel());
527 item->Cancel(true); 541 item->Cancel(true);
528 EXPECT_EQ(DownloadItem::CANCELLED, item->GetState()); 542 EXPECT_EQ(DownloadItem::CANCELLED, item->GetState());
543 RunAllPendingInMessageLoops();
529 } 544 }
530 545
531 TEST_F(DownloadItemTest, FileRemoved) { 546 TEST_F(DownloadItemTest, FileRemoved) {
532 DownloadItemImpl* item = CreateDownloadItem(DownloadItem::IN_PROGRESS); 547 DownloadItemImpl* item = CreateDownloadItem(DownloadItem::IN_PROGRESS);
533 548
534 EXPECT_FALSE(item->GetFileExternallyRemoved()); 549 EXPECT_FALSE(item->GetFileExternallyRemoved());
535 item->OnDownloadedFileRemoved(); 550 item->OnDownloadedFileRemoved();
536 EXPECT_TRUE(item->GetFileExternallyRemoved()); 551 EXPECT_TRUE(item->GetFileExternallyRemoved());
537 } 552 }
538 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
539 TEST(MockDownloadItem, Compiles) { 636 TEST(MockDownloadItem, Compiles) {
540 MockDownloadItem mock_item; 637 MockDownloadItem mock_item;
541 } 638 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698