Commit 2be632d5 authored by David Bokan's avatar David Bokan Committed by Commit Bot

Add web platform tests for ViewportAPI.

Bug: 635031
Change-Id: If116b73922b27263fc5934f85939a95ad861ffd0
Reviewed-on: https://chromium-review.googlesource.com/528374
Commit-Queue: David Bokan <bokan@chromium.org>
Reviewed-by: default avatarDave Tapuska <dtapuska@chromium.org>
Cr-Commit-Position: refs/heads/master@{#478718}
parent 108d296c
......@@ -2362,6 +2362,14 @@ crbug.com/720545 external/wpt/html/the-xhtml-syntax/parsing-xhtml-documents/xhtm
# Manual tests that have not been automated.
crbug.com/626703 external/wpt/fullscreen/api/element-request-fullscreen-two-iframes-manual.html [ Timeout ]
crbug.com/732451 external/wpt/viewport/viewport-page-manual.html [ Skip ]
crbug.com/732451 external/wpt/viewport/viewport-scroll-event-manual.html [ Skip ]
crbug.com/732451 external/wpt/viewport/viewport-dimensions-scrollbars-manual.html [ Skip ]
crbug.com/732451 external/wpt/viewport/viewport-resize-event-manual.html [ Skip ]
crbug.com/732451 external/wpt/viewport/viewport-offset-manual.html [ Skip ]
crbug.com/732451 external/wpt/viewport/viewport-scale-iframe-manual.html [ Skip ]
crbug.com/732451 external/wpt/viewport/viewport-dimensions-custom-scrollbars-manual.html [ Skip ]
crbug.com/732451 external/wpt/viewport/viewport-scale-manual.html [ Skip ]
# Other untriaged test failures, timeouts and crashes from newly-imported WPT tests.
crbug.com/666703 external/wpt/html/browsers/sandboxing/sandbox-disallow-same-origin.html [ Timeout ]
......
# TEAM: input-dev@chromium.org
# COMPONENT: Blink>Input
<!doctype html>
<html>
<head>
<title>Viewport: Dimensions with custom scrollbars</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, minimum-scale=1">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="viewport_support.js"></script>
<script>
setup({explicit_done: true, explicit_timeout: true});
</script>
<style>
#spacer {
width: 10000px;
height: 10000px;
position: absolute;
visibility: hidden;
}
::-webkit-scrollbar {
width: 20px;
height: 25px;
}
::-webkit-scrollbar-track {
background-color: #b46868;
}
::-webkit-scrollbar-thumb {
background-color: rgba(0, 0, 0, 0.2);
}
</style>
</head>
<body>
<h1>Viewport: Dimensions with custom scrollbars</h1>
<h4>
Test Description: Tests the viewport dimensions correctly account for
custom scrollbars
</h4>
<h2 style="color: red">THIS IS A MANUAL TEST</h2>
<p id="skip">
<button id="skipbtn" onclick="skipManualTest();">Skip</button>
<p>
Skip this test if your browser doesn't support custom scrollbars or
browser-zoom (Ctrl+/-).
</p>
</p>
<p id="instruction"></p>
<button id="continue">Start Test</button>
<div id="log"></div>
<div id="spacer"></div>
</body>
<script>
var continueBtn = document.getElementById("continue");
function continueTest() {
nextStep(function(instructionText) {
var instruction = document.getElementById("instruction");
continueBtn.innerText = "Continue";
instruction.innerText = instructionText;
});
}
continueBtn.addEventListener('click', continueTest);
var originalWidth = 0;
var originalHeight = 0;
var originalInnerWidth = 0;
addManualTestStep(
function() {},
null,
'1. Ensure the browser is at the default pinch and browser zoom ' +
'levels (100%). Most browsers: ctrl+0');
addManualTestStep(
function() {
originalWidth = window.view.width;
originalHeight = window.view.height;
originalInnerWidth = window.innerWidth;
assert_equals(
window.view.width,
window.innerWidth - 20,
"Custom scrollbar width subtracted from viewport.");
assert_equals(
window.view.height,
window.innerHeight - 25,
"Custom scrollbar height subtracted from viewport.");
},
'No zoom or scale applied',
'2. Browser-zoom into 200% (ctrl +)');
addManualTestStep(
function() {
// Ensure we zoomed in to about what we expect.
assert_approx_equals(
originalInnerWidth / window.innerWidth,
2.0,
0.1,
"Browser zoom to correct level");
assert_equals(
window.view.width,
window.innerWidth - 20,
"Custom scrollbar width subtracted from viewport.");
assert_equals(
window.view.height,
window.innerHeight - 25,
"Custom scrollbar height subtracted from viewport.");
},
'With 200% browser zoom',
'3. Reset browser zoom (ctrl+0).');
addManualTestStep(
showPinchWidget.bind(null, 2.0, 0, 0, continueTest),
null,
'Pinch-zoom dialog in progress');
addManualTestStep(
function() {
assert_approx_equals(
window.view.scale, 2, 0.2, "Pinch zoom to correct scale");
// Scrollbars do not grow with pinch-zoom so they take up fewer
// CSS pixels as you zoom in.
assert_approx_equals(
window.view.width,
originalWidth / window.view.scale,
1,
"Custom scrollbar width subtracted from viewport.");
assert_approx_equals(
window.view.height,
originalHeight / window.view.scale,
1,
"Custom scrollbar width subtracted from viewport.");
},
'With ~200% pinch zoom',
'4. Pinch-zoom out.');
addManualTestStep(
function() { continueBtn.remove(); },
null,
'Test Complete');
</script>
</html>
<!doctype html>
<html>
<head>
<title>Viewport: Dimensions with scrollbars</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, minimum-scale=1">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="viewport_support.js"></script>
<script>
setup({explicit_done: true, explicit_timeout: true});
</script>
<style>
#spacer {
width: 10000px;
height: 10000px;
position: absolute;
visibility: hidden;
}
</style>
</head>
<body>
<h1>Viewport: Dimensions with scrollbars</h1>
<h4>
Test Description: Tests the viewport dimensions correctly account for
scrollbars
</h4>
<h2 style="color: red">THIS IS A MANUAL TEST</h2>
<p id="skip">
<button id="skipbtn" onclick="skipManualTest();">Skip Test</button>
<p>
If your browser doesn't support browser-zoom (Ctrl+/-, e.g. Mobile
Browsers) please skip.
</p>
</p>
<p id="instruction"></p>
<button id="continue">Start Test</button>
<div id="log"></div>
<div id="spacer"></div>
</body>
<script>
var continueBtn = document.getElementById("continue");
var scrollbarThickness = calculateScrollbarThickness();
function continueTest() {
nextStep(function(instructionText) {
var instruction = document.getElementById("instruction");
continueBtn.innerText = "Continue";
instruction.innerText = instructionText;
});
}
continueBtn.addEventListener('click', continueTest);
var originalWidth = 0;
var originalHeight = 0;
var originalInnerWidth = 0;
addManualTestStep(
function() {},
null,
'1. Ensure the browser is at the default pinch and browser zoom ' +
'levels (100%). Most browsers: ctrl+0');
addManualTestStep(
function() {
originalWidth = window.view.width;
originalHeight = window.view.height;
originalInnerWidth = window.innerWidth;
assert_equals(
window.view.width,
window.innerWidth - scrollbarThickness,
"Scrollbar width subtracted from viewport.");
assert_equals(
window.view.height,
window.innerHeight - scrollbarThickness,
"Scrollbar height subtracted from viewport.");
},
'No zoom or scale applied',
'2. Browser-zoom into 200% (ctrl +)');
addManualTestStep(
function() {
assert_approx_equals(
originalInnerWidth / window.innerWidth,
2.0,
0.1,
"Browser zoom to correct level");
// Scrollbars on the window don't grow with browser-zoom so
// they'll be fewer CSS pixels as the user zooms in.
assert_equals(
window.view.width,
window.innerWidth - scrollbarThickness / 2,
"Scrollbar width subtracted from viewport.");
assert_equals(
window.view.height,
window.innerHeight - scrollbarThickness / 2,
"Scrollbar height subtracted from viewport.");
},
'With 200% browser zoom',
'3. Reset browser zoom (ctrl+0).');
addManualTestStep(
showPinchWidget.bind(null, 2.0, 0, 0, continueTest),
null,
'Pinch-zoom dialog in progress');
addManualTestStep(
function() {
assert_approx_equals(
window.view.scale, 2, 0.2, "Pinch zoom to correct scale");
assert_approx_equals(window.view.width,
originalWidth / window.view.scale,
1,
"Scrollbar width subtracted from viewport.");
assert_approx_equals(window.view.height,
originalHeight / window.view.scale,
1,
"Scrollbar width subtracted from viewport.");
},
'With ~200% pinch zoom',
'4. Pinch-zoom out.');
addManualTestStep(
function() { continueBtn.remove(); },
null,
'Test Complete');
</script>
</html>
<!doctype html>
<html>
<head>
<title>Viewport: Offset</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, minimum-scale=1">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="viewport_support.js"></script>
<script>
setup({explicit_done: true, explicit_timeout: true});
</script>
<style>
html {
width: 100%;
height: 100%;
}
#fullscreenBox {
position: fixed;
left: 0;
top: 0;
width: 100%;
height: 100%;
visibility: hidden;
}
</style>
</head>
<body>
<h1>Viewport: Offset</h1>
<h4>
Test Description: Tests the offset scrolling properties on an
unscrollable page.
</h4>
<h2 style="color: red">THIS IS A MANUAL TEST</h2>
<p id="skip">
<button id="skipbtn" onclick="skipManualTest();">Skip Test</button>
</p>
<h4>Instruction</h4>
<p id="instruction"></p>
<button id="continue">Start Test</button>
<div id="log"></div>
<div id="fullscreenBox">
<!-- Invisible but needed to get maximum scrollable extents in the
presence of a collapsible URL bar. -->
</div>
</body>
<script>
var continueBtn = document.getElementById("continue");
function continueTest() {
nextStep(function(instructionText) {
var instruction = document.getElementById("instruction");
continueBtn.innerText = "Continue";
instruction.innerText = instructionText;
});
}
continueBtn.addEventListener('click', continueTest);
// Prevent scrolling (though there should be no overflow) so that all
// scrolling must happen as panning the visual viewport within the
// layout viewport.
document.documentElement.style.overflow = "hidden";
addManualTestStep(
function() {},
null,
'1. Ensure the browser is at the default pinch and browser zoom ' +
'levels (100%). Most browsers: ctrl+0');
var scale = 3.0;
var xTarget = 2 * window.innerWidth / scale;
var yTarget = 2 * window.innerHeight / scale;
addManualTestStep(
showPinchWidget.bind(null, scale, xTarget, yTarget, continueTest),
null,
'2.Follow instructions on pinch zoom dialog.');
addManualTestStep(
function() {
var actualScale = window.view.scale;
var actualOffsetLeft = window.view.offsetLeft;
var actualOffsetTop = window.view.offsetTop;
// This needs to happen before assertions in case they fail. A
// failed assertion stops running this function.
window.scrollTo(0, 0);
// Ensure we zoomed in to about what we expect.
assert_approx_equals(actualScale, scale, 0.2,
"window.view.scale reflects pinch-zoom level");
assert_approx_equals(actualOffsetLeft, xTarget, 5,
"offsetLeft value is correct.");
assert_approx_equals(actualOffsetTop, yTarget, 5,
"offsetTop value is correct.");
},
'With ~300% pinch-zoom',
'3. Pinch-zoom back out to the minimum scale');
addManualTestStep(
showPinchWidget.bind(null, 2, 0, 0, continueTest),
null,
'4.Follow instructions on pinch zoom dialog.');
addManualTestStep(
function() {
document.documentElement.style.overflow = "";
continueBtn.style.position = "absolute";
continueBtn.style.left = "150%";
continueBtn.style.top = "150%";
assert_approx_equals(window.view.scale, 2, 0.2,
"window.view.scale reflects pinch-zoom level");
},
'Tester pinch zoomed in correctly',
'5. Scroll fully to the bottom right. Click the continue button ' +
'there.');
addManualTestStep(
function() {
var fullscreenBox = document.getElementById('fullscreenBox');
var expectedLeft = fullscreenBox.clientWidth / 2;
var expectedTop = fullscreenBox.clientHeight / 2;
var viewOffsetLeft = window.view.offsetLeft;
var viewOffsetTop = window.view.offsetTop;
// This needs to happen before assertions in case they fail. A
// failed assertion stops running this function.
continueBtn.style.position = "";
continueBtn.style.left = "";
continueBtn.style.top = "";
window.scrollTo(0, 0);
assert_approx_equals(viewOffsetLeft, expectedLeft, 10,
"OffsetLeft is correct");
assert_approx_equals(viewOffsetTop, expectedTop, 10,
"OffsetTop");
},
'OffsetLeft and OffsetTop correct when there\'s some layout ' +
'viewport scrolling as well.',
'6. Pinch-zoom out fully');
addManualTestStep(
function() {
continueBtn.remove();
},
null,
'Test Complete');
</script>
</html>
<!doctype html>
<html>
<head>
<title>Viewport: Page</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, minimum-scale=1">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="viewport_support.js"></script>
<script>
setup({explicit_done: true, explicit_timeout: true});
</script>
<style>
html {
width: 100%;
height: 100%;
}
</style>
</head>
<body>
<h1>Viewport: Page</h1>
<h4>
Test Description: Tests the page scrolling properties.
</h4>
<h2 style="color: red">THIS IS A MANUAL TEST</h2>
<p id="skip">
<button id="skipbtn" onclick="skipManualTest();">Skip Test</button>
</p>
<h4>Instruction</h4>
<p id="instruction"></p>
<button id="continue">Start Test</button>
<div id="log"></div>
</body>
<script>
var continueBtn = document.getElementById("continue");
var icbWidth = 0;
var icbHeight = 0;
function continueTest() {
nextStep(function(instructionText) {
var instruction = document.getElementById("instruction");
continueBtn.innerText = "Continue";
instruction.innerText = instructionText;
});
}
continueBtn.addEventListener('click', continueTest);
addManualTestStep(
function() {},
null,
'1. Ensure the browser is at the default pinch and browser zoom ' +
'levels (100%). Most browsers: ctrl+0');
addManualTestStep(
showPinchWidget.bind(null, 1.5, 0, 0, continueTest),
null,
'2.Follow instructions on pinch zoom dialog.');
addManualTestStep(
function() {
continueBtn.style.position = "absolute";
continueBtn.style.left = "400%";
continueBtn.style.top = "400%";
assert_approx_equals(window.view.scale, 1.5, 0.2,
"window.view.scale reflects pinch-zoom level");
},
'Tester pinch zoomed in correctly',
'3. Scroll fully to the bottom right. Click the continue button there.');
addManualTestStep(
function() {
var expectedLeft =
document.documentElement.clientWidth * 4 +
continueBtn.clientWidth -
window.view.width;
var expectedTop =
document.documentElement.clientHeight * 4 +
continueBtn.clientHeight -
window.view.height;
var viewPageLeft = window.view.pageLeft;
var viewPageTop = window.view.pageTop;
// This needs to happen before assertions in case they fail. A
// failed assertion stops running this function.
continueBtn.style.position = "";
continueBtn.style.left = "";
continueBtn.style.top = "";
window.scrollTo(0, 0);
assert_approx_equals(viewPageLeft, expectedLeft, 10,
"window.view.scale reflects pinch-zoom level");
assert_approx_equals(viewPageTop, expectedTop, 10,
"window.view.scale reflects pinch-zoom level");
},
'PageLeft and PageTop correct when scrolled',
'4. Pinch-zoom out fully');
addManualTestStep(
function() {
continueBtn.remove();
},
null,
'Test Complete');
</script>
</html>
<!DOCTYPE html>
<script src="../../../resources/testharness.js"></script>
<script src="../../../resources/testharnessreport.js"></script>
<style>
html {
height: 100%;
}
</style>
<h4>This test checks that requesting the viewport size causes any pending layout to occur.</h4>
<script>
async_test(function(t) {
window.onload = t.step_func(function() {
assert_equals(window.view.width, document.documentElement.clientWidth,
"window.view.width should match the window width.");
assert_equals(view.height, document.documentElement.clientHeight,
"window.view.height should match the window height.");
// Add overflow so scrollbars appear.
document.body.style.width = "2000px";
document.body.style.height = "2000px";
var viewportWidth = window.view.width;
var viewportHeight = window.view.height;
assert_equals(viewportWidth, document.documentElement.clientWidth,
"Reading viewport width should cause a layout and exclude the new scrollbar.");
assert_equals(viewportHeight, document.documentElement.clientHeight,
"Reading viewport height should cause a layout and exclude the new scrollbar.");
t.done();
});
});
</script>
<!DOCTYPE html>
<script src="../../../resources/testharness.js"></script>
<script src="../../../resources/testharnessreport.js"></script>
<style>
iframe {
width: 200px;
height: 300px;
}
</style>
<h4>This test checks that requesting the viewport size in an iframe causes any pending layout to occur.</h4>
<iframe srcdoc="<!DOCTYPE html><style>html{height:100%}</style>"></iframe>
<script>
async_test(function(t) {
window.onload = t.step_func(function() {
assert_equals(frames[0].window.view.width, 200,
"Reading width of iframe viewport should match iframe width.");
assert_equals(frames[0].window.view.height, 300,
"Reading height of iframe viewport should match iframe height.");
// Add overflow so scrollbars appear.
window.frames[0].window.document.body.style.width = "2000px";
window.frames[0].window.document.body.style.height = "2000px";
var viewportWidth = frames[0].window.view.width;
var viewportHeight = frames[0].window.view.height;
assert_equals(viewportWidth, frames[0].window.document.documentElement.clientWidth,
"Reading width of iframe viewport should cause a layout and exclude the new scrollbar.");
assert_equals(viewportHeight, frames[0].window.document.documentElement.clientHeight,
"Reading height of iframe viewport should cause a layout and exclude the new scrollbar.");
t.done();
});
});
</script>
<!doctype html>
<html>
<head>
<title>Viewport: Window Resize Fires Event</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="viewport_support.js"></script>
<script>
setup({explicit_timeout: true, explicit_done: true})
</script>
</head>
<body>
<h1>Viewport: Window Resize Fires Event</h1>
<h4>
Test Description: This test checks that a resize event is fired against
the window.view object when the browser window is resized.
</h4>
<h2 style="color: red">THIS IS A MANUAL TEST</h2>
<p id="skip">
<button id="skipbtn" onclick="skipManualTest();">Skip Test</button>
</p>
<p id="instruction"></p>
<button id="continue">Start Test</button>
<div id="log"></div>
</body>
<script>
var continueBtn = document.getElementById("continue");
function continueTest() {
nextStep(function(instructionText) {
var instruction = document.getElementById("instruction");
continueBtn.innerText = "Continue";
instruction.innerText = instructionText;
});
}
continueBtn.addEventListener('click', continueTest);
var didResizeView;
var cancelable;
var bubbles;
function resetValues() {
didResizeView = false;
cancelable = undefined;
bubbles = undefined;
}
addManualTestStep(
function() {
resetValues();
window.view.addEventListener('resize', function(e) {
didResizeView = true;
cancelable = e.cancelable;
bubbles = e.bubbles;
});
},
null,
'1. Resize the browser window (if on mobile, rotate the device)');
addManualTestStep(
function() {
assert_true(didResizeView);
assert_false(cancelable);
assert_false(bubbles);
},
'Resize event fired at window.view after window resized',
'2. Unrotate the device or reset window size if needed.');
addManualTestStep(
resetValues,
null,
'3. Pinch-zoom anywhere on the page by any amount.');
addManualTestStep(
function() {
assert_true(didResizeView);
assert_false(cancelable);
assert_false(bubbles);
},
'Pinch-zooming fires a resize event',
'4. Pinch-zoom back out');
addManualTestStep(
function() { continueBtn.remove(); },
null,
'Test Complete');
</script>
</html>
<!doctype html>
<html>
<head>
<title>Viewport: Scale iframe</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, minimum-scale=1">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="viewport_support.js"></script>
<script>
setup({explicit_done: true, explicit_timeout: true});
</script>
<style>
iframe {
width: 200px;
height: 200px;
}
</style>
</head>
<body>
<h1>Viewport: Scale iframe</h1>
<h4>Test Description: Tests the view.scale property inside an iframe</h4>
<h2 style="color: red">THIS IS A MANUAL TEST</h2>
<p id="skip">
<button id="skipbtn" onclick="skipManualTest();">Skip Test</button>
</p>
<p id="instruction"></p>
<button id="continue">Start Test</button>
<p>
<iframe srcdoc="<!DOCTYPE html><style>html {background-color: coral;}</style>"></iframe>
</p>
<div id="log"></div>
</body>
<script>
var continueBtn = document.getElementById("continue");
function continueTest() {
nextStep(function(instructionText) {
var instruction = document.getElementById("instruction");
continueBtn.innerText = "Continue";
instruction.innerText = instructionText;
});
}
continueBtn.addEventListener('click', continueTest);
addManualTestStep(
function() {},
null,
'1. Ensure the browser is at the default pinch and browser zoom ' +
'levels (100%). Most browsers: ctrl+0');
addManualTestStep(
showPinchWidget.bind(null, 2.0, 0, 0, continueTest),
null,
'2.Follow instructions on pinch zoom dialog.');
addManualTestStep(
function() {
// Ensure we zoomed in to about what we expect.
assert_approx_equals(window.view.scale, 2.0, 0.2,
"Main window.view.scale reflects pinch-zoom level");
assert_equals(frames[0].window.view.scale, 1.0,
"Iframe scale unchanged even when pinch-zoomed");
},
'Check iframe scale is unchanged when page is pinch-zoomed',
'3. Pinch-zoom back out to the minimum scale');
addManualTestStep(
function() {
continueBtn.remove();
},
null,
'Test Complete');
</script>
</html>
<!doctype html>
<html>
<head>
<title>Viewport: Scale</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, minimum-scale=1">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="viewport_support.js"></script>
<script>
setup({explicit_done: true, explicit_timeout: true});
</script>
</head>
<body>
<h1>Viewport: Scale</h1>
<h4>Test Description: Tests the view.scale property</h4>
<h2 style="color: red">THIS IS A MANUAL TEST</h2>
<p id="skip">
<button id="skipbtn" onclick="skipManualTest();">Skip Test</button>
</p>
<p id="instruction"></p>
<button id="continue">Start Test</button>
<div id="log"></div>
<div id="spacer"></div>
</body>
<script>
var continueBtn = document.getElementById("continue");
function continueTest() {
nextStep(function(instructionText) {
var instruction = document.getElementById("instruction");
continueBtn.innerText = "Continue";
instruction.innerText = instructionText;
});
}
continueBtn.addEventListener('click', continueTest);
addManualTestStep(
function() {},
null,
'1. Ensure the browser is at the default pinch and browser zoom ' +
'levels (100%). Most browsers: ctrl+0');
addManualTestStep(
showPinchWidget.bind(null, 2.0, 0, 0, continueTest),
null,
'2.Follow instructions on pinch zoom dialog.');
addManualTestStep(
function() {
// Ensure we zoomed in to about what we expect.
assert_approx_equals(window.view.scale, 2.0, 0.2,
"window.view.scale reflects pinch-zoom level");
},
'With ~200% pinch-zoom',
'3. Pinch-zoom back out to the minimum scale');
addManualTestStep(
function() {
assert_equals(window.view.scale, 1);
},
'Fully pinch-zoomed out',
'4. If your browser supports it, browser-zoom in (using ctrl-+). ' +
'Otherwise just click continue.');
addManualTestStep(
function() {
assert_equals(window.view.scale, 1);
},
'Browser zoom doesn\'t change view.scale',
'5. Reset browser zoom to default (ctrl-0)');
addManualTestStep(
function() {
continueBtn.remove();
},
null,
'Test Complete');
</script>
</html>
<!doctype html>
<html>
<head>
<title>Viewport: Scroll Event</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, minimum-scale=1">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="viewport_support.js"></script>
<script>
setup({explicit_timeout: true, explicit_done: true})
</script>
<style>
html {
width: 100%;
height: 100%;
}
</style>
</head>
<body>
<h1>Viewport: Scroll Event</h1>
<h4>
Test Description: This test checks that a scroll event is fired against
the window.view object when the viewport is scrolled.
</h4>
<h2 style="color: red">THIS IS A MANUAL TEST</h2>
<p id="skip">
<button id="skipbtn" onclick="skipManualTest();">Skip Test</button>
</p>
<h4>Instruction</h4>
<p id="instruction"></p>
<button id="continue">Start Test</button>
<div id="log"></div>
</body>
<script>
var continueBtn = document.getElementById("continue");
function continueTest() {
nextStep(function(instructionText) {
var instruction = document.getElementById("instruction");
continueBtn.innerText = "Continue";
instruction.innerText = instructionText;
});
}
continueBtn.addEventListener('click', continueTest);
var didGetScrollEvent = false;
var cancelable = undefined;
var bubbles = undefined;
function resetValues() {
didGetScrollEvent = false;
cancelable = undefined;
bubbles = undefined;
}
addManualTestStep(
function() {
window.view.addEventListener('scroll', function(e) {
didGetScrollEvent = true;
cancelable = e.cancelable;
bubbles = e.bubbles;
});
document.documentElement.style.overflow = "hidden";
},
null,
'1. Pinch-zoom a little near the "Continue" button but don\'t ' +
'perform any scrolling.');
addManualTestStep(
function() {
requestAnimationFrame(continueTest);
assert_true(didGetScrollEvent, "Got event");
assert_false(cancelable, "Event is not cancelable");
assert_false(bubbles, "Event does not bubble");
},
'Got scroll event while pinch-zooming',
'');
addManualTestStep(
resetValues,
null,
'2. Scroll in any direction.');
addManualTestStep(
function() {
requestAnimationFrame(continueTest);
assert_true(didGetScrollEvent, "Got event");
assert_false(cancelable, "Event is not cancelable");
assert_false(bubbles, "Event does not bubble");
},
'Panning viewport fires a scroll event',
'');
addManualTestStep(
function() {
continueBtn.style.position = "absolute";
continueBtn.style.right = "10px";
continueBtn.style.bottom = "10px";
},
null,
'3. Scroll fully to the bottom right and click the continue ' +
'button.');
var offsetLeft;
var offsetTop;
addManualTestStep(
function() {
resetValues();
document.documentElement.style.overflow = "";
document.body.style.width = "500%";
document.body.style.height = "500%";
continueBtn.style.position = "";
continueBtn.style.left = "";
continueBtn.style.top = "";
offsetLeft = window.view.offsetLeft;
offsetTop = window.view.offsetTop;
// The visual viewport should be fully scrolled so even if
// scrollTo does normally "push" the layout viewport with the
// visual, there should be no change to either offsetValue
window.scrollTo(10000, 10000);
requestAnimationFrame(continueTest);
assert_equals(window.view.offsetLeft, offsetLeft,
"OffsetLeft Unchanged");
assert_equals(window.view.offsetTop, offsetTop,
"OffsetTop Unchanged");
assert_false(didGetScrollEvent,
"Should not get view scroll event");
},
'scrollTo down and right on a fully scrolled visual viewport ' +
'shouldn\'t change offsets',
'');
addManualTestStep(
function() {
requestAnimationFrame(continueTest);
assert_false(didGetScrollEvent,
"Should not get view scroll event");
resetValues();
},
'scrollTo without changing offsets shouldn\'t fire scroll event ' +
'on view',
'');
addManualTestStep(
function() {
requestAnimationFrame(continueTest);
resetValues();
window.scrollTo(0, 0);
},
null,
'');
addManualTestStep(
function() {
// How scrollTo behaves in this case isn't fully spec'd but
// make sure it's at least rational if it does change the
// offset values.
var scrollChangedOffset =
offsetLeft != window.view.offsetLeft ||
offsetTop != window.view.offsetTop;
document.body.style.width = "";
document.body.style.height = "";
assert_equals(didGetScrollEvent, scrollChangedOffset,
'If the scrollTo changed offsets it must have fired a ' +
'scroll event');
},
'scrollTo must fire scroll event if it changes view.offsetLeft|Top',
'6. Pinch-zoom out fully');
addManualTestStep(
function() { continueBtn.remove(); },
null,
'Test Complete');
</script>
</html>
<!doctype html>
<html>
<head>
<title>Viewport: Scrollbars Cause Resize</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, minimum-scale=1">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="viewport_support.js"></script>
</head>
<body>
<h1>Viewport: Scrollbars Cause Resize</h1>
<h4>
Test Description: This test checks that the appearance of classic
scrollbars will cause a resize event to be fired at window.view.
</h4>
<script>
function runTest() {
var scrollbarThickness = calculateScrollbarThickness();
document.documentElement.style.overflow = "hidden";
var initialWidth = view.width;
var initialHeight = view.height;
test(function() {
assert_equals(window.view.width, window.innerWidth);
assert_equals(window.view.height, window.innerHeight);
}, "view size initially matches window size");
var t = async_test(
"Resize event was fired at window.view if, and only if, " +
"scrollbars are classic (i.e. affect flow)");
var viewResized = false;
window.view.addEventListener('resize', function() {
viewResized = true;
});
requestAnimationFrame(t.step_func_done(function() {
assert_equals(viewResized, scrollbarThickness > 0);
}));
document.documentElement.style.overflow = "";
document.body.style.width = "10000px";
document.body.style.height = "10000px";
var expectedWidth = initialWidth - scrollbarThickness;
var expectedHeight = initialHeight - scrollbarThickness;
test(function() {
assert_equals(window.view.width, expectedWidth);
assert_equals(window.view.height, expectedHeight);
}, "view size reflects appearance of classic scrollbars");
document.body.style.width = "";
document.body.style.height = "";
}
// Run the test after load to make sure any resize from a previous test
// doesn't interfere.
window.onload = runTest;
</script>
<div id="log"></div>
</body>
</html>
<!doctype html>
<html>
<head>
<title>Viewport: window.view type</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<h1>Viewport: window.view type</h1>
<h4>Test Description: This test checks that window.view is an object of type VisualViewport.</h4>
<script>
test(function() {
assert_equals(typeof(window.view), "object");
}, "window.view is an object");
test(function() {
assert_equals(window.view.toString(), "[object VisualViewport]");
}, "window.view has type `VisualViewport`");
addEventListener("load", function() {
document.getElementById("viewtype-log").innerText = typeof(window.view);
});
</script>
<div id="complete-notice">
<p>window.view is of type: <span id="viewtype-log"></span>.</p>
</div>
<div id="log"></div>
</body>
</html>
<!doctype html>
<html>
<head>
<title>Viewport: Unscaled scale iframe</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="viewport_support.js"></script>
<style>
iframe {
width: 200px;
height: 300px;
}
</style>
</head>
<body>
<h1>Viewport: Unscaled scale iframe</h1>
<h4>Test Description: This test checks that the default value for scale inside an iframe is 1.</h4>
<iframe></iframe>
<div id="complete-notice">
<p>iframe's window.view.scale is <span id="view-scale-log"></span>.</p>
</div>
<div id="log"></div>
</body>
<script>
test(function() {
assert_equals(frames[0].window.view.scale, 1);
}, "iframe's view.scale default value.");
document.getElementById("view-scale-log").innerText = frames[0].window.view.scale;
</script>
</html>
<!doctype html>
<html>
<head>
<title>Viewport: Unscaled scale</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="viewport_support.js"></script>
</head>
<body>
<h1>Viewport: Unscaled scale</h1>
<h4>Test Description: This test checks that the default value for scale is 1.</h4>
<div id="complete-notice">
<p>window.view.scale is <span id="view-scale-log"></span>.</p>
</div>
<div id="log"></div>
</body>
<script>
test(function() {
assert_equals(window.view.scale, 1);
}, "view.scale default value.");
document.getElementById("view-scale-log").innerText = window.view.scale;
</script>
</html>
<!doctype html>
<html>
<head>
<title>Viewport: Scroll in iframe - no page scale</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="viewport_support.js"></script>
<style>
iframe {
width: 200px;
height: 300px;
border: 0;
}
</style>
</head>
<body>
<h1>Viewport: Scroll in iframe - no page scale</h1>
<h4>Test Description: This test checks that window.view returns correct offset and scroll values without any pinch-zoom page scale applied.</h4>
<iframe></iframe>
<div id="complete-notice">
<p>frames[0].window.view's offsetLeft and offsetTop is (<span id="scroll-offset-log"></span>).</p>
<p>frames[0].window.view's pageLeft and pageTop is (<span id="scroll-page-log"></span>).</p>
</div>
<div id="log"></div>
</body>
<script>
var iframe = frames[0].window;
// Add overflow we can scroll.
iframe.document.body.style.width = "2000px";
iframe.document.body.style.height = "2000px";
iframe.scrollTo(1000, 1200);
test(function() {
assert_equals(iframe.view.offsetLeft, 0);
}, "offsetLeft must be 0.");
test(function() {
assert_equals(iframe.view.offsetTop, 0);
}, "offsetTop must be 0.");
test(function() {
assert_equals(iframe.view.pageLeft, 1000);
}, "pageLeft must reflect location of viewport in document.");
test(function() {
assert_equals(iframe.view.pageTop, 1200);
}, "pageTop must reflect location of viewport in document.");
document.getElementById("scroll-offset-log").innerText = iframe.view.offsetLeft+ ", " + iframe.view.offsetTop;
document.getElementById("scroll-page-log").innerText = iframe.view.pageLeft + ", " + iframe.view.pageTop;
</script>
</html>
<!doctype html>
<html>
<head>
<title>Viewport: Scroll - no page scale</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, minimum-scale=1">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="viewport_support.js"></script>
</head>
<body>
<h1>Viewport: Scroll - no page scale</h1>
<h4>Test Description: This test checks that window.view returns correct offset and scroll values without any pinch-zoom page scale applied.</h4>
<div id="complete-notice">
<p>window.view's offsetLeft and offsetTop is (<span id="scroll-offset-log"></span>).</p>
<p>window.view's pageLeft and pageTop is (<span id="scroll-page-log"></span>).</p>
</div>
<div id="log"></div>
</body>
<script>
// Add overflow we can scroll.
document.body.style.width = "5000px";
document.body.style.height = "5000px";
scrollTo(1000, 1200);
test(function() {
assert_equals(window.view.offsetLeft, 0);
}, "offsetLeft must be 0.");
test(function() {
assert_equals(window.view.offsetTop, 0);
}, "offsetTop must be 0.");
test(function() {
assert_equals(window.view.pageLeft, 1000);
}, "pageLeft must reflect location of viewport in document.");
test(function() {
assert_equals(window.view.pageTop, 1200);
}, "pageTop must reflect location of viewport in document.");
document.getElementById("scroll-offset-log").innerText = window.view.offsetLeft+ ", " + window.view.offsetTop;
document.getElementById("scroll-page-log").innerText = window.view.pageLeft + ", " + window.view.pageTop;
scrollTo(0, 0);
</script>
</html>
<!doctype html>
<html>
<head>
<title>Viewport: Size in iframe - no page scale</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="viewport_support.js"></script>
<style>
iframe {
width: 200px;
height: 300px;
border: 0;
}
</style>
</head>
<body>
<h1>Viewport: Size in iframe - no page scale</h1>
<h4>Test Description: This test checks that window.view returns correct sizes without any pinch-zoom page scale applied but with scrollbars.</h4>
<iframe></iframe>
<div id="complete-notice">
<p>frames[0].window.view width and height is (<span id="size-log"></span>).</p>
<p>frames[0].window.view width and height when scrollbars are present is (<span id="size-scrollbars-log"></span>).</p>
</div>
<div id="log"></div>
</body>
<script>
var scrollbarThickness = calculateScrollbarThickness();
test(function() {
assert_equals(frames[0].window.view.width, 200);
}, "window.view.width of iframe viewport should match iframe width.");
test(function() {
assert_equals(frames[0].window.view.height, 300);
}, "window.view.height of iframe viewport should match iframe height.");
document.getElementById("size-log").innerText = frames[0].window.view.width + ", " + frames[0].window.view.height;
// Add overflow so scrollbars appear.
window.frames[0].window.document.body.style.width = "2000px";
window.frames[0].window.document.body.style.height = "2000px";
test(function() {
assert_equals(frames[0].window.view.width, 200 - scrollbarThickness);
}, "window.view.width of iframe viewport should not include scrollbar.");
test(function() {
assert_equals(frames[0].window.view.height, 300 - scrollbarThickness);
}, "window.view.height of iframe viewport should not include scrollbar.");
document.getElementById("size-scrollbars-log").innerText = frames[0].window.view.width + ", " + frames[0].window.view.height;
</script>
</html>
<!doctype html>
<html>
<head>
<title>Viewport: Size unscaled</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, minimum-scale=1">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="viewport_support.js"></script>
<style>
html {
width: 100%;
height: 100%;
}
</style>
</head>
<body>
<h1>Viewport: Size unscaled</h1>
<h4>Test Description: This test checks that window.view returns correct sizes without any pinch-zoom page scale applied.</h4>
<div id="complete-notice">
<p>window.view width and height is (<span id="view-size-log"></span>).</p>
<p>window.view width and height when scrollbars are present is (<span id="view-size-scrollbar-log"></span>).</p>
</div>
<div id="log"></div>
</body>
<script>
var scrollbarThickness = calculateScrollbarThickness();
test(function() {
assert_equals(window.view.width, document.documentElement.clientWidth);
}, "view.width should match documentElement.clientWidth when unzoomed.");
test(function() {
assert_equals(window.view.height, document.documentElement.clientHeight);
}, "view.height should match documentElement.clientHeight when unzoomed.");
document.getElementById("view-size-log").innerText = window.view.width + ", " + window.view.height;
// Add overflow so scrollbars appear.
document.body.style.width = "2000px";
document.body.style.height = "2000px";
test(function() {
assert_equals(window.view.width, document.documentElement.clientWidth);
}, "view.width should exclude scrollbar.");
test(function() {
assert_equals(window.view.height, document.documentElement.clientHeight);
}, "view.height should exclude scrollbar.");
document.getElementById("view-size-scrollbar-log").innerText = window.view.width + ", " + window.view.height;
</script>
</html>
// If scrollbars affect layout (i.e. what the CSS Overflow spec calls "classic
// scrollbars", as opposed to overlay scrollbars), return the scrollbar
// thickness in CSS pixels. Returns 0 otherwise.
function calculateScrollbarThickness() {
var container = document.createElement("div");
container.style.width = "100px";
container.style.height = "100px";
container.style.position = "absolute";
container.style.visibility = "hidden";
container.style.overflow = "auto";
document.body.appendChild(container);
var widthBefore = container.clientWidth;
var longContent = document.createElement("div");
longContent.style.height = "1000px";
container.appendChild(longContent);
var widthAfter = container.clientWidth;
container.remove();
return widthBefore - widthAfter;
}
// Puts up a widget on screen instructing the user to pinch-zoom in to the
// given scale. The widget is sized such that the given scale is achieved. The
// widget is placed at (x, y) on the page. A button on the widget is used by
// the user to let the widget know that the user has finished. If a callback is
// provided, it will be called when the user dismisses the widget.
function showPinchWidget(scale, x, y, callback) {
var border = 10;
var width = window.innerWidth / scale - border;
var height = window.innerHeight / scale - border;
var box = document.createElement("div");
box.style.width = width + "px";
box.style.height = height + "px";
// Adjust the x/y coordinates by the border width. We want the box to
// appear in a place such that if the user gets the window edges exactly on
// the half-point of the border they end up at x/y
box.style.left = x - border/2 + "px";
box.style.top = y - border/2 + "px";
box.style.position = "absolute";
box.style.backgroundColor = "coral";
box.style.border = border + "px solid blue";
box.style.borderBottom = "0";
box.style.overflow = "auto";
var oldDocumentOverflow = document.documentElement.style.overflow;
var instructions = document.createElement("p");
instructions.innerText =
"Pinch-zoom and align this box so that the left, right, and top " +
"window edges are over the border on each side. When done, click the " +
"'DONE' button above";
instructions.style.textAlign = "center";
instructions.style.fontSize = "medium";
var button = document.createElement("button");
button.innerText = "DONE";
button.style.width = "50%";
button.style.height = "20%";
button.style.fontSize = "medium";
button.style.marginLeft = "25%";
button.addEventListener("click", function() {
box.remove();
document.documentElement.style.overflow = oldDocumentOverflow;
if (callback)
callback();
});
box.appendChild(button);
box.appendChild(instructions);
document.documentElement.style.overflow = "hidden";
document.body.appendChild(box);
}
// Ends a manual test. Must be called before any async tests are started.
function skipManualTest() {
test(function() { assert_true(false); }, "Manual Test Skipped");
done();
}
var stepInstructions = [];
var testNames = [];
var stepFunctions = [];
var steps;
var curStep = 0;
// Adds a manual test step to the test. A test will add a series of steps,
// along with instructions. Once all the tests steps are added, the test can
// be run by continually running the nextStep() function. All manual test steps
// must be added before calling nextStep.
//
// |func| A function to be executed at the given step. This function can include
// testharness assertions if |testName| is provided. If this is the last
// step, the |done()| function (used for manual testharness.js tests)
// will be called after |func| is executed.
// |testName| If provided, the |func| will be wrapped in a testharness.js
// async_test with this name. If null, |func| will be executed as a
// free function.
// |instructions| The text to display to the user. Note, these are shown after
// step is executed so these should be instructions to setup the
// checks in the next step.
function addManualTestStep(func, testName, instructions) {
stepFunctions.push(func);
testNames.push(testName);
stepInstructions.push(instructions);
}
// Runs the next step of the test. This must be called only after all test steps
// have been added using |addManualTestStep|.
//
// |callbackFunc| If provided, will be called with a single argument being the
// instruction string for the current step. Use this to update
// any necessary UI.
function nextStep(callbackFunc) {
if (curStep == 0)
_startManualTest();
if (typeof(callbackFunc) === 'function')
callbackFunc(stepInstructions[curStep]);
steps[curStep]();
curStep++;
}
function _startManualTest() {
steps = [];
for (let i = 0; i < stepFunctions.length; ++i) {
var stepFunc = stepFunctions[i];
var testName = testNames[i];
if (testName) {
steps.push(async_test(testName).step_func(function() {
stepFunctions[i]();
this.done();
if (i == stepFunctions.length - 1)
done();
}));
} else {
steps.push(function() {
stepFunctions[i]();
if (i == stepFunctions.length - 1)
done();
});
}
}
}
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