| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "base/message_loop/message_loop.h" | 5 #include "base/message_loop/message_loop.h" |
| 6 #include "core/dom/TaskRunnerHelper.h" | 6 #include "core/dom/TaskRunnerHelper.h" |
| 7 #include "platform/scheduler/renderer/web_view_scheduler.h" | 7 #include "platform/scheduler/renderer/web_view_scheduler.h" |
| 8 #include "platform/testing/UnitTestHelpers.h" | 8 #include "platform/testing/UnitTestHelpers.h" |
| 9 #include "public/platform/Platform.h" | 9 #include "public/platform/Platform.h" |
| 10 #include "public/web/WebLocalFrame.h" | 10 #include "public/web/WebLocalFrame.h" |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 | 201 |
| 202 // http://crbug.com/633321 | 202 // http://crbug.com/633321 |
| 203 #if OS(ANDROID) | 203 #if OS(ANDROID) |
| 204 #define MAYBE_DOMTimersSuspended DISABLED_DOMTimersSuspended | 204 #define MAYBE_DOMTimersSuspended DISABLED_DOMTimersSuspended |
| 205 #else | 205 #else |
| 206 #define MAYBE_DOMTimersSuspended DOMTimersSuspended | 206 #define MAYBE_DOMTimersSuspended DOMTimersSuspended |
| 207 #endif | 207 #endif |
| 208 TEST_F(VirtualTimeTest, MAYBE_DOMTimersSuspended) { | 208 TEST_F(VirtualTimeTest, MAYBE_DOMTimersSuspended) { |
| 209 WebView().Scheduler()->EnableVirtualTime(); | 209 WebView().Scheduler()->EnableVirtualTime(); |
| 210 | 210 |
| 211 // Schedule a normal DOM timer to run at 1s in the future. | 211 // Schedule normal DOM timers to run at 1s and 1.001s in the future. |
| 212 ExecuteJavaScript( | 212 ExecuteJavaScript( |
| 213 "var run_order = [];" | 213 "var run_order = [];" |
| 214 "setTimeout(() => { run_order.push(1); }, 1000);"); | 214 "setTimeout(() => { run_order.push(1); }, 1000);" |
| 215 "setTimeout(() => { run_order.push(2); }, 1001);"); |
| 215 | 216 |
| 216 RefPtr<WebTaskRunner> runner = | 217 RefPtr<WebTaskRunner> runner = |
| 217 TaskRunnerHelper::Get(TaskType::kTimer, Window().GetExecutionContext()); | 218 TaskRunnerHelper::Get(TaskType::kTimer, Window().GetExecutionContext()); |
| 218 | 219 |
| 219 // Schedule a task to suspend virtual time at the same point in time. | 220 // Schedule a task to suspend virtual time at the same point in time. |
| 220 runner->PostDelayedTask(BLINK_FROM_HERE, | 221 runner->PostDelayedTask(BLINK_FROM_HERE, |
| 221 WTF::Bind( | 222 WTF::Bind( |
| 222 [](WebViewScheduler* scheduler) { | 223 [](WebViewScheduler* scheduler) { |
| 223 scheduler->SetVirtualTimePolicy( | 224 scheduler->SetVirtualTimePolicy( |
| 224 WebViewScheduler::VirtualTimePolicy::PAUSE); | 225 WebViewScheduler::VirtualTimePolicy::PAUSE); |
| 225 }, | 226 }, |
| 226 WTF::Unretained(WebView().Scheduler())), | 227 WTF::Unretained(WebView().Scheduler())), |
| 227 TimeDelta::FromMilliseconds(1000)); | 228 TimeDelta::FromMilliseconds(1000)); |
| 228 | 229 |
| 229 // ALso schedule a second timer for the same point in time. | 230 // ALso schedule a third timer for the same point in time. |
| 230 ExecuteJavaScript("setTimeout(() => { run_order.push(2); }, 1000);"); | 231 ExecuteJavaScript("setTimeout(() => { run_order.push(2); }, 1000);"); |
| 231 | 232 |
| 232 // The second DOM timer shouldn't have run because pausing virtual time also | 233 // The second DOM timer shouldn't have run because the virtual time budget |
| 233 // atomically pauses DOM timers. | 234 // expired. |
| 234 testing::RunPendingTasks(); | 235 testing::RunPendingTasks(); |
| 235 EXPECT_EQ("1", ExecuteJavaScript("run_order.join(', ')")); | 236 EXPECT_EQ("1, 2", ExecuteJavaScript("run_order.join(', ')")); |
| 236 } | 237 } |
| 237 | 238 |
| 238 } // namespace blink | 239 } // namespace blink |
| OLD | NEW |