зеркало из https://github.com/mozilla/gecko-dev.git
Bug 959066 - Test for hi-res screenshot for getScreenshot API. r=smaug
This commit is contained in:
Родитель
ba289d36b7
Коммит
fd4975a3c5
|
@ -41,7 +41,9 @@ MOCHITEST_FILES = \
|
|||
test_browserElement_inproc_Metachange.html \
|
||||
test_browserElement_inproc_Opensearch.html \
|
||||
browserElement_GetScreenshot.js \
|
||||
browserElement_GetScreenshotDppx.js \
|
||||
test_browserElement_inproc_GetScreenshot.html \
|
||||
test_browserElement_inproc_GetScreenshotDppx.html \
|
||||
browserElement_BadScreenshot.js \
|
||||
test_browserElement_inproc_BadScreenshot.html \
|
||||
browserElement_SetVisible.js \
|
||||
|
@ -212,6 +214,7 @@ MOCHITEST_FILES += \
|
|||
test_browserElement_oop_Metachange.html \
|
||||
test_browserElement_oop_Opensearch.html \
|
||||
test_browserElement_oop_GetScreenshot.html \
|
||||
test_browserElement_oop_GetScreenshotDppx.html \
|
||||
test_browserElement_oop_BadScreenshot.html \
|
||||
test_browserElement_oop_XFrameOptions.html \
|
||||
test_browserElement_oop_XFrameOptionsDeny.html \
|
||||
|
|
|
@ -0,0 +1,108 @@
|
|||
/* Any copyright is dedicated to the public domain.
|
||||
http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
// Test the getScreenshot property for mozbrowser
|
||||
"use strict";
|
||||
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
browserElementTestHelpers.setEnabledPref(true);
|
||||
browserElementTestHelpers.addPermission();
|
||||
|
||||
function runTest() {
|
||||
var dppxPref = 'layout.css.devPixelsPerPx';
|
||||
var cssPixelWidth = 600;
|
||||
var cssPixelHeight = 400;
|
||||
|
||||
var iframe1 = document.createElement('iframe');
|
||||
iframe1.setAttribute('width', cssPixelWidth);
|
||||
iframe1.setAttribute('height', cssPixelHeight);
|
||||
SpecialPowers.wrap(iframe1).mozbrowser = true;
|
||||
|
||||
iframe1.src = 'data:text/html,<html><body>hello</body></html>';
|
||||
document.body.appendChild(iframe1);
|
||||
|
||||
var images = [];
|
||||
|
||||
function screenshotTaken(image) {
|
||||
images.push(image);
|
||||
if (images.length === 1) {
|
||||
ok(true, 'Got initial non blank screenshot');
|
||||
|
||||
if (image.width !== cssPixelWidth || image.height !== cssPixelHeight) {
|
||||
ok(false, 'The pixel width of the image received is not correct');
|
||||
SimpleTest.finish();
|
||||
return;
|
||||
}
|
||||
ok(true, 'The pixel width of the image received is correct');
|
||||
|
||||
SpecialPowers.pushPrefEnv(
|
||||
{'set': [['layout.css.devPixelsPerPx', 2]]}, takeScreenshot);
|
||||
}
|
||||
else if (images.length === 2) {
|
||||
ok(true, 'Got updated screenshot after source page changed');
|
||||
|
||||
if (image.width !== cssPixelWidth * 2 ||
|
||||
image.height !== cssPixelHeight * 2) {
|
||||
ok(false, 'The pixel width of the 2dppx image received is not correct');
|
||||
SimpleTest.finish();
|
||||
return;
|
||||
}
|
||||
ok(true, 'The pixel width of the 2dppx image received is correct');
|
||||
SimpleTest.finish();
|
||||
}
|
||||
}
|
||||
|
||||
function takeScreenshot() {
|
||||
function gotImage(e) {
|
||||
// |this| is the Image.
|
||||
|
||||
URL.revokeObjectURL(this.src);
|
||||
|
||||
if (e.type === 'error' || !this.width || !this.height) {
|
||||
tryAgain();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
screenshotTaken(this);
|
||||
}
|
||||
|
||||
function tryAgain() {
|
||||
if (--attempts === 0) {
|
||||
ok(false, 'Timed out waiting for correct screenshot');
|
||||
SimpleTest.finish();
|
||||
} else {
|
||||
setTimeout(function() {
|
||||
iframe1.getScreenshot(cssPixelWidth, cssPixelHeight).onsuccess =
|
||||
getScreenshotImageData;
|
||||
}, 200);
|
||||
}
|
||||
}
|
||||
|
||||
function getScreenshotImageData(e) {
|
||||
var blob = e.target.result;
|
||||
if (blob.size === 0) {
|
||||
tryAgain();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
var img = new Image();
|
||||
img.src = URL.createObjectURL(blob);
|
||||
img.onload = img.onerror = gotImage;
|
||||
}
|
||||
|
||||
var attempts = 10;
|
||||
iframe1.getScreenshot(cssPixelWidth, cssPixelHeight).onsuccess =
|
||||
getScreenshotImageData;
|
||||
}
|
||||
|
||||
function iframeLoadedHandler() {
|
||||
SpecialPowers.pushPrefEnv(
|
||||
{'set': [['layout.css.devPixelsPerPx', 1]]}, takeScreenshot);
|
||||
}
|
||||
|
||||
iframe1.addEventListener('mozbrowserloadend', iframeLoadedHandler);
|
||||
}
|
||||
|
||||
addEventListener('testready', runTest);
|
|
@ -0,0 +1,19 @@
|
|||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<!--
|
||||
https://bugzilla.mozilla.org/show_bug.cgi?id=959066
|
||||
-->
|
||||
<head>
|
||||
<title>Test for Bug 959066</title>
|
||||
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<script type="application/javascript" src="browserElementTestHelpers.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
||||
</head>
|
||||
<body>
|
||||
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=959066">Mozilla Bug 959066</a>
|
||||
|
||||
<script type="application/javascript;version=1.7" src='browserElement_GetScreenshotDppx.js'>
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,19 @@
|
|||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<!--
|
||||
https://bugzilla.mozilla.org/show_bug.cgi?id=959066
|
||||
-->
|
||||
<head>
|
||||
<title>Test for Bug 959066</title>
|
||||
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<script type="application/javascript" src="browserElementTestHelpers.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
||||
</head>
|
||||
<body>
|
||||
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=959066">Mozilla Bug 959066</a>
|
||||
|
||||
<script type="application/javascript;version=1.7" src='browserElement_GetScreenshotDppx.js'>
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
Загрузка…
Ссылка в новой задаче