Bug 1431601 - Rewrite test_meta_viewportX.html with add_task. r=botond

Depends on D8318

Differential Revision: https://phabricator.services.mozilla.com/D8319

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Hiroyuki Ikezoe 2018-10-15 23:53:43 +00:00
Родитель c43cc6396c
Коммит d513867baa
8 изменённых файлов: 156 добавлений и 295 удалений

Просмотреть файл

@ -4,6 +4,7 @@
<meta charset="utf-8">
<title>meta viewport test</title>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="application/javascript" src="/tests/SimpleTest/AddTask.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
<script src="viewport_helpers.js"></script>
</head>
@ -12,52 +13,34 @@
<script type="application/javascript">
"use strict";
SimpleTest.waitForExplicitFinish();
let tests = [];
function fuzzeq(a, b, msg) {
ok(Math.abs(a - b) < 1e-6, msg);
}
tests.push(function test1() {
SpecialPowers.pushPrefEnv(scaleRatio(1.0),
function() {
let info = getViewportInfo(800, 480);
fuzzeq(info.defaultZoom, 0.1, "initial scale is unspecified");
fuzzeq(info.minZoom, 0.1, "minimum scale defaults to the absolute minimum");
is(info.maxZoom, 10, "maximum scale defaults to the absolute maximum");
is(info.width, 980, "width is the default width");
is(info.height, 588, "height is proportional to displayHeight");
is(info.autoSize, false, "autoSize is disabled by default");
is(info.allowZoom, true, "zooming is enabled by default");
add_task(async function test1() {
await SpecialPowers.pushPrefEnv(scaleRatio(1.0));
info = getViewportInfo(490, 600);
is(info.width, 980, "width is still the default width");
is(info.height, 1200, "height is proportional to the new displayHeight");
let info = getViewportInfo(800, 480);
fuzzeq(info.defaultZoom, 0.1, "initial scale is unspecified");
fuzzeq(info.minZoom, 0.1, "minimum scale defaults to the absolute minimum");
is(info.maxZoom, 10, "maximum scale defaults to the absolute maximum");
is(info.width, 980, "width is the default width");
is(info.height, 588, "height is proportional to displayHeight");
is(info.autoSize, false, "autoSize is disabled by default");
is(info.allowZoom, true, "zooming is enabled by default");
nextTest();
});
info = getViewportInfo(490, 600);
is(info.width, 980, "width is still the default width");
is(info.height, 1200, "height is proportional to the new displayHeight");
});
tests.push(function test2() {
SpecialPowers.pushPrefEnv(scaleRatio(1.5),
function() {
let info = getViewportInfo(800, 480);
is(info.width, 980, "width is still the default width");
is(info.height, 588, "height is still proportional to displayHeight");
add_task(async function test2() {
await SpecialPowers.pushPrefEnv(scaleRatio(1.5));
nextTest();
});
let info = getViewportInfo(800, 480);
is(info.width, 980, "width is still the default width");
is(info.height, 588, "height is still proportional to displayHeight");
});
function nextTest() {
if (tests.length)
(tests.shift())();
else
SimpleTest.finish();
}
addEventListener("load", nextTest);
</script>
</body>
</html>

Просмотреть файл

@ -4,6 +4,7 @@
<meta charset="utf-8">
<title>meta viewport test</title>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="application/javascript" src="/tests/SimpleTest/AddTask.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="viewport_helpers.js"></script>
@ -13,47 +14,29 @@
<script type="application/javascript">
"use strict";
SimpleTest.waitForExplicitFinish();
add_task(async function test1() {
await SpecialPowers.pushPrefEnv(scaleRatio(1.0));
let tests = [];
let info = getViewportInfo(800, 480);
is(info.defaultZoom, 1, "initial zoom is 100%");
is(info.width, 800, "width is the same as the displayWidth");
is(info.height, 480, "height is the same as the displayHeight");
is(info.autoSize, true, "width=device-width enables autoSize");
is(info.allowZoom, true, "zooming is enabled by default");
tests.push(function test1() {
SpecialPowers.pushPrefEnv(scaleRatio(1.0),
function() {
let info = getViewportInfo(800, 480);
is(info.defaultZoom, 1, "initial zoom is 100%");
is(info.width, 800, "width is the same as the displayWidth");
is(info.height, 480, "height is the same as the displayHeight");
is(info.autoSize, true, "width=device-width enables autoSize");
is(info.allowZoom, true, "zooming is enabled by default");
info = getViewportInfo(900, 600);
is(info.width, 900, "changing the displayWidth changes the width");
is(info.height, 600, "changing the displayHeight changes the height");
nextTest();
});
info = getViewportInfo(900, 600);
is(info.width, 900, "changing the displayWidth changes the width");
is(info.height, 600, "changing the displayHeight changes the height");
});
tests.push(function test2() {
SpecialPowers.pushPrefEnv(scaleRatio(1.5),
function() {
let info = getViewportInfo(900, 600);
is(info.defaultZoom, 1.5, "initial zoom is 150%");
is(info.width, 600, "width equals displayWidth/1.5");
is(info.height, 400, "height equals displayHeight/1.5");
add_task(async function test2() {
await SpecialPowers.pushPrefEnv(scaleRatio(1.5));
nextTest();
});
let info = getViewportInfo(900, 600);
is(info.defaultZoom, 1.5, "initial zoom is 150%");
is(info.width, 600, "width equals displayWidth/1.5");
is(info.height, 400, "height equals displayHeight/1.5");
});
function nextTest() {
if (tests.length)
(tests.shift())();
else
SimpleTest.finish();
}
addEventListener("load", nextTest);
</script>
</body>
</html>

Просмотреть файл

@ -4,6 +4,7 @@
<meta charset="utf-8">
<title>meta viewport test</title>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="application/javascript" src="/tests/SimpleTest/AddTask.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
<meta name="viewport" content="width=device-width">
<script src="viewport_helpers.js"></script>
@ -13,47 +14,29 @@
<script type="application/javascript">
"use strict";
SimpleTest.waitForExplicitFinish();
add_task(async function test1() {
await SpecialPowers.pushPrefEnv(scaleRatio(1.0));
let tests = [];
let info = getViewportInfo(800, 480);
is(info.defaultZoom, 1, "initial zoom is 100%");
is(info.width, 800, "width is the same as the displayWidth");
is(info.height, 480, "height is the same as the displayHeight");
is(info.autoSize, true, "width=device-width enables autoSize");
is(info.allowZoom, true, "zooming is enabled by default");
tests.push(function test1() {
SpecialPowers.pushPrefEnv(scaleRatio(1.0),
function() {
let info = getViewportInfo(800, 480);
is(info.defaultZoom, 1, "initial zoom is 100%");
is(info.width, 800, "width is the same as the displayWidth");
is(info.height, 480, "height is the same as the displayHeight");
is(info.autoSize, true, "width=device-width enables autoSize");
is(info.allowZoom, true, "zooming is enabled by default");
info = getViewportInfo(900, 600);
is(info.width, 900, "changing the displayWidth changes the width");
is(info.height, 600, "changing the displayHeight changes the height");
nextTest();
});
info = getViewportInfo(900, 600);
is(info.width, 900, "changing the displayWidth changes the width");
is(info.height, 600, "changing the displayHeight changes the height");
});
tests.push(function test2() {
SpecialPowers.pushPrefEnv(scaleRatio(1.5),
function() {
let info = getViewportInfo(900, 600);
is(info.defaultZoom, 1.5, "initial zoom is 150%");
is(info.width, 600, "width equals displayWidth/1.5");
is(info.height, 400, "height equals displayHeight/1.5");
add_task(async function test2() {
await SpecialPowers.pushPrefEnv(scaleRatio(1.5));
nextTest();
});
let info = getViewportInfo(900, 600);
is(info.defaultZoom, 1.5, "initial zoom is 150%");
is(info.width, 600, "width equals displayWidth/1.5");
is(info.height, 400, "height equals displayHeight/1.5");
});
function nextTest() {
if (tests.length)
(tests.shift())();
else
SimpleTest.finish();
}
addEventListener("load", nextTest);
</script>
</body>
</html>

Просмотреть файл

@ -4,6 +4,7 @@
<meta charset="utf-8">
<title>meta viewport test</title>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="application/javascript" src="/tests/SimpleTest/AddTask.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
<meta name="viewport" content="width=320">
<script src="viewport_helpers.js"></script>
@ -13,49 +14,31 @@
<script type="application/javascript">
"use strict";
SimpleTest.waitForExplicitFinish();
add_task(async function test1() {
await SpecialPowers.pushPrefEnv(scaleRatio(1.0));
let tests = [];
let info = getViewportInfo(800, 80);
is(info.defaultZoom, 2.5, "initial zoom fits the displayWidth");
is(info.width, 320, "width is set explicitly");
is(info.height, 40, "height is at the absolute minimum");
is(info.autoSize, false, "width=device-width enables autoSize");
is(info.allowZoom, true, "zooming is enabled by default");
tests.push(function test1() {
SpecialPowers.pushPrefEnv(scaleRatio(1.0),
function() {
let info = getViewportInfo(800, 80);
is(info.defaultZoom, 2.5, "initial zoom fits the displayWidth");
is(info.width, 320, "width is set explicitly");
is(info.height, 40, "height is at the absolute minimum");
is(info.autoSize, false, "width=device-width enables autoSize");
is(info.allowZoom, true, "zooming is enabled by default");
info = getViewportInfo(480, 800);
is(info.defaultZoom, 1.5, "initial zoom fits the new displayWidth");
is(info.width, 320, "explicit width is unchanged");
is(info.height, 533, "height changes proportional to displayHeight");
nextTest();
});
info = getViewportInfo(480, 800);
is(info.defaultZoom, 1.5, "initial zoom fits the new displayWidth");
is(info.width, 320, "explicit width is unchanged");
is(info.height, 533, "height changes proportional to displayHeight");
});
tests.push(function test2() {
SpecialPowers.pushPrefEnv(scaleRatio(1.5),
function() {
// With an explicit width in CSS px, the scaleRatio has no effect.
let info = getViewportInfo(800, 80);
is(info.defaultZoom, 2.5, "initial zoom still fits the displayWidth");
is(info.width, 320, "width is still set explicitly");
is(info.height, 40, "height is still minimum height");
add_task(async function test2() {
await SpecialPowers.pushPrefEnv(scaleRatio(1.5));
nextTest();
});
// With an explicit width in CSS px, the scaleRatio has no effect.
let info = getViewportInfo(800, 80);
is(info.defaultZoom, 2.5, "initial zoom still fits the displayWidth");
is(info.width, 320, "width is still set explicitly");
is(info.height, 40, "height is still minimum height");
});
function nextTest() {
if (tests.length)
(tests.shift())();
else
SimpleTest.finish();
}
addEventListener("load", nextTest);
</script>
</body>
</html>

Просмотреть файл

@ -4,6 +4,7 @@
<meta charset="utf-8">
<title>meta viewport test</title>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="application/javascript" src="/tests/SimpleTest/AddTask.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<script src="viewport_helpers.js"></script>
@ -13,48 +14,30 @@
<script type="application/javascript">
"use strict";
SimpleTest.waitForExplicitFinish();
add_task(async function test1() {
await SpecialPowers.pushPrefEnv(scaleRatio(1.0));
let tests = [];
let info = getViewportInfo(800, 480);
is(info.defaultZoom, 1, "initial zoom is set explicitly");
is(info.width, 800, "width fits the initial zoom level");
is(info.height, 480, "height fits the initial zoom level");
is(info.autoSize, true, "initial-scale=1 enables autoSize");
is(info.allowZoom, false, "zooming is explicitly disabled");
tests.push(function test1() {
SpecialPowers.pushPrefEnv(scaleRatio(1.0),
function() {
let info = getViewportInfo(800, 480);
is(info.defaultZoom, 1, "initial zoom is set explicitly");
is(info.width, 800, "width fits the initial zoom level");
is(info.height, 480, "height fits the initial zoom level");
is(info.autoSize, true, "initial-scale=1 enables autoSize");
is(info.allowZoom, false, "zooming is explicitly disabled");
info = getViewportInfo(480, 800);
is(info.defaultZoom, 1, "initial zoom is still set explicitly");
is(info.width, 480, "width changes to match the displayWidth");
is(info.height, 800, "height changes to match the displayHeight");
nextTest();
});
info = getViewportInfo(480, 800);
is(info.defaultZoom, 1, "initial zoom is still set explicitly");
is(info.width, 480, "width changes to match the displayWidth");
is(info.height, 800, "height changes to match the displayHeight");
});
tests.push(function test2() {
SpecialPowers.pushPrefEnv(scaleRatio(1.5),
function() {
let info = getViewportInfo(800, 480);
is(info.defaultZoom, 1.5, "initial zoom is adjusted for device pixel ratio");
is(info.width, 533, "width fits the initial zoom");
is(info.height, 320, "height fits the initial zoom");
add_task(async function test2() {
await SpecialPowers.pushPrefEnv(scaleRatio(1.5));
nextTest();
});
let info = getViewportInfo(800, 480);
is(info.defaultZoom, 1.5, "initial zoom is adjusted for device pixel ratio");
is(info.width, 533, "width fits the initial zoom");
is(info.height, 320, "height fits the initial zoom");
});
function nextTest() {
if (tests.length)
(tests.shift())();
else
SimpleTest.finish();
}
addEventListener("load", nextTest);
</script>
</body>
</html>

Просмотреть файл

@ -4,6 +4,7 @@
<meta charset="utf-8">
<title>meta viewport test</title>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="application/javascript" src="/tests/SimpleTest/AddTask.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
<meta name="viewport" content="user-scalable=NO">
<script src="viewport_helpers.js"></script>
@ -13,24 +14,10 @@
<script type="application/javascript">
"use strict";
SimpleTest.waitForExplicitFinish();
let tests = [];
tests.push(function test1() {
add_task(function test1() {
let info = getViewportInfo(800, 480);
is(info.allowZoom, true, "user-scalable values are case-sensitive; 'NO' is not valid");
nextTest();
});
function nextTest() {
if (tests.length)
(tests.shift())();
else
SimpleTest.finish();
}
addEventListener("load", nextTest);
</script>
</body>
</html>

Просмотреть файл

@ -4,6 +4,7 @@
<meta charset="utf-8">
<title>meta viewport test</title>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="application/javascript" src="/tests/SimpleTest/AddTask.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
<meta name="viewport" content="width=2000, minimum-scale=0.75">
<script src="viewport_helpers.js"></script>
@ -13,53 +14,35 @@
<script type="application/javascript">
"use strict";
SimpleTest.waitForExplicitFinish();
add_task(async function test1() {
await SpecialPowers.pushPrefEnv(scaleRatio(1.0));
let tests = [];
let info = getViewportInfo(800, 480);
is(info.minZoom, 0.75, "minumum scale is set explicitly");
is(info.defaultZoom, 0.75, "initial scale is bounded by the minimum scale");
is(info.maxZoom, 10, "maximum scale defaults to the absolute maximum");
is(info.width, 2000, "width is set explicitly");
is(info.height, 1200, "height is proportional to displayHeight");
is(info.autoSize, false, "autoSize is disabled by default");
is(info.allowZoom, true, "zooming is enabled by default");
tests.push(function test1() {
SpecialPowers.pushPrefEnv(scaleRatio(1.0),
function() {
let info = getViewportInfo(800, 480);
is(info.minZoom, 0.75, "minumum scale is set explicitly");
is(info.defaultZoom, 0.75, "initial scale is bounded by the minimum scale");
is(info.maxZoom, 10, "maximum scale defaults to the absolute maximum");
is(info.width, 2000, "width is set explicitly");
is(info.height, 1200, "height is proportional to displayHeight");
is(info.autoSize, false, "autoSize is disabled by default");
is(info.allowZoom, true, "zooming is enabled by default");
info = getViewportInfo(2000, 1000);
is(info.minZoom, 0.75, "minumum scale is still set explicitly");
is(info.defaultZoom, 1, "initial scale fits the width");
is(info.width, 2000, "width is set explicitly");
is(info.height, 1000, "height is proportional to the new displayHeight");
nextTest();
});
info = getViewportInfo(2000, 1000);
is(info.minZoom, 0.75, "minumum scale is still set explicitly");
is(info.defaultZoom, 1, "initial scale fits the width");
is(info.width, 2000, "width is set explicitly");
is(info.height, 1000, "height is proportional to the new displayHeight");
});
tests.push(function test2() {
SpecialPowers.pushPrefEnv(scaleRatio(1.5),
function() {
let info = getViewportInfo(800, 480);
is(info.minZoom, 1.125, "minumum scale is converted to device pixel scale");
is(info.defaultZoom, 1.125, "initial scale is bounded by the minimum scale");
is(info.maxZoom, 15, "maximum scale defaults to the absolute maximum");
is(info.width, 2000, "width is still set explicitly");
is(info.height, 1200, "height is still proportional to displayHeight");
add_task(async function test2() {
await SpecialPowers.pushPrefEnv(scaleRatio(1.5));
nextTest();
});
let info = getViewportInfo(800, 480);
is(info.minZoom, 1.125, "minumum scale is converted to device pixel scale");
is(info.defaultZoom, 1.125, "initial scale is bounded by the minimum scale");
is(info.maxZoom, 15, "maximum scale defaults to the absolute maximum");
is(info.width, 2000, "width is still set explicitly");
is(info.height, 1200, "height is still proportional to displayHeight");
});
function nextTest() {
if (tests.length)
(tests.shift())();
else
SimpleTest.finish();
}
addEventListener("load", nextTest);
</script>
</body>
</html>

Просмотреть файл

@ -4,6 +4,7 @@
<meta charset="utf-8">
<title>meta viewport test</title>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="application/javascript" src="/tests/SimpleTest/AddTask.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
<meta name="viewport" content="width=320">
<script src="viewport_helpers.js"></script>
@ -13,84 +14,59 @@
<script type="application/javascript">
"use strict";
SimpleTest.waitForExplicitFinish();
add_task(async function test1() {
await SpecialPowers.pushPrefEnv(scaleRatio(1.0));
let tests = [];
updateViewport("width=device-width");
let info = getViewportInfo(800, 480);
is(info.defaultZoom, 1, "initial zoom is 100%");
is(info.width, 800, "width is the same as the displayWidth");
is(info.height, 480, "height is the same as the displayHeight");
is(info.autoSize, true, "width=device-width enables autoSize");
is(info.allowZoom, true, "zooming is enabled by default");
tests.push(function test1() {
SpecialPowers.pushPrefEnv(scaleRatio(1.0),
function() {
updateViewport("width=device-width");
let info = getViewportInfo(800, 480);
is(info.defaultZoom, 1, "initial zoom is 100%");
is(info.width, 800, "width is the same as the displayWidth");
is(info.height, 480, "height is the same as the displayHeight");
is(info.autoSize, true, "width=device-width enables autoSize");
is(info.allowZoom, true, "zooming is enabled by default");
info = getViewportInfo(900, 600);
is(info.width, 900, "changing the displayWidth changes the width");
is(info.height, 600, "changing the displayHeight changes the height");
nextTest();
});
info = getViewportInfo(900, 600);
is(info.width, 900, "changing the displayWidth changes the width");
is(info.height, 600, "changing the displayHeight changes the height");
});
tests.push(function test2() {
SpecialPowers.pushPrefEnv(scaleRatio(1.0),
function() {
updateViewport("width=320");
let info = getViewportInfo(800, 80);
is(info.defaultZoom, 2.5, "initial zoom fits the displayWidth");
is(info.width, 320, "width is set explicitly");
is(info.height, 40, "height is at the absolute minimum");
is(info.autoSize, false, "width=device-width enables autoSize");
is(info.allowZoom, true, "zooming is enabled by default");
add_task(async function test2() {
await SpecialPowers.pushPrefEnv(scaleRatio(1.0));
info = getViewportInfo(480, 800);
is(info.defaultZoom, 1.5, "initial zoom fits the new displayWidth");
is(info.width, 320, "explicit width is unchanged");
is(info.height, 533, "height changes proportional to displayHeight");
updateViewport("width=320");
let info = getViewportInfo(800, 80);
is(info.defaultZoom, 2.5, "initial zoom fits the displayWidth");
is(info.width, 320, "width is set explicitly");
is(info.height, 40, "height is at the absolute minimum");
is(info.autoSize, false, "width=device-width enables autoSize");
is(info.allowZoom, true, "zooming is enabled by default");
nextTest();
});
info = getViewportInfo(480, 800);
is(info.defaultZoom, 1.5, "initial zoom fits the new displayWidth");
is(info.width, 320, "explicit width is unchanged");
is(info.height, 533, "height changes proportional to displayHeight");
});
tests.push(function test3() {
SpecialPowers.pushPrefEnv(scaleRatio(1.0),
function() {
updateViewport("user-scalable=no");
let info = getViewportInfo(800, 480);
is(info.allowZoom, false, "zooming is explicitly disabled");
add_task(async function test3() {
await SpecialPowers.pushPrefEnv(scaleRatio(1.0));
nextTest();
});
updateViewport("user-scalable=no");
let info = getViewportInfo(800, 480);
is(info.allowZoom, false, "zooming is explicitly disabled");
});
tests.push(function test4() {
SpecialPowers.pushPrefEnv(scaleRatio(1.0),
function() {
updateViewport("user-scalable=yes");
let info = getViewportInfo(800, 480);
is(info.allowZoom, true, "zooming is explicitly allowed");
add_task(async function test4() {
await SpecialPowers.pushPrefEnv(scaleRatio(1.0));
nextTest();
});
updateViewport("user-scalable=yes");
let info = getViewportInfo(800, 480);
is(info.allowZoom, true, "zooming is explicitly allowed");
});
function updateViewport(content) {
let meta = document.querySelector("meta[name=viewport]");
meta.content = content;
}
function nextTest() {
if (tests.length) {
(tests.shift())();
} else {
SimpleTest.finish();
}
}
addEventListener("load", nextTest);
</script>
</body>
</html>