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

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

Issue 10735089: DownloadManager::Observer::OnDownloadCreated (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 5 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_manager.h"
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 MockObserver observer(item); 292 MockObserver observer(item);
293 293
294 item->Remove(); 294 item->Remove();
295 ASSERT_TRUE(observer.CheckUpdated()); 295 ASSERT_TRUE(observer.CheckUpdated());
296 } 296 }
297 297
298 TEST_F(DownloadItemTest, NotificationAfterOnTargetPathDetermined) { 298 TEST_F(DownloadItemTest, NotificationAfterOnTargetPathDetermined) {
299 DownloadItemImpl* safe_item = CreateDownloadItem(DownloadItem::IN_PROGRESS); 299 DownloadItemImpl* safe_item = CreateDownloadItem(DownloadItem::IN_PROGRESS);
300 MockObserver safe_observer(safe_item); 300 MockObserver safe_observer(safe_item);
301 301
302 // Calling OnTargetPathDetermined does not trigger notification if danger type 302 // Calling OnTargetPathDetermined triggers notification regardless of danger
303 // is NOT_DANGEROUS. 303 // type.
304 safe_item->OnTargetPathDetermined( 304 safe_item->OnTargetPathDetermined(
305 FilePath(kDummyPath), DownloadItem::TARGET_DISPOSITION_OVERWRITE, 305 FilePath(kDummyPath), DownloadItem::TARGET_DISPOSITION_OVERWRITE,
306 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS); 306 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS);
307 EXPECT_FALSE(safe_observer.CheckUpdated()); 307 EXPECT_TRUE(safe_observer.CheckUpdated());
308 308
309 DownloadItemImpl* dangerous_item = 309 DownloadItemImpl* dangerous_item =
310 CreateDownloadItem(DownloadItem::IN_PROGRESS); 310 CreateDownloadItem(DownloadItem::IN_PROGRESS);
311 MockObserver dangerous_observer(dangerous_item); 311 MockObserver dangerous_observer(dangerous_item);
312 312
313 // Calling OnTargetPathDetermined does trigger notification if danger type 313 // Calling OnTargetPathDetermined does trigger notification if danger type
314 // anything other than NOT_DANGEROUS. 314 // anything other than NOT_DANGEROUS.
315 dangerous_item->OnTargetPathDetermined( 315 dangerous_item->OnTargetPathDetermined(
316 FilePath(kDummyPath), DownloadItem::TARGET_DISPOSITION_OVERWRITE, 316 FilePath(kDummyPath), DownloadItem::TARGET_DISPOSITION_OVERWRITE,
317 content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE); 317 content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE);
318 EXPECT_TRUE(dangerous_observer.CheckUpdated()); 318 EXPECT_TRUE(dangerous_observer.CheckUpdated());
319 } 319 }
320 320
321 TEST_F(DownloadItemTest, NotificationAfterOnTargetPathSelected) { 321 TEST_F(DownloadItemTest, NotificationAfterOnTargetPathSelected) {
322 DownloadItemImpl* item = CreateDownloadItem(DownloadItem::IN_PROGRESS); 322 DownloadItemImpl* item = CreateDownloadItem(DownloadItem::IN_PROGRESS);
323 MockObserver observer(item); 323 MockObserver observer(item);
324 324
325 item->OnTargetPathDetermined( 325 item->OnTargetPathDetermined(
326 FilePath(kDummyPath), DownloadItem::TARGET_DISPOSITION_PROMPT, 326 FilePath(kDummyPath), DownloadItem::TARGET_DISPOSITION_PROMPT,
327 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS); 327 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS);
328 item->OnTargetPathSelected(FilePath(kDummyPath)); 328 item->OnTargetPathSelected(FilePath(kDummyPath));
329 EXPECT_FALSE(observer.CheckUpdated()); 329 EXPECT_TRUE(observer.CheckUpdated());
330 } 330 }
331 331
332 TEST_F(DownloadItemTest, NotificationAfterOnContentCheckCompleted) { 332 TEST_F(DownloadItemTest, NotificationAfterOnContentCheckCompleted) {
333 // Setting to NOT_DANGEROUS does not trigger a notification. 333 // Setting to NOT_DANGEROUS does not trigger a notification.
334 DownloadItemImpl* safe_item = CreateDownloadItem(DownloadItem::IN_PROGRESS); 334 DownloadItemImpl* safe_item = CreateDownloadItem(DownloadItem::IN_PROGRESS);
335 MockObserver safe_observer(safe_item); 335 MockObserver safe_observer(safe_item);
336 336
337 safe_item->OnTargetPathDetermined( 337 safe_item->OnTargetPathDetermined(
338 FilePath(kDummyPath), DownloadItem::TARGET_DISPOSITION_OVERWRITE, 338 FilePath(kDummyPath), DownloadItem::TARGET_DISPOSITION_OVERWRITE,
339 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS); 339 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS);
340 EXPECT_FALSE(safe_observer.CheckUpdated()); 340 EXPECT_TRUE(safe_observer.CheckUpdated());
341 safe_item->OnAllDataSaved(1, ""); 341 safe_item->OnAllDataSaved(1, "");
342 EXPECT_TRUE(safe_observer.CheckUpdated()); 342 EXPECT_TRUE(safe_observer.CheckUpdated());
343 safe_item->OnContentCheckCompleted( 343 safe_item->OnContentCheckCompleted(
344 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS); 344 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS);
345 EXPECT_FALSE(safe_observer.CheckUpdated()); 345 EXPECT_FALSE(safe_observer.CheckUpdated());
346 346
347 // Setting to unsafe url or unsafe file should trigger a notification. 347 // Setting to unsafe url or unsafe file should trigger a notification.
348 DownloadItemImpl* unsafeurl_item = 348 DownloadItemImpl* unsafeurl_item =
349 CreateDownloadItem(DownloadItem::IN_PROGRESS); 349 CreateDownloadItem(DownloadItem::IN_PROGRESS);
350 MockObserver unsafeurl_observer(unsafeurl_item); 350 MockObserver unsafeurl_observer(unsafeurl_item);
351 351
352 unsafeurl_item->OnTargetPathDetermined( 352 unsafeurl_item->OnTargetPathDetermined(
353 FilePath(kDummyPath), DownloadItem::TARGET_DISPOSITION_OVERWRITE, 353 FilePath(kDummyPath), DownloadItem::TARGET_DISPOSITION_OVERWRITE,
354 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS); 354 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS);
355 EXPECT_FALSE(unsafeurl_observer.CheckUpdated()); 355 EXPECT_TRUE(unsafeurl_observer.CheckUpdated());
356 unsafeurl_item->OnAllDataSaved(1, ""); 356 unsafeurl_item->OnAllDataSaved(1, "");
357 EXPECT_TRUE(unsafeurl_observer.CheckUpdated()); 357 EXPECT_TRUE(unsafeurl_observer.CheckUpdated());
358 unsafeurl_item->OnContentCheckCompleted( 358 unsafeurl_item->OnContentCheckCompleted(
359 content::DOWNLOAD_DANGER_TYPE_DANGEROUS_URL); 359 content::DOWNLOAD_DANGER_TYPE_DANGEROUS_URL);
360 EXPECT_TRUE(unsafeurl_observer.CheckUpdated()); 360 EXPECT_TRUE(unsafeurl_observer.CheckUpdated());
361 361
362 unsafeurl_item->DangerousDownloadValidated(); 362 unsafeurl_item->DangerousDownloadValidated();
363 EXPECT_TRUE(unsafeurl_observer.CheckUpdated()); 363 EXPECT_TRUE(unsafeurl_observer.CheckUpdated());
364 364
365 DownloadItemImpl* unsafefile_item = 365 DownloadItemImpl* unsafefile_item =
366 CreateDownloadItem(DownloadItem::IN_PROGRESS); 366 CreateDownloadItem(DownloadItem::IN_PROGRESS);
367 MockObserver unsafefile_observer(unsafefile_item); 367 MockObserver unsafefile_observer(unsafefile_item);
368 368
369 unsafefile_item->OnTargetPathDetermined( 369 unsafefile_item->OnTargetPathDetermined(
370 FilePath(kDummyPath), DownloadItem::TARGET_DISPOSITION_OVERWRITE, 370 FilePath(kDummyPath), DownloadItem::TARGET_DISPOSITION_OVERWRITE,
371 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS); 371 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS);
372 EXPECT_FALSE(unsafefile_observer.CheckUpdated()); 372 EXPECT_TRUE(unsafefile_observer.CheckUpdated());
373 unsafefile_item->OnAllDataSaved(1, ""); 373 unsafefile_item->OnAllDataSaved(1, "");
374 EXPECT_TRUE(unsafefile_observer.CheckUpdated()); 374 EXPECT_TRUE(unsafefile_observer.CheckUpdated());
375 unsafefile_item->OnContentCheckCompleted( 375 unsafefile_item->OnContentCheckCompleted(
376 content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE); 376 content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE);
377 EXPECT_TRUE(unsafefile_observer.CheckUpdated()); 377 EXPECT_TRUE(unsafefile_observer.CheckUpdated());
378 378
379 unsafefile_item->DangerousDownloadValidated(); 379 unsafefile_item->DangerousDownloadValidated();
380 EXPECT_TRUE(unsafefile_observer.CheckUpdated()); 380 EXPECT_TRUE(unsafefile_observer.CheckUpdated());
381 } 381 }
382 382
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
583 DownloadItemImpl* item = CreateDownloadItem(DownloadItem::IN_PROGRESS); 583 DownloadItemImpl* item = CreateDownloadItem(DownloadItem::IN_PROGRESS);
584 584
585 EXPECT_FALSE(item->GetFileExternallyRemoved()); 585 EXPECT_FALSE(item->GetFileExternallyRemoved());
586 item->OnDownloadedFileRemoved(); 586 item->OnDownloadedFileRemoved();
587 EXPECT_TRUE(item->GetFileExternallyRemoved()); 587 EXPECT_TRUE(item->GetFileExternallyRemoved());
588 } 588 }
589 589
590 TEST(MockDownloadItem, Compiles) { 590 TEST(MockDownloadItem, Compiles) {
591 MockDownloadItem mock_item; 591 MockDownloadItem mock_item;
592 } 592 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698