Commit 84c8813f authored by Pavel Feldman's avatar Pavel Feldman Committed by Commit Bot

Headless: port even more virtual time tests to the protocol harness.

Change-Id: Ie619816b44b7dbd6c5becfa7307c758c1b18246e
TBR: alexclarke
Reviewed-on: https://chromium-review.googlesource.com/1066806Reviewed-by: default avatarPavel Feldman <pfeldman@chromium.org>
Commit-Queue: Pavel Feldman <pfeldman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#560112}
parent 0ac6bd83
Tests that dom timer respect virtual time order.
c, b, a
\ No newline at end of file
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
(async function(testRunner) {
var {page, session, dp} = await testRunner.startBlank(
`Tests that dom timer respect virtual time order.`);
await dp.Emulation.setVirtualTimePolicy({policy: 'pause'});
await session.evaluate(`
var run_order = [];
function timerFn(delay, value) {
setTimeout(() => { run_order.push(value); }, delay);
};
var one_minute = 60 * 1000;
timerFn(one_minute * 4, 'a');
timerFn(one_minute * 2, 'b');
timerFn(one_minute, 'c');`);
// Normally the JS runs pretty much instantly but the timer callbacks will
// take 4 mins to fire, but thanks to timer fast forwarding we can make them
// fire immediatly.
await dp.Emulation.setVirtualTimePolicy({
policy: 'pauseIfNetworkFetchesPending', budget: 60 * 1000 * 4});
await dp.Emulation.onceVirtualTimeBudgetExpired();
testRunner.log(await session.evaluate(`run_order.join(', ')`));
testRunner.completeTest();
})
Tests that dom timer respects virtual time.
Grant first budget
1000
Grant second budget
1001
\ No newline at end of file
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
(async function(testRunner) {
var {page, session, dp} = await testRunner.startBlank(
`Tests that dom timer respects virtual time.`);
await dp.Runtime.enable();
dp.Runtime.onConsoleAPICalled(data => {
const text = data.params.args[0].value;
testRunner.log(text);
});
await dp.Emulation.setVirtualTimePolicy({policy: 'pause'});
await session.evaluate(`
setTimeout(() => { console.log(1000); }, 1000);
setTimeout(() => { console.log(1001); }, 1001);`);
testRunner.log('Grant first budget');
await dp.Emulation.setVirtualTimePolicy({
policy: 'pauseIfNetworkFetchesPending', budget: 1001});
await dp.Emulation.onceVirtualTimeBudgetExpired();
testRunner.log('Grant second budget');
await dp.Emulation.setVirtualTimePolicy({
policy: 'pauseIfNetworkFetchesPending', budget: 1});
await dp.Emulation.onceVirtualTimeBudgetExpired();
testRunner.completeTest();
})
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "base/json/json_reader.h" #include "base/json/json_reader.h"
#include "base/path_service.h" #include "base/path_service.h"
#include "base/threading/thread_restrictions.h" #include "base/threading/thread_restrictions.h"
#include "build/build_config.h"
#include "content/public/test/browser_test.h" #include "content/public/test/browser_test.h"
#include "headless/public/devtools/domains/runtime.h" #include "headless/public/devtools/domains/runtime.h"
#include "headless/public/headless_browser.h" #include "headless/public/headless_browser.h"
...@@ -180,4 +181,19 @@ HEADLESS_PROTOCOL_TEST(VirtualTimeStarvation, ...@@ -180,4 +181,19 @@ HEADLESS_PROTOCOL_TEST(VirtualTimeStarvation,
"emulation/virtual-time-starvation.js"); "emulation/virtual-time-starvation.js");
HEADLESS_PROTOCOL_TEST(VirtualTimeVideo, "emulation/virtual-time-video.js"); HEADLESS_PROTOCOL_TEST(VirtualTimeVideo, "emulation/virtual-time-video.js");
// http://crbug.com/633321
#if defined(OS_ANDROID)
#define MAYBE_VirtualTimeTimerOrder DISABLED_VirtualTimeTimerOrder
#define MAYBE_VirtualTimeTimerSuspend DISABLED_VirtualTimeTimerSuspend
#else
#define MAYBE_VirtualTimeTimerOrder VirtualTimeTimerOrder
#define MAYBE_VirtualTimeTimerSuspend VirtualTimeTimerSuspend
#endif
HEADLESS_PROTOCOL_TEST(MAYBE_VirtualTimeTimerSuspend,
"emulation/virtual-time-timer-suspended.js");
HEADLESS_PROTOCOL_TEST(MAYBE_VirtualTimeTimerOrder,
"emulation/virtual-time-timer-order.js");
#undef MAYBE_VirtualTimeTimerOrder
#undef MAYBE_VirtualTimeTimerSuspend
} // namespace headless } // namespace headless
...@@ -75,35 +75,6 @@ class VirtualTimeTest : public SimTest { ...@@ -75,35 +75,6 @@ class VirtualTimeTest : public SimTest {
} }
}; };
// http://crbug.com/633321
#if defined(OS_ANDROID)
#define MAYBE_DOMTimersFireInExpectedOrder DISABLED_DOMTimersFireInExpectedOrder
#else
#define MAYBE_DOMTimersFireInExpectedOrder DOMTimersFireInExpectedOrder
#endif
TEST_F(VirtualTimeTest, MAYBE_DOMTimersFireInExpectedOrder) {
WebView().Scheduler()->EnableVirtualTime();
WebView().Scheduler()->SetVirtualTimePolicy(
PageScheduler::VirtualTimePolicy::kAdvance);
ExecuteJavaScript(
"var run_order = [];"
"function timerFn(delay, value) {"
" setTimeout(function() { run_order.push(value); }, delay);"
"};"
"var one_minute = 60 * 1000;"
"timerFn(one_minute * 4, 'a');"
"timerFn(one_minute * 2, 'b');"
"timerFn(one_minute, 'c');");
// Normally the JS runs pretty much instantly but the timer callbacks will
// take 4 mins to fire, but thanks to timer fast forwarding we can make them
// fire immediatly.
RunTasksForPeriod(60 * 1000 * 4);
EXPECT_EQ("c, b, a", ExecuteJavaScript("run_order.join(', ')"));
}
// http://crbug.com/633321 // http://crbug.com/633321
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
#define MAYBE_SetInterval DISABLED_SetInterval #define MAYBE_SetInterval DISABLED_SetInterval
...@@ -213,49 +184,8 @@ TEST_F(VirtualTimeTest, ...@@ -213,49 +184,8 @@ TEST_F(VirtualTimeTest,
RunTasksForPeriod(10); RunTasksForPeriod(10);
} }
// http://crbug.com/633321
#if defined(OS_ANDROID)
#define MAYBE_DOMTimersSuspended DISABLED_DOMTimersSuspended
#else
#define MAYBE_DOMTimersSuspended DOMTimersSuspended
#endif
TEST_F(VirtualTimeTest, MAYBE_DOMTimersSuspended) {
WebView().Scheduler()->EnableVirtualTime();
WebView().Scheduler()->SetVirtualTimePolicy(
PageScheduler::VirtualTimePolicy::kAdvance);
// Schedule normal DOM timers to run at 1s and 1.001s in the future.
ExecuteJavaScript(
"var run_order = [];"
"setTimeout(() => { run_order.push(1); }, 1000);"
"setTimeout(() => { run_order.push(2); }, 1001);");
scoped_refptr<base::SingleThreadTaskRunner> runner =
Window().GetExecutionContext()->GetTaskRunner(TaskType::kJavascriptTimer);
// Schedule a task to suspend virtual time at the same point in time.
runner->PostDelayedTask(FROM_HERE,
WTF::Bind(
[](PageScheduler* scheduler) {
scheduler->SetVirtualTimePolicy(
PageScheduler::VirtualTimePolicy::kPause);
},
WTF::Unretained(WebView().Scheduler())),
TimeDelta::FromMilliseconds(1000));
// ALso schedule a third timer for the same point in time.
ExecuteJavaScript("setTimeout(() => { run_order.push(2); }, 1000);");
// The second DOM timer shouldn't have run because the virtual time budget
// expired.
test::RunPendingTasks();
EXPECT_EQ("1, 2", ExecuteJavaScript("run_order.join(', ')"));
}
#undef MAYBE_DOMTimersFireInExpectedOrder
#undef MAYBE_SetInterval #undef MAYBE_SetInterval
#undef MAYBE_AllowVirtualTimeToAdvance #undef MAYBE_AllowVirtualTimeToAdvance
#undef MAYBE_VirtualTimeNotAllowedToAdvanceWhileResourcesLoading #undef MAYBE_VirtualTimeNotAllowedToAdvanceWhileResourcesLoading
#undef MAYBE_DOMTimersSuspended
} // namespace virtual_time_test } // namespace virtual_time_test
} // namespace blink } // namespace blink
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment