diff options
author | reveman@chromium.org <reveman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-03-22 16:10:24 +0000 |
---|---|---|
committer | reveman@chromium.org <reveman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-03-22 16:10:24 +0000 |
commit | 730021f97c480ca3603318872c93717769f9ea34 (patch) | |
tree | be12a9f7c0cd162d0c43c81b0ece3fd6a2c33b56 /cc/scheduler/delay_based_time_source_unittest.cc | |
parent | c77fbfb9f7662fd293f17d43552d9cd65fd24bdf (diff) | |
download | chromium_src-730021f97c480ca3603318872c93717769f9ea34.zip chromium_src-730021f97c480ca3603318872c93717769f9ea34.tar.gz chromium_src-730021f97c480ca3603318872c93717769f9ea34.tar.bz2 |
cc: Chromify FakeTimeSourceClient, FakeThread, FakeTimeSource, FakeDelayBasedTimeSource, FakeFrameRateController.
R=enne@chromium.org
BUG=none
NOTRY=true
Review URL: https://chromiumcodereview.appspot.com/12806008
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@189822 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'cc/scheduler/delay_based_time_source_unittest.cc')
-rw-r--r-- | cc/scheduler/delay_based_time_source_unittest.cc | 222 |
1 files changed, 111 insertions, 111 deletions
diff --git a/cc/scheduler/delay_based_time_source_unittest.cc b/cc/scheduler/delay_based_time_source_unittest.cc index 8343cce..a4493a5 100644 --- a/cc/scheduler/delay_based_time_source_unittest.cc +++ b/cc/scheduler/delay_based_time_source_unittest.cc @@ -20,56 +20,56 @@ TEST(DelayBasedTimeSourceTest, TaskPostedAndTickCalled) { FakeThread thread; FakeTimeSourceClient client; scoped_refptr<FakeDelayBasedTimeSource> timer = - FakeDelayBasedTimeSource::create(Interval(), &thread); + FakeDelayBasedTimeSource::Create(Interval(), &thread); timer->SetClient(&client); timer->SetActive(true); EXPECT_TRUE(timer->Active()); - EXPECT_TRUE(thread.hasPendingTask()); + EXPECT_TRUE(thread.HasPendingTask()); - timer->setNow(timer->Now() + base::TimeDelta::FromMilliseconds(16)); - thread.runPendingTask(); + timer->SetNow(timer->Now() + base::TimeDelta::FromMilliseconds(16)); + thread.RunPendingTask(); EXPECT_TRUE(timer->Active()); - EXPECT_TRUE(client.tickCalled()); + EXPECT_TRUE(client.TickCalled()); } TEST(DelayBasedTimeSource, TickNotCalledWithTaskPosted) { FakeThread thread; FakeTimeSourceClient client; scoped_refptr<FakeDelayBasedTimeSource> timer = - FakeDelayBasedTimeSource::create(Interval(), &thread); + FakeDelayBasedTimeSource::Create(Interval(), &thread); timer->SetClient(&client); timer->SetActive(true); - EXPECT_TRUE(thread.hasPendingTask()); + EXPECT_TRUE(thread.HasPendingTask()); timer->SetActive(false); - thread.runPendingTask(); - EXPECT_FALSE(client.tickCalled()); + thread.RunPendingTask(); + EXPECT_FALSE(client.TickCalled()); } TEST(DelayBasedTimeSource, StartTwiceEnqueuesOneTask) { FakeThread thread; FakeTimeSourceClient client; scoped_refptr<FakeDelayBasedTimeSource> timer = - FakeDelayBasedTimeSource::create(Interval(), &thread); + FakeDelayBasedTimeSource::Create(Interval(), &thread); timer->SetClient(&client); timer->SetActive(true); - EXPECT_TRUE(thread.hasPendingTask()); - thread.reset(); + EXPECT_TRUE(thread.HasPendingTask()); + thread.Reset(); timer->SetActive(true); - EXPECT_FALSE(thread.hasPendingTask()); + EXPECT_FALSE(thread.HasPendingTask()); } TEST(DelayBasedTimeSource, StartWhenRunningDoesntTick) { FakeThread thread; FakeTimeSourceClient client; scoped_refptr<FakeDelayBasedTimeSource> timer = - FakeDelayBasedTimeSource::create(Interval(), &thread); + FakeDelayBasedTimeSource::Create(Interval(), &thread); timer->SetClient(&client); timer->SetActive(true); - thread.runPendingTask(); - thread.reset(); + thread.RunPendingTask(); + thread.Reset(); timer->SetActive(true); - EXPECT_FALSE(thread.hasPendingTask()); + EXPECT_FALSE(thread.HasPendingTask()); } // At 60Hz, when the tick returns at exactly the requested next time, make sure @@ -78,18 +78,18 @@ TEST(DelayBasedTimeSource, NextDelaySaneWhenExactlyOnRequestedTime) { FakeThread thread; FakeTimeSourceClient client; scoped_refptr<FakeDelayBasedTimeSource> timer = - FakeDelayBasedTimeSource::create(Interval(), &thread); + FakeDelayBasedTimeSource::Create(Interval(), &thread); timer->SetClient(&client); timer->SetActive(true); // Run the first task, as that activates the timer and picks up a timebase. - thread.runPendingTask(); + thread.RunPendingTask(); - EXPECT_EQ(16, thread.pendingDelayMs()); + EXPECT_EQ(16, thread.PendingDelayMs()); - timer->setNow(timer->Now() + Interval()); - thread.runPendingTask(); + timer->SetNow(timer->Now() + Interval()); + thread.RunPendingTask(); - EXPECT_EQ(16, thread.pendingDelayMs()); + EXPECT_EQ(16, thread.PendingDelayMs()); } // At 60Hz, when the tick returns at slightly after the requested next time, @@ -98,19 +98,19 @@ TEST(DelayBasedTimeSource, NextDelaySaneWhenSlightlyAfterRequestedTime) { FakeThread thread; FakeTimeSourceClient client; scoped_refptr<FakeDelayBasedTimeSource> timer = - FakeDelayBasedTimeSource::create(Interval(), &thread); + FakeDelayBasedTimeSource::Create(Interval(), &thread); timer->SetClient(&client); timer->SetActive(true); // Run the first task, as that activates the timer and picks up a timebase. - thread.runPendingTask(); + thread.RunPendingTask(); - EXPECT_EQ(16, thread.pendingDelayMs()); + EXPECT_EQ(16, thread.PendingDelayMs()); - timer->setNow(timer->Now() + Interval() + + timer->SetNow(timer->Now() + Interval() + base::TimeDelta::FromMicroseconds(1)); - thread.runPendingTask(); + thread.RunPendingTask(); - EXPECT_EQ(16, thread.pendingDelayMs()); + EXPECT_EQ(16, thread.PendingDelayMs()); } // At 60Hz, when the tick returns at exactly 2*interval after the requested next @@ -119,18 +119,18 @@ TEST(DelayBasedTimeSource, NextDelaySaneWhenExactlyTwiceAfterRequestedTime) { FakeThread thread; FakeTimeSourceClient client; scoped_refptr<FakeDelayBasedTimeSource> timer = - FakeDelayBasedTimeSource::create(Interval(), &thread); + FakeDelayBasedTimeSource::Create(Interval(), &thread); timer->SetClient(&client); timer->SetActive(true); // Run the first task, as that activates the timer and picks up a timebase. - thread.runPendingTask(); + thread.RunPendingTask(); - EXPECT_EQ(16, thread.pendingDelayMs()); + EXPECT_EQ(16, thread.PendingDelayMs()); - timer->setNow(timer->Now() + 2 * Interval()); - thread.runPendingTask(); + timer->SetNow(timer->Now() + 2 * Interval()); + thread.RunPendingTask(); - EXPECT_EQ(16, thread.pendingDelayMs()); + EXPECT_EQ(16, thread.PendingDelayMs()); } // At 60Hz, when the tick returns at 2*interval and a bit after the requested @@ -139,19 +139,19 @@ TEST(DelayBasedTimeSource, NextDelaySaneWhenSlightlyAfterTwiceRequestedTime) { FakeThread thread; FakeTimeSourceClient client; scoped_refptr<FakeDelayBasedTimeSource> timer = - FakeDelayBasedTimeSource::create(Interval(), &thread); + FakeDelayBasedTimeSource::Create(Interval(), &thread); timer->SetClient(&client); timer->SetActive(true); // Run the first task, as that activates the timer and picks up a timebase. - thread.runPendingTask(); + thread.RunPendingTask(); - EXPECT_EQ(16, thread.pendingDelayMs()); + EXPECT_EQ(16, thread.PendingDelayMs()); - timer->setNow(timer->Now() + 2 * Interval() + + timer->SetNow(timer->Now() + 2 * Interval() + base::TimeDelta::FromMicroseconds(1)); - thread.runPendingTask(); + thread.RunPendingTask(); - EXPECT_EQ(16, thread.pendingDelayMs()); + EXPECT_EQ(16, thread.PendingDelayMs()); } // At 60Hz, when the tick returns halfway to the next frame time, make sure @@ -160,19 +160,19 @@ TEST(DelayBasedTimeSource, NextDelaySaneWhenHalfAfterRequestedTime) { FakeThread thread; FakeTimeSourceClient client; scoped_refptr<FakeDelayBasedTimeSource> timer = - FakeDelayBasedTimeSource::create(Interval(), &thread); + FakeDelayBasedTimeSource::Create(Interval(), &thread); timer->SetClient(&client); timer->SetActive(true); // Run the first task, as that activates the timer and picks up a timebase. - thread.runPendingTask(); + thread.RunPendingTask(); - EXPECT_EQ(16, thread.pendingDelayMs()); + EXPECT_EQ(16, thread.PendingDelayMs()); - timer->setNow(timer->Now() + Interval() + + timer->SetNow(timer->Now() + Interval() + base::TimeDelta::FromMilliseconds(8)); - thread.runPendingTask(); + thread.RunPendingTask(); - EXPECT_EQ(8, thread.pendingDelayMs()); + EXPECT_EQ(8, thread.PendingDelayMs()); } // If the timebase and interval are updated with a jittery source, we want to @@ -181,114 +181,114 @@ TEST(DelayBasedTimeSource, SaneHandlingOfJitteryTimebase) { FakeThread thread; FakeTimeSourceClient client; scoped_refptr<FakeDelayBasedTimeSource> timer = - FakeDelayBasedTimeSource::create(Interval(), &thread); + FakeDelayBasedTimeSource::Create(Interval(), &thread); timer->SetClient(&client); timer->SetActive(true); // Run the first task, as that activates the timer and picks up a timebase. - thread.runPendingTask(); + thread.RunPendingTask(); - EXPECT_EQ(16, thread.pendingDelayMs()); + EXPECT_EQ(16, thread.PendingDelayMs()); // Jitter timebase ~1ms late - timer->setNow(timer->Now() + Interval()); + timer->SetNow(timer->Now() + Interval()); timer->SetTimebaseAndInterval( timer->Now() + base::TimeDelta::FromMilliseconds(1), Interval()); - thread.runPendingTask(); + thread.RunPendingTask(); - // Without double tick prevention, pendingDelayMs would be 1. - EXPECT_EQ(17, thread.pendingDelayMs()); + // Without double tick prevention, PendingDelayMs would be 1. + EXPECT_EQ(17, thread.PendingDelayMs()); // Jitter timebase ~1ms early - timer->setNow(timer->Now() + Interval()); + timer->SetNow(timer->Now() + Interval()); timer->SetTimebaseAndInterval( timer->Now() - base::TimeDelta::FromMilliseconds(1), Interval()); - thread.runPendingTask(); + thread.RunPendingTask(); - EXPECT_EQ(15, thread.pendingDelayMs()); + EXPECT_EQ(15, thread.PendingDelayMs()); } TEST(DelayBasedTimeSource, HandlesSignificantTimebaseChangesImmediately) { FakeThread thread; FakeTimeSourceClient client; scoped_refptr<FakeDelayBasedTimeSource> timer = - FakeDelayBasedTimeSource::create(Interval(), &thread); + FakeDelayBasedTimeSource::Create(Interval(), &thread); timer->SetClient(&client); timer->SetActive(true); // Run the first task, as that activates the timer and picks up a timebase. - thread.runPendingTask(); + thread.RunPendingTask(); - EXPECT_EQ(16, thread.pendingDelayMs()); + EXPECT_EQ(16, thread.PendingDelayMs()); // Tick, then shift timebase by +7ms. - timer->setNow(timer->Now() + Interval()); - thread.runPendingTask(); + timer->SetNow(timer->Now() + Interval()); + thread.RunPendingTask(); - EXPECT_EQ(16, thread.pendingDelayMs()); + EXPECT_EQ(16, thread.PendingDelayMs()); - client.reset(); - thread.runPendingTaskOnOverwrite(true); + client.Reset(); + thread.RunPendingTaskOnOverwrite(true); base::TimeDelta jitter = base::TimeDelta::FromMilliseconds(7) + base::TimeDelta::FromMicroseconds(1); timer->SetTimebaseAndInterval(timer->Now() + jitter, Interval()); - thread.runPendingTaskOnOverwrite(false); + thread.RunPendingTaskOnOverwrite(false); - EXPECT_FALSE(client.tickCalled()); // Make sure pending tasks were canceled. - EXPECT_EQ(7, thread.pendingDelayMs()); + EXPECT_FALSE(client.TickCalled()); // Make sure pending tasks were canceled. + EXPECT_EQ(7, thread.PendingDelayMs()); // Tick, then shift timebase by -7ms. - timer->setNow(timer->Now() + jitter); - thread.runPendingTask(); + timer->SetNow(timer->Now() + jitter); + thread.RunPendingTask(); - EXPECT_EQ(16, thread.pendingDelayMs()); + EXPECT_EQ(16, thread.PendingDelayMs()); - client.reset(); - thread.runPendingTaskOnOverwrite(true); + client.Reset(); + thread.RunPendingTaskOnOverwrite(true); timer->SetTimebaseAndInterval(base::TimeTicks() + Interval(), Interval()); - thread.runPendingTaskOnOverwrite(false); + thread.RunPendingTaskOnOverwrite(false); - EXPECT_FALSE(client.tickCalled()); // Make sure pending tasks were canceled. - EXPECT_EQ(16 - 7, thread.pendingDelayMs()); + EXPECT_FALSE(client.TickCalled()); // Make sure pending tasks were canceled. + EXPECT_EQ(16 - 7, thread.PendingDelayMs()); } TEST(DelayBasedTimeSource, HanldlesSignificantIntervalChangesImmediately) { FakeThread thread; FakeTimeSourceClient client; scoped_refptr<FakeDelayBasedTimeSource> timer = - FakeDelayBasedTimeSource::create(Interval(), &thread); + FakeDelayBasedTimeSource::Create(Interval(), &thread); timer->SetClient(&client); timer->SetActive(true); // Run the first task, as that activates the timer and picks up a timebase. - thread.runPendingTask(); + thread.RunPendingTask(); - EXPECT_EQ(16, thread.pendingDelayMs()); + EXPECT_EQ(16, thread.PendingDelayMs()); // Tick, then double the interval. - timer->setNow(timer->Now() + Interval()); - thread.runPendingTask(); + timer->SetNow(timer->Now() + Interval()); + thread.RunPendingTask(); - EXPECT_EQ(16, thread.pendingDelayMs()); + EXPECT_EQ(16, thread.PendingDelayMs()); - client.reset(); - thread.runPendingTaskOnOverwrite(true); + client.Reset(); + thread.RunPendingTaskOnOverwrite(true); timer->SetTimebaseAndInterval(base::TimeTicks() + Interval(), Interval() * 2); - thread.runPendingTaskOnOverwrite(false); + thread.RunPendingTaskOnOverwrite(false); - EXPECT_FALSE(client.tickCalled()); // Make sure pending tasks were canceled. - EXPECT_EQ(33, thread.pendingDelayMs()); + EXPECT_FALSE(client.TickCalled()); // Make sure pending tasks were canceled. + EXPECT_EQ(33, thread.PendingDelayMs()); // Tick, then halve the interval. - timer->setNow(timer->Now() + Interval() * 2); - thread.runPendingTask(); + timer->SetNow(timer->Now() + Interval() * 2); + thread.RunPendingTask(); - EXPECT_EQ(33, thread.pendingDelayMs()); + EXPECT_EQ(33, thread.PendingDelayMs()); - client.reset(); - thread.runPendingTaskOnOverwrite(true); + client.Reset(); + thread.RunPendingTaskOnOverwrite(true); timer->SetTimebaseAndInterval(base::TimeTicks() + Interval() * 3, Interval()); - thread.runPendingTaskOnOverwrite(false); + thread.RunPendingTaskOnOverwrite(false); - EXPECT_FALSE(client.tickCalled()); // Make sure pending tasks were canceled. - EXPECT_EQ(16, thread.pendingDelayMs()); + EXPECT_FALSE(client.TickCalled()); // Make sure pending tasks were canceled. + EXPECT_EQ(16, thread.PendingDelayMs()); } TEST(DelayBasedTimeSourceTest, AchievesTargetRateWithNoNoise) { @@ -297,20 +297,20 @@ TEST(DelayBasedTimeSourceTest, AchievesTargetRateWithNoNoise) { FakeThread thread; FakeTimeSourceClient client; scoped_refptr<FakeDelayBasedTimeSource> timer = - FakeDelayBasedTimeSource::create(Interval(), &thread); + FakeDelayBasedTimeSource::Create(Interval(), &thread); timer->SetClient(&client); timer->SetActive(true); double total_frame_time = 0.0; for (int i = 0; i < num_iterations; ++i) { - long long delay_ms = thread.pendingDelayMs(); + long long delay_ms = thread.PendingDelayMs(); // accumulate the "delay" total_frame_time += delay_ms / 1000.0; // Run the callback exactly when asked - timer->setNow(timer->Now() + base::TimeDelta::FromMilliseconds(delay_ms)); - thread.runPendingTask(); + timer->SetNow(timer->Now() + base::TimeDelta::FromMilliseconds(delay_ms)); + thread.RunPendingTask(); } double average_interval = total_frame_time / static_cast<double>(num_iterations); @@ -321,60 +321,60 @@ TEST(DelayBasedTimeSource, TestDeactivateWhilePending) { FakeThread thread; FakeTimeSourceClient client; scoped_refptr<FakeDelayBasedTimeSource> timer = - FakeDelayBasedTimeSource::create(Interval(), &thread); + FakeDelayBasedTimeSource::Create(Interval(), &thread); timer->SetClient(&client); timer->SetActive(true); // Should post a task. timer->SetActive(false); timer = NULL; - thread.runPendingTask(); // Should run the posted task without crashing. + thread.RunPendingTask(); // Should run the posted task without crashing. } TEST(DelayBasedTimeSource, TestDeactivateAndReactivateBeforeNextTickTime) { FakeThread thread; FakeTimeSourceClient client; scoped_refptr<FakeDelayBasedTimeSource> timer = - FakeDelayBasedTimeSource::create(Interval(), &thread); + FakeDelayBasedTimeSource::Create(Interval(), &thread); timer->SetClient(&client); // Should run the activate task, and pick up a new timebase. timer->SetActive(true); - thread.runPendingTask(); + thread.RunPendingTask(); // Stop the timer timer->SetActive(false); // Task will be pending anyway, run it - thread.runPendingTask(); + thread.RunPendingTask(); // Start the timer again, but before the next tick time the timer previously // planned on using. That same tick time should still be targeted. - timer->setNow(timer->Now() + base::TimeDelta::FromMilliseconds(4)); + timer->SetNow(timer->Now() + base::TimeDelta::FromMilliseconds(4)); timer->SetActive(true); - EXPECT_EQ(12, thread.pendingDelayMs()); + EXPECT_EQ(12, thread.PendingDelayMs()); } TEST(DelayBasedTimeSource, TestDeactivateAndReactivateAfterNextTickTime) { FakeThread thread; FakeTimeSourceClient client; scoped_refptr<FakeDelayBasedTimeSource> timer = - FakeDelayBasedTimeSource::create(Interval(), &thread); + FakeDelayBasedTimeSource::Create(Interval(), &thread); timer->SetClient(&client); // Should run the activate task, and pick up a new timebase. timer->SetActive(true); - thread.runPendingTask(); + thread.RunPendingTask(); // Stop the timer. timer->SetActive(false); // Task will be pending anyway, run it. - thread.runPendingTask(); + thread.RunPendingTask(); // Start the timer again, but before the next tick time the timer previously // planned on using. That same tick time should still be targeted. - timer->setNow(timer->Now() + base::TimeDelta::FromMilliseconds(20)); + timer->SetNow(timer->Now() + base::TimeDelta::FromMilliseconds(20)); timer->SetActive(true); - EXPECT_EQ(13, thread.pendingDelayMs()); + EXPECT_EQ(13, thread.PendingDelayMs()); } } // namespace |