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: chrome/browser/download/download_history_unittest.cc

Issue 833033002: Remove dependency on //content from history DownloadDatabase (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove obsolete #include Created 5 years, 11 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
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 <vector> 5 #include <vector>
6 6
7 #include "base/memory/weak_ptr.h" 7 #include "base/memory/weak_ptr.h"
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"
11 #include "chrome/browser/history/download_database.h"
12 #include "chrome/browser/history/download_row.h"
13 #include "chrome/browser/history/history_service.h" 11 #include "chrome/browser/history/history_service.h"
12 #include "components/history/content/browser/download_constants_utils.h"
13 #include "components/history/core/browser/download_constants.h"
14 #include "components/history/core/browser/download_row.h"
14 #include "content/public/test/mock_download_item.h" 15 #include "content/public/test/mock_download_item.h"
15 #include "content/public/test/mock_download_manager.h" 16 #include "content/public/test/mock_download_manager.h"
16 #include "content/public/test/test_browser_thread.h" 17 #include "content/public/test/test_browser_thread.h"
17 #include "content/public/test/test_utils.h" 18 #include "content/public/test/test_utils.h"
18 #include "testing/gtest/include/gtest/gtest.h" 19 #include "testing/gtest/include/gtest/gtest.h"
19 20
20 #if defined(ENABLE_EXTENSIONS) 21 #if defined(ENABLE_EXTENSIONS)
21 #include "chrome/browser/extensions/api/downloads/downloads_api.h" 22 #include "chrome/browser/extensions/api/downloads/downloads_api.h"
22 #endif 23 #endif
23 24
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 } 222 }
222 223
223 void CreateDownloadHistory(scoped_ptr<InfoVector> infos) { 224 void CreateDownloadHistory(scoped_ptr<InfoVector> infos) {
224 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 225 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
225 CHECK(infos.get()); 226 CHECK(infos.get());
226 EXPECT_CALL(manager(), AddObserver(_)).WillOnce(WithArg<0>(Invoke( 227 EXPECT_CALL(manager(), AddObserver(_)).WillOnce(WithArg<0>(Invoke(
227 this, &DownloadHistoryTest::SetManagerObserver))); 228 this, &DownloadHistoryTest::SetManagerObserver)));
228 EXPECT_CALL(manager(), RemoveObserver(_)); 229 EXPECT_CALL(manager(), RemoveObserver(_));
229 download_created_index_ = 0; 230 download_created_index_ = 0;
230 for (size_t index = 0; index < infos->size(); ++index) { 231 for (size_t index = 0; index < infos->size(); ++index) {
232 const history::DownloadRow& row = infos->at(index);
231 content::MockDownloadManager::CreateDownloadItemAdapter adapter( 233 content::MockDownloadManager::CreateDownloadItemAdapter adapter(
232 infos->at(index).id, 234 history::ToContentDownloadId(row.id),
233 infos->at(index).current_path, 235 row.current_path,
234 infos->at(index).target_path, 236 row.target_path,
235 infos->at(index).url_chain, 237 row.url_chain,
236 infos->at(index).referrer_url, 238 row.referrer_url,
237 infos->at(index).mime_type, 239 row.mime_type,
238 infos->at(index).original_mime_type, 240 row.original_mime_type,
239 infos->at(index).start_time, 241 row.start_time,
240 infos->at(index).end_time, 242 row.end_time,
241 infos->at(index).etag, 243 row.etag,
242 infos->at(index).last_modified, 244 row.last_modified,
243 infos->at(index).received_bytes, 245 row.received_bytes,
244 infos->at(index).total_bytes, 246 row.total_bytes,
245 infos->at(index).state, 247 history::ToContentDownloadState(row.state),
246 infos->at(index).danger_type, 248 history::ToContentDownloadDangerType(row.danger_type),
247 infos->at(index).interrupt_reason, 249 history::ToContentDownloadInterruptReason(row.interrupt_reason),
248 infos->at(index).opened); 250 row.opened);
249 EXPECT_CALL(manager(), MockCreateDownloadItem(adapter)) 251 EXPECT_CALL(manager(), MockCreateDownloadItem(adapter))
250 .WillOnce(DoAll( 252 .WillOnce(DoAll(
251 InvokeWithoutArgs( 253 InvokeWithoutArgs(
252 this, &DownloadHistoryTest::CallOnDownloadCreatedInOrder), 254 this, &DownloadHistoryTest::CallOnDownloadCreatedInOrder),
253 Return(&item(index)))); 255 Return(&item(index))));
254 } 256 }
255 EXPECT_CALL(manager(), CheckForHistoryFilesRemoval()); 257 EXPECT_CALL(manager(), CheckForHistoryFilesRemoval());
256 history_ = new FakeHistoryAdapter(); 258 history_ = new FakeHistoryAdapter();
257 history_->ExpectWillQueryDownloads(infos.Pass()); 259 history_->ExpectWillQueryDownloads(infos.Pass());
258 EXPECT_CALL(*manager_.get(), GetAllDownloads(_)).WillRepeatedly(Return()); 260 EXPECT_CALL(*manager_.get(), GetAllDownloads(_)).WillRepeatedly(Return());
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
398 info->url_chain = url_chain; 400 info->url_chain = url_chain;
399 info->referrer_url = referrer; 401 info->referrer_url = referrer;
400 info->mime_type = mime_type; 402 info->mime_type = mime_type;
401 info->original_mime_type = original_mime_type; 403 info->original_mime_type = original_mime_type;
402 info->start_time = start_time; 404 info->start_time = start_time;
403 info->end_time = end_time; 405 info->end_time = end_time;
404 info->etag = etag; 406 info->etag = etag;
405 info->last_modified = last_modified; 407 info->last_modified = last_modified;
406 info->received_bytes = received_bytes; 408 info->received_bytes = received_bytes;
407 info->total_bytes = total_bytes; 409 info->total_bytes = total_bytes;
408 info->state = state; 410 info->state = history::ToHistoryDownloadState(state);
409 info->danger_type = danger_type; 411 info->danger_type = history::ToHistoryDownloadDangerType(danger_type);
410 info->interrupt_reason = interrupt_reason; 412 info->interrupt_reason =
411 info->id = id; 413 history::ToHistoryDownloadInterruptReason(interrupt_reason);
414 info->id = history::ToHistoryDownloadId(id);
412 info->opened = opened; 415 info->opened = opened;
413 info->by_ext_id = by_extension_id; 416 info->by_ext_id = by_extension_id;
414 info->by_ext_name = by_extension_name; 417 info->by_ext_name = by_extension_name;
415 418
416 EXPECT_CALL(item(index), GetId()).WillRepeatedly(Return(id)); 419 EXPECT_CALL(item(index), GetId()).WillRepeatedly(Return(id));
417 EXPECT_CALL(item(index), GetFullPath()) 420 EXPECT_CALL(item(index), GetFullPath())
418 .WillRepeatedly(ReturnRefOfCopy(current_path)); 421 .WillRepeatedly(ReturnRefOfCopy(current_path));
419 EXPECT_CALL(item(index), GetTargetFilePath()) 422 EXPECT_CALL(item(index), GetTargetFilePath())
420 .WillRepeatedly(ReturnRefOfCopy(target_path)); 423 .WillRepeatedly(ReturnRefOfCopy(target_path));
421 DCHECK_LE(1u, url_chain.size()); 424 DCHECK_LE(1u, url_chain.size());
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
654 // last_modified 657 // last_modified
655 EXPECT_CALL(item(0), GetLastModifiedTime()) 658 EXPECT_CALL(item(0), GetLastModifiedTime())
656 .WillRepeatedly(ReturnRefOfCopy(new_last_modifed)); 659 .WillRepeatedly(ReturnRefOfCopy(new_last_modifed));
657 info.last_modified = new_last_modifed; 660 info.last_modified = new_last_modifed;
658 item(0).NotifyObserversDownloadUpdated(); 661 item(0).NotifyObserversDownloadUpdated();
659 ExpectDownloadUpdated(info); 662 ExpectDownloadUpdated(info);
660 663
661 // state 664 // state
662 EXPECT_CALL(item(0), GetState()) 665 EXPECT_CALL(item(0), GetState())
663 .WillRepeatedly(Return(content::DownloadItem::INTERRUPTED)); 666 .WillRepeatedly(Return(content::DownloadItem::INTERRUPTED));
664 info.state = content::DownloadItem::INTERRUPTED; 667 info.state = history::DownloadState::INTERRUPTED;
665 item(0).NotifyObserversDownloadUpdated(); 668 item(0).NotifyObserversDownloadUpdated();
666 ExpectDownloadUpdated(info); 669 ExpectDownloadUpdated(info);
667 670
668 // danger_type 671 // danger_type
669 EXPECT_CALL(item(0), GetDangerType()) 672 EXPECT_CALL(item(0), GetDangerType())
670 .WillRepeatedly(Return(content::DOWNLOAD_DANGER_TYPE_DANGEROUS_CONTENT)); 673 .WillRepeatedly(Return(content::DOWNLOAD_DANGER_TYPE_DANGEROUS_CONTENT));
671 info.danger_type = content::DOWNLOAD_DANGER_TYPE_DANGEROUS_CONTENT; 674 info.danger_type = history::DownloadDangerType::DANGEROUS_CONTENT;
672 item(0).NotifyObserversDownloadUpdated(); 675 item(0).NotifyObserversDownloadUpdated();
673 ExpectDownloadUpdated(info); 676 ExpectDownloadUpdated(info);
674 677
675 // interrupt_reason 678 // interrupt_reason
676 EXPECT_CALL(item(0), GetLastReason()) 679 EXPECT_CALL(item(0), GetLastReason())
677 .WillRepeatedly(Return(content::DOWNLOAD_INTERRUPT_REASON_SERVER_FAILED)); 680 .WillRepeatedly(Return(content::DOWNLOAD_INTERRUPT_REASON_SERVER_FAILED));
678 info.interrupt_reason = content::DOWNLOAD_INTERRUPT_REASON_SERVER_FAILED; 681 info.interrupt_reason = history::ToHistoryDownloadInterruptReason(
682 content::DOWNLOAD_INTERRUPT_REASON_SERVER_FAILED);
679 item(0).NotifyObserversDownloadUpdated(); 683 item(0).NotifyObserversDownloadUpdated();
680 ExpectDownloadUpdated(info); 684 ExpectDownloadUpdated(info);
681 685
682 // opened 686 // opened
683 EXPECT_CALL(item(0), GetOpened()).WillRepeatedly(Return(true)); 687 EXPECT_CALL(item(0), GetOpened()).WillRepeatedly(Return(true));
684 info.opened = true; 688 info.opened = true;
685 item(0).NotifyObserversDownloadUpdated(); 689 item(0).NotifyObserversDownloadUpdated();
686 ExpectDownloadUpdated(info); 690 ExpectDownloadUpdated(info);
687 } 691 }
688 692
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
857 FinishCreateDownload(); 861 FinishCreateDownload();
858 EXPECT_TRUE(DownloadHistory::IsPersisted(&item(0))); 862 EXPECT_TRUE(DownloadHistory::IsPersisted(&item(0)));
859 863
860 // ItemAdded should call OnDownloadUpdated, which should detect that the item 864 // ItemAdded should call OnDownloadUpdated, which should detect that the item
861 // changed while it was being added and call UpdateDownload immediately. 865 // changed while it was being added and call UpdateDownload immediately.
862 info.opened = true; 866 info.opened = true;
863 ExpectDownloadUpdated(info); 867 ExpectDownloadUpdated(info);
864 } 868 }
865 869
866 } // anonymous namespace 870 } // anonymous namespace
OLDNEW
« no previous file with comments | « chrome/browser/download/download_history.cc ('k') | chrome/browser/download/download_ui_controller_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698