| 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> | |
| 6 #include <vector> | 5 #include <vector> |
| 7 | 6 |
| 8 #include "base/memory/weak_ptr.h" | 7 #include "base/memory/weak_ptr.h" |
| 9 #include "base/rand_util.h" | 8 #include "base/rand_util.h" |
| 10 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
| 11 #include "chrome/browser/download/download_history.h" | 10 #include "chrome/browser/download/download_history.h" |
| 12 #include "chrome/browser/history/download_database.h" | 11 #include "chrome/browser/history/download_database.h" |
| 13 #include "chrome/browser/history/download_row.h" | 12 #include "chrome/browser/history/download_row.h" |
| 14 #include "chrome/browser/history/history_service.h" | 13 #include "chrome/browser/history/history_service.h" |
| 15 #include "content/public/test/mock_download_item.h" | 14 #include "content/public/test/mock_download_item.h" |
| (...skipping 20 matching lines...) Expand all Loading... |
| 36 const history::DownloadRow& right) { | 35 const history::DownloadRow& right) { |
| 37 EXPECT_EQ(left.current_path.value(), right.current_path.value()); | 36 EXPECT_EQ(left.current_path.value(), right.current_path.value()); |
| 38 EXPECT_EQ(left.target_path.value(), right.target_path.value()); | 37 EXPECT_EQ(left.target_path.value(), right.target_path.value()); |
| 39 EXPECT_EQ(left.url_chain.size(), right.url_chain.size()); | 38 EXPECT_EQ(left.url_chain.size(), right.url_chain.size()); |
| 40 for (unsigned int i = 0; | 39 for (unsigned int i = 0; |
| 41 i < left.url_chain.size() && i < right.url_chain.size(); | 40 i < left.url_chain.size() && i < right.url_chain.size(); |
| 42 ++i) { | 41 ++i) { |
| 43 EXPECT_EQ(left.url_chain[i].spec(), right.url_chain[i].spec()); | 42 EXPECT_EQ(left.url_chain[i].spec(), right.url_chain[i].spec()); |
| 44 } | 43 } |
| 45 EXPECT_EQ(left.referrer_url.spec(), right.referrer_url.spec()); | 44 EXPECT_EQ(left.referrer_url.spec(), right.referrer_url.spec()); |
| 45 EXPECT_EQ(left.mime_type, right.mime_type); |
| 46 EXPECT_EQ(left.original_mime_type, right.original_mime_type); |
| 46 EXPECT_EQ(left.start_time.ToTimeT(), right.start_time.ToTimeT()); | 47 EXPECT_EQ(left.start_time.ToTimeT(), right.start_time.ToTimeT()); |
| 47 EXPECT_EQ(left.end_time.ToTimeT(), right.end_time.ToTimeT()); | 48 EXPECT_EQ(left.end_time.ToTimeT(), right.end_time.ToTimeT()); |
| 48 EXPECT_EQ(left.etag, right.etag); | 49 EXPECT_EQ(left.etag, right.etag); |
| 49 EXPECT_EQ(left.last_modified, right.last_modified); | 50 EXPECT_EQ(left.last_modified, right.last_modified); |
| 50 EXPECT_EQ(left.received_bytes, right.received_bytes); | 51 EXPECT_EQ(left.received_bytes, right.received_bytes); |
| 51 EXPECT_EQ(left.total_bytes, right.total_bytes); | 52 EXPECT_EQ(left.total_bytes, right.total_bytes); |
| 52 EXPECT_EQ(left.state, right.state); | 53 EXPECT_EQ(left.state, right.state); |
| 53 EXPECT_EQ(left.danger_type, right.danger_type); | 54 EXPECT_EQ(left.danger_type, right.danger_type); |
| 54 EXPECT_EQ(left.id, right.id); | 55 EXPECT_EQ(left.id, right.id); |
| 55 EXPECT_EQ(left.opened, right.opened); | 56 EXPECT_EQ(left.opened, right.opened); |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 this, &DownloadHistoryTest::SetManagerObserver))); | 232 this, &DownloadHistoryTest::SetManagerObserver))); |
| 232 EXPECT_CALL(manager(), RemoveObserver(_)); | 233 EXPECT_CALL(manager(), RemoveObserver(_)); |
| 233 download_created_index_ = 0; | 234 download_created_index_ = 0; |
| 234 for (size_t index = 0; index < infos->size(); ++index) { | 235 for (size_t index = 0; index < infos->size(); ++index) { |
| 235 content::MockDownloadManager::CreateDownloadItemAdapter adapter( | 236 content::MockDownloadManager::CreateDownloadItemAdapter adapter( |
| 236 infos->at(index).id, | 237 infos->at(index).id, |
| 237 infos->at(index).current_path, | 238 infos->at(index).current_path, |
| 238 infos->at(index).target_path, | 239 infos->at(index).target_path, |
| 239 infos->at(index).url_chain, | 240 infos->at(index).url_chain, |
| 240 infos->at(index).referrer_url, | 241 infos->at(index).referrer_url, |
| 242 infos->at(index).mime_type, |
| 243 infos->at(index).original_mime_type, |
| 241 infos->at(index).start_time, | 244 infos->at(index).start_time, |
| 242 infos->at(index).end_time, | 245 infos->at(index).end_time, |
| 243 infos->at(index).etag, | 246 infos->at(index).etag, |
| 244 infos->at(index).last_modified, | 247 infos->at(index).last_modified, |
| 245 infos->at(index).received_bytes, | 248 infos->at(index).received_bytes, |
| 246 infos->at(index).total_bytes, | 249 infos->at(index).total_bytes, |
| 247 infos->at(index).state, | 250 infos->at(index).state, |
| 248 infos->at(index).danger_type, | 251 infos->at(index).danger_type, |
| 249 infos->at(index).interrupt_reason, | 252 infos->at(index).interrupt_reason, |
| 250 infos->at(index).opened); | 253 infos->at(index).opened); |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 344 history::DownloadRow* info) { | 347 history::DownloadRow* info) { |
| 345 GURL url(url_string); | 348 GURL url(url_string); |
| 346 GURL referrer(referrer_string); | 349 GURL referrer(referrer_string); |
| 347 std::vector<GURL> url_chain; | 350 std::vector<GURL> url_chain; |
| 348 url_chain.push_back(url); | 351 url_chain.push_back(url); |
| 349 InitItem(static_cast<uint32>(items_.size() + 1), | 352 InitItem(static_cast<uint32>(items_.size() + 1), |
| 350 base::FilePath(path), | 353 base::FilePath(path), |
| 351 base::FilePath(path), | 354 base::FilePath(path), |
| 352 url_chain, | 355 url_chain, |
| 353 referrer, | 356 referrer, |
| 357 "application/octet-stream", |
| 358 "application/octet-stream", |
| 354 (base::Time::Now() - base::TimeDelta::FromMinutes(10)), | 359 (base::Time::Now() - base::TimeDelta::FromMinutes(10)), |
| 355 (base::Time::Now() - base::TimeDelta::FromMinutes(1)), | 360 (base::Time::Now() - base::TimeDelta::FromMinutes(1)), |
| 356 "Etag", | 361 "Etag", |
| 357 "abc", | 362 "abc", |
| 358 100, | 363 100, |
| 359 100, | 364 100, |
| 360 content::DownloadItem::COMPLETE, | 365 content::DownloadItem::COMPLETE, |
| 361 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, | 366 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, |
| 362 content::DOWNLOAD_INTERRUPT_REASON_NONE, | 367 content::DOWNLOAD_INTERRUPT_REASON_NONE, |
| 363 false, | 368 false, |
| 364 std::string(), | 369 std::string(), |
| 365 std::string(), | 370 std::string(), |
| 366 info); | 371 info); |
| 367 } | 372 } |
| 368 | 373 |
| 369 void InitItem( | 374 void InitItem( |
| 370 uint32 id, | 375 uint32 id, |
| 371 const base::FilePath& current_path, | 376 const base::FilePath& current_path, |
| 372 const base::FilePath& target_path, | 377 const base::FilePath& target_path, |
| 373 const std::vector<GURL>& url_chain, | 378 const std::vector<GURL>& url_chain, |
| 374 const GURL& referrer, | 379 const GURL& referrer, |
| 380 const std::string& mime_type, |
| 381 const std::string& original_mime_type, |
| 375 const base::Time& start_time, | 382 const base::Time& start_time, |
| 376 const base::Time& end_time, | 383 const base::Time& end_time, |
| 377 const std::string& etag, | 384 const std::string& etag, |
| 378 const std::string& last_modified, | 385 const std::string& last_modified, |
| 379 int64 received_bytes, | 386 int64 received_bytes, |
| 380 int64 total_bytes, | 387 int64 total_bytes, |
| 381 content::DownloadItem::DownloadState state, | 388 content::DownloadItem::DownloadState state, |
| 382 content::DownloadDangerType danger_type, | 389 content::DownloadDangerType danger_type, |
| 383 content::DownloadInterruptReason interrupt_reason, | 390 content::DownloadInterruptReason interrupt_reason, |
| 384 bool opened, | 391 bool opened, |
| 385 const std::string& by_extension_id, | 392 const std::string& by_extension_id, |
| 386 const std::string& by_extension_name, | 393 const std::string& by_extension_name, |
| 387 history::DownloadRow* info) { | 394 history::DownloadRow* info) { |
| 388 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 395 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 389 | 396 |
| 390 size_t index = items_.size(); | 397 size_t index = items_.size(); |
| 391 StrictMockDownloadItem* mock_item = new StrictMockDownloadItem(); | 398 StrictMockDownloadItem* mock_item = new StrictMockDownloadItem(); |
| 392 items_.push_back(mock_item); | 399 items_.push_back(mock_item); |
| 393 | 400 |
| 394 info->current_path = current_path; | 401 info->current_path = current_path; |
| 395 info->target_path = target_path; | 402 info->target_path = target_path; |
| 396 info->url_chain = url_chain; | 403 info->url_chain = url_chain; |
| 397 info->referrer_url = referrer; | 404 info->referrer_url = referrer; |
| 405 info->mime_type = mime_type; |
| 406 info->original_mime_type = original_mime_type; |
| 398 info->start_time = start_time; | 407 info->start_time = start_time; |
| 399 info->end_time = end_time; | 408 info->end_time = end_time; |
| 400 info->etag = etag; | 409 info->etag = etag; |
| 401 info->last_modified = last_modified; | 410 info->last_modified = last_modified; |
| 402 info->received_bytes = received_bytes; | 411 info->received_bytes = received_bytes; |
| 403 info->total_bytes = total_bytes; | 412 info->total_bytes = total_bytes; |
| 404 info->state = state; | 413 info->state = state; |
| 405 info->danger_type = danger_type; | 414 info->danger_type = danger_type; |
| 406 info->interrupt_reason = interrupt_reason; | 415 info->interrupt_reason = interrupt_reason; |
| 407 info->id = id; | 416 info->id = id; |
| 408 info->opened = opened; | 417 info->opened = opened; |
| 409 info->by_ext_id = by_extension_id; | 418 info->by_ext_id = by_extension_id; |
| 410 info->by_ext_name = by_extension_name; | 419 info->by_ext_name = by_extension_name; |
| 411 | 420 |
| 412 EXPECT_CALL(item(index), GetId()).WillRepeatedly(Return(id)); | 421 EXPECT_CALL(item(index), GetId()).WillRepeatedly(Return(id)); |
| 413 EXPECT_CALL(item(index), GetFullPath()) | 422 EXPECT_CALL(item(index), GetFullPath()) |
| 414 .WillRepeatedly(ReturnRefOfCopy(current_path)); | 423 .WillRepeatedly(ReturnRefOfCopy(current_path)); |
| 415 EXPECT_CALL(item(index), GetTargetFilePath()) | 424 EXPECT_CALL(item(index), GetTargetFilePath()) |
| 416 .WillRepeatedly(ReturnRefOfCopy(target_path)); | 425 .WillRepeatedly(ReturnRefOfCopy(target_path)); |
| 417 DCHECK_LE(1u, url_chain.size()); | 426 DCHECK_LE(1u, url_chain.size()); |
| 418 EXPECT_CALL(item(index), GetURL()) | 427 EXPECT_CALL(item(index), GetURL()) |
| 419 .WillRepeatedly(ReturnRefOfCopy(url_chain[0])); | 428 .WillRepeatedly(ReturnRefOfCopy(url_chain[0])); |
| 420 EXPECT_CALL(item(index), GetUrlChain()) | 429 EXPECT_CALL(item(index), GetUrlChain()) |
| 421 .WillRepeatedly(ReturnRefOfCopy(url_chain)); | 430 .WillRepeatedly(ReturnRefOfCopy(url_chain)); |
| 422 EXPECT_CALL(item(index), GetMimeType()) | 431 EXPECT_CALL(item(index), GetMimeType()).WillRepeatedly(Return(mime_type)); |
| 423 .WillRepeatedly(Return("application/octet-stream")); | 432 EXPECT_CALL(item(index), GetOriginalMimeType()).WillRepeatedly(Return( |
| 433 original_mime_type)); |
| 424 EXPECT_CALL(item(index), GetReferrerUrl()) | 434 EXPECT_CALL(item(index), GetReferrerUrl()) |
| 425 .WillRepeatedly(ReturnRefOfCopy(referrer)); | 435 .WillRepeatedly(ReturnRefOfCopy(referrer)); |
| 426 EXPECT_CALL(item(index), GetStartTime()).WillRepeatedly(Return(start_time)); | 436 EXPECT_CALL(item(index), GetStartTime()).WillRepeatedly(Return(start_time)); |
| 427 EXPECT_CALL(item(index), GetEndTime()).WillRepeatedly(Return(end_time)); | 437 EXPECT_CALL(item(index), GetEndTime()).WillRepeatedly(Return(end_time)); |
| 428 EXPECT_CALL(item(index), GetETag()).WillRepeatedly(ReturnRefOfCopy(etag)); | 438 EXPECT_CALL(item(index), GetETag()).WillRepeatedly(ReturnRefOfCopy(etag)); |
| 429 EXPECT_CALL(item(index), GetLastModifiedTime()) | 439 EXPECT_CALL(item(index), GetLastModifiedTime()) |
| 430 .WillRepeatedly(ReturnRefOfCopy(last_modified)); | 440 .WillRepeatedly(ReturnRefOfCopy(last_modified)); |
| 431 EXPECT_CALL(item(index), GetReceivedBytes()) | 441 EXPECT_CALL(item(index), GetReceivedBytes()) |
| 432 .WillRepeatedly(Return(received_bytes)); | 442 .WillRepeatedly(Return(received_bytes)); |
| 433 EXPECT_CALL(item(index), GetTotalBytes()) | 443 EXPECT_CALL(item(index), GetTotalBytes()) |
| (...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 852 FinishCreateDownload(); | 862 FinishCreateDownload(); |
| 853 EXPECT_TRUE(DownloadHistory::IsPersisted(&item(0))); | 863 EXPECT_TRUE(DownloadHistory::IsPersisted(&item(0))); |
| 854 | 864 |
| 855 // ItemAdded should call OnDownloadUpdated, which should detect that the item | 865 // ItemAdded should call OnDownloadUpdated, which should detect that the item |
| 856 // changed while it was being added and call UpdateDownload immediately. | 866 // changed while it was being added and call UpdateDownload immediately. |
| 857 info.opened = true; | 867 info.opened = true; |
| 858 ExpectDownloadUpdated(info); | 868 ExpectDownloadUpdated(info); |
| 859 } | 869 } |
| 860 | 870 |
| 861 } // anonymous namespace | 871 } // anonymous namespace |
| OLD | NEW |