Remove friend classes from PasswordStore.
[chromium-blink-merge.git] / content / child / blink_platform_unittest.cc
blob88a3c0dc518ac59b0b313d7e6be96d6f741845e6
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "base/run_loop.h"
6 #include "base/time/time.h"
7 #include "content/child/blink_platform_impl.h"
8 #include "testing/gtest/include/gtest/gtest.h"
10 namespace content {
12 // Derives BlinkPlatformImpl for testing shared timers.
13 class TestBlinkPlatformImpl : public BlinkPlatformImpl {
14 public:
15 TestBlinkPlatformImpl() : mock_monotonically_increasing_time_(0) {}
17 // Returns mock time when enabled.
18 virtual double monotonicallyIncreasingTime() OVERRIDE {
19 if (mock_monotonically_increasing_time_ > 0.0)
20 return mock_monotonically_increasing_time_;
21 return BlinkPlatformImpl::monotonicallyIncreasingTime();
24 virtual void OnStartSharedTimer(base::TimeDelta delay) OVERRIDE {
25 shared_timer_delay_ = delay;
28 base::TimeDelta shared_timer_delay() { return shared_timer_delay_; }
30 void set_mock_monotonically_increasing_time(double mock_time) {
31 mock_monotonically_increasing_time_ = mock_time;
34 private:
35 base::TimeDelta shared_timer_delay_;
36 double mock_monotonically_increasing_time_;
38 DISALLOW_COPY_AND_ASSIGN(TestBlinkPlatformImpl);
41 TEST(BlinkPlatformTest, SuspendResumeSharedTimer) {
42 base::MessageLoop message_loop;
44 TestBlinkPlatformImpl platform_impl;
46 // Set a timer to fire as soon as possible.
47 platform_impl.setSharedTimerFireInterval(0);
49 // Suspend timers immediately so the above timer wouldn't be fired.
50 platform_impl.SuspendSharedTimer();
52 // The above timer would have posted a task which can be processed out of the
53 // message loop.
54 base::RunLoop().RunUntilIdle();
56 // Set a mock time after 1 second to simulate timers suspended for 1 second.
57 double new_time = base::Time::Now().ToDoubleT() + 1;
58 platform_impl.set_mock_monotonically_increasing_time(new_time);
60 // Resume timers so that the timer set above will be set again to fire
61 // immediately.
62 platform_impl.ResumeSharedTimer();
64 EXPECT_TRUE(base::TimeDelta() == platform_impl.shared_timer_delay());
67 } // namespace content