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

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

Issue 10799005: Replace the DownloadFileManager with direct ownership (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed Windows compile error. Created 8 years, 4 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));
117 } 80 }
118 81
119 // Similarly for scheduling a completion callback. 82 // Similarly for scheduling a completion callback.
120 ACTION(ScheduleCompleteCallback) { 83 ACTION(ScheduleCompleteCallback) {
121 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, base::Bind(arg1)); 84 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, base::Bind(arg1));
122 } 85 }
123 86
124 MockDownloadFileManager::MockDownloadFileManager()
125 : DownloadFileManager(new MockDownloadFileFactory) {
126 }
127
128 } // namespace 87 } // namespace
129 88
130 class DownloadItemTest : public testing::Test { 89 class DownloadItemTest : public testing::Test {
131 public: 90 public:
132 class MockObserver : public DownloadItem::Observer { 91 class MockObserver : public DownloadItem::Observer {
133 public: 92 public:
134 explicit MockObserver(DownloadItem* item) 93 explicit MockObserver(DownloadItem* item)
135 : item_(item), 94 : item_(item),
136 removed_(false), 95 removed_(false),
137 destroyed_(false), 96 destroyed_(false),
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 private: 136 private:
178 DownloadItem* item_; 137 DownloadItem* item_;
179 bool removed_; 138 bool removed_;
180 bool destroyed_; 139 bool destroyed_;
181 bool updated_; 140 bool updated_;
182 }; 141 };
183 142
184 DownloadItemTest() 143 DownloadItemTest()
185 : ui_thread_(BrowserThread::UI, &loop_), 144 : ui_thread_(BrowserThread::UI, &loop_),
186 file_thread_(BrowserThread::FILE, &loop_), 145 file_thread_(BrowserThread::FILE, &loop_),
187 file_manager_(new MockDownloadFileManager), 146 delegate_() {
188 delegate_(file_manager_.get()) {
189 } 147 }
190 148
191 ~DownloadItemTest() { 149 ~DownloadItemTest() {
192 } 150 }
193 151
194 virtual void SetUp() { 152 virtual void SetUp() {
195 } 153 }
196 154
197 virtual void TearDown() { 155 virtual void TearDown() {
198 ui_thread_.DeprecatedGetThreadObject()->message_loop()->RunAllPending(); 156 ui_thread_.DeprecatedGetThreadObject()->message_loop()->RunAllPending();
(...skipping 20 matching lines...) Expand all
219 177
220 scoped_ptr<DownloadRequestHandleInterface> request_handle( 178 scoped_ptr<DownloadRequestHandleInterface> request_handle(
221 new testing::NiceMock<MockRequestHandle>); 179 new testing::NiceMock<MockRequestHandle>);
222 DownloadItemImpl* download = 180 DownloadItemImpl* download =
223 new DownloadItemImpl(&delegate_, *(info_.get()), 181 new DownloadItemImpl(&delegate_, *(info_.get()),
224 request_handle.Pass(), false, net::BoundNetLog()); 182 request_handle.Pass(), false, net::BoundNetLog());
225 allocated_downloads_.insert(download); 183 allocated_downloads_.insert(download);
226 return download; 184 return download;
227 } 185 }
228 186
187 // Add DownloadFile to DownloadItem
188 MockDownloadFile* AddDownloadFileToDownloadItem(DownloadItemImpl* item) {
189 MockDownloadFile* mock_download_file(new StrictMock<MockDownloadFile>);
190 scoped_ptr<content::DownloadFile> download_file(mock_download_file);
191 EXPECT_CALL(*mock_download_file, Initialize(_));
192 item->Start(download_file.Pass());
193 loop_.RunAllPending();
194 return mock_download_file;
195 }
196
197 // Cleanup a download item (specifically get rid of the DownloadFile on it).
198 // The item must be in the IN_PROGRESS state.
199 void CleanupItem(DownloadItemImpl* item, MockDownloadFile* download_file) {
200 EXPECT_EQ(content::DownloadItem::IN_PROGRESS, item->GetState());
201
202 EXPECT_CALL(*download_file, Cancel());
203 EXPECT_CALL(delegate_, DownloadStopped(item));
204 item->Cancel(true);
205 loop_.RunAllPending();
206 }
207
229 // Destroy a previously created download item. 208 // Destroy a previously created download item.
230 void DestroyDownloadItem(DownloadItem* item) { 209 void DestroyDownloadItem(DownloadItem* item) {
231 allocated_downloads_.erase(item); 210 allocated_downloads_.erase(item);
232 delete item; 211 delete item;
233 } 212 }
234 213
235 void RunAllPendingInMessageLoops() { 214 void RunAllPendingInMessageLoops() {
236 loop_.RunAllPending(); 215 loop_.RunAllPending();
237 } 216 }
238 217
239 MockDelegate* mock_delegate() { 218 MockDelegate* mock_delegate() {
240 return &delegate_; 219 return &delegate_;
241 } 220 }
242 221
243 MockDownloadFileManager* mock_file_manager() {
244 return file_manager_.get();
245 }
246
247 private: 222 private:
248 MessageLoopForUI loop_; 223 MessageLoopForUI loop_;
249 content::TestBrowserThread ui_thread_; // UI thread 224 content::TestBrowserThread ui_thread_; // UI thread
250 content::TestBrowserThread file_thread_; // FILE thread 225 content::TestBrowserThread file_thread_; // FILE thread
251 scoped_refptr<MockDownloadFileManager> file_manager_;
252 testing::NiceMock<MockDelegate> delegate_; 226 testing::NiceMock<MockDelegate> delegate_;
253 std::set<DownloadItem*> allocated_downloads_; 227 std::set<DownloadItem*> allocated_downloads_;
254 }; 228 };
255 229
256 namespace { 230 namespace {
257 231
258 const int kDownloadChunkSize = 1000; 232 const int kDownloadChunkSize = 1000;
259 const int kDownloadSpeed = 1000; 233 const int kDownloadSpeed = 1000;
260 const int kDummyDBHandle = 10; 234 const int kDummyDBHandle = 10;
261 const FilePath::CharType kDummyPath[] = FILE_PATH_LITERAL("/testpath"); 235 const FilePath::CharType kDummyPath[] = FILE_PATH_LITERAL("/testpath");
(...skipping 13 matching lines...) Expand all
275 DownloadItemImpl* item = CreateDownloadItem(DownloadItem::IN_PROGRESS); 249 DownloadItemImpl* item = CreateDownloadItem(DownloadItem::IN_PROGRESS);
276 MockObserver observer(item); 250 MockObserver observer(item);
277 251
278 item->UpdateProgress(kDownloadChunkSize, kDownloadSpeed, ""); 252 item->UpdateProgress(kDownloadChunkSize, kDownloadSpeed, "");
279 ASSERT_TRUE(observer.CheckUpdated()); 253 ASSERT_TRUE(observer.CheckUpdated());
280 EXPECT_EQ(kDownloadSpeed, item->CurrentSpeed()); 254 EXPECT_EQ(kDownloadSpeed, item->CurrentSpeed());
281 } 255 }
282 256
283 TEST_F(DownloadItemTest, NotificationAfterCancel) { 257 TEST_F(DownloadItemTest, NotificationAfterCancel) {
284 DownloadItemImpl* user_cancel = CreateDownloadItem(DownloadItem::IN_PROGRESS); 258 DownloadItemImpl* user_cancel = CreateDownloadItem(DownloadItem::IN_PROGRESS);
259 MockDownloadFile* download_file = AddDownloadFileToDownloadItem(user_cancel);
260 EXPECT_CALL(*download_file, Cancel());
285 MockObserver observer1(user_cancel); 261 MockObserver observer1(user_cancel);
286 262
287 user_cancel->Cancel(true); 263 user_cancel->Cancel(true);
288 ASSERT_TRUE(observer1.CheckUpdated()); 264 ASSERT_TRUE(observer1.CheckUpdated());
265 RunAllPendingInMessageLoops();
289 266
290 DownloadItemImpl* system_cancel = 267 DownloadItemImpl* system_cancel =
291 CreateDownloadItem(DownloadItem::IN_PROGRESS); 268 CreateDownloadItem(DownloadItem::IN_PROGRESS);
269 download_file = AddDownloadFileToDownloadItem(system_cancel);
270 EXPECT_CALL(*download_file, Cancel());
292 MockObserver observer2(system_cancel); 271 MockObserver observer2(system_cancel);
293 272
294 system_cancel->Cancel(false); 273 system_cancel->Cancel(false);
295 ASSERT_TRUE(observer2.CheckUpdated()); 274 ASSERT_TRUE(observer2.CheckUpdated());
275 RunAllPendingInMessageLoops();
296 } 276 }
297 277
298 TEST_F(DownloadItemTest, NotificationAfterComplete) { 278 TEST_F(DownloadItemTest, NotificationAfterComplete) {
299 DownloadItemImpl* item = CreateDownloadItem(DownloadItem::IN_PROGRESS); 279 DownloadItemImpl* item = CreateDownloadItem(DownloadItem::IN_PROGRESS);
300 MockObserver observer(item); 280 MockObserver observer(item);
301 281
302 item->OnAllDataSaved(kDownloadChunkSize, DownloadItem::kEmptyFileHash); 282 item->OnAllDataSaved(DownloadItem::kEmptyFileHash);
303 ASSERT_TRUE(observer.CheckUpdated()); 283 ASSERT_TRUE(observer.CheckUpdated());
304 284
305 item->MarkAsComplete(); 285 item->MarkAsComplete();
306 ASSERT_TRUE(observer.CheckUpdated()); 286 ASSERT_TRUE(observer.CheckUpdated());
307 } 287 }
308 288
309 TEST_F(DownloadItemTest, NotificationAfterDownloadedFileRemoved) { 289 TEST_F(DownloadItemTest, NotificationAfterDownloadedFileRemoved) {
310 DownloadItemImpl* item = CreateDownloadItem(DownloadItem::IN_PROGRESS); 290 DownloadItemImpl* item = CreateDownloadItem(DownloadItem::IN_PROGRESS);
311 MockObserver observer(item); 291 MockObserver observer(item);
312 292
313 item->OnDownloadedFileRemoved(); 293 item->OnDownloadedFileRemoved();
314 ASSERT_TRUE(observer.CheckUpdated()); 294 ASSERT_TRUE(observer.CheckUpdated());
315 } 295 }
316 296
317 TEST_F(DownloadItemTest, NotificationAfterInterrupted) { 297 TEST_F(DownloadItemTest, NotificationAfterInterrupted) {
318 DownloadItemImpl* item = CreateDownloadItem(DownloadItem::IN_PROGRESS); 298 DownloadItemImpl* item = CreateDownloadItem(DownloadItem::IN_PROGRESS);
299 MockDownloadFile* download_file = AddDownloadFileToDownloadItem(item);
300 EXPECT_CALL(*download_file, Cancel());
319 MockObserver observer(item); 301 MockObserver observer(item);
320 302
321 item->Interrupt(content::DOWNLOAD_INTERRUPT_REASON_NONE); 303 item->Interrupt(content::DOWNLOAD_INTERRUPT_REASON_NONE);
322 ASSERT_TRUE(observer.CheckUpdated()); 304 ASSERT_TRUE(observer.CheckUpdated());
305 RunAllPendingInMessageLoops();
323 } 306 }
324 307
325 TEST_F(DownloadItemTest, NotificationAfterDelete) { 308 TEST_F(DownloadItemTest, NotificationAfterDelete) {
326 DownloadItemImpl* item = CreateDownloadItem(DownloadItem::IN_PROGRESS); 309 DownloadItemImpl* item = CreateDownloadItem(DownloadItem::IN_PROGRESS);
310 MockDownloadFile* download_file = AddDownloadFileToDownloadItem(item);
311 EXPECT_CALL(*download_file, Cancel());
327 MockObserver observer(item); 312 MockObserver observer(item);
328 313
329 item->Delete(DownloadItem::DELETE_DUE_TO_BROWSER_SHUTDOWN); 314 item->Delete(DownloadItem::DELETE_DUE_TO_BROWSER_SHUTDOWN);
330 ASSERT_TRUE(observer.CheckUpdated()); 315 ASSERT_TRUE(observer.CheckUpdated());
316 RunAllPendingInMessageLoops();
331 } 317 }
332 318
333 TEST_F(DownloadItemTest, NotificationAfterDestroyed) { 319 TEST_F(DownloadItemTest, NotificationAfterDestroyed) {
334 DownloadItemImpl* item = CreateDownloadItem(DownloadItem::IN_PROGRESS); 320 DownloadItemImpl* item = CreateDownloadItem(DownloadItem::IN_PROGRESS);
335 MockObserver observer(item); 321 MockObserver observer(item);
336 322
337 DestroyDownloadItem(item); 323 DestroyDownloadItem(item);
338 ASSERT_TRUE(observer.CheckDestroyed()); 324 ASSERT_TRUE(observer.CheckDestroyed());
339 } 325 }
340 326
341 TEST_F(DownloadItemTest, NotificationAfterRemove) { 327 TEST_F(DownloadItemTest, NotificationAfterRemove) {
342 DownloadItemImpl* item = CreateDownloadItem(DownloadItem::IN_PROGRESS); 328 DownloadItemImpl* item = CreateDownloadItem(DownloadItem::IN_PROGRESS);
329 MockDownloadFile* download_file = AddDownloadFileToDownloadItem(item);
330 EXPECT_CALL(*download_file, Cancel());
343 MockObserver observer(item); 331 MockObserver observer(item);
344 332
345 item->Remove(); 333 item->Remove();
346 ASSERT_TRUE(observer.CheckUpdated()); 334 ASSERT_TRUE(observer.CheckUpdated());
347 ASSERT_TRUE(observer.CheckRemoved()); 335 ASSERT_TRUE(observer.CheckRemoved());
348 } 336 }
349 337
350 TEST_F(DownloadItemTest, NotificationAfterOnContentCheckCompleted) { 338 TEST_F(DownloadItemTest, NotificationAfterOnContentCheckCompleted) {
351 // Setting to NOT_DANGEROUS does not trigger a notification. 339 // Setting to NOT_DANGEROUS does not trigger a notification.
352 DownloadItemImpl* safe_item = CreateDownloadItem(DownloadItem::IN_PROGRESS); 340 DownloadItemImpl* safe_item = CreateDownloadItem(DownloadItem::IN_PROGRESS);
353 MockObserver safe_observer(safe_item); 341 MockObserver safe_observer(safe_item);
354 342
355 safe_item->OnAllDataSaved(1, ""); 343 safe_item->OnAllDataSaved("");
356 EXPECT_TRUE(safe_observer.CheckUpdated()); 344 EXPECT_TRUE(safe_observer.CheckUpdated());
357 safe_item->OnContentCheckCompleted( 345 safe_item->OnContentCheckCompleted(
358 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS); 346 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS);
359 EXPECT_TRUE(safe_observer.CheckUpdated()); 347 EXPECT_TRUE(safe_observer.CheckUpdated());
360 348
361 // Setting to unsafe url or unsafe file should trigger a notification. 349 // Setting to unsafe url or unsafe file should trigger a notification.
362 DownloadItemImpl* unsafeurl_item = 350 DownloadItemImpl* unsafeurl_item =
363 CreateDownloadItem(DownloadItem::IN_PROGRESS); 351 CreateDownloadItem(DownloadItem::IN_PROGRESS);
364 MockObserver unsafeurl_observer(unsafeurl_item); 352 MockObserver unsafeurl_observer(unsafeurl_item);
365 353
366 unsafeurl_item->OnAllDataSaved(1, ""); 354 unsafeurl_item->OnAllDataSaved("");
367 EXPECT_TRUE(unsafeurl_observer.CheckUpdated()); 355 EXPECT_TRUE(unsafeurl_observer.CheckUpdated());
368 unsafeurl_item->OnContentCheckCompleted( 356 unsafeurl_item->OnContentCheckCompleted(
369 content::DOWNLOAD_DANGER_TYPE_DANGEROUS_URL); 357 content::DOWNLOAD_DANGER_TYPE_DANGEROUS_URL);
370 EXPECT_TRUE(unsafeurl_observer.CheckUpdated()); 358 EXPECT_TRUE(unsafeurl_observer.CheckUpdated());
371 359
372 unsafeurl_item->DangerousDownloadValidated(); 360 unsafeurl_item->DangerousDownloadValidated();
373 EXPECT_TRUE(unsafeurl_observer.CheckUpdated()); 361 EXPECT_TRUE(unsafeurl_observer.CheckUpdated());
374 362
375 DownloadItemImpl* unsafefile_item = 363 DownloadItemImpl* unsafefile_item =
376 CreateDownloadItem(DownloadItem::IN_PROGRESS); 364 CreateDownloadItem(DownloadItem::IN_PROGRESS);
377 MockObserver unsafefile_observer(unsafefile_item); 365 MockObserver unsafefile_observer(unsafefile_item);
378 366
379 unsafefile_item->OnAllDataSaved(1, ""); 367 unsafefile_item->OnAllDataSaved("");
380 EXPECT_TRUE(unsafefile_observer.CheckUpdated()); 368 EXPECT_TRUE(unsafefile_observer.CheckUpdated());
381 unsafefile_item->OnContentCheckCompleted( 369 unsafefile_item->OnContentCheckCompleted(
382 content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE); 370 content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE);
383 EXPECT_TRUE(unsafefile_observer.CheckUpdated()); 371 EXPECT_TRUE(unsafefile_observer.CheckUpdated());
384 372
385 unsafefile_item->DangerousDownloadValidated(); 373 unsafefile_item->DangerousDownloadValidated();
386 EXPECT_TRUE(unsafefile_observer.CheckUpdated()); 374 EXPECT_TRUE(unsafefile_observer.CheckUpdated());
387 } 375 }
388 376
389 // DownloadItemImpl::OnDownloadTargetDetermined will schedule a task to run 377 // DownloadItemImpl::OnDownloadTargetDetermined will schedule a task to run
390 // DownloadFileManager::RenameDownloadFile(). Once the rename 378 // DownloadFile::Rename(). Once the rename
391 // completes, DownloadItemImpl receives a notification with the new file 379 // completes, DownloadItemImpl receives a notification with the new file
392 // name. Check that observers are updated when the new filename is available and 380 // name. Check that observers are updated when the new filename is available and
393 // not before. 381 // not before.
394 TEST_F(DownloadItemTest, NotificationAfterOnDownloadTargetDetermined) { 382 TEST_F(DownloadItemTest, NotificationAfterOnDownloadTargetDetermined) {
395 DownloadItemImpl* item = CreateDownloadItem(DownloadItem::IN_PROGRESS); 383 DownloadItemImpl* item = CreateDownloadItem(DownloadItem::IN_PROGRESS);
384 MockDownloadFile* download_file = AddDownloadFileToDownloadItem(item);
396 MockObserver observer(item); 385 MockObserver observer(item);
397 FilePath target_path(kDummyPath); 386 FilePath target_path(kDummyPath);
398 FilePath intermediate_path(target_path.InsertBeforeExtensionASCII("x")); 387 FilePath intermediate_path(target_path.InsertBeforeExtensionASCII("x"));
399 FilePath new_intermediate_path(target_path.InsertBeforeExtensionASCII("y")); 388 FilePath new_intermediate_path(target_path.InsertBeforeExtensionASCII("y"));
400 EXPECT_CALL(*mock_file_manager(), 389 EXPECT_CALL(*download_file, Rename(intermediate_path, false, _))
401 RenameDownloadFile(_,intermediate_path,false,_))
402 .WillOnce(ScheduleRenameCallback(new_intermediate_path)); 390 .WillOnce(ScheduleRenameCallback(new_intermediate_path));
403 391
404 // Currently, a notification would be generated if the danger type is anything 392 // Currently, a notification would be generated if the danger type is anything
405 // other than NOT_DANGEROUS. 393 // other than NOT_DANGEROUS.
406 item->OnDownloadTargetDetermined(target_path, 394 item->OnDownloadTargetDetermined(target_path,
407 DownloadItem::TARGET_DISPOSITION_OVERWRITE, 395 DownloadItem::TARGET_DISPOSITION_OVERWRITE,
408 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, 396 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS,
409 intermediate_path); 397 intermediate_path);
410 EXPECT_FALSE(observer.CheckUpdated()); 398 EXPECT_FALSE(observer.CheckUpdated());
411 RunAllPendingInMessageLoops(); 399 RunAllPendingInMessageLoops();
412 EXPECT_TRUE(observer.CheckUpdated()); 400 EXPECT_TRUE(observer.CheckUpdated());
413 EXPECT_EQ(new_intermediate_path, item->GetFullPath()); 401 EXPECT_EQ(new_intermediate_path, item->GetFullPath());
402
403 CleanupItem(item, download_file);
414 } 404 }
415 405
416 TEST_F(DownloadItemTest, NotificationAfterTogglePause) { 406 TEST_F(DownloadItemTest, NotificationAfterTogglePause) {
417 DownloadItemImpl* item = CreateDownloadItem(DownloadItem::IN_PROGRESS); 407 DownloadItemImpl* item = CreateDownloadItem(DownloadItem::IN_PROGRESS);
418 MockObserver observer(item); 408 MockObserver observer(item);
419 409
420 item->TogglePause(); 410 item->TogglePause();
421 ASSERT_TRUE(observer.CheckUpdated()); 411 ASSERT_TRUE(observer.CheckUpdated());
422 412
423 item->TogglePause(); 413 item->TogglePause();
424 ASSERT_TRUE(observer.CheckUpdated()); 414 ASSERT_TRUE(observer.CheckUpdated());
425 } 415 }
426 416
427 TEST_F(DownloadItemTest, DisplayName) { 417 TEST_F(DownloadItemTest, DisplayName) {
428 DownloadItemImpl* item = CreateDownloadItem(DownloadItem::IN_PROGRESS); 418 DownloadItemImpl* item = CreateDownloadItem(DownloadItem::IN_PROGRESS);
419 MockDownloadFile* download_file = AddDownloadFileToDownloadItem(item);
429 FilePath target_path(FilePath(kDummyPath).AppendASCII("foo.bar")); 420 FilePath target_path(FilePath(kDummyPath).AppendASCII("foo.bar"));
430 FilePath intermediate_path(target_path.InsertBeforeExtensionASCII("x")); 421 FilePath intermediate_path(target_path.InsertBeforeExtensionASCII("x"));
431 EXPECT_EQ(FILE_PATH_LITERAL(""), 422 EXPECT_EQ(FILE_PATH_LITERAL(""),
432 item->GetFileNameToReportUser().value()); 423 item->GetFileNameToReportUser().value());
433 EXPECT_CALL(*mock_file_manager(), 424 EXPECT_CALL(*download_file, Rename(_, false, _))
434 RenameDownloadFile(_,_,false,_))
435 .WillOnce(ScheduleRenameCallback(intermediate_path)); 425 .WillOnce(ScheduleRenameCallback(intermediate_path));
436 item->OnDownloadTargetDetermined(target_path, 426 item->OnDownloadTargetDetermined(target_path,
437 DownloadItem::TARGET_DISPOSITION_OVERWRITE, 427 DownloadItem::TARGET_DISPOSITION_OVERWRITE,
438 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, 428 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS,
439 intermediate_path); 429 intermediate_path);
440 RunAllPendingInMessageLoops(); 430 RunAllPendingInMessageLoops();
441 EXPECT_EQ(FILE_PATH_LITERAL("foo.bar"), 431 EXPECT_EQ(FILE_PATH_LITERAL("foo.bar"),
442 item->GetFileNameToReportUser().value()); 432 item->GetFileNameToReportUser().value());
443 item->SetDisplayName(FilePath(FILE_PATH_LITERAL("new.name"))); 433 item->SetDisplayName(FilePath(FILE_PATH_LITERAL("new.name")));
444 EXPECT_EQ(FILE_PATH_LITERAL("new.name"), 434 EXPECT_EQ(FILE_PATH_LITERAL("new.name"),
445 item->GetFileNameToReportUser().value()); 435 item->GetFileNameToReportUser().value());
436 CleanupItem(item, download_file);
437 }
438
439 // Test to make sure that Start method calls DF initialize properly.
440 TEST_F(DownloadItemTest, Start) {
441 MockDownloadFile* mock_download_file(new MockDownloadFile);
442 scoped_ptr<content::DownloadFile> download_file(mock_download_file);
443 DownloadItemImpl* item = CreateDownloadItem(DownloadItem::IN_PROGRESS);
444 EXPECT_CALL(*mock_download_file, Initialize(_));
445 item->Start(download_file.Pass());
446
447 CleanupItem(item, mock_download_file);
446 } 448 }
447 449
448 static char external_data_test_string[] = "External data test"; 450 static char external_data_test_string[] = "External data test";
449 static int destructor_called = 0; 451 static int destructor_called = 0;
450 452
451 class TestExternalData : public DownloadItem::ExternalData { 453 class TestExternalData : public DownloadItem::ExternalData {
452 public: 454 public:
453 int value; 455 int value;
454 virtual ~TestExternalData() { 456 virtual ~TestExternalData() {
455 destructor_called++; 457 destructor_called++;
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
512 EXPECT_EQ(3, destructor_called); 514 EXPECT_EQ(3, destructor_called);
513 } 515 }
514 516
515 // Test that the delegate is invoked after the download file is renamed. 517 // Test that the delegate is invoked after the download file is renamed.
516 // Delegate::DownloadRenamedToIntermediateName() should be invoked when the 518 // Delegate::DownloadRenamedToIntermediateName() should be invoked when the
517 // download is renamed to the intermediate name. 519 // download is renamed to the intermediate name.
518 // Delegate::DownloadRenamedToFinalName() should be invoked after the final 520 // Delegate::DownloadRenamedToFinalName() should be invoked after the final
519 // rename. 521 // rename.
520 TEST_F(DownloadItemTest, CallbackAfterRename) { 522 TEST_F(DownloadItemTest, CallbackAfterRename) {
521 DownloadItemImpl* item = CreateDownloadItem(DownloadItem::IN_PROGRESS); 523 DownloadItemImpl* item = CreateDownloadItem(DownloadItem::IN_PROGRESS);
524 MockDownloadFile* download_file = AddDownloadFileToDownloadItem(item);
522 FilePath final_path(FilePath(kDummyPath).AppendASCII("foo.bar")); 525 FilePath final_path(FilePath(kDummyPath).AppendASCII("foo.bar"));
523 FilePath intermediate_path(final_path.InsertBeforeExtensionASCII("x")); 526 FilePath intermediate_path(final_path.InsertBeforeExtensionASCII("x"));
524 FilePath new_intermediate_path(final_path.InsertBeforeExtensionASCII("y")); 527 FilePath new_intermediate_path(final_path.InsertBeforeExtensionASCII("y"));
525 EXPECT_CALL(*mock_file_manager(), 528 EXPECT_CALL(*download_file, Rename(intermediate_path, false, _))
526 RenameDownloadFile(item->GetGlobalId(),
527 intermediate_path, false, _))
528 .WillOnce(ScheduleRenameCallback(new_intermediate_path)); 529 .WillOnce(ScheduleRenameCallback(new_intermediate_path));
530
529 // DownloadItemImpl should invoke this callback on the delegate once the 531 // DownloadItemImpl should invoke this callback on the delegate once the
530 // download is renamed to the intermediate name. Also check that GetFullPath() 532 // download is renamed to the intermediate name. Also check that GetFullPath()
531 // returns the intermediate path at the time of the call. 533 // returns the intermediate path at the time of the call.
532 EXPECT_CALL(*mock_delegate(), 534 EXPECT_CALL(*mock_delegate(),
533 DownloadRenamedToIntermediateName( 535 DownloadRenamedToIntermediateName(
534 AllOf(item, 536 AllOf(item,
535 Property(&DownloadItem::GetFullPath, 537 Property(&DownloadItem::GetFullPath,
536 new_intermediate_path)))); 538 new_intermediate_path))));
537 item->OnDownloadTargetDetermined(final_path, 539 item->OnDownloadTargetDetermined(final_path,
538 DownloadItem::TARGET_DISPOSITION_OVERWRITE, 540 DownloadItem::TARGET_DISPOSITION_OVERWRITE,
539 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, 541 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS,
540 intermediate_path); 542 intermediate_path);
541 RunAllPendingInMessageLoops(); 543 RunAllPendingInMessageLoops();
542 // All the callbacks should have happened by now. 544 // All the callbacks should have happened by now.
543 ::testing::Mock::VerifyAndClearExpectations(mock_file_manager()); 545 ::testing::Mock::VerifyAndClearExpectations(download_file);
544 ::testing::Mock::VerifyAndClearExpectations(mock_delegate()); 546 ::testing::Mock::VerifyAndClearExpectations(mock_delegate());
545 547
546 item->OnAllDataSaved(10, ""); 548 item->OnAllDataSaved("");
547 EXPECT_CALL(*mock_file_manager(), 549 EXPECT_CALL(*download_file, Rename(final_path, true, _))
548 RenameDownloadFile(item->GetGlobalId(),
549 final_path, true, _))
550 .WillOnce(ScheduleRenameCallback(final_path)); 550 .WillOnce(ScheduleRenameCallback(final_path));
551 EXPECT_CALL(*mock_file_manager(),
552 CompleteDownload(item->GetGlobalId(), _))
553 .WillOnce(ScheduleCompleteCallback());
554 // DownloadItemImpl should invoke this callback on the delegate after the 551 // DownloadItemImpl should invoke this callback on the delegate after the
555 // final rename has completed. Also check that GetFullPath() and 552 // final rename has completed. Also check that GetFullPath() and
556 // GetTargetFilePath() return the final path at the time of the call. 553 // GetTargetFilePath() return the final path at the time of the call.
557 EXPECT_CALL(*mock_delegate(), 554 EXPECT_CALL(*mock_delegate(),
558 DownloadRenamedToFinalName( 555 DownloadRenamedToFinalName(
559 AllOf(item, 556 AllOf(item,
560 Property(&DownloadItem::GetFullPath, final_path), 557 Property(&DownloadItem::GetFullPath, final_path),
561 Property(&DownloadItem::GetTargetFilePath, 558 Property(&DownloadItem::GetTargetFilePath,
562 final_path)))); 559 final_path))));
563 EXPECT_CALL(*mock_delegate(), DownloadCompleted(item)); 560 EXPECT_CALL(*mock_delegate(), DownloadCompleted(item));
564 EXPECT_CALL(*mock_delegate(), ShouldOpenDownload(item)) 561 EXPECT_CALL(*mock_delegate(), ShouldOpenDownload(item))
565 .WillOnce(Return(true)); 562 .WillOnce(Return(true));
563 EXPECT_CALL(*download_file, Detach());
566 item->OnDownloadCompleting(); 564 item->OnDownloadCompleting();
567 RunAllPendingInMessageLoops(); 565 RunAllPendingInMessageLoops();
568 ::testing::Mock::VerifyAndClearExpectations(mock_file_manager()); 566 ::testing::Mock::VerifyAndClearExpectations(download_file);
569 ::testing::Mock::VerifyAndClearExpectations(mock_delegate()); 567 ::testing::Mock::VerifyAndClearExpectations(mock_delegate());
570 } 568 }
571 569
572 TEST_F(DownloadItemTest, Interrupted) { 570 TEST_F(DownloadItemTest, Interrupted) {
573 DownloadItemImpl* item = CreateDownloadItem(DownloadItem::IN_PROGRESS); 571 DownloadItemImpl* item = CreateDownloadItem(DownloadItem::IN_PROGRESS);
572 MockDownloadFile* download_file = AddDownloadFileToDownloadItem(item);
574 573
575 const content::DownloadInterruptReason reason( 574 const content::DownloadInterruptReason reason(
576 content::DOWNLOAD_INTERRUPT_REASON_FILE_ACCESS_DENIED); 575 content::DOWNLOAD_INTERRUPT_REASON_FILE_ACCESS_DENIED);
577 576
578 // Confirm interrupt sets state properly. 577 // Confirm interrupt sets state properly.
578 EXPECT_CALL(*download_file, Cancel());
579 item->Interrupt(reason); 579 item->Interrupt(reason);
580 RunAllPendingInMessageLoops();
580 EXPECT_EQ(DownloadItem::INTERRUPTED, item->GetState()); 581 EXPECT_EQ(DownloadItem::INTERRUPTED, item->GetState());
581 EXPECT_EQ(reason, item->GetLastReason()); 582 EXPECT_EQ(reason, item->GetLastReason());
582 583
583 // Cancel should result in no change. 584 // Cancel should result in no change.
584 item->Cancel(true); 585 item->Cancel(true);
585 EXPECT_EQ(DownloadItem::INTERRUPTED, item->GetState()); 586 EXPECT_EQ(DownloadItem::INTERRUPTED, item->GetState());
586 EXPECT_EQ(content::DOWNLOAD_INTERRUPT_REASON_USER_CANCELED, 587 EXPECT_EQ(content::DOWNLOAD_INTERRUPT_REASON_USER_CANCELED,
587 item->GetLastReason()); 588 item->GetLastReason());
588 } 589 }
589 590
590 TEST_F(DownloadItemTest, Canceled) { 591 TEST_F(DownloadItemTest, Canceled) {
591 DownloadItemImpl* item = CreateDownloadItem(DownloadItem::IN_PROGRESS); 592 DownloadItemImpl* item = CreateDownloadItem(DownloadItem::IN_PROGRESS);
593 MockDownloadFile* download_file = AddDownloadFileToDownloadItem(item);
592 594
593 // Confirm cancel sets state properly. 595 // Confirm cancel sets state properly.
594 EXPECT_CALL(*mock_delegate(), DownloadStopped(item)); 596 EXPECT_CALL(*mock_delegate(), DownloadStopped(item));
597 EXPECT_CALL(*download_file, Cancel());
595 item->Cancel(true); 598 item->Cancel(true);
596 EXPECT_EQ(DownloadItem::CANCELLED, item->GetState()); 599 EXPECT_EQ(DownloadItem::CANCELLED, item->GetState());
600 RunAllPendingInMessageLoops();
597 } 601 }
598 602
599 TEST_F(DownloadItemTest, FileRemoved) { 603 TEST_F(DownloadItemTest, FileRemoved) {
600 DownloadItemImpl* item = CreateDownloadItem(DownloadItem::IN_PROGRESS); 604 DownloadItemImpl* item = CreateDownloadItem(DownloadItem::IN_PROGRESS);
601 605
602 EXPECT_FALSE(item->GetFileExternallyRemoved()); 606 EXPECT_FALSE(item->GetFileExternallyRemoved());
603 item->OnDownloadedFileRemoved(); 607 item->OnDownloadedFileRemoved();
604 EXPECT_TRUE(item->GetFileExternallyRemoved()); 608 EXPECT_TRUE(item->GetFileExternallyRemoved());
605 } 609 }
606 610
611 TEST_F(DownloadItemTest, DestinationUpdate) {
612 DownloadItemImpl* item = CreateDownloadItem(DownloadItem::IN_PROGRESS);
613 base::WeakPtr<content::DownloadDestinationObserver> as_observer(
614 item->DestinationObserverAsWeakPtr());
615 MockObserver observer(item);
616
617 EXPECT_EQ(0l, item->CurrentSpeed());
618 EXPECT_EQ("", item->GetHashState());
619 EXPECT_EQ(0l, item->GetReceivedBytes());
620 EXPECT_EQ(0l, item->GetTotalBytes());
621 EXPECT_FALSE(observer.CheckUpdated());
622 item->SetTotalBytes(100l);
623 EXPECT_EQ(100l, item->GetTotalBytes());
624
625 as_observer->DestinationUpdate(10, 20, "deadbeef");
626 EXPECT_EQ(20l, item->CurrentSpeed());
627 EXPECT_EQ("deadbeef", item->GetHashState());
628 EXPECT_EQ(10l, item->GetReceivedBytes());
629 EXPECT_EQ(100l, item->GetTotalBytes());
630 EXPECT_TRUE(observer.CheckUpdated());
631
632 as_observer->DestinationUpdate(200, 20, "livebeef");
633 EXPECT_EQ(20l, item->CurrentSpeed());
634 EXPECT_EQ("livebeef", item->GetHashState());
635 EXPECT_EQ(200l, item->GetReceivedBytes());
636 EXPECT_EQ(0l, item->GetTotalBytes());
637 EXPECT_TRUE(observer.CheckUpdated());
638 }
639
640 TEST_F(DownloadItemTest, DestinationError) {
641 DownloadItemImpl* item = CreateDownloadItem(DownloadItem::IN_PROGRESS);
642 MockDownloadFile* download_file = AddDownloadFileToDownloadItem(item);
643 base::WeakPtr<content::DownloadDestinationObserver> as_observer(
644 item->DestinationObserverAsWeakPtr());
645 MockObserver observer(item);
646
647 EXPECT_EQ(content::DownloadItem::IN_PROGRESS, item->GetState());
648 EXPECT_EQ(content::DOWNLOAD_INTERRUPT_REASON_NONE, item->GetLastReason());
649 EXPECT_FALSE(observer.CheckUpdated());
650
651 EXPECT_CALL(*mock_delegate(), DownloadStopped(item));
652 EXPECT_CALL(*download_file, Cancel());
653 as_observer->DestinationError(
654 content::DOWNLOAD_INTERRUPT_REASON_FILE_ACCESS_DENIED);
655 ::testing::Mock::VerifyAndClearExpectations(mock_delegate());
656 EXPECT_TRUE(observer.CheckUpdated());
657 EXPECT_EQ(content::DownloadItem::INTERRUPTED, item->GetState());
658 EXPECT_EQ(content::DOWNLOAD_INTERRUPT_REASON_FILE_ACCESS_DENIED,
659 item->GetLastReason());
660 RunAllPendingInMessageLoops();
661 }
662
663 TEST_F(DownloadItemTest, DestinationCompleted) {
664 DownloadItemImpl* item = CreateDownloadItem(DownloadItem::IN_PROGRESS);
665 base::WeakPtr<content::DownloadDestinationObserver> as_observer(
666 item->DestinationObserverAsWeakPtr());
667 MockObserver observer(item);
668
669 EXPECT_EQ(content::DownloadItem::IN_PROGRESS, item->GetState());
670 EXPECT_EQ("", item->GetHash());
671 EXPECT_EQ("", item->GetHashState());
672 EXPECT_FALSE(item->AllDataSaved());
673 EXPECT_FALSE(observer.CheckUpdated());
674
675 as_observer->DestinationUpdate(10, 20, "deadbeef");
676 EXPECT_TRUE(observer.CheckUpdated());
677 EXPECT_FALSE(observer.CheckUpdated()); // Confirm reset.
678 EXPECT_EQ(content::DownloadItem::IN_PROGRESS, item->GetState());
679 EXPECT_EQ("", item->GetHash());
680 EXPECT_EQ("deadbeef", item->GetHashState());
681 EXPECT_FALSE(item->AllDataSaved());
682
683 EXPECT_CALL(*mock_delegate(), MaybeCompleteDownload(item));
684 as_observer->DestinationCompleted("livebeef");
685 ::testing::Mock::VerifyAndClearExpectations(mock_delegate());
686 EXPECT_EQ(content::DownloadItem::IN_PROGRESS, item->GetState());
687 EXPECT_TRUE(observer.CheckUpdated());
688 EXPECT_EQ("livebeef", item->GetHash());
689 EXPECT_EQ("", item->GetHashState());
690 EXPECT_TRUE(item->AllDataSaved());
691 }
692
607 TEST(MockDownloadItem, Compiles) { 693 TEST(MockDownloadItem, Compiles) {
608 MockDownloadItem mock_item; 694 MockDownloadItem mock_item;
609 } 695 }
696
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698