This source file includes following definitions.
- monotonicallyIncreasingTime
- OnStartSharedTimer
- shared_timer_delay
- set_mock_monotonically_increasing_time
- TEST
#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 {
class TestBlinkPlatformImpl : public BlinkPlatformImpl {
public:
TestBlinkPlatformImpl() : mock_monotonically_increasing_time_(0) {}
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;
}
private:
base::TimeDelta shared_timer_delay_;
double mock_monotonically_increasing_time_;
DISALLOW_COPY_AND_ASSIGN(TestBlinkPlatformImpl);
};
TEST(BlinkPlatformTest, SuspendResumeSharedTimer) {
base::MessageLoop message_loop;
TestBlinkPlatformImpl platform_impl;
platform_impl.setSharedTimerFireInterval(0);
platform_impl.SuspendSharedTimer();
base::RunLoop().RunUntilIdle();
double new_time = base::Time::Now().ToDoubleT() + 1;
platform_impl.set_mock_monotonically_increasing_time(new_time);
platform_impl.ResumeSharedTimer();
EXPECT_TRUE(base::TimeDelta() == platform_impl.shared_timer_delay());
}
}