blob: 88a3c0dc518ac59b0b313d7e6be96d6f741845e6 [file] [log] [blame]
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/run_loop.h"
#include "base/time/time.h"
#include "content/child/blink_platform_impl.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace content {
// Derives BlinkPlatformImpl for testing shared timers.
class TestBlinkPlatformImpl : public BlinkPlatformImpl {
TestBlinkPlatformImpl() : mock_monotonically_increasing_time_(0) {}
// Returns mock time when enabled.
virtual double monotonicallyIncreasingTime() OVERRIDE {
if (mock_monotonically_increasing_time_ > 0.0)
return mock_monotonically_increasing_time_;
return BlinkPlatformImpl::monotonicallyIncreasingTime();
virtual void OnStartSharedTimer(base::TimeDelta delay) OVERRIDE {
shared_timer_delay_ = delay;
base::TimeDelta shared_timer_delay() { return shared_timer_delay_; }
void set_mock_monotonically_increasing_time(double mock_time) {
mock_monotonically_increasing_time_ = mock_time;
base::TimeDelta shared_timer_delay_;
double mock_monotonically_increasing_time_;
TEST(BlinkPlatformTest, SuspendResumeSharedTimer) {
base::MessageLoop message_loop;
TestBlinkPlatformImpl platform_impl;
// Set a timer to fire as soon as possible.
// Suspend timers immediately so the above timer wouldn't be fired.
// The above timer would have posted a task which can be processed out of the
// message loop.
// Set a mock time after 1 second to simulate timers suspended for 1 second.
double new_time = base::Time::Now().ToDoubleT() + 1;
// Resume timers so that the timer set above will be set again to fire
// immediately.
EXPECT_TRUE(base::TimeDelta() == platform_impl.shared_timer_delay());
} // namespace content