Commit 52a2526d authored by dgozman@chromium.org's avatar dgozman@chromium.org

[DevTools] Add test for screen size and position overrides.

BUG=393493

Review URL: https://codereview.chromium.org/1209013002

git-svn-id: svn://svn.chromium.org/blink/trunk@197917 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 3099665b
Tests that device emulation with insets affects window.screenWidth, window.screenHeight, screen.width and screen.height.
Page reloaded.
Emulating device: 1200x1000x1 viewport='none'
Emulation warning: You might need to reload the page for proper user agent spoofing and viewport rendering.
Device:
window.screenX = 10px
window.screenY = 20px
Viewport: = ?none
@media orientation = landscape
window.orientation
@media resolution = 96dpi
@media device-pixel-ratio = 1
window.devicePixelRatio = 1
Widths:
@media device-width = 1240px
screen.width = 1240px
screen.availWidth = 1240px
window.outerWidth = 1200px
window.innerWidth = 1200px
@media width = 1200px
doc.docElem.clientWidth = 1200px
doc.docElem.offsetWidth = 1200px
doc.docElem.scrollWidth = 1200px
doc.body.clientWidth = 1200px
doc.body.offsetWidth = 1200px
doc.body.scrollWidth = 1200px
Heights:
@media device-height = 1060px
screen.height = 1060px
screen.availHeight = 1060px
window.outerHeight = 1000px
window.innerHeight = 1000px
@media height = 1000px
doc.docElem.clientHeight = 1000px
doc.docElem.offsetHeight = 1000px
doc.docElem.scrollHeight = 1000px
doc.body.clientHeight = 1000px
doc.body.offsetHeight = 1000px
doc.body.scrollHeight = 1000px
<html>
<head>
<script src="../../http/tests/inspector/inspector-test.js"></script>
<script src="../../http/tests/inspector/elements-test.js"></script>
<script src="device-emulation-test.js"></script>
<script>
// This test is based on http://jsbin.com/urowoh/latest.
setMetaViewport();
</script>
<style>
html {
overflow-x: hidden;
}
body {
margin: 0;
min-height: 1000px;
overflow-x: hidden;
}
</style>
<script>
function test()
{
InspectorTest.testDeviceEmulation("device-emulation-insets.html", 1200, 1000, 1, "none", new Insets(10, 20, 30, 40));
}
</script>
</head>
<body onload="runTest()">
<p>
Tests that device emulation with insets affects window.screenWidth, window.screenHeight, screen.width and screen.height.
</p>
</body>
</html>
......@@ -29,12 +29,12 @@ function test()
InspectorTest._deviceEmulationResults = [];
var originalMetrics;
InspectorTest.applyEmulationAndReload(false, 0, 0, 1, "none", InspectorTest.getPageMetrics.bind(InspectorTest, true, saveMetrics));
InspectorTest.applyEmulationAndReload(false, 0, 0, 1, "none", null, InspectorTest.getPageMetrics.bind(InspectorTest, true, saveMetrics));
function saveMetrics(metrics)
{
originalMetrics = metrics.value;
InspectorTest.emulateAndGetMetrics(1200, 1000, 1, "w=320", restore);
InspectorTest.emulateAndGetMetrics(1200, 1000, 1, "w=320", null, restore);
}
function restore()
......@@ -50,7 +50,7 @@ function test()
InspectorTest.completeTest();
}
InspectorTest.applyEmulationAndReload(false, 0, 0, 1, "none", InspectorTest.getPageMetrics.bind(InspectorTest, true, callback));
InspectorTest.applyEmulationAndReload(false, 0, 0, 1, "none", null, InspectorTest.getPageMetrics.bind(InspectorTest, true, callback));
}
}
</script>
......
......@@ -187,9 +187,24 @@ InspectorTest.getPageMetrics = function(full, callback)
InspectorTest.evaluateInPage("dumpMetrics(" + full + ")", callback);
}
InspectorTest.applyEmulationAndReload = function(enabled, width, height, deviceScaleFactor, viewport, callback)
InspectorTest.applyEmulationAndReload = function(enabled, width, height, deviceScaleFactor, viewport, insets, callback)
{
function PageResizer()
{
}
PageResizer.prototype =
{
update: function(dipWidth, dipHeight, scale) { },
__proto__: WebInspector.Object.prototype
}
InspectorTest.addSniffer(WebInspector.overridesSupport, "_deviceMetricsOverrideAppliedForTest", emulateCallback);
if (insets)
WebInspector.overridesSupport.setPageResizer(new PageResizer(), new Size(10, 10), insets);
else
WebInspector.overridesSupport.setPageResizer(null, new Size(0, 0), new Insets(0, 0));
if (enabled) {
var device = {title: "", width: width, height: height, deviceScaleFactor: deviceScaleFactor, userAgent: "", touch: false, mobile: true};
WebInspector.overridesSupport.emulateDevice(device);
......@@ -207,11 +222,11 @@ InspectorTest.applyEmulationAndReload = function(enabled, width, height, deviceS
}
};
InspectorTest.emulateAndGetMetrics = function(width, height, deviceScaleFactor, viewport, callback)
InspectorTest.emulateAndGetMetrics = function(width, height, deviceScaleFactor, viewport, insets, callback)
{
InspectorTest._deviceEmulationResults.push("Emulating device: " + width + "x" + height + "x" + deviceScaleFactor + " viewport='" + viewport + "'");
var full = !!width && !!height && !!deviceScaleFactor;
InspectorTest.applyEmulationAndReload(true, width, height, deviceScaleFactor, viewport, InspectorTest.getPageMetrics.bind(InspectorTest, full, printMetrics));
InspectorTest.applyEmulationAndReload(true, width, height, deviceScaleFactor, viewport, insets, InspectorTest.getPageMetrics.bind(InspectorTest, full, printMetrics));
function printMetrics(metrics)
{
......@@ -220,11 +235,11 @@ InspectorTest.emulateAndGetMetrics = function(width, height, deviceScaleFactor,
}
};
InspectorTest.testDeviceEmulation = function(pageUrl, width, height, deviceScaleFactor, viewport)
InspectorTest.testDeviceEmulation = function(pageUrl, width, height, deviceScaleFactor, viewport, insets)
{
InspectorTest._deviceEmulationPageUrl = pageUrl;
InspectorTest._deviceEmulationResults = [];
InspectorTest.emulateAndGetMetrics(width, height, deviceScaleFactor, viewport, callback);
InspectorTest.emulateAndGetMetrics(width, height, deviceScaleFactor, viewport, insets, callback);
function callback()
{
......
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