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

Side by Side Diff: chrome/browser/download/download_history_unittest.cc

Issue 257983002: Move downloads API to extensions namespace (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix compile error for unittest Created 6 years, 7 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
« no previous file with comments | « chrome/browser/download/download_history.cc ('k') | chrome/browser/download/download_service.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <set> 5 #include <set>
6 #include <vector> 6 #include <vector>
7 7
8 #include "base/rand_util.h" 8 #include "base/rand_util.h"
9 #include "base/stl_util.h" 9 #include "base/stl_util.h"
10 #include "chrome/browser/download/download_history.h" 10 #include "chrome/browser/download/download_history.h"
(...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after
431 .WillRepeatedly( 431 .WillRepeatedly(
432 Return(content::DownloadItem::TARGET_DISPOSITION_OVERWRITE)); 432 Return(content::DownloadItem::TARGET_DISPOSITION_OVERWRITE));
433 EXPECT_CALL(manager(), GetDownload(id)) 433 EXPECT_CALL(manager(), GetDownload(id))
434 .WillRepeatedly(Return(&item(index))); 434 .WillRepeatedly(Return(&item(index)));
435 EXPECT_CALL(item(index), AddObserver(_)) 435 EXPECT_CALL(item(index), AddObserver(_))
436 .WillOnce(WithArg<0>( 436 .WillOnce(WithArg<0>(
437 Invoke(this, &DownloadHistoryTest::SetItemObserver))); 437 Invoke(this, &DownloadHistoryTest::SetItemObserver)));
438 EXPECT_CALL(item(index), RemoveObserver(_)); 438 EXPECT_CALL(item(index), RemoveObserver(_));
439 EXPECT_CALL(item(index), IsTemporary()).WillRepeatedly(Return(false)); 439 EXPECT_CALL(item(index), IsTemporary()).WillRepeatedly(Return(false));
440 #if !defined(OS_ANDROID) 440 #if !defined(OS_ANDROID)
441 new DownloadedByExtension(&item(index), by_extension_id, by_extension_name); 441 new extensions::DownloadedByExtension(
442 &item(index), by_extension_id, by_extension_name);
442 #endif 443 #endif
443 444
444 std::vector<content::DownloadItem*> items; 445 std::vector<content::DownloadItem*> items;
445 for (size_t i = 0; i < items_.size(); ++i) { 446 for (size_t i = 0; i < items_.size(); ++i) {
446 items.push_back(&item(i)); 447 items.push_back(&item(i));
447 } 448 }
448 EXPECT_CALL(*manager_.get(), GetAllDownloads(_)) 449 EXPECT_CALL(*manager_.get(), GetAllDownloads(_))
449 .WillRepeatedly(SetArgPointee<0>(items)); 450 .WillRepeatedly(SetArgPointee<0>(items));
450 } 451 }
451 452
452 private: 453 private:
453 base::MessageLoopForUI loop_; 454 base::MessageLoopForUI loop_;
454 content::TestBrowserThread ui_thread_; 455 content::TestBrowserThread ui_thread_;
455 std::vector<StrictMockDownloadItem*> items_; 456 std::vector<StrictMockDownloadItem*> items_;
456 scoped_ptr<content::MockDownloadManager> manager_; 457 scoped_ptr<content::MockDownloadManager> manager_;
457 FakeHistoryAdapter* history_; 458 FakeHistoryAdapter* history_;
458 scoped_ptr<DownloadHistory> download_history_; 459 scoped_ptr<DownloadHistory> download_history_;
459 content::DownloadManager::Observer* manager_observer_; 460 content::DownloadManager::Observer* manager_observer_;
460 content::DownloadItem::Observer* item_observer_; 461 content::DownloadItem::Observer* item_observer_;
461 size_t download_created_index_; 462 size_t download_created_index_;
462 463
463 DISALLOW_COPY_AND_ASSIGN(DownloadHistoryTest); 464 DISALLOW_COPY_AND_ASSIGN(DownloadHistoryTest);
464 }; 465 };
465 466
466 } // anonymous namespace 467 } // namespace
467 468
468 // Test loading an item from the database, changing it, saving it back, removing 469 // Test loading an item from the database, changing it, saving it back, removing
469 // it. 470 // it.
470 TEST_F(DownloadHistoryTest, DownloadHistoryTest_Load) { 471 TEST_F(DownloadHistoryTest, DownloadHistoryTest_Load) {
471 // Load a download from history, create the item, OnDownloadCreated, 472 // Load a download from history, create the item, OnDownloadCreated,
472 // OnDownloadUpdated, OnDownloadRemoved. 473 // OnDownloadUpdated, OnDownloadRemoved.
473 history::DownloadRow info; 474 history::DownloadRow info;
474 InitBasicItem(FILE_PATH_LITERAL("/foo/bar.pdf"), 475 InitBasicItem(FILE_PATH_LITERAL("/foo/bar.pdf"),
475 "http://example.com/bar.pdf", 476 "http://example.com/bar.pdf",
476 "http://example.com/referrer.html", 477 "http://example.com/referrer.html",
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after
787 item_observer()->OnDownloadUpdated(&item(0)); 788 item_observer()->OnDownloadUpdated(&item(0));
788 789
789 FinishCreateDownload(); 790 FinishCreateDownload();
790 EXPECT_TRUE(DownloadHistory::IsPersisted(&item(0))); 791 EXPECT_TRUE(DownloadHistory::IsPersisted(&item(0)));
791 792
792 // ItemAdded should call OnDownloadUpdated, which should detect that the item 793 // ItemAdded should call OnDownloadUpdated, which should detect that the item
793 // changed while it was being added and call UpdateDownload immediately. 794 // changed while it was being added and call UpdateDownload immediately.
794 info.opened = true; 795 info.opened = true;
795 ExpectDownloadUpdated(info); 796 ExpectDownloadUpdated(info);
796 } 797 }
OLDNEW
« no previous file with comments | « chrome/browser/download/download_history.cc ('k') | chrome/browser/download/download_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698