gecko-dev/dom/tests/mochitest/browser-frame/test_browserFrame9.html

96 lines
2.5 KiB
HTML
Raw Normal View History

<!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">
"use strict";
SimpleTest.waitForExplicitFinish();
function runTest() {
browserFrameHelpers.setEnabledPref(true);
browserFrameHelpers.addToWhitelist();
var iframe1 = document.createElement('iframe');
iframe1.mozbrowser = true;
document.body.appendChild(iframe1);
iframe1.src = 'data:text/html,<html>' +
'<body style="background:green">hello</body></html>';
var screenshots = [];
var numLoaded = 0;
function screenshotTaken(screenshot) {
screenshots.push(screenshot);
if (screenshots.length === 1) {
ok(true, 'Got initial non blank screenshot');
iframe1.src = 'data:text/html,<html>' +
'<body style="background:blue">hello</body></html>';
waitForScreenshot(function(screenshot) {
return screenshot !== screenshots[0];
});
}
else if (screenshots.length === 2) {
ok(true, 'Got updated screenshot after source page changed');
SimpleTest.finish();
}
}
// 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;
iframe1.getScreenshot().onsuccess = screenshotLoaded;
}
function iframeLoadedHandler() {
numLoaded++;
if (numLoaded === 2) {
waitForScreenshot(function(screenshot) {
return screenshot !== 'data:,';
});
}
}
iframe1.addEventListener('mozbrowserloadend', iframeLoadedHandler);
}
addEventListener('load', function() { SimpleTest.executeSoon(runTest); });
</script>
</body>
</html>