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