Index: third_party/WebKit/Source/web/tests/VirtualTimeTest.cpp |
diff --git a/third_party/WebKit/Source/web/tests/VirtualTimeTest.cpp b/third_party/WebKit/Source/web/tests/VirtualTimeTest.cpp |
index 7d78d7724299548e3869b301efb561bedbbca158..85c06d9aa96519ce4f3a7f680010c105b9c61d1e 100644 |
--- a/third_party/WebKit/Source/web/tests/VirtualTimeTest.cpp |
+++ b/third_party/WebKit/Source/web/tests/VirtualTimeTest.cpp |
@@ -38,23 +38,10 @@ |
ScriptExecutionCallbackHelper callbackHelper; |
webView().mainFrame()->toWebLocalFrame()->requestExecuteScriptAndReturnValue( |
WebScriptSource(WebString(scriptSource)), false, &callbackHelper); |
+ testing::runPendingTasks(); |
return callbackHelper.result(); |
} |
}; |
- |
-namespace { |
- void quitRunLoop() |
- { |
- base::MessageLoop::current()->QuitNow(); |
- } |
- |
- // Some task queues may have repeating v8 tasks that run forever so we impose a hard time limit. |
- void runTasksForPeriod(double delayMs) |
- { |
- Platform::current()->currentThread()->getWebTaskRunner()->postDelayedTask(BLINK_FROM_HERE, WTF::bind(&quitRunLoop), delayMs); |
- testing::enterRunLoop(); |
- } |
-} |
TEST_F(VirtualTimeTest, DOMTimersFireInExpectedOrder) |
{ |
@@ -74,7 +61,6 @@ |
// take 100h to fire, but thanks to timer fast forwarding we can make them |
// fire immediatly. |
- testing::runPendingTasks(); |
EXPECT_EQ("c, b, a", ExecuteJavaScript("run_order.join(', ')")); |
} |
@@ -93,8 +79,8 @@ |
"}, 1000);" |
"setTimeout(function() { run_order.push('timer'); }, 1500);"); |
- runTasksForPeriod(12000); |
- |
+ // If virtual time is not supplied to TimerBase then the setInterval |
+ // won't fire 10x. |
EXPECT_EQ("9, timer, 8, 7, 6, 5, 4, 3, 2, 1, 0", ExecuteJavaScript("run_order.join(', ')")); |
} |
@@ -112,11 +98,10 @@ |
"timerFn(10, 'b');" |
"timerFn(1, 'c');"); |
- testing::runPendingTasks(); |
EXPECT_EQ("", ExecuteJavaScript("run_order.join(', ')")); |
webView().scheduler()->setVirtualTimePolicy(WebViewScheduler::VirtualTimePolicy::ADVANCE); |
- runTasksForPeriod(1000); |
+ testing::runPendingTasks(); |
EXPECT_EQ("c, b, a", ExecuteJavaScript("run_order.join(', ')")); |
} |
@@ -126,11 +111,13 @@ |
webView().scheduler()->enableVirtualTime(); |
webView().scheduler()->setVirtualTimePolicy(WebViewScheduler::VirtualTimePolicy::DETERMINISTIC_LOADING); |
- // To ensure determinism virtual time is not allowed to advance until we have seen at least one load. |
- EXPECT_FALSE(webView().scheduler()->virtualTimeAllowedToAdvance()); |
+ EXPECT_TRUE(webView().scheduler()->virtualTimeAllowedToAdvance()); |
SimRequest mainResource("https://example.com/test.html", "text/html"); |
SimRequest cssResource("https://example.com/test.css", "text/css"); |
+ |
+ // Not loading, virtual time should be able to advance. |
+ EXPECT_TRUE(webView().scheduler()->virtualTimeAllowedToAdvance()); |
// Loading, virtual time should not advance. |
loadURL("https://example.com/test.html"); |