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