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