Source code

Revision control

Copy as Markdown

Other Tools

Test Info:

<!DOCTYPE html>
<meta charset="utf-8">
<title>HTML: window.open `features`: negative values for `top`, `left`</title>
<meta name=timeout content=long>
<!-- user agents are not required to support open features other than `noopener`
and on some platforms position and size features don't make sense -->
<meta name="flags" content="may" />
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/common/PrefixedPostMessage.js"></script>
<script>
var featuresPrefix = `width=401,height=404,`;
var windowURL = 'resources/message-opener.html';
setup (() => {
// Before running tests, open a window using features that mimic
// what would happen if the feature tested here were set to 0
// for comparison later.
var featureString = `${featuresPrefix}top=0,left=0`;
var prefixedMessage = new PrefixedMessageTest();
prefixedMessage.onMessage((data, e) => {
e.source.close();
runWindowTests(data);
});
var win = window.open(prefixedMessage.url(windowURL), '', featureString);
});
function runWindowTests (baselineDimensions) {
// Negative values for `top`, `left` should be interpreted as 0
[ 'top=-204',
'top=-204.5',
'top=-0'
].forEach(feature => {
async_test(t => {
var prefixedMessage = new PrefixedMessageTest();
var featureString = `${featuresPrefix}left=0,${feature}`;
prefixedMessage.onMessage(t.step_func_done((data, e) => {
e.source.close();
assert_equals(data.top, baselineDimensions.top, `"${feature} is negative and should be set to 0"`);
}));
var win = window.open(prefixedMessage.url(windowURL) + '&expected_screenY=' + baselineDimensions.top, '', featureString);
}, `features "${feature}" should NOT set "top=204"`);
});
// Negative values for `top`, `left` should be interpreted as 0
[ 'left=-204',
'left=-204.5',
'left=-0'
].forEach(feature => {
async_test(t => {
var prefixedMessage = new PrefixedMessageTest();
var featureString = `${featuresPrefix}top=0,${feature}`;
prefixedMessage.onMessage(t.step_func_done((data, e) => {
e.source.close();
assert_equals(data.left, baselineDimensions.left, `"${feature} is negative and should be set to 0"`);
}));
var win = window.open(prefixedMessage.url(windowURL) + '&expected_screenX=' + baselineDimensions.left, '', featureString);
}, `features "${feature}" should NOT set "left=204"`);
});
}
</script>