2012-06-10 23:37:47 +00:00
|
|
|
<!DOCTYPE HTML>
|
|
|
|
<html>
|
|
|
|
<!--
|
|
|
|
https://bugzilla.mozilla.org/show_bug.cgi?id=753595
|
|
|
|
-->
|
|
|
|
<head>
|
|
|
|
<title>Test for Bug 753595</title>
|
|
|
|
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
|
|
|
<script type="application/javascript" src="browserFrameHelpers.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=753595">Mozilla Bug 753595</a>
|
|
|
|
|
|
|
|
<!--
|
|
|
|
Test the getScreenshot property for mozbrowser
|
|
|
|
-->
|
|
|
|
|
|
|
|
<script type="application/javascript;version=1.7">
|
2012-06-09 16:05:31 +00:00
|
|
|
|
2012-05-19 00:47:20 +00:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
SimpleTest.waitForExplicitFinish();
|
|
|
|
|
|
|
|
function runTest() {
|
|
|
|
|
2012-06-10 23:37:47 +00:00
|
|
|
browserFrameHelpers.setEnabledPref(true);
|
|
|
|
browserFrameHelpers.addToWhitelist();
|
2012-05-19 00:47:20 +00:00
|
|
|
|
|
|
|
var iframe1 = document.createElement('iframe');
|
|
|
|
iframe1.mozbrowser = true;
|
|
|
|
document.body.appendChild(iframe1);
|
2012-05-31 02:15:12 +00:00
|
|
|
iframe1.src = 'data:text/html,<html>' +
|
|
|
|
'<body style="background:green">hello</body></html>';
|
2012-05-19 00:47:20 +00:00
|
|
|
|
|
|
|
var screenshots = [];
|
|
|
|
var numLoaded = 0;
|
|
|
|
|
2012-05-31 02:15:12 +00:00
|
|
|
function screenshotTaken(screenshot) {
|
|
|
|
screenshots.push(screenshot);
|
2012-05-19 00:47:20 +00:00
|
|
|
if (screenshots.length === 1) {
|
2012-05-31 02:15:12 +00:00
|
|
|
ok(true, 'Got initial non blank screenshot');
|
2012-05-19 00:47:20 +00:00
|
|
|
iframe1.src = 'data:text/html,<html>' +
|
|
|
|
'<body style="background:blue">hello</body></html>';
|
2012-05-31 02:15:12 +00:00
|
|
|
waitForScreenshot(function(screenshot) {
|
|
|
|
return screenshot !== screenshots[0];
|
|
|
|
});
|
2012-05-19 00:47:20 +00:00
|
|
|
}
|
|
|
|
else if (screenshots.length === 2) {
|
2012-05-31 02:15:12 +00:00
|
|
|
ok(true, 'Got updated screenshot after source page changed');
|
2012-05-19 00:47:20 +00:00
|
|
|
SimpleTest.finish();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-31 02:15:12 +00:00
|
|
|
// We continually take screenshots until we get one that we are
|
|
|
|
// happy with
|
|
|
|
function waitForScreenshot(filter) {
|
|
|
|
|
|
|
|
function screenshotLoaded(e) {
|
|
|
|
if (filter(e.target.result)) {
|
|
|
|
screenshotTaken(e.target.result);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (--attempts === 0) {
|
|
|
|
ok(false, 'Timed out waiting for correct screenshot');
|
|
|
|
SimpleTest.finish();
|
|
|
|
} else {
|
|
|
|
content.document.defaultView.setTimeout(function() {
|
|
|
|
iframe1.getScreenshot().onsuccess = screenshotLoaded;
|
|
|
|
}, 200);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var attempts = 10;
|
2012-05-24 03:57:26 +00:00
|
|
|
iframe1.getScreenshot().onsuccess = screenshotLoaded;
|
|
|
|
}
|
|
|
|
|
2012-05-19 00:47:20 +00:00
|
|
|
function iframeLoadedHandler() {
|
|
|
|
numLoaded++;
|
2012-05-31 02:15:12 +00:00
|
|
|
if (numLoaded === 2) {
|
|
|
|
waitForScreenshot(function(screenshot) {
|
|
|
|
return screenshot !== 'data:,';
|
|
|
|
});
|
2012-05-19 00:47:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
iframe1.addEventListener('mozbrowserloadend', iframeLoadedHandler);
|
|
|
|
}
|
|
|
|
|
|
|
|
addEventListener('load', function() { SimpleTest.executeSoon(runTest); });
|
|
|
|
|
2012-06-10 23:37:47 +00:00
|
|
|
</script>
|
2012-05-19 00:47:20 +00:00
|
|
|
|
2012-06-10 23:37:47 +00:00
|
|
|
</body>
|
|
|
|
</html>
|