OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <string> | |
6 | |
7 #include "base/run_loop.h" | 5 #include "base/run_loop.h" |
8 #include "base/time/time.h" | 6 #include "base/time/time.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
10 #include "webkit/child/webkitplatformsupport_impl.h" | 8 #include "webkit/child/webkitplatformsupport_impl.h" |
11 | 9 |
12 namespace { | 10 namespace content { |
13 | 11 |
14 // Derives WebKitPlatformSupportImpl for testing shared timers. | 12 // Derives WebKitPlatformSupportImpl for testing shared timers. |
15 class TestWebKitPlatformSupport | 13 class TestBlinkPlatformImpl : public webkit_glue::WebKitPlatformSupportImpl { |
16 : public webkit_glue::WebKitPlatformSupportImpl { | |
17 public: | 14 public: |
18 TestWebKitPlatformSupport() : mock_monotonically_increasing_time_(0) { | 15 TestBlinkPlatformImpl() : mock_monotonically_increasing_time_(0) {} |
19 } | |
20 | 16 |
21 // WebKitPlatformSupportImpl implementation | 17 // webkit_glue::WebKitPlatformSupportImpl: |
22 virtual base::string16 GetLocalizedString(int) OVERRIDE { | 18 virtual base::string16 GetLocalizedString(int) OVERRIDE { |
23 return base::string16(); | 19 return base::string16(); |
24 } | 20 } |
25 | 21 |
26 virtual base::StringPiece GetDataResource(int, ui::ScaleFactor) OVERRIDE { | 22 virtual base::StringPiece GetDataResource(int, ui::ScaleFactor) OVERRIDE { |
27 return base::StringPiece(); | 23 return base::StringPiece(); |
28 } | 24 } |
29 | 25 |
30 virtual webkit_glue::ResourceLoaderBridge* CreateResourceLoader( | 26 virtual webkit_glue::ResourceLoaderBridge* CreateResourceLoader( |
31 const webkit_glue::ResourceLoaderBridge::RequestInfo&) OVERRIDE { | 27 const webkit_glue::ResourceLoaderBridge::RequestInfo&) OVERRIDE { |
(...skipping 11 matching lines...) Expand all Loading... |
43 if (mock_monotonically_increasing_time_ > 0.0) | 39 if (mock_monotonically_increasing_time_ > 0.0) |
44 return mock_monotonically_increasing_time_; | 40 return mock_monotonically_increasing_time_; |
45 return webkit_glue::WebKitPlatformSupportImpl:: | 41 return webkit_glue::WebKitPlatformSupportImpl:: |
46 monotonicallyIncreasingTime(); | 42 monotonicallyIncreasingTime(); |
47 } | 43 } |
48 | 44 |
49 virtual void OnStartSharedTimer(base::TimeDelta delay) OVERRIDE { | 45 virtual void OnStartSharedTimer(base::TimeDelta delay) OVERRIDE { |
50 shared_timer_delay_ = delay; | 46 shared_timer_delay_ = delay; |
51 } | 47 } |
52 | 48 |
53 base::TimeDelta shared_timer_delay() { | 49 base::TimeDelta shared_timer_delay() { return shared_timer_delay_; } |
54 return shared_timer_delay_; | |
55 } | |
56 | 50 |
57 void set_mock_monotonically_increasing_time(double mock_time) { | 51 void set_mock_monotonically_increasing_time(double mock_time) { |
58 mock_monotonically_increasing_time_ = mock_time; | 52 mock_monotonically_increasing_time_ = mock_time; |
59 } | 53 } |
60 | 54 |
61 private: | 55 private: |
62 base::TimeDelta shared_timer_delay_; | 56 base::TimeDelta shared_timer_delay_; |
63 double mock_monotonically_increasing_time_; | 57 double mock_monotonically_increasing_time_; |
| 58 |
| 59 DISALLOW_COPY_AND_ASSIGN(TestBlinkPlatformImpl); |
64 }; | 60 }; |
65 | 61 |
66 TEST(WebkitGlueTest, SuspendResumeSharedTimer) { | 62 TEST(BlinkPlatformTest, SuspendResumeSharedTimer) { |
67 base::MessageLoop message_loop; | 63 base::MessageLoop message_loop; |
68 | 64 |
69 TestWebKitPlatformSupport platform_support; | 65 TestBlinkPlatformImpl platform_impl; |
70 | 66 |
71 // Set a timer to fire as soon as possible. | 67 // Set a timer to fire as soon as possible. |
72 platform_support.setSharedTimerFireInterval(0); | 68 platform_impl.setSharedTimerFireInterval(0); |
| 69 |
73 // Suspend timers immediately so the above timer wouldn't be fired. | 70 // Suspend timers immediately so the above timer wouldn't be fired. |
74 platform_support.SuspendSharedTimer(); | 71 platform_impl.SuspendSharedTimer(); |
| 72 |
75 // The above timer would have posted a task which can be processed out of the | 73 // The above timer would have posted a task which can be processed out of the |
76 // message loop. | 74 // message loop. |
77 base::RunLoop().RunUntilIdle(); | 75 base::RunLoop().RunUntilIdle(); |
| 76 |
78 // Set a mock time after 1 second to simulate timers suspended for 1 second. | 77 // Set a mock time after 1 second to simulate timers suspended for 1 second. |
79 double new_time = base::Time::Now().ToDoubleT() + 1; | 78 double new_time = base::Time::Now().ToDoubleT() + 1; |
80 platform_support.set_mock_monotonically_increasing_time(new_time); | 79 platform_impl.set_mock_monotonically_increasing_time(new_time); |
| 80 |
81 // Resume timers so that the timer set above will be set again to fire | 81 // Resume timers so that the timer set above will be set again to fire |
82 // immediately. | 82 // immediately. |
83 platform_support.ResumeSharedTimer(); | 83 platform_impl.ResumeSharedTimer(); |
84 EXPECT_TRUE(base::TimeDelta() == platform_support.shared_timer_delay()); | 84 |
| 85 EXPECT_TRUE(base::TimeDelta() == platform_impl.shared_timer_delay()); |
85 } | 86 } |
86 | 87 |
87 } // namespace | 88 } // namespace content |
OLD | NEW |