diff options
author | benwells@chromium.org <benwells@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-11-30 06:37:20 +0000 |
---|---|---|
committer | benwells@chromium.org <benwells@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-11-30 06:37:20 +0000 |
commit | e384fd8b3eaa3044dcbd60abc529f4b9711d89bf (patch) | |
tree | c22facc3dd9a5cbde57d72691208738f7dcaca7e /content/browser/download/base_file_unittest.cc | |
parent | 64d5c30d9869c2ab4781a7728f12498e19a5cfb8 (diff) | |
download | chromium_src-e384fd8b3eaa3044dcbd60abc529f4b9711d89bf.zip chromium_src-e384fd8b3eaa3044dcbd60abc529f4b9711d89bf.tar.gz chromium_src-e384fd8b3eaa3044dcbd60abc529f4b9711d89bf.tar.bz2 |
Move download speed calculation to file thread / DownloadFile class.
This change doesn't change the way the calculation is performed but moves
it to the file thread, in preperation for implementing a different speed
calculation method.
BUG=None
TEST=Manually tested; automated tests needed.
Review URL: http://codereview.chromium.org/8595004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@112152 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/browser/download/base_file_unittest.cc')
-rw-r--r-- | content/browser/download/base_file_unittest.cc | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/content/browser/download/base_file_unittest.cc b/content/browser/download/base_file_unittest.cc index 6d6edc7..030a635 100644 --- a/content/browser/download/base_file_unittest.cc +++ b/content/browser/download/base_file_unittest.cc @@ -29,6 +29,9 @@ const int kTestDataLength1 = arraysize(kTestData1) - 1; const int kTestDataLength2 = arraysize(kTestData2) - 1; const int kTestDataLength3 = arraysize(kTestData3) - 1; const int kTestDataLength4 = arraysize(kTestData4) - 1; +const int kElapsedTimeSeconds = 5; +const base::TimeDelta kElapsedTimeDelta = base::TimeDelta::FromSeconds( + kElapsedTimeSeconds); } // namespace @@ -144,6 +147,16 @@ class BaseFileTest : public testing::Test { duplicate_file.Detach(); } + int64 CurrentSpeedAtTime(base::TimeTicks current_time) { + EXPECT_TRUE(base_file_.get()); + return base_file_->CurrentSpeedAtTime(current_time); + } + + base::TimeTicks StartTick() { + EXPECT_TRUE(base_file_.get()); + return base_file_->start_tick_; + } + protected: linked_ptr<net::FileStream> file_stream_; linked_ptr<net::testing::MockFileStream> mock_file_stream_; @@ -412,3 +425,43 @@ TEST_F(BaseFileTest, IsEmptySha256Hash) { EXPECT_FALSE(BaseFile::IsEmptySha256Hash(not_empty)); EXPECT_FALSE(BaseFile::IsEmptySha256Hash("")); } + +// Test that calculating speed after no writes. +TEST_F(BaseFileTest, SpeedWithoutWrite) { + ASSERT_EQ(net::OK, base_file_->Initialize(false)); + base::TimeTicks current = StartTick() + kElapsedTimeDelta; + ASSERT_EQ(0, CurrentSpeedAtTime(current)); + base_file_->Finish(); +} + +// Test that calculating speed after a single write. +TEST_F(BaseFileTest, SpeedAfterSingleWrite) { + ASSERT_EQ(net::OK, base_file_->Initialize(false)); + ASSERT_EQ(net::OK, AppendDataToFile(kTestData1)); + base::TimeTicks current = StartTick() + kElapsedTimeDelta; + int64 expected_speed = kTestDataLength1 / kElapsedTimeSeconds; + ASSERT_EQ(expected_speed, CurrentSpeedAtTime(current)); + base_file_->Finish(); +} + +// Test that calculating speed after a multiple writes. +TEST_F(BaseFileTest, SpeedAfterMultipleWrite) { + ASSERT_EQ(net::OK, base_file_->Initialize(false)); + ASSERT_EQ(net::OK, AppendDataToFile(kTestData1)); + ASSERT_EQ(net::OK, AppendDataToFile(kTestData2)); + ASSERT_EQ(net::OK, AppendDataToFile(kTestData3)); + ASSERT_EQ(net::OK, AppendDataToFile(kTestData4)); + base::TimeTicks current = StartTick() + kElapsedTimeDelta; + int64 expected_speed = (kTestDataLength1 + kTestDataLength2 + + kTestDataLength3 + kTestDataLength4) / kElapsedTimeSeconds; + ASSERT_EQ(expected_speed, CurrentSpeedAtTime(current)); + base_file_->Finish(); +} + +// Test that calculating speed after no delay - should not divide by 0. +TEST_F(BaseFileTest, SpeedAfterNoElapsedTime) { + ASSERT_EQ(net::OK, base_file_->Initialize(false)); + ASSERT_EQ(net::OK, AppendDataToFile(kTestData1)); + ASSERT_EQ(0, CurrentSpeedAtTime(StartTick())); + base_file_->Finish(); +} |