Commit c3e19fc0 authored by Pavel Feldman's avatar Pavel Feldman Committed by Commit Bot

Headless: reapply new virtual time tests: r560024, r560074, r560103, r560112, r560140.

Change-Id: Idbc930f4087158b413bd447698098792ec1b9b04
TBR: dgozman
Reviewed-on: https://chromium-review.googlesource.com/1067133
Commit-Queue: Pavel Feldman <pfeldman@chromium.org>
Reviewed-by: default avatarPavel Feldman <pfeldman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#560190}
parent 008312af
...@@ -759,6 +759,7 @@ test("headless_browsertests") { ...@@ -759,6 +759,7 @@ test("headless_browsertests") {
"public/util/testing/test_in_memory_protocol_handler.h", "public/util/testing/test_in_memory_protocol_handler.h",
"test/headless_browser_test.cc", "test/headless_browser_test.cc",
"test/headless_browser_test.h", "test/headless_browser_test.h",
"test/headless_protocol_browsertest.cc",
"test/headless_test_launcher.cc", "test/headless_test_launcher.cc",
"test/test_protocol_handler.cc", "test/test_protocol_handler.cc",
"test/test_protocol_handler.h", "test/test_protocol_handler.h",
...@@ -771,6 +772,7 @@ test("headless_browsertests") { ...@@ -771,6 +772,7 @@ test("headless_browsertests") {
"lib/dom_tree_extraction_expected_styles.txt", "lib/dom_tree_extraction_expected_styles.txt",
"$root_out_dir/headless_lib.pak", "$root_out_dir/headless_lib.pak",
"//net/tools/testserver/", "//net/tools/testserver/",
"//third_party/WebKit/LayoutTests/http/tests/inspector-protocol/",
"//third_party/pyftpdlib/", "//third_party/pyftpdlib/",
"//third_party/pywebsocket/", "//third_party/pywebsocket/",
"//third_party/tlslite/", "//third_party/tlslite/",
......
This diff is collapsed.
<!doctype html>
<head>
<script>
// Note define() defines a module in the mojo module dependency
// system. While we don't expose our module, the callback below only
// fires after the requested modules have been loaded.
define([
'headless/lib/embedder_test.mojom',
'content/public/renderer/frame_interfaces',
], function(embedderMojom, frameInterfaces) {
var testEmbedderService = new embedderMojom.TestEmbedderServicePtr(
frameInterfaces.getInterface(embedderMojom.TestEmbedderService.name));
// Send a message to the embedder!
testEmbedderService.returnTestResult('page one');
});
</script>
</head>
<body><h1>Page one</h1></body>
<!doctype html>
<head>
<script>
// Note define() defines a module in the mojo module dependency
// system. While we don't expose our module, the callback below only
// fires after the requested modules have been loaded.
define([
'headless/lib/embedder_test.mojom',
'content/public/renderer/frame_interfaces',
], function(embedderMojom, frameInterfaces) {
var testEmbedderService = new embedderMojom.TestEmbedderServicePtr(
frameInterfaces.getInterface(embedderMojom.TestEmbedderService.name));
// Send a message to the embedder!
testEmbedderService.returnTestResult('page two');
});
</script>
</head>
<body><h1>Page two</h1></body>
<html>
<script>
var counter = 1;
</script>
<img src="1" onerror="this.src='' + ++counter">
</html>
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
window.addEventListener('message', callback, false); window.addEventListener('message', callback, false);
window.postMessage('message', '*'); window.postMessage('message', '*');
window.setTimeout(function() { window.setTimeout(function() {
console.log('event count: ' + event_count); console.log('Timer Fired, alot of events seen: ' + (event_count > 1));
}, 4000); }, 4000);
</script> </script>
</html> </html>
<!DOCTYPE html>
<html>
<body>
<video controls>
<source src="video.webm" type="audio/webm">
</video>
</body>
</html>
Tests virtual time is not blocked by 404 page.
\ 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 virtual time is not blocked by 404 page.`);
dp.Emulation.onVirtualTimeBudgetExpired(data => testRunner.completeTest());
await dp.Emulation.setVirtualTimePolicy({policy: 'pause'});
await dp.Emulation.setVirtualTimePolicy({
policy: 'pauseIfNetworkFetchesPending',
budget: 5000, waitForNavigation: true});
dp.Page.navigate({url: testRunner.url('/no-such-file.html')});
})
Tests that virtual time advances.
Paused @ 0ms
Paused @ 0ms
Advanced to 10ms
step1
Advanced to 110ms
step2
Paused @ 110ms
Advanced to 210ms
step3
Paused @ 210ms
Advanced to 310ms
step4
pass
\ 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 virtual time advances.`);
await dp.Page.enable();
await dp.Runtime.enable();
dp.Emulation.onVirtualTimePaused(data =>
testRunner.log(`Paused @ ${data.params.virtualTimeElapsed}ms`));
dp.Emulation.onVirtualTimeAdvanced(data => {
// Debug chrome schedules stray tasks that break this test.
// Our numbers are round, so we prevent this flake 999 times of 1000.
const time = data.params.virtualTimeElapsed;
if (time !== Math.round(time))
return;
testRunner.log(`Advanced to ${time}ms`);
});
dp.Runtime.onConsoleAPICalled(data => {
const text = data.params.args[0].value;
testRunner.log(text);
if (text === 'pass')
testRunner.completeTest();
});
await dp.Emulation.setVirtualTimePolicy({policy: 'pause'});
await dp.Emulation.setVirtualTimePolicy({
policy: 'pauseIfNetworkFetchesPending', budget: 5000, waitForNavigation: true});
dp.Page.navigate({url: testRunner.url('resources/virtual-time-advance.html')});
})
Tests virtual time basics.
\ 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 virtual time basics.`);
dp.Emulation.onVirtualTimeBudgetExpired(data => testRunner.completeTest());
await dp.Emulation.setVirtualTimePolicy({policy: 'pause'});
await dp.Emulation.setVirtualTimePolicy({
policy: 'pauseIfNetworkFetchesPending',
budget: 1000, waitForNavigation: true});
dp.Page.navigate({url: testRunner.url('/resources/blank.html')});
})
Tests that virtual time advances 10ms on every navigation.
Resources loaded: 500
\ 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 virtual time advances 10ms on every navigation.`);
await dp.Network.enable();
let resourceCounter = 0;
dp.Network.onRequestWillBeSent(() => { resourceCounter++ });
dp.Emulation.onVirtualTimeBudgetExpired(data => {
testRunner.log('Resources loaded: ' + resourceCounter);
testRunner.completeTest();
});
await dp.Emulation.setVirtualTimePolicy({policy: 'pause'});
await dp.Emulation.setVirtualTimePolicy({
policy: 'pauseIfNetworkFetchesPending',
budget: 5000, waitForNavigation: true,
maxVirtualTimeTaskStarvationCount: 1000000}); // starvation prevents flakes
dp.Page.navigate({url: testRunner.url('resources/virtual-time-error-loop.html')});
})
Tests virtual time with local storage.
400
\ 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 virtual time with local storage.`);
await dp.Runtime.enable();
dp.Runtime.onConsoleAPICalled(data => {
const text = data.params.args[0].value;
testRunner.log(text);
});
dp.Emulation.onVirtualTimeBudgetExpired(data => testRunner.completeTest());
await dp.Emulation.setVirtualTimePolicy({policy: 'pause'});
await dp.Emulation.setVirtualTimePolicy({
policy: 'pauseIfNetworkFetchesPending',
budget: 5000, waitForNavigation: true});
dp.Page.navigate({url: testRunner.url('resources/virtual-time-local-storage.html')});
})
Tests virtual time with session storage.
400
\ 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 virtual time with session storage.`);
await dp.Runtime.enable();
dp.Runtime.onConsoleAPICalled(data => {
const text = data.params.args[0].value;
testRunner.log(text);
});
dp.Emulation.onVirtualTimeBudgetExpired(data => testRunner.completeTest());
await dp.Emulation.setVirtualTimePolicy({policy: 'pause'});
await dp.Emulation.setVirtualTimePolicy({
policy: 'pauseIfNetworkFetchesPending',
budget: 5000, waitForNavigation: true});
dp.Page.navigate({url: testRunner.url('resources/virtual-time-session-storage.html')});
})
Tests that virtual time advances.
Timer Fired, alot of events seen: true
\ 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 virtual time advances.`);
await dp.Page.enable();
await dp.Runtime.enable();
// If there is no starvation, budget never expires.
dp.Emulation.onVirtualTimeBudgetExpired(data => testRunner.completeTest());
dp.Runtime.onConsoleAPICalled(data => {
const text = data.params.args[0].value;
testRunner.log(text);
});
await dp.Emulation.setVirtualTimePolicy({policy: 'pause'});
await dp.Emulation.setVirtualTimePolicy({
policy: 'pauseIfNetworkFetchesPending', budget: 4011, waitForNavigation: true,
maxVirtualTimeTaskStarvationCount: 100});
dp.Page.navigate({url: testRunner.url('resources/virtual-time-starvation.html')});
})
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();
})
Tests that video does not block virtual time.
\ 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 video does not block virtual time.`);
dp.Emulation.onVirtualTimeBudgetExpired(data => testRunner.completeTest());
await dp.Emulation.setVirtualTimePolicy({policy: 'pause'});
await dp.Emulation.setVirtualTimePolicy({
policy: 'pauseIfNetworkFetchesPending',
budget: 5000, waitForNavigation: true});
dp.Page.navigate({url: testRunner.url('resources/virtual-time-video.html')});
})
<!--
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.
-->
<html>
<head>
<script>
var output = [];
var testRunner = {};
testRunner.dumpAsText = () => {};
testRunner.waitUntilDone = () => {};
testRunner.setCanOpenWindows = () => {};
testRunner.notifyDone = () => {
console.debug(JSON.stringify({id: 0, method: 'DONE', params: {}, result: output.join('\n')}));
};
DevToolsHost = {};
DevToolsHost.sendMessageToEmbedder = (message) => {
const object = JSON.parse(message);
console.debug(object.params[0]);
}
DevToolsHost.dummyPageURL = `http://127.0.0.1:${window.location.port}/protocol/inspector-protocol-page.html`;
</script>
<script src="../../resources/inspector-protocol-test.js"></script>
<script>
DevToolsAPI._log = text => output.push(text);
DevToolsAPI._fetch = url => {
var params = new URLSearchParams(window.location.search);
var testScriptURL = params.get('test');
if (url === testScriptURL)
return Promise.resolve(decodeURIComponent(params.get('script')));
throw new Error('Can not fetch ' + url);
};
function onmessage(json) { DevToolsAPI.dispatchMessage(json); }
</script>
</head>
</html>
\ 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.
#include <memory>
#include "base/base64.h"
#include "base/base_paths.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/json/json_reader.h"
#include "base/path_service.h"
#include "base/threading/thread_restrictions.h"
#include "build/build_config.h"
#include "content/public/test/browser_test.h"
#include "headless/public/devtools/domains/runtime.h"
#include "headless/public/headless_browser.h"
#include "headless/public/headless_browser_context.h"
#include "headless/public/headless_devtools_client.h"
#include "headless/public/headless_devtools_target.h"
#include "headless/public/headless_web_contents.h"
#include "headless/test/headless_browser_test.h"
#include "net/test/spawned_test_server/spawned_test_server.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "url/url_util.h"
namespace headless {
namespace {
static const char kResetResults[] = "reset-results";
} // namespace
class HeadlessProtocolBrowserTest
: public HeadlessAsyncDevTooledBrowserTest,
public HeadlessDevToolsClient::RawProtocolListener,
public runtime::Observer {
public:
HeadlessProtocolBrowserTest() {
embedded_test_server()->ServeFilesFromSourceDirectory(
"third_party/WebKit/LayoutTests/http/tests/inspector-protocol");
EXPECT_TRUE(embedded_test_server()->Start());
}
private:
// HeadlessWebContentsObserver implementation.
void DevToolsTargetReady() override {
HeadlessAsyncDevTooledBrowserTest::DevToolsTargetReady();
devtools_client_->GetRuntime()->AddObserver(this);
devtools_client_->GetRuntime()->Enable();
browser_devtools_client_->SetRawProtocolListener(this);
}
std::string EncodeQuery(const std::string& query) {
url::RawCanonOutputT<char> buffer;
url::EncodeURIComponent(query.data(), query.size(), &buffer);
return std::string(buffer.data(), buffer.length());
}
void RunDevTooledTest() override {
base::ScopedAllowBlockingForTesting allow_blocking;
base::FilePath src_dir;
CHECK(base::PathService::Get(base::DIR_SOURCE_ROOT, &src_dir));
static const base::FilePath kTestsDirectory(
FILE_PATH_LITERAL("headless/test/data/protocol"));
base::FilePath test_path = src_dir.Append(kTestsDirectory)
.AppendASCII(script_name_);
std::string script;
if (!base::ReadFileToString(test_path, &script)) {
ADD_FAILURE() << "Unable to read test at " << test_path;
FinishTest();
return;
}
GURL test_url = embedded_test_server()->GetURL("/protocol/" + script_name_);
GURL page_url = embedded_test_server() ->GetURL(
"harness.test",
"/protocol/inspector-protocol-test.html?test=" +
test_url.spec() + "&script=" + EncodeQuery(script));
devtools_client_->GetPage()->Navigate(page_url.spec());
}
// runtime::Observer implementation.
void OnConsoleAPICalled(
const runtime::ConsoleAPICalledParams& params) override {
const std::vector<std::unique_ptr<runtime::RemoteObject>>& args =
*params.GetArgs();
if (args.empty())
return;
if (params.GetType() != runtime::ConsoleAPICalledType::DEBUG)
return;
runtime::RemoteObject* object = args[0].get();
if (object->GetType() != runtime::RemoteObjectType::STRING)
return;
DispatchMessageFromJS(object->GetValue()->GetString());
}
void DispatchMessageFromJS(const std::string& json_message) {
std::unique_ptr<base::Value> message = base::JSONReader::Read(json_message);
const base::DictionaryValue* message_dict;
const base::DictionaryValue* params_dict;
std::string method;
int id;
if (!message || !message->GetAsDictionary(&message_dict) ||
!message_dict->GetString("method", &method) ||
!message_dict->GetDictionary("params", &params_dict) ||
!message_dict->GetInteger("id", &id)) {
LOG(ERROR) << "Poorly formed message " << json_message;
FinishTest();
return;
}
if (method != "DONE") {
// Pass unhandled commands onto the inspector.
browser_devtools_client_->SendRawDevToolsMessage(json_message);
return;
}
std::string test_result;
message_dict->GetString("result", &test_result);
static const base::FilePath kTestsDirectory(
FILE_PATH_LITERAL("headless/test/data/protocol"));
base::ScopedAllowBlockingForTesting allow_blocking;
base::FilePath src_dir;
CHECK(base::PathService::Get(base::DIR_SOURCE_ROOT, &src_dir));
base::FilePath expectation_path =
src_dir.Append(kTestsDirectory)
.AppendASCII(script_name_.substr(0, script_name_.length() - 3) +
"-expected.txt");
if (base::CommandLine::ForCurrentProcess()->HasSwitch(kResetResults)) {
LOG(INFO) << "Updating expectations at " << expectation_path;
int result = base::WriteFile(expectation_path, test_result.data(),
static_cast<int>(test_result.size()));
CHECK(test_result.size() == static_cast<size_t>(result));
}
std::string expectation;
if (!base::ReadFileToString(expectation_path, &expectation)) {
ADD_FAILURE() << "Unable to read expectations at " << expectation_path;
}
EXPECT_EQ(test_result, expectation);
FinishTest();
}
// HeadlessDevToolsClient::RawProtocolListener
bool OnProtocolMessage(const std::string& devtools_agent_host_id,
const std::string& json_message,
const base::DictionaryValue& parsed_message) override {
SendMessageToJS(json_message);
return true;
}
void SendMessageToJS(const std::string& message) {
if (test_finished_)
return;
std::string encoded;
base::Base64Encode(message, &encoded);
devtools_client_->GetRuntime()->Evaluate("onmessage(atob(\"" + encoded +
"\"))");
}
void FinishTest() {
test_finished_ = true;
FinishAsynchronousTest();
}
// HeadlessBrowserTest overrides.
void CustomizeHeadlessBrowserContext(
HeadlessBrowserContext::Builder& builder) override {
// Make sure the navigations spawn new processes. We run test harness
// in one process (harness.test) and tests in another.
builder.SetSitePerProcess(true);
builder.SetHostResolverRules("MAP *.test 127.0.0.1");
}
protected:
bool test_finished_ = false;
std::string test_folder_;
std::string script_name_;
};
#define HEADLESS_PROTOCOL_TEST(TEST_NAME, SCRIPT_NAME) \
IN_PROC_BROWSER_TEST_F(HeadlessProtocolBrowserTest, TEST_NAME) { \
test_folder_ = "/protocol/"; \
script_name_ = SCRIPT_NAME; \
RunTest(); \
}
#define LAYOUT_PROTOCOL_TEST(TEST_NAME, SCRIPT_NAME) \
IN_PROC_BROWSER_TEST_F(HeadlessProtocolBrowserTest, TEST_NAME) { \
test_folder_ = "/"; \
script_name_ = SCRIPT_NAME; \
RunTest(); \
}
// Headless-specific tests
HEADLESS_PROTOCOL_TEST(VirtualTimeAdvance, "emulation/virtual-time-advance.js");
HEADLESS_PROTOCOL_TEST(VirtualTimeBasics, "emulation/virtual-time-basics.js");
HEADLESS_PROTOCOL_TEST(VirtualTimeErrorLoop,
"emulation/virtual-time-error-loop.js");
HEADLESS_PROTOCOL_TEST(VirtualTimeNoBlock404, "emulation/virtual-time-404.js");
HEADLESS_PROTOCOL_TEST(VirtualTimeLocalStorage,
"emulation/virtual-time-local-storage.js");
HEADLESS_PROTOCOL_TEST(VirtualTimeSessionStorage,
"emulation/virtual-time-session-storage.js");
HEADLESS_PROTOCOL_TEST(VirtualTimeStarvation,
"emulation/virtual-time-starvation.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
...@@ -133,8 +133,11 @@ var TestRunner = class { ...@@ -133,8 +133,11 @@ var TestRunner = class {
var targetId = (await DevToolsAPI._sendCommandOrDie('Target.createTarget', {url: 'about:blank'})).targetId; var targetId = (await DevToolsAPI._sendCommandOrDie('Target.createTarget', {url: 'about:blank'})).targetId;
await DevToolsAPI._sendCommandOrDie('Target.activateTarget', {targetId}); await DevToolsAPI._sendCommandOrDie('Target.activateTarget', {targetId});
var page = new TestRunner.Page(this, targetId); var page = new TestRunner.Page(this, targetId);
var dummyURL = window.location.href; var dummyURL = DevToolsHost.dummyPageURL;
dummyURL = dummyURL.substring(0, dummyURL.indexOf('inspector-protocol-test.html')) + 'inspector-protocol-page.html'; if (!dummyURL) {
dummyURL = window.location.href;
dummyURL = dummyURL.substring(0, dummyURL.indexOf('inspector-protocol-test.html')) + 'inspector-protocol-page.html';
}
await page._navigate(dummyURL); await page._navigate(dummyURL);
return page; return page;
} }
......
...@@ -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