summaryrefslogtreecommitdiffstats
path: root/devtools/shared/qrcode/tests
diff options
context:
space:
mode:
Diffstat (limited to 'devtools/shared/qrcode/tests')
-rw-r--r--devtools/shared/qrcode/tests/mochitest/chrome.ini5
-rw-r--r--devtools/shared/qrcode/tests/mochitest/test_decode.html68
-rw-r--r--devtools/shared/qrcode/tests/unit/test_encode.js27
-rw-r--r--devtools/shared/qrcode/tests/unit/xpcshell.ini7
4 files changed, 107 insertions, 0 deletions
diff --git a/devtools/shared/qrcode/tests/mochitest/chrome.ini b/devtools/shared/qrcode/tests/mochitest/chrome.ini
new file mode 100644
index 000000000..f73f845e7
--- /dev/null
+++ b/devtools/shared/qrcode/tests/mochitest/chrome.ini
@@ -0,0 +1,5 @@
+[DEFAULT]
+skip-if = os == 'android'
+tags = devtools
+
+[test_decode.html]
diff --git a/devtools/shared/qrcode/tests/mochitest/test_decode.html b/devtools/shared/qrcode/tests/mochitest/test_decode.html
new file mode 100644
index 000000000..d7bf4dfb1
--- /dev/null
+++ b/devtools/shared/qrcode/tests/mochitest/test_decode.html
@@ -0,0 +1,68 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+Test decoding a simple message
+-->
+<head>
+ <meta charset="utf-8">
+ <title>Test decoding a simple message</title>
+
+ <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
+ <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css">
+ <script type="application/javascript;version=1.8">
+window.onload = function() {
+ const { utils: Cu } = Components;
+ const { require } = Cu.import("resource://devtools/shared/Loader.jsm", {});
+ const { Task } = require("devtools/shared/task");
+ const promise = require("promise");
+ const defer = require("devtools/shared/defer");
+
+ const QR = require("devtools/shared/qrcode/index");
+
+ SimpleTest.waitForExplicitFinish();
+
+ const testImage =
+ "data:image/gif;base64,R0lGODdhOgA6AIAAAAAAAP///ywAAAAAOgA6AAAC" +
+ "/4yPqcvtD6OctNqLs968+w+G4gKU5nkaKKquLuW+QVy2tAkDTj3rfQts8CRDko" +
+ "+HPPoYRUgy9YsyldDm44mLWhHYZM6W7WaDqyCRGkZDySxpRGw2sqvLt1q5w/fo" +
+ "XyE6vnUQOJUHBlinMGh046V1F5PDqNcoqcgBOWKBKbK2N+aY+Ih49VkmqMcl2l" +
+ "dkhZUK1umE6jZXJ2ZJaujZaRqH4bpb2uZrJxvIt4Ebe9qoYYrJOsw8apz2bCut" +
+ "m9kqDcw52uuImyr5Oh1KXH1jrn2anuunywtODU/o2c6teceW39ZcLFg/fNMo1b" +
+ "t3jVw2dwTPwJq1KYG3gAklCgu37yGxeScYKyiCc+7DR34hPVQiuQ7UhJMagyEb" +
+ "lymmzJk0a9q8iTOnzp0NCgAAOw==";
+
+ Task.spawn(function() {
+ let result = yield QR.decodeFromURI(testImage);
+ is(result, "HELLO", "Decoded data URI result matches");
+ let canvas = yield drawToCanvas(testImage);
+ result = QR.decodeFromCanvas(canvas);
+ is(result, "HELLO", "Decoded canvas result matches");
+ }).then(SimpleTest.finish, ok.bind(null, false));
+
+ function drawToCanvas(src) {
+ let deferred = defer();
+ let canvas = document.createElement("canvas");
+ let context = canvas.getContext("2d");
+ let image = new Image();
+
+ image.onload = () => {
+ canvas.width = image.width;
+ canvas.height = image.height;
+ context.drawImage(image, 0, 0);
+ deferred.resolve(canvas);
+ };
+ image.src = src;
+
+ return deferred.promise;
+ }
+};
+ </script>
+</head>
+<body>
+<p id="display"></p>
+<div id="content" style="display: none">
+</div>
+<pre id="test">
+</pre>
+</body>
+</html>
diff --git a/devtools/shared/qrcode/tests/unit/test_encode.js b/devtools/shared/qrcode/tests/unit/test_encode.js
new file mode 100644
index 000000000..92455eb6a
--- /dev/null
+++ b/devtools/shared/qrcode/tests/unit/test_encode.js
@@ -0,0 +1,27 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+"use strict";
+
+/**
+ * Test encoding a simple message.
+ */
+
+var { utils: Cu } = Components;
+const { require } = Cu.import("resource://devtools/shared/Loader.jsm", {});
+
+const QR = require("devtools/shared/qrcode/index");
+
+function run_test() {
+ let imgData = QR.encodeToDataURI("HELLO", "L");
+ do_check_eq(imgData.src,
+ "data:image/gif;base64,R0lGODdhOgA6AIAAAAAAAP///ywAAAAAOgA6AAAC" +
+ "/4yPqcvtD6OctNqLs968+w+G4gKU5nkaKKquLuW+QVy2tAkDTj3rfQts8CRDko" +
+ "+HPPoYRUgy9YsyldDm44mLWhHYZM6W7WaDqyCRGkZDySxpRGw2sqvLt1q5w/fo" +
+ "XyE6vnUQOJUHBlinMGh046V1F5PDqNcoqcgBOWKBKbK2N+aY+Ih49VkmqMcl2l" +
+ "dkhZUK1umE6jZXJ2ZJaujZaRqH4bpb2uZrJxvIt4Ebe9qoYYrJOsw8apz2bCut" +
+ "m9kqDcw52uuImyr5Oh1KXH1jrn2anuunywtODU/o2c6teceW39ZcLFg/fNMo1b" +
+ "t3jVw2dwTPwJq1KYG3gAklCgu37yGxeScYKyiCc+7DR34hPVQiuQ7UhJMagyEb" +
+ "lymmzJk0a9q8iTOnzp0NCgAAOw==");
+ do_check_eq(imgData.width, 58);
+ do_check_eq(imgData.height, 58);
+}
diff --git a/devtools/shared/qrcode/tests/unit/xpcshell.ini b/devtools/shared/qrcode/tests/unit/xpcshell.ini
new file mode 100644
index 000000000..f265ea382
--- /dev/null
+++ b/devtools/shared/qrcode/tests/unit/xpcshell.ini
@@ -0,0 +1,7 @@
+[DEFAULT]
+tags = devtools
+head =
+tail =
+firefox-appdir = browser
+
+[test_encode.js]