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

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

Powered by Google App Engine
This is Rietveld 408576698