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

Side by Side Diff: content/browser/download/download_item_impl_unittest.cc

Issue 2811293004: Fix an issue that we didn't clean url request properly. (Closed)
Patch Set: Fixed compiling for unit tests. Created 3 years, 8 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 "content/browser/download/download_item_impl.h" 5 #include "content/browser/download/download_item_impl.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <deque> 9 #include <deque>
10 #include <iterator> 10 #include <iterator>
(...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after
425 // set_* mutators 425 // set_* mutators
426 426
427 TEST_F(DownloadItemTest, NotificationAfterUpdate) { 427 TEST_F(DownloadItemTest, NotificationAfterUpdate) {
428 DownloadItemImpl* item = CreateDownloadItem(); 428 DownloadItemImpl* item = CreateDownloadItem();
429 MockDownloadFile* file = 429 MockDownloadFile* file =
430 DoIntermediateRename(item, DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS); 430 DoIntermediateRename(item, DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS);
431 ASSERT_EQ(DownloadItem::IN_PROGRESS, item->GetState()); 431 ASSERT_EQ(DownloadItem::IN_PROGRESS, item->GetState());
432 TestDownloadItemObserver observer(item); 432 TestDownloadItemObserver observer(item);
433 433
434 item->DestinationUpdate(kDownloadChunkSize, kDownloadSpeed, 434 item->DestinationUpdate(kDownloadChunkSize, kDownloadSpeed,
435 std::vector<DownloadItem::ReceivedSlice>()); 435 std::vector<DownloadItem::ReceivedSlice>(),
436 std::unordered_set<int64_t>());
436 ASSERT_TRUE(observer.CheckAndResetDownloadUpdated()); 437 ASSERT_TRUE(observer.CheckAndResetDownloadUpdated());
437 EXPECT_EQ(kDownloadSpeed, item->CurrentSpeed()); 438 EXPECT_EQ(kDownloadSpeed, item->CurrentSpeed());
438 CleanupItem(item, file, DownloadItem::IN_PROGRESS); 439 CleanupItem(item, file, DownloadItem::IN_PROGRESS);
439 } 440 }
440 441
441 TEST_F(DownloadItemTest, NotificationAfterCancel) { 442 TEST_F(DownloadItemTest, NotificationAfterCancel) {
442 DownloadItemImpl* user_cancel = CreateDownloadItem(); 443 DownloadItemImpl* user_cancel = CreateDownloadItem();
443 DownloadTargetCallback target_callback; 444 DownloadTargetCallback target_callback;
444 MockDownloadFile* download_file = 445 MockDownloadFile* download_file =
445 CallDownloadItemStart(user_cancel, &target_callback); 446 CallDownloadItemStart(user_cancel, &target_callback);
(...skipping 526 matching lines...) Expand 10 before | Expand all | Expand 10 after
972 DownloadItem::ReceivedSlice(0, 10)}; 973 DownloadItem::ReceivedSlice(0, 10)};
973 create_info()->etag = kFirstETag; 974 create_info()->etag = kFirstETag;
974 975
975 DownloadItemImpl* item = CreateDownloadItem(); 976 DownloadItemImpl* item = CreateDownloadItem();
976 MockDownloadFile* download_file = 977 MockDownloadFile* download_file =
977 DoIntermediateRename(item, DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS); 978 DoIntermediateRename(item, DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS);
978 979
979 EXPECT_CALL(*mock_delegate(), MockResumeInterruptedDownload(_, _)); 980 EXPECT_CALL(*mock_delegate(), MockResumeInterruptedDownload(_, _));
980 EXPECT_CALL(*download_file, Detach()); 981 EXPECT_CALL(*download_file, Detach());
981 982
982 item->DestinationObserverAsWeakPtr()->DestinationUpdate(10, 100, 983 item->DestinationObserverAsWeakPtr()->DestinationUpdate(
983 kReceivedSlice); 984 10, 100, kReceivedSlice, std::unordered_set<int64_t>());
984 EXPECT_EQ(kReceivedSlice, item->GetReceivedSlices()); 985 EXPECT_EQ(kReceivedSlice, item->GetReceivedSlices());
985 EXPECT_EQ(10, item->GetReceivedBytes()); 986 EXPECT_EQ(10, item->GetReceivedBytes());
986 987
987 item->DestinationObserverAsWeakPtr()->DestinationError( 988 item->DestinationObserverAsWeakPtr()->DestinationError(
988 DOWNLOAD_INTERRUPT_REASON_FILE_TRANSIENT_ERROR, 0, 989 DOWNLOAD_INTERRUPT_REASON_FILE_TRANSIENT_ERROR, 0,
989 std::unique_ptr<crypto::SecureHash>()); 990 std::unique_ptr<crypto::SecureHash>());
990 EXPECT_EQ(kReceivedSlice, item->GetReceivedSlices()); 991 EXPECT_EQ(kReceivedSlice, item->GetReceivedSlices());
991 992
992 RunAllPendingInMessageLoops(); 993 RunAllPendingInMessageLoops();
993 994
(...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after
1398 1399
1399 EXPECT_EQ(0l, item->CurrentSpeed()); 1400 EXPECT_EQ(0l, item->CurrentSpeed());
1400 EXPECT_EQ(0l, item->GetReceivedBytes()); 1401 EXPECT_EQ(0l, item->GetReceivedBytes());
1401 EXPECT_EQ(0l, item->GetTotalBytes()); 1402 EXPECT_EQ(0l, item->GetTotalBytes());
1402 EXPECT_FALSE(observer.CheckAndResetDownloadUpdated()); 1403 EXPECT_FALSE(observer.CheckAndResetDownloadUpdated());
1403 item->SetTotalBytes(100l); 1404 item->SetTotalBytes(100l);
1404 EXPECT_EQ(100l, item->GetTotalBytes()); 1405 EXPECT_EQ(100l, item->GetTotalBytes());
1405 1406
1406 std::vector<DownloadItem::ReceivedSlice> received_slices; 1407 std::vector<DownloadItem::ReceivedSlice> received_slices;
1407 received_slices.emplace_back(0, 10); 1408 received_slices.emplace_back(0, 10);
1408 as_observer->DestinationUpdate(10, 20, received_slices); 1409 as_observer->DestinationUpdate(10, 20, received_slices,
1410 std::unordered_set<int64_t>());
1409 EXPECT_EQ(20l, item->CurrentSpeed()); 1411 EXPECT_EQ(20l, item->CurrentSpeed());
1410 EXPECT_EQ(10l, item->GetReceivedBytes()); 1412 EXPECT_EQ(10l, item->GetReceivedBytes());
1411 EXPECT_EQ(100l, item->GetTotalBytes()); 1413 EXPECT_EQ(100l, item->GetTotalBytes());
1412 EXPECT_EQ(received_slices, item->GetReceivedSlices()); 1414 EXPECT_EQ(received_slices, item->GetReceivedSlices());
1413 EXPECT_TRUE(observer.CheckAndResetDownloadUpdated()); 1415 EXPECT_TRUE(observer.CheckAndResetDownloadUpdated());
1414 1416
1415 received_slices.emplace_back(200, 100); 1417 received_slices.emplace_back(200, 100);
1416 as_observer->DestinationUpdate(200, 20, received_slices); 1418 as_observer->DestinationUpdate(200, 20, received_slices,
1419 std::unordered_set<int64_t>());
1417 EXPECT_EQ(20l, item->CurrentSpeed()); 1420 EXPECT_EQ(20l, item->CurrentSpeed());
1418 EXPECT_EQ(200l, item->GetReceivedBytes()); 1421 EXPECT_EQ(200l, item->GetReceivedBytes());
1419 EXPECT_EQ(0l, item->GetTotalBytes()); 1422 EXPECT_EQ(0l, item->GetTotalBytes());
1420 EXPECT_EQ(received_slices, item->GetReceivedSlices()); 1423 EXPECT_EQ(received_slices, item->GetReceivedSlices());
1421 EXPECT_TRUE(observer.CheckAndResetDownloadUpdated()); 1424 EXPECT_TRUE(observer.CheckAndResetDownloadUpdated());
1422 1425
1423 CleanupItem(item, file, DownloadItem::IN_PROGRESS); 1426 CleanupItem(item, file, DownloadItem::IN_PROGRESS);
1424 } 1427 }
1425 1428
1426 TEST_F(DownloadItemTest, DestinationError_NoRestartRequired) { 1429 TEST_F(DownloadItemTest, DestinationError_NoRestartRequired) {
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
1483 DoIntermediateRename(item, DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS); 1486 DoIntermediateRename(item, DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS);
1484 base::WeakPtr<DownloadDestinationObserver> as_observer( 1487 base::WeakPtr<DownloadDestinationObserver> as_observer(
1485 item->DestinationObserverAsWeakPtr()); 1488 item->DestinationObserverAsWeakPtr());
1486 TestDownloadItemObserver observer(item); 1489 TestDownloadItemObserver observer(item);
1487 1490
1488 EXPECT_EQ(DownloadItem::IN_PROGRESS, item->GetState()); 1491 EXPECT_EQ(DownloadItem::IN_PROGRESS, item->GetState());
1489 EXPECT_EQ("", item->GetHash()); 1492 EXPECT_EQ("", item->GetHash());
1490 EXPECT_FALSE(item->AllDataSaved()); 1493 EXPECT_FALSE(item->AllDataSaved());
1491 EXPECT_FALSE(observer.CheckAndResetDownloadUpdated()); 1494 EXPECT_FALSE(observer.CheckAndResetDownloadUpdated());
1492 1495
1493 as_observer->DestinationUpdate( 1496 as_observer->DestinationUpdate(10, 20,
1494 10, 20, std::vector<DownloadItem::ReceivedSlice>()); 1497 std::vector<DownloadItem::ReceivedSlice>(),
1498 std::unordered_set<int64_t>());
1495 EXPECT_TRUE(observer.CheckAndResetDownloadUpdated()); 1499 EXPECT_TRUE(observer.CheckAndResetDownloadUpdated());
1496 EXPECT_FALSE(observer.CheckAndResetDownloadUpdated()); // Confirm reset. 1500 EXPECT_FALSE(observer.CheckAndResetDownloadUpdated()); // Confirm reset.
1497 EXPECT_EQ(DownloadItem::IN_PROGRESS, item->GetState()); 1501 EXPECT_EQ(DownloadItem::IN_PROGRESS, item->GetState());
1498 EXPECT_EQ("", item->GetHash()); 1502 EXPECT_EQ("", item->GetHash());
1499 EXPECT_FALSE(item->AllDataSaved()); 1503 EXPECT_FALSE(item->AllDataSaved());
1500 1504
1501 std::unique_ptr<crypto::SecureHash> hash( 1505 std::unique_ptr<crypto::SecureHash> hash(
1502 crypto::SecureHash::Create(crypto::SecureHash::SHA256)); 1506 crypto::SecureHash::Create(crypto::SecureHash::SHA256));
1503 hash->Update(kTestData1, sizeof(kTestData1)); 1507 hash->Update(kTestData1, sizeof(kTestData1));
1504 1508
(...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after
1941 // Chromium doesn't allow using std::bind for good reasons. 1945 // Chromium doesn't allow using std::bind for good reasons.
1942 void DestinationUpdateInvoker( 1946 void DestinationUpdateInvoker(
1943 int64_t bytes_so_far, 1947 int64_t bytes_so_far,
1944 int64_t bytes_per_sec, 1948 int64_t bytes_per_sec,
1945 base::WeakPtr<DownloadDestinationObserver> observer) { 1949 base::WeakPtr<DownloadDestinationObserver> observer) {
1946 DVLOG(20) << "DestinationUpdate(bytes_so_far:" << bytes_so_far 1950 DVLOG(20) << "DestinationUpdate(bytes_so_far:" << bytes_so_far
1947 << ", bytes_per_sec:" << bytes_per_sec 1951 << ", bytes_per_sec:" << bytes_per_sec
1948 << ") observer:" << !!observer; 1952 << ") observer:" << !!observer;
1949 if (observer) { 1953 if (observer) {
1950 observer->DestinationUpdate(bytes_so_far, bytes_per_sec, 1954 observer->DestinationUpdate(bytes_so_far, bytes_per_sec,
1951 std::vector<DownloadItem::ReceivedSlice>()); 1955 std::vector<DownloadItem::ReceivedSlice>(),
1956 std::unordered_set<int64_t>());
1952 } 1957 }
1953 } 1958 }
1954 1959
1955 void DestinationErrorInvoker( 1960 void DestinationErrorInvoker(
1956 DownloadInterruptReason reason, 1961 DownloadInterruptReason reason,
1957 int64_t bytes_so_far, 1962 int64_t bytes_so_far,
1958 base::WeakPtr<DownloadDestinationObserver> observer) { 1963 base::WeakPtr<DownloadDestinationObserver> observer) {
1959 DVLOG(20) << "DestinationError(reason:" 1964 DVLOG(20) << "DestinationError(reason:"
1960 << DownloadInterruptReasonToString(reason) 1965 << DownloadInterruptReasonToString(reason)
1961 << ", bytes_so_far:" << bytes_so_far << ") observer:" << !!observer; 1966 << ", bytes_so_far:" << bytes_so_far << ") observer:" << !!observer;
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after
2293 2298
2294 item_->Cancel(true); 2299 item_->Cancel(true);
2295 RunAllPendingInMessageLoops(); 2300 RunAllPendingInMessageLoops();
2296 } 2301 }
2297 2302
2298 TEST(MockDownloadItem, Compiles) { 2303 TEST(MockDownloadItem, Compiles) {
2299 MockDownloadItem mock_item; 2304 MockDownloadItem mock_item;
2300 } 2305 }
2301 2306
2302 } // namespace content 2307 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698