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

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: Fix unit tests and move download_database.{cc,h} 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_database.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 static_cast<uint32>(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 = static_cast<history::DownloadId>(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 435 matching lines...) Expand 10 before | Expand all | Expand 10 after
857 FinishCreateDownload(); 860 FinishCreateDownload();
858 EXPECT_TRUE(DownloadHistory::IsPersisted(&item(0))); 861 EXPECT_TRUE(DownloadHistory::IsPersisted(&item(0)));
859 862
860 // ItemAdded should call OnDownloadUpdated, which should detect that the item 863 // ItemAdded should call OnDownloadUpdated, which should detect that the item
861 // changed while it was being added and call UpdateDownload immediately. 864 // changed while it was being added and call UpdateDownload immediately.
862 info.opened = true; 865 info.opened = true;
863 ExpectDownloadUpdated(info); 866 ExpectDownloadUpdated(info);
864 } 867 }
865 868
866 } // anonymous namespace 869 } // anonymous namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698