Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* Any copyright is dedicated to the public domain. |
michael@0 | 2 | http://creativecommons.org/publicdomain/zero/1.0/ */ |
michael@0 | 3 | |
michael@0 | 4 | // Bug 800170 - Test that we get errors when we pass bad arguments to |
michael@0 | 5 | // mozbrowser's getScreenshot. |
michael@0 | 6 | "use strict"; |
michael@0 | 7 | |
michael@0 | 8 | SimpleTest.waitForExplicitFinish(); |
michael@0 | 9 | browserElementTestHelpers.setEnabledPref(true); |
michael@0 | 10 | browserElementTestHelpers.addPermission(); |
michael@0 | 11 | |
michael@0 | 12 | var iframe; |
michael@0 | 13 | var numPendingTests = 0; |
michael@0 | 14 | |
michael@0 | 15 | // Call iframe.getScreenshot with the given args. If expectSuccess is true, we |
michael@0 | 16 | // expect the screenshot's onsuccess handler to fire. Otherwise, we expect |
michael@0 | 17 | // getScreenshot() to throw an exception. |
michael@0 | 18 | function checkScreenshotResult(expectSuccess, args) { |
michael@0 | 19 | var req; |
michael@0 | 20 | try { |
michael@0 | 21 | req = iframe.getScreenshot.apply(iframe, args); |
michael@0 | 22 | } |
michael@0 | 23 | catch(e) { |
michael@0 | 24 | ok(!expectSuccess, "getScreenshot(" + JSON.stringify(args) + ") threw an exception."); |
michael@0 | 25 | return; |
michael@0 | 26 | } |
michael@0 | 27 | |
michael@0 | 28 | numPendingTests++; |
michael@0 | 29 | req.onsuccess = function() { |
michael@0 | 30 | ok(expectSuccess, "getScreenshot(" + JSON.stringify(args) + ") succeeded."); |
michael@0 | 31 | numPendingTests--; |
michael@0 | 32 | if (numPendingTests == 0) { |
michael@0 | 33 | SimpleTest.finish(); |
michael@0 | 34 | } |
michael@0 | 35 | }; |
michael@0 | 36 | |
michael@0 | 37 | // We never expect to see onerror. |
michael@0 | 38 | req.onerror = function() { |
michael@0 | 39 | ok(false, "getScreenshot(" + JSON.stringify(args) + ") ran onerror."); |
michael@0 | 40 | numPendingTests--; |
michael@0 | 41 | if (numPendingTests == 0) { |
michael@0 | 42 | SimpleTest.finish(); |
michael@0 | 43 | } |
michael@0 | 44 | }; |
michael@0 | 45 | } |
michael@0 | 46 | |
michael@0 | 47 | function runTest() { |
michael@0 | 48 | iframe = document.createElement('iframe'); |
michael@0 | 49 | SpecialPowers.wrap(iframe).mozbrowser = true; |
michael@0 | 50 | document.body.appendChild(iframe); |
michael@0 | 51 | iframe.src = 'data:text/html,<html>' + |
michael@0 | 52 | '<body style="background:green">hello</body></html>'; |
michael@0 | 53 | |
michael@0 | 54 | iframe.addEventListener('mozbrowserfirstpaint', function() { |
michael@0 | 55 | // This one should succeed. |
michael@0 | 56 | checkScreenshotResult(true, [100, 100]); |
michael@0 | 57 | |
michael@0 | 58 | // These should fail. |
michael@0 | 59 | checkScreenshotResult(false, []); |
michael@0 | 60 | checkScreenshotResult(false, [100]); |
michael@0 | 61 | checkScreenshotResult(false, ['a', 100]); |
michael@0 | 62 | checkScreenshotResult(false, [100, 'a']); |
michael@0 | 63 | checkScreenshotResult(false, [-1, 100]); |
michael@0 | 64 | checkScreenshotResult(false, [100, -1]); |
michael@0 | 65 | |
michael@0 | 66 | if (numPendingTests == 0) { |
michael@0 | 67 | SimpleTest.finish(); |
michael@0 | 68 | } |
michael@0 | 69 | }); |
michael@0 | 70 | } |
michael@0 | 71 | |
michael@0 | 72 | addEventListener('testready', runTest); |