fune/dom/browser-element/mochitest/browserElement_BadScreenshot.js
Alexandre Lissy 6798f02654 Bug 1286530 - Clean AvailableIn, CheckAnyPermissions and CheckAllPermissions from WebIDL r=bz,fabrice
MozReview-Commit-ID: 6EQfBM09xUE

--HG--
rename : dom/contacts/tests/test_contacts_cache.xul => dom/contacts/tests/test_contacts_a_cache.xul
rename : dom/contacts/tests/test_contacts_shutdown.xul => dom/contacts/tests/test_contacts_a_shutdown.xul
rename : dom/contacts/tests/test_contacts_upgrade.xul => dom/contacts/tests/test_contacts_a_upgrade.xul
rename : dom/mobilemessage/tests/mochitest/mochitest.ini => dom/mobilemessage/tests/mochitest/chrome.ini
extra : rebase_source : 5f708f2a927fafff66626367ef07080785ba9f55
2016-04-21 15:48:59 +02:00

71 lines
2 KiB
JavaScript

/* Any copyright is dedicated to the public domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
// Bug 800170 - Test that we get errors when we pass bad arguments to
// mozbrowser's getScreenshot.
"use strict";
SimpleTest.waitForExplicitFinish();
browserElementTestHelpers.setEnabledPref(true);
var iframe;
var numPendingTests = 0;
// Call iframe.getScreenshot with the given args. If expectSuccess is true, we
// expect the screenshot's onsuccess handler to fire. Otherwise, we expect
// getScreenshot() to throw an exception.
function checkScreenshotResult(expectSuccess, args) {
var req;
try {
req = iframe.getScreenshot.apply(iframe, args);
}
catch(e) {
ok(!expectSuccess, "getScreenshot(" + JSON.stringify(args) + ") threw an exception.");
return;
}
numPendingTests++;
req.onsuccess = function() {
ok(expectSuccess, "getScreenshot(" + JSON.stringify(args) + ") succeeded.");
numPendingTests--;
if (numPendingTests == 0) {
SimpleTest.finish();
}
};
// We never expect to see onerror.
req.onerror = function() {
ok(false, "getScreenshot(" + JSON.stringify(args) + ") ran onerror.");
numPendingTests--;
if (numPendingTests == 0) {
SimpleTest.finish();
}
};
}
function runTest() {
iframe = document.createElement('iframe');
iframe.setAttribute('mozbrowser', 'true');
document.body.appendChild(iframe);
iframe.src = 'data:text/html,<html>' +
'<body style="background:green">hello</body></html>';
iframe.addEventListener('mozbrowserfirstpaint', function() {
// This one should succeed.
checkScreenshotResult(true, [100, 100]);
// These should fail.
checkScreenshotResult(false, []);
checkScreenshotResult(false, [100]);
checkScreenshotResult(false, ['a', 100]);
checkScreenshotResult(false, [100, 'a']);
checkScreenshotResult(false, [-1, 100]);
checkScreenshotResult(false, [100, -1]);
if (numPendingTests == 0) {
SimpleTest.finish();
}
});
}
addEventListener('testready', runTest);