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

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

Issue 102683004: Add mime type information to the download database (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Review fixes Created 7 years 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 <set>
6 #include <vector> 5 #include <vector>
7 6
8 #include "base/rand_util.h" 7 #include "base/rand_util.h"
9 #include "base/stl_util.h" 8 #include "base/stl_util.h"
10 #include "chrome/browser/download/download_history.h" 9 #include "chrome/browser/download/download_history.h"
11 #include "chrome/browser/history/download_database.h" 10 #include "chrome/browser/history/download_database.h"
12 #include "chrome/browser/history/download_row.h" 11 #include "chrome/browser/history/download_row.h"
13 #include "chrome/browser/history/history_service.h" 12 #include "chrome/browser/history/history_service.h"
14 #include "content/public/test/mock_download_item.h" 13 #include "content/public/test/mock_download_item.h"
15 #include "content/public/test/mock_download_manager.h" 14 #include "content/public/test/mock_download_manager.h"
(...skipping 19 matching lines...) Expand all
35 const history::DownloadRow& right) { 34 const history::DownloadRow& right) {
36 EXPECT_EQ(left.current_path.value(), right.current_path.value()); 35 EXPECT_EQ(left.current_path.value(), right.current_path.value());
37 EXPECT_EQ(left.target_path.value(), right.target_path.value()); 36 EXPECT_EQ(left.target_path.value(), right.target_path.value());
38 EXPECT_EQ(left.url_chain.size(), right.url_chain.size()); 37 EXPECT_EQ(left.url_chain.size(), right.url_chain.size());
39 for (unsigned int i = 0; 38 for (unsigned int i = 0;
40 i < left.url_chain.size() && i < right.url_chain.size(); 39 i < left.url_chain.size() && i < right.url_chain.size();
41 ++i) { 40 ++i) {
42 EXPECT_EQ(left.url_chain[i].spec(), right.url_chain[i].spec()); 41 EXPECT_EQ(left.url_chain[i].spec(), right.url_chain[i].spec());
43 } 42 }
44 EXPECT_EQ(left.referrer_url.spec(), right.referrer_url.spec()); 43 EXPECT_EQ(left.referrer_url.spec(), right.referrer_url.spec());
44 EXPECT_EQ(left.mime_type, right.mime_type);
45 EXPECT_EQ(left.original_mime_type, right.original_mime_type);
45 EXPECT_EQ(left.start_time.ToTimeT(), right.start_time.ToTimeT()); 46 EXPECT_EQ(left.start_time.ToTimeT(), right.start_time.ToTimeT());
46 EXPECT_EQ(left.end_time.ToTimeT(), right.end_time.ToTimeT()); 47 EXPECT_EQ(left.end_time.ToTimeT(), right.end_time.ToTimeT());
47 EXPECT_EQ(left.etag, right.etag); 48 EXPECT_EQ(left.etag, right.etag);
48 EXPECT_EQ(left.last_modified, right.last_modified); 49 EXPECT_EQ(left.last_modified, right.last_modified);
49 EXPECT_EQ(left.received_bytes, right.received_bytes); 50 EXPECT_EQ(left.received_bytes, right.received_bytes);
50 EXPECT_EQ(left.total_bytes, right.total_bytes); 51 EXPECT_EQ(left.total_bytes, right.total_bytes);
51 EXPECT_EQ(left.state, right.state); 52 EXPECT_EQ(left.state, right.state);
52 EXPECT_EQ(left.danger_type, right.danger_type); 53 EXPECT_EQ(left.danger_type, right.danger_type);
53 EXPECT_EQ(left.id, right.id); 54 EXPECT_EQ(left.id, right.id);
54 EXPECT_EQ(left.opened, right.opened); 55 EXPECT_EQ(left.opened, right.opened);
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 this, &DownloadHistoryTest::SetManagerObserver))); 237 this, &DownloadHistoryTest::SetManagerObserver)));
237 EXPECT_CALL(manager(), RemoveObserver(_)); 238 EXPECT_CALL(manager(), RemoveObserver(_));
238 download_created_index_ = 0; 239 download_created_index_ = 0;
239 for (size_t index = 0; index < infos->size(); ++index) { 240 for (size_t index = 0; index < infos->size(); ++index) {
240 content::MockDownloadManager::CreateDownloadItemAdapter adapter( 241 content::MockDownloadManager::CreateDownloadItemAdapter adapter(
241 infos->at(index).id, 242 infos->at(index).id,
242 infos->at(index).current_path, 243 infos->at(index).current_path,
243 infos->at(index).target_path, 244 infos->at(index).target_path,
244 infos->at(index).url_chain, 245 infos->at(index).url_chain,
245 infos->at(index).referrer_url, 246 infos->at(index).referrer_url,
247 infos->at(index).mime_type,
248 infos->at(index).original_mime_type,
246 infos->at(index).start_time, 249 infos->at(index).start_time,
247 infos->at(index).end_time, 250 infos->at(index).end_time,
248 infos->at(index).etag, 251 infos->at(index).etag,
249 infos->at(index).last_modified, 252 infos->at(index).last_modified,
250 infos->at(index).received_bytes, 253 infos->at(index).received_bytes,
251 infos->at(index).total_bytes, 254 infos->at(index).total_bytes,
252 infos->at(index).state, 255 infos->at(index).state,
253 infos->at(index).danger_type, 256 infos->at(index).danger_type,
254 infos->at(index).interrupt_reason, 257 infos->at(index).interrupt_reason,
255 infos->at(index).opened); 258 infos->at(index).opened);
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 history::DownloadRow* info) { 336 history::DownloadRow* info) {
334 GURL url(url_string); 337 GURL url(url_string);
335 GURL referrer(referrer_string); 338 GURL referrer(referrer_string);
336 std::vector<GURL> url_chain; 339 std::vector<GURL> url_chain;
337 url_chain.push_back(url); 340 url_chain.push_back(url);
338 InitItem(static_cast<uint32>(items_.size() + 1), 341 InitItem(static_cast<uint32>(items_.size() + 1),
339 base::FilePath(path), 342 base::FilePath(path),
340 base::FilePath(path), 343 base::FilePath(path),
341 url_chain, 344 url_chain,
342 referrer, 345 referrer,
346 "application/octet-stream",
347 "application/octet-stream",
343 (base::Time::Now() - base::TimeDelta::FromMinutes(10)), 348 (base::Time::Now() - base::TimeDelta::FromMinutes(10)),
344 (base::Time::Now() - base::TimeDelta::FromMinutes(1)), 349 (base::Time::Now() - base::TimeDelta::FromMinutes(1)),
345 "Etag", 350 "Etag",
346 "abc", 351 "abc",
347 100, 352 100,
348 100, 353 100,
349 content::DownloadItem::COMPLETE, 354 content::DownloadItem::COMPLETE,
350 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, 355 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS,
351 content::DOWNLOAD_INTERRUPT_REASON_NONE, 356 content::DOWNLOAD_INTERRUPT_REASON_NONE,
352 false, 357 false,
353 std::string(), 358 std::string(),
354 std::string(), 359 std::string(),
355 info); 360 info);
356 } 361 }
357 362
358 void InitItem( 363 void InitItem(
359 uint32 id, 364 uint32 id,
360 const base::FilePath& current_path, 365 const base::FilePath& current_path,
361 const base::FilePath& target_path, 366 const base::FilePath& target_path,
362 const std::vector<GURL>& url_chain, 367 const std::vector<GURL>& url_chain,
363 const GURL& referrer, 368 const GURL& referrer,
369 const std::string& mime_type,
370 const std::string& original_mime_type,
364 const base::Time& start_time, 371 const base::Time& start_time,
365 const base::Time& end_time, 372 const base::Time& end_time,
366 const std::string& etag, 373 const std::string& etag,
367 const std::string& last_modified, 374 const std::string& last_modified,
368 int64 received_bytes, 375 int64 received_bytes,
369 int64 total_bytes, 376 int64 total_bytes,
370 content::DownloadItem::DownloadState state, 377 content::DownloadItem::DownloadState state,
371 content::DownloadDangerType danger_type, 378 content::DownloadDangerType danger_type,
372 content::DownloadInterruptReason interrupt_reason, 379 content::DownloadInterruptReason interrupt_reason,
373 bool opened, 380 bool opened,
374 const std::string& by_extension_id, 381 const std::string& by_extension_id,
375 const std::string& by_extension_name, 382 const std::string& by_extension_name,
376 history::DownloadRow* info) { 383 history::DownloadRow* info) {
377 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 384 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
378 385
379 size_t index = items_.size(); 386 size_t index = items_.size();
380 StrictMockDownloadItem* mock_item = new StrictMockDownloadItem(); 387 StrictMockDownloadItem* mock_item = new StrictMockDownloadItem();
381 items_.push_back(mock_item); 388 items_.push_back(mock_item);
382 389
383 info->current_path = current_path; 390 info->current_path = current_path;
384 info->target_path = target_path; 391 info->target_path = target_path;
385 info->url_chain = url_chain; 392 info->url_chain = url_chain;
386 info->referrer_url = referrer; 393 info->referrer_url = referrer;
394 info->mime_type = mime_type;
395 info->original_mime_type = original_mime_type;
387 info->start_time = start_time; 396 info->start_time = start_time;
388 info->end_time = end_time; 397 info->end_time = end_time;
389 info->etag = etag; 398 info->etag = etag;
390 info->last_modified = last_modified; 399 info->last_modified = last_modified;
391 info->received_bytes = received_bytes; 400 info->received_bytes = received_bytes;
392 info->total_bytes = total_bytes; 401 info->total_bytes = total_bytes;
393 info->state = state; 402 info->state = state;
394 info->danger_type = danger_type; 403 info->danger_type = danger_type;
395 info->interrupt_reason = interrupt_reason; 404 info->interrupt_reason = interrupt_reason;
396 info->id = id; 405 info->id = id;
397 info->opened = opened; 406 info->opened = opened;
398 info->by_ext_id = by_extension_id; 407 info->by_ext_id = by_extension_id;
399 info->by_ext_name = by_extension_name; 408 info->by_ext_name = by_extension_name;
400 409
401 EXPECT_CALL(item(index), GetId()).WillRepeatedly(Return(id)); 410 EXPECT_CALL(item(index), GetId()).WillRepeatedly(Return(id));
402 EXPECT_CALL(item(index), GetFullPath()) 411 EXPECT_CALL(item(index), GetFullPath())
403 .WillRepeatedly(ReturnRefOfCopy(current_path)); 412 .WillRepeatedly(ReturnRefOfCopy(current_path));
404 EXPECT_CALL(item(index), GetTargetFilePath()) 413 EXPECT_CALL(item(index), GetTargetFilePath())
405 .WillRepeatedly(ReturnRefOfCopy(target_path)); 414 .WillRepeatedly(ReturnRefOfCopy(target_path));
406 DCHECK_LE(1u, url_chain.size()); 415 DCHECK_LE(1u, url_chain.size());
407 EXPECT_CALL(item(index), GetURL()) 416 EXPECT_CALL(item(index), GetURL())
408 .WillRepeatedly(ReturnRefOfCopy(url_chain[0])); 417 .WillRepeatedly(ReturnRefOfCopy(url_chain[0]));
409 EXPECT_CALL(item(index), GetUrlChain()) 418 EXPECT_CALL(item(index), GetUrlChain())
410 .WillRepeatedly(ReturnRefOfCopy(url_chain)); 419 .WillRepeatedly(ReturnRefOfCopy(url_chain));
411 EXPECT_CALL(item(index), GetMimeType()) 420 EXPECT_CALL(item(index), GetMimeType()).WillRepeatedly(Return(mime_type));
412 .WillRepeatedly(Return("application/octet-stream")); 421 EXPECT_CALL(item(index), GetOriginalMimeType()).WillRepeatedly(Return(
422 original_mime_type));
413 EXPECT_CALL(item(index), GetReferrerUrl()) 423 EXPECT_CALL(item(index), GetReferrerUrl())
414 .WillRepeatedly(ReturnRefOfCopy(referrer)); 424 .WillRepeatedly(ReturnRefOfCopy(referrer));
415 EXPECT_CALL(item(index), GetStartTime()).WillRepeatedly(Return(start_time)); 425 EXPECT_CALL(item(index), GetStartTime()).WillRepeatedly(Return(start_time));
416 EXPECT_CALL(item(index), GetEndTime()).WillRepeatedly(Return(end_time)); 426 EXPECT_CALL(item(index), GetEndTime()).WillRepeatedly(Return(end_time));
417 EXPECT_CALL(item(index), GetETag()).WillRepeatedly(ReturnRefOfCopy(etag)); 427 EXPECT_CALL(item(index), GetETag()).WillRepeatedly(ReturnRefOfCopy(etag));
418 EXPECT_CALL(item(index), GetLastModifiedTime()) 428 EXPECT_CALL(item(index), GetLastModifiedTime())
419 .WillRepeatedly(ReturnRefOfCopy(last_modified)); 429 .WillRepeatedly(ReturnRefOfCopy(last_modified));
420 EXPECT_CALL(item(index), GetReceivedBytes()) 430 EXPECT_CALL(item(index), GetReceivedBytes())
421 .WillRepeatedly(Return(received_bytes)); 431 .WillRepeatedly(Return(received_bytes));
422 EXPECT_CALL(item(index), GetTotalBytes()) 432 EXPECT_CALL(item(index), GetTotalBytes())
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after
787 item_observer()->OnDownloadUpdated(&item(0)); 797 item_observer()->OnDownloadUpdated(&item(0));
788 798
789 FinishCreateDownload(); 799 FinishCreateDownload();
790 EXPECT_TRUE(DownloadHistory::IsPersisted(&item(0))); 800 EXPECT_TRUE(DownloadHistory::IsPersisted(&item(0)));
791 801
792 // ItemAdded should call OnDownloadUpdated, which should detect that the item 802 // ItemAdded should call OnDownloadUpdated, which should detect that the item
793 // changed while it was being added and call UpdateDownload immediately. 803 // changed while it was being added and call UpdateDownload immediately.
794 info.opened = true; 804 info.opened = true;
795 ExpectDownloadUpdated(info); 805 ExpectDownloadUpdated(info);
796 } 806 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698