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

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

Issue 14697023: downloads: Improve download rate estimation. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Comment typo Created 7 years, 7 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 | Annotate | Revision Log
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/base_file.h" 5 #include "content/browser/download/base_file.h"
6 6
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/files/scoped_temp_dir.h" 8 #include "base/files/scoped_temp_dir.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/message_loop.h" 10 #include "base/message_loop.h"
(...skipping 594 matching lines...) Expand 10 before | Expand all | Expand 10 after
605 } 605 }
606 606
607 TEST_F(BaseFileTest, IsEmptyHash) { 607 TEST_F(BaseFileTest, IsEmptyHash) {
608 std::string empty(BaseFile::kSha256HashLen, '\x00'); 608 std::string empty(BaseFile::kSha256HashLen, '\x00');
609 EXPECT_TRUE(BaseFile::IsEmptyHash(empty)); 609 EXPECT_TRUE(BaseFile::IsEmptyHash(empty));
610 std::string not_empty(BaseFile::kSha256HashLen, '\x01'); 610 std::string not_empty(BaseFile::kSha256HashLen, '\x01');
611 EXPECT_FALSE(BaseFile::IsEmptyHash(not_empty)); 611 EXPECT_FALSE(BaseFile::IsEmptyHash(not_empty));
612 EXPECT_FALSE(BaseFile::IsEmptyHash(std::string())); 612 EXPECT_FALSE(BaseFile::IsEmptyHash(std::string()));
613 } 613 }
614 614
615 // Test that calculating speed after no writes.
616 TEST_F(BaseFileTest, SpeedWithoutWrite) {
617 ASSERT_TRUE(InitializeFile());
618 base::TimeTicks current = StartTick() + kElapsedTimeDelta;
619 ASSERT_EQ(0, CurrentSpeedAtTime(current));
620 base_file_->Finish();
621 }
622
623 // Test that calculating speed after a single write.
624 TEST_F(BaseFileTest, SpeedAfterSingleWrite) {
625 ASSERT_TRUE(InitializeFile());
626 ASSERT_TRUE(AppendDataToFile(kTestData1));
627 base::TimeTicks current = StartTick() + kElapsedTimeDelta;
628 int64 expected_speed = kTestDataLength1 / kElapsedTimeSeconds;
629 ASSERT_EQ(expected_speed, CurrentSpeedAtTime(current));
630 base_file_->Finish();
631 }
632
633 // Test that calculating speed after a multiple writes.
634 TEST_F(BaseFileTest, SpeedAfterMultipleWrite) {
635 ASSERT_TRUE(InitializeFile());
636 ASSERT_TRUE(AppendDataToFile(kTestData1));
637 ASSERT_TRUE(AppendDataToFile(kTestData2));
638 ASSERT_TRUE(AppendDataToFile(kTestData3));
639 ASSERT_TRUE(AppendDataToFile(kTestData4));
640 base::TimeTicks current = StartTick() + kElapsedTimeDelta;
641 int64 expected_speed = (kTestDataLength1 + kTestDataLength2 +
642 kTestDataLength3 + kTestDataLength4) / kElapsedTimeSeconds;
643 ASSERT_EQ(expected_speed, CurrentSpeedAtTime(current));
644 base_file_->Finish();
645 }
646
647 // Test that calculating speed after no delay - should not divide by 0.
648 TEST_F(BaseFileTest, SpeedAfterNoElapsedTime) {
649 ASSERT_TRUE(InitializeFile());
650 ASSERT_TRUE(AppendDataToFile(kTestData1));
651 ASSERT_EQ(0, CurrentSpeedAtTime(StartTick()));
652 base_file_->Finish();
653 }
654
655 // Test that a temporary file is created in the default download directory. 615 // Test that a temporary file is created in the default download directory.
656 TEST_F(BaseFileTest, CreatedInDefaultDirectory) { 616 TEST_F(BaseFileTest, CreatedInDefaultDirectory) {
657 ASSERT_TRUE(base_file_->full_path().empty()); 617 ASSERT_TRUE(base_file_->full_path().empty());
658 ASSERT_TRUE(InitializeFile()); 618 ASSERT_TRUE(InitializeFile());
659 EXPECT_FALSE(base_file_->full_path().empty()); 619 EXPECT_FALSE(base_file_->full_path().empty());
660 620
661 // On Windows, CreateTemporaryFileInDir() will cause a path with short names 621 // On Windows, CreateTemporaryFileInDir() will cause a path with short names
662 // to be expanded into a path with long names. Thus temp_dir.path() might not 622 // to be expanded into a path with long names. Thus temp_dir.path() might not
663 // be a string-wise match to base_file_->full_path().DirName() even though 623 // be a string-wise match to base_file_->full_path().DirName() even though
664 // they are in the same directory. 624 // they are in the same directory.
665 base::FilePath temp_file; 625 base::FilePath temp_file;
666 ASSERT_TRUE(file_util::CreateTemporaryFileInDir(temp_dir_.path(), 626 ASSERT_TRUE(file_util::CreateTemporaryFileInDir(temp_dir_.path(),
667 &temp_file)); 627 &temp_file));
668 ASSERT_FALSE(temp_file.empty()); 628 ASSERT_FALSE(temp_file.empty());
669 EXPECT_STREQ(temp_file.DirName().value().c_str(), 629 EXPECT_STREQ(temp_file.DirName().value().c_str(),
670 base_file_->full_path().DirName().value().c_str()); 630 base_file_->full_path().DirName().value().c_str());
671 base_file_->Finish(); 631 base_file_->Finish();
672 } 632 }
673 633
674 } // namespace content 634 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698