Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(63)

Side by Side Diff: third_party/WebKit/Source/web/tests/VirtualTimeTest.cpp

Issue 2876513002: Use WTF::TimeDelta to specify delays on WebTaskRunner (Closed)
Patch Set: mac fix Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/WebKit/Source/platform/testing/UnitTestHelpers.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 54
55 namespace { 55 namespace {
56 void QuitRunLoop() { 56 void QuitRunLoop() {
57 base::MessageLoop::current()->QuitNow(); 57 base::MessageLoop::current()->QuitNow();
58 } 58 }
59 59
60 // Some task queues may have repeating v8 tasks that run forever so we impose a 60 // Some task queues may have repeating v8 tasks that run forever so we impose a
61 // hard time limit. 61 // hard time limit.
62 void RunTasksForPeriod(double delay_ms) { 62 void RunTasksForPeriod(double delay_ms) {
63 Platform::Current()->CurrentThread()->GetWebTaskRunner()->PostDelayedTask( 63 Platform::Current()->CurrentThread()->GetWebTaskRunner()->PostDelayedTask(
64 BLINK_FROM_HERE, WTF::Bind(&QuitRunLoop), delay_ms); 64 BLINK_FROM_HERE, WTF::Bind(&QuitRunLoop),
65 TimeDelta::FromMillisecondsD(delay_ms));
65 testing::EnterRunLoop(); 66 testing::EnterRunLoop();
66 } 67 }
67 } 68 }
68 69
69 // http://crbug.com/633321 70 // http://crbug.com/633321
70 #if OS(ANDROID) 71 #if OS(ANDROID)
71 #define MAYBE_DOMTimersFireInExpectedOrder DISABLED_DOMTimersFireInExpectedOrder 72 #define MAYBE_DOMTimersFireInExpectedOrder DISABLED_DOMTimersFireInExpectedOrder
72 #else 73 #else
73 #define MAYBE_DOMTimersFireInExpectedOrder DOMTimersFireInExpectedOrder 74 #define MAYBE_DOMTimersFireInExpectedOrder DOMTimersFireInExpectedOrder
74 #endif 75 #endif
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 TaskRunnerHelper::Get(TaskType::kTimer, Window().GetExecutionContext()); 217 TaskRunnerHelper::Get(TaskType::kTimer, Window().GetExecutionContext());
217 218
218 // Schedule a task to suspend virtual time at the same point in time. 219 // Schedule a task to suspend virtual time at the same point in time.
219 runner->PostDelayedTask(BLINK_FROM_HERE, 220 runner->PostDelayedTask(BLINK_FROM_HERE,
220 WTF::Bind( 221 WTF::Bind(
221 [](WebViewScheduler* scheduler) { 222 [](WebViewScheduler* scheduler) {
222 scheduler->SetVirtualTimePolicy( 223 scheduler->SetVirtualTimePolicy(
223 WebViewScheduler::VirtualTimePolicy::PAUSE); 224 WebViewScheduler::VirtualTimePolicy::PAUSE);
224 }, 225 },
225 WTF::Unretained(WebView().Scheduler())), 226 WTF::Unretained(WebView().Scheduler())),
226 1000); 227 TimeDelta::FromMilliseconds(1000));
227 228
228 // ALso schedule a second timer for the same point in time. 229 // ALso schedule a second timer for the same point in time.
229 ExecuteJavaScript("setTimeout(() => { run_order.push(2); }, 1000);"); 230 ExecuteJavaScript("setTimeout(() => { run_order.push(2); }, 1000);");
230 231
231 // The second DOM timer shouldn't have run because pausing virtual time also 232 // The second DOM timer shouldn't have run because pausing virtual time also
232 // atomically pauses DOM timers. 233 // atomically pauses DOM timers.
233 testing::RunPendingTasks(); 234 testing::RunPendingTasks();
234 EXPECT_EQ("1", ExecuteJavaScript("run_order.join(', ')")); 235 EXPECT_EQ("1", ExecuteJavaScript("run_order.join(', ')"));
235 } 236 }
236 237
237 } // namespace blink 238 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/platform/testing/UnitTestHelpers.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698