summaryrefslogtreecommitdiffstats
path: root/dom/browser-element/mochitest/browserElement_BadScreenshot.js
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /dom/browser-element/mochitest/browserElement_BadScreenshot.js
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip
Add m-esr52 at 52.6.0
Diffstat (limited to 'dom/browser-element/mochitest/browserElement_BadScreenshot.js')
-rw-r--r--dom/browser-element/mochitest/browserElement_BadScreenshot.js71
1 files changed, 71 insertions, 0 deletions
diff --git a/dom/browser-element/mochitest/browserElement_BadScreenshot.js b/dom/browser-element/mochitest/browserElement_BadScreenshot.js
new file mode 100644
index 000000000..7b194da86
--- /dev/null
+++ b/dom/browser-element/mochitest/browserElement_BadScreenshot.js
@@ -0,0 +1,71 @@
+/* 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);