Commit ed3020b1 authored by Peter Kvitek's avatar Peter Kvitek Committed by Commit Bot

Implemented basic headless renderer tests.

This is an initial portion of the set of tests that are going to be
converted to JS.

Change-Id: I42eecccf4bf1abef520fce21ae940559e2f0ac39
Reviewed-on: https://chromium-review.googlesource.com/1145823Reviewed-by: default avatarPavel Feldman <pfeldman@chromium.org>
Commit-Queue: Peter Kvitek <kvitekp@chromium.org>
Cr-Commit-Position: refs/heads/master@{#577304}
parent 45d4ae5e
Tests renderer: chained client redirection.
requested url: http://www.example.com/
requested url: http://www.example.com/1
requested url: http://www.example.com/2
requested url: http://www.example.com/3
requested url: http://www.example.com/pass
Pass
Frames: 1
frameId=MainFrame
url=http://www.example.com/
url=http://www.example.com/1
url=http://www.example.com/2
url=http://www.example.com/3
ScheduledNavigations: 1
frameId=MainFrame
url=http://www.example.com/1 reason=metaTagRefresh
url=http://www.example.com/2 reason=scriptInitiated
url=http://www.example.com/3 reason=scriptInitiated
\ No newline at end of file
Tests renderer: chained client redirection with js disabled.
requested url: http://www.example.com/
requested url: http://www.example.com/1
Hello, World 1
Frames: 1
frameId=MainFrame
url=http://www.example.com/
url=http://www.example.com/1
ScheduledNavigations: 1
frameId=MainFrame
url=http://www.example.com/1 reason=metaTagRefresh
\ 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) {
let {page, session, dp} = await testRunner.startBlank(
'Tests renderer: chained client redirection with js disabled.');
let RendererTestHelper =
await testRunner.loadScript('../helpers/renderer-test-helper.js');
let {httpInterceptor, frameNavigationHelper, virtualTimeController} =
await (new RendererTestHelper(testRunner, dp, page)).init();
httpInterceptor.addResponse(
`http://www.example.com/`,
`<html>
<head>
<meta http-equiv="refresh" content="0; url=http://www.example.com/1"/>
<title>Hello, World 0</title>
</head>
<body>http://www.example.com/</body>
</html>`);
httpInterceptor.addResponse(
`http://www.example.com/1`,
`<html>
<head>
<title>Hello, World 1</title>
<script>
document.location='http://www.example.com/2';
</script>
</head>
<body>http://www.example.com/1</body>
</html>`);
httpInterceptor.addResponse(
`http://www.example.com/2`,
`<html>
<head>
<title>Hello, World 2</title>
<script>
setTimeout("document.location='http://www.example.com/3'", 1000);
</script>
</head>
<body>http://www.example.com/2</body>
</html>`);
httpInterceptor.addResponse(
`http://www.example.com/3`,
`<html>
<head>
<title>Pass</title>
</head>
<body>
http://www.example.com/3
<img src="pass">
</body>
</html>`);
httpInterceptor.addResponse(
`http://www.example.com/pass`,
`<html>
<body>
pass
</body>
</html>`);
await dp.Emulation.setScriptExecutionDisabled({value: true});
await virtualTimeController.grantInitialTime(1000 + 100, 1000,
null,
async () => {
testRunner.log(await session.evaluate('document.title'));
frameNavigationHelper.logFrames();
frameNavigationHelper.logScheduledNavigations();
testRunner.completeTest();
}
);
await frameNavigationHelper.navigate('http://www.example.com/');
})
// 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) {
let {page, session, dp} = await testRunner.startBlank(
'Tests renderer: chained client redirection.');
let RendererTestHelper =
await testRunner.loadScript('../helpers/renderer-test-helper.js');
let {httpInterceptor, frameNavigationHelper, virtualTimeController} =
await (new RendererTestHelper(testRunner, dp, page)).init();
httpInterceptor.addResponse(
`http://www.example.com/`,
`<html>
<head>
<meta http-equiv="refresh" content="0; url=http://www.example.com/1"/>
<title>Hello, World 0</title>
</head>
<body>http://www.example.com/</body>
</html>`);
httpInterceptor.addResponse(
`http://www.example.com/1`,
`<html>
<head>
<title>Hello, World 1</title>
<script>
document.location='http://www.example.com/2';
</script>
</head>
<body>http://www.example.com/1</body>
</html>`);
httpInterceptor.addResponse(
`http://www.example.com/2`,
`<html>
<head>
<title>Hello, World 2</title>
<script>
setTimeout("document.location='http://www.example.com/3'", 1000);
</script>
</head>
<body>http://www.example.com/2</body>
</html>`);
httpInterceptor.addResponse(
`http://www.example.com/3`,
`<html>
<head>
<title>Pass</title>
</head>
<body>
http://www.example.com/3
<img src="pass">
</body>
</html>`);
httpInterceptor.addResponse(
`http://www.example.com/pass`,
`<html>
<body>
pass
</body>
</html>`);
await virtualTimeController.grantInitialTime(1000 + 100, 1000,
null,
async () => {
testRunner.log(await session.evaluate('document.title'));
frameNavigationHelper.logFrames();
frameNavigationHelper.logScheduledNavigations();
testRunner.completeTest();
}
);
await frameNavigationHelper.navigate('http://www.example.com/');
})
Tests renderer: delayed completion.
requested url: http://example.com/foobar
<p>delayed text</p>
\ 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) {
let {page, session, dp} = await testRunner.startBlank(
'Tests renderer: delayed completion.');
let RendererTestHelper =
await testRunner.loadScript('../helpers/renderer-test-helper.js');
let {httpInterceptor, frameNavigationHelper, virtualTimeController} =
await (new RendererTestHelper(testRunner, dp, page)).init();
httpInterceptor.addResponse(
`http://example.com/foobar`,
`<html>
<body>
<script type="text/javascript">
setTimeout(() => {
var div = document.getElementById('content');
var p = document.createElement('p');
p.textContent = 'delayed text';
div.appendChild(p);
}, 3000);
</script>
<div id="content"/>
</body>
</html>`);
await virtualTimeController.grantInitialTime(3000 + 100, 1000,
null,
async () => {
testRunner.log(await session.evaluate(
`document.getElementById('content').innerHTML.trim()`));
testRunner.completeTest();
}
);
await frameNavigationHelper.navigate('http://example.com/foobar');
})
Tests renderer: hello world.
requested url: http://example.com/foobar
<h1>Hello headless world!</h1>
Frames: 1
frameId=MainFrame
url=http://example.com/foobar
ScheduledNavigations: 0
\ 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) {
let {page, session, dp} = await testRunner.startBlank(
'Tests renderer: hello world.');
let RendererTestHelper =
await testRunner.loadScript('../helpers/renderer-test-helper.js');
let {httpInterceptor, frameNavigationHelper, virtualTimeController} =
await (new RendererTestHelper(testRunner, dp, page)).init();
httpInterceptor.addResponse(
`http://example.com/foobar`,
`<!doctype html><h1>Hello headless world!</h1>`);
await virtualTimeController.grantInitialTime(500, 1000,
null,
async () => {
testRunner.log(await session.evaluate('document.body.innerHTML'));
frameNavigationHelper.logFrames();
frameNavigationHelper.logScheduledNavigations();
testRunner.completeTest();
}
);
await frameNavigationHelper.navigate('http://example.com/foobar');
})
Tests renderer: verify JavaScript console errors reporting.
requested url: http://example.com/foobar
Uncaught SyntaxError: Unexpected token <
Uncaught ReferenceError: func1 is not defined
Uncaught ReferenceError: func2 is not defined
Hello, Script!
Uncaught ReferenceError: func3 is not defined
\ 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) {
let {page, session, dp} = await testRunner.startBlank(
'Tests renderer: verify JavaScript console errors reporting.');
let RendererTestHelper =
await testRunner.loadScript('../helpers/renderer-test-helper.js');
let {httpInterceptor, frameNavigationHelper, virtualTimeController} =
await (new RendererTestHelper(testRunner, dp, page)).init();
httpInterceptor.addResponse(
`http://example.com/foobar` ,
`<html>
<head>
<script language="JavaScript">
<![CDATA[
function image() {
window.open('<xsl:value-of select="/IMAGE/@href" />');
}
]]>
</script>
</head>
<body onload="func3()">
<script type="text/javascript">
func1()
</script>
<script type="text/javascript">
func2();
</script>
<script type="text/javascript">
console.log("Hello, Script!");
</script>
</body>
</html>`);
await dp.Runtime.enable();
dp.Runtime.onConsoleAPICalled(data => {
const text = data.params.args[0].value;
testRunner.log(`${text}`);
});
dp.Runtime.onExceptionThrown(data => {
const details = data.params.exceptionDetails;
testRunner.log(
`${details.text} ${details.exception.description.replace(/\n.*/, '')}`);
});
await virtualTimeController.grantInitialTime(500, 1000,
null,
async () => {
testRunner.completeTest();
}
);
await frameNavigationHelper.navigate('http://example.com/foobar');
})
Tests renderer: override title with JavaScript disabled.
requested url: http://example.com/foobar
JavaScript is off
\ 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) {
let {page, session, dp} = await testRunner.startBlank(
'Tests renderer: override title with JavaScript disabled.');
let RendererTestHelper =
await testRunner.loadScript('../helpers/renderer-test-helper.js');
let {httpInterceptor, frameNavigationHelper, virtualTimeController} =
await (new RendererTestHelper(testRunner, dp, page)).init();
await dp.Emulation.setScriptExecutionDisabled({value: true});
httpInterceptor.addResponse(
`http://example.com/foobar`,
`<html>
<head>
<title>JavaScript is off</title>
<script language="JavaScript">
function settitle() {
document.title = 'JavaScript is on';
}
</script>
</head>
<body onload="settitle()">
Hello, World!
</body>
</html>`);
await virtualTimeController.grantInitialTime(500, 1000,
null,
async () => {
testRunner.log(await session.evaluate('document.title'));
testRunner.completeTest();
}
);
await frameNavigationHelper.navigate('http://example.com/foobar');
})
Tests renderer: override title with JavaScript enabled.
requested url: http://example.com/foobar
JavaScript is on
\ 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) {
let {page, session, dp} = await testRunner.startBlank(
'Tests renderer: override title with JavaScript enabled.');
let RendererTestHelper =
await testRunner.loadScript('../helpers/renderer-test-helper.js');
let {httpInterceptor, frameNavigationHelper, virtualTimeController} =
await (new RendererTestHelper(testRunner, dp, page)).init();
await dp.Emulation.setScriptExecutionDisabled({value: false});
httpInterceptor.addResponse(
`http://example.com/foobar`,
`<html>
<head>
<title>JavaScript is off</title>
<script language="JavaScript">
function settitle() {
document.title = 'JavaScript is on';
}
</script>
</head>
<body onload="settitle()">
Hello, World!
</body>
</html>`);
await virtualTimeController.grantInitialTime(500, 1000,
null,
async () => {
testRunner.log(await session.evaluate('document.title'));
testRunner.completeTest();
}
);
await frameNavigationHelper.navigate('http://example.com/foobar');
})
...@@ -283,39 +283,52 @@ class HeadlessProtocolCompositorBrowserTest ...@@ -283,39 +283,52 @@ class HeadlessProtocolCompositorBrowserTest
base::test::ScopedFeatureList scoped_feature_list_; base::test::ScopedFeatureList scoped_feature_list_;
}; };
// BeginFrameControl is not supported on MacOS yet, see: https://cs.chromium.org
// chromium/src/headless/lib/browser/protocol/target_handler.cc?
// rcl=5811aa08e60ba5ac7622f029163213cfbdb682f7&l=32
#if defined(OS_MACOSX)
#define HEADLESS_PROTOCOL_COMPOSITOR_TEST(TEST_NAME, SCRIPT_NAME) \
IN_PROC_BROWSER_TEST_F(HeadlessProtocolCompositorBrowserTest, \
DISABLED_##TEST_NAME) { \
test_folder_ = "/protocol/"; \
script_name_ = SCRIPT_NAME; \
RunTest(); \
}
#else
#define HEADLESS_PROTOCOL_COMPOSITOR_TEST(TEST_NAME, SCRIPT_NAME) \ #define HEADLESS_PROTOCOL_COMPOSITOR_TEST(TEST_NAME, SCRIPT_NAME) \
IN_PROC_BROWSER_TEST_F(HeadlessProtocolCompositorBrowserTest, TEST_NAME) { \ IN_PROC_BROWSER_TEST_F(HeadlessProtocolCompositorBrowserTest, TEST_NAME) { \
test_folder_ = "/protocol/"; \ test_folder_ = "/protocol/"; \
script_name_ = SCRIPT_NAME; \ script_name_ = SCRIPT_NAME; \
RunTest(); \ RunTest(); \
} }
// BeginFrameControl is not supported on MacOS yet, see: https://cs.chromium.org
// chromium/src/headless/lib/browser/protocol/target_handler.cc?
// rcl=5811aa08e60ba5ac7622f029163213cfbdb682f7&l=32
#if defined(OS_MACOSX)
#define MAYBE_CompositorBasicRaf DISABLED_CompositorBasicRaf
#define MAYBE_CompositorImageAnimation DISABLED_CompositorImageAnimation
#define MAYBE_CompositorCssAnimation DISABLED_CompositorCssAnimation
#define MAYBE_VirtualTimeControllerTest DISABLED_VirtualTimeControllerTest
#else
#define MAYBE_CompositorBasicRaf CompositorBasicRaf
#define MAYBE_CompositorImageAnimation CompositorImageAnimation
#define MAYBE_CompositorCssAnimation CompositorCssAnimation
#define MAYBE_VirtualTimeControllerTest VirtualTimeControllerTest
#endif #endif
HEADLESS_PROTOCOL_COMPOSITOR_TEST(MAYBE_CompositorBasicRaf,
HEADLESS_PROTOCOL_COMPOSITOR_TEST(CompositorBasicRaf,
"emulation/compositor-basic-raf.js"); "emulation/compositor-basic-raf.js");
HEADLESS_PROTOCOL_COMPOSITOR_TEST( HEADLESS_PROTOCOL_COMPOSITOR_TEST(
MAYBE_CompositorImageAnimation, CompositorImageAnimation,
"emulation/compositor-image-animation-test.js"); "emulation/compositor-image-animation-test.js");
HEADLESS_PROTOCOL_COMPOSITOR_TEST(MAYBE_CompositorCssAnimation, HEADLESS_PROTOCOL_COMPOSITOR_TEST(CompositorCssAnimation,
"emulation/compositor-css-animation-test.js"); "emulation/compositor-css-animation-test.js");
HEADLESS_PROTOCOL_TEST(MAYBE_VirtualTimeControllerTest, HEADLESS_PROTOCOL_COMPOSITOR_TEST(VirtualTimeControllerTest,
"helpers/virtual-time-controller-test.js"); "helpers/virtual-time-controller-test.js");
#undef MAYBE_CompositorBasicRaf HEADLESS_PROTOCOL_COMPOSITOR_TEST(RendererHelloWorld,
#undef MAYBE_CompositorImageAnimation "sanity/renderer-hello-world.js");
#undef MAYBE_CompositorCssAnimation HEADLESS_PROTOCOL_COMPOSITOR_TEST(
#undef MAYBE_VirtualTimeControllerTest RendererOverrideTitleJsEnabled,
"sanity/renderer-override-title-js-enabled.js");
HEADLESS_PROTOCOL_COMPOSITOR_TEST(
RendererOverrideTitleJsDisabled,
"sanity/renderer-override-title-js-disabled.js");
HEADLESS_PROTOCOL_COMPOSITOR_TEST(
RendererJavaScriptConsoleErrors,
"sanity/renderer-javascript-console-errors.js");
HEADLESS_PROTOCOL_COMPOSITOR_TEST(RendererDelayedCompletion,
"sanity/renderer-delayed-completion.js");
HEADLESS_PROTOCOL_COMPOSITOR_TEST(RendererClientRedirectChain,
"sanity/renderer-client-redirect-chain.js");
HEADLESS_PROTOCOL_COMPOSITOR_TEST(
RendererClientRedirectChainNoJs,
"sanity/renderer-client-redirect-chain-no-js.js");
} // namespace headless } // namespace headless
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