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

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

Issue 2457923002: Remove stl_util's deletion function use and ScopedVector from chrome/browser/download/. (Closed)
Patch Set: sky Created 4 years, 1 month 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
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 "chrome/browser/download/download_history.h" 5 #include "chrome/browser/download/download_history.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 #include <utility> 9 #include <utility>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/guid.h" 12 #include "base/guid.h"
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/memory/ptr_util.h"
14 #include "base/memory/weak_ptr.h" 15 #include "base/memory/weak_ptr.h"
15 #include "base/rand_util.h" 16 #include "base/rand_util.h"
16 #include "base/stl_util.h" 17 #include "base/stl_util.h"
17 #include "components/history/content/browser/download_constants_utils.h" 18 #include "components/history/content/browser/download_constants_utils.h"
18 #include "components/history/core/browser/download_constants.h" 19 #include "components/history/core/browser/download_constants.h"
19 #include "components/history/core/browser/download_row.h" 20 #include "components/history/core/browser/download_row.h"
20 #include "components/history/core/browser/history_service.h" 21 #include "components/history/core/browser/history_service.h"
21 #include "content/public/test/mock_download_item.h" 22 #include "content/public/test/mock_download_item.h"
22 #include "content/public/test/mock_download_manager.h" 23 #include "content/public/test/mock_download_manager.h"
23 #include "content/public/test/test_browser_thread.h" 24 #include "content/public/test/test_browser_thread.h"
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 public: 185 public:
185 // Generic callback that receives a pointer to a StrictMockDownloadItem. 186 // Generic callback that receives a pointer to a StrictMockDownloadItem.
186 typedef base::Callback<void(content::MockDownloadItem*)> DownloadItemCallback; 187 typedef base::Callback<void(content::MockDownloadItem*)> DownloadItemCallback;
187 188
188 DownloadHistoryTest() 189 DownloadHistoryTest()
189 : ui_thread_(content::BrowserThread::UI, &loop_), 190 : ui_thread_(content::BrowserThread::UI, &loop_),
190 manager_(new content::MockDownloadManager()), 191 manager_(new content::MockDownloadManager()),
191 history_(NULL), 192 history_(NULL),
192 manager_observer_(NULL), 193 manager_observer_(NULL),
193 download_created_index_(0) {} 194 download_created_index_(0) {}
194 ~DownloadHistoryTest() override { base::STLDeleteElements(&items_); } 195 ~DownloadHistoryTest() override {}
195 196
196 protected: 197 protected:
197 void TearDown() override { download_history_.reset(); } 198 void TearDown() override { download_history_.reset(); }
198 199
199 content::MockDownloadManager& manager() { return *manager_.get(); } 200 content::MockDownloadManager& manager() { return *manager_.get(); }
200 content::MockDownloadItem& item(size_t index) { return *items_[index]; } 201 content::MockDownloadItem& item(size_t index) { return *items_[index]; }
201 DownloadHistory* download_history() { return download_history_.get(); } 202 DownloadHistory* download_history() { return download_history_.get(); }
202 203
203 void SetManagerObserver( 204 void SetManagerObserver(
204 content::DownloadManager::Observer* manager_observer) { 205 content::DownloadManager::Observer* manager_observer) {
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
359 content::DownloadItem::DownloadState state, 360 content::DownloadItem::DownloadState state,
360 content::DownloadDangerType danger_type, 361 content::DownloadDangerType danger_type,
361 content::DownloadInterruptReason interrupt_reason, 362 content::DownloadInterruptReason interrupt_reason,
362 bool opened, 363 bool opened,
363 const std::string& by_extension_id, 364 const std::string& by_extension_id,
364 const std::string& by_extension_name, 365 const std::string& by_extension_name,
365 history::DownloadRow* info) { 366 history::DownloadRow* info) {
366 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 367 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
367 368
368 size_t index = items_.size(); 369 size_t index = items_.size();
369 StrictMockDownloadItem* mock_item = new StrictMockDownloadItem(); 370 items_.push_back(base::MakeUnique<StrictMockDownloadItem>());
370 items_.push_back(mock_item);
371 371
372 info->current_path = current_path; 372 info->current_path = current_path;
373 info->target_path = target_path; 373 info->target_path = target_path;
374 info->url_chain = url_chain; 374 info->url_chain = url_chain;
375 info->referrer_url = referrer; 375 info->referrer_url = referrer;
376 info->site_url = site_url; 376 info->site_url = site_url;
377 info->tab_url = tab_url; 377 info->tab_url = tab_url;
378 info->tab_referrer_url = tab_referrer_url; 378 info->tab_referrer_url = tab_referrer_url;
379 info->mime_type = mime_type; 379 info->mime_type = mime_type;
380 info->original_mime_type = original_mime_type; 380 info->original_mime_type = original_mime_type;
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
452 452
453 private: 453 private:
454 void CheckDownloadWasRestoredFromHistory(bool expected_value, 454 void CheckDownloadWasRestoredFromHistory(bool expected_value,
455 content::MockDownloadItem* item) { 455 content::MockDownloadItem* item) {
456 ASSERT_TRUE(download_history_.get()); 456 ASSERT_TRUE(download_history_.get());
457 EXPECT_EQ(expected_value, download_history_->WasRestoredFromHistory(item)); 457 EXPECT_EQ(expected_value, download_history_->WasRestoredFromHistory(item));
458 } 458 }
459 459
460 base::MessageLoopForUI loop_; 460 base::MessageLoopForUI loop_;
461 content::TestBrowserThread ui_thread_; 461 content::TestBrowserThread ui_thread_;
462 std::vector<StrictMockDownloadItem*> items_; 462 std::vector<std::unique_ptr<StrictMockDownloadItem>> items_;
463 std::unique_ptr<content::MockDownloadManager> manager_; 463 std::unique_ptr<content::MockDownloadManager> manager_;
464 FakeHistoryAdapter* history_; 464 FakeHistoryAdapter* history_;
465 std::unique_ptr<DownloadHistory> download_history_; 465 std::unique_ptr<DownloadHistory> download_history_;
466 content::DownloadManager::Observer* manager_observer_; 466 content::DownloadManager::Observer* manager_observer_;
467 size_t download_created_index_; 467 size_t download_created_index_;
468 DownloadItemCallback pre_on_create_handler_; 468 DownloadItemCallback pre_on_create_handler_;
469 DownloadItemCallback post_on_create_handler_; 469 DownloadItemCallback post_on_create_handler_;
470 470
471 DISALLOW_COPY_AND_ASSIGN(DownloadHistoryTest); 471 DISALLOW_COPY_AND_ASSIGN(DownloadHistoryTest);
472 }; 472 };
(...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after
895 FinishCreateDownload(); 895 FinishCreateDownload();
896 EXPECT_TRUE(DownloadHistory::IsPersisted(&item(0))); 896 EXPECT_TRUE(DownloadHistory::IsPersisted(&item(0)));
897 897
898 // ItemAdded should call OnDownloadUpdated, which should detect that the item 898 // ItemAdded should call OnDownloadUpdated, which should detect that the item
899 // changed while it was being added and call UpdateDownload immediately. 899 // changed while it was being added and call UpdateDownload immediately.
900 info.opened = true; 900 info.opened = true;
901 ExpectDownloadUpdated(info); 901 ExpectDownloadUpdated(info);
902 } 902 }
903 903
904 } // anonymous namespace 904 } // anonymous namespace
OLDNEW
« no previous file with comments | « chrome/browser/download/download_browsertest.cc ('k') | chrome/browser/download/download_query.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698