tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_QRCodeWorker.js (2068B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this
      3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      4 
      5 "use strict";
      6 
      7 /**
      8 * Test QRCodeWorker functionality
      9 */
     10 
     11 const { QRCodeWorker } = ChromeUtils.importESModule(
     12  "moz-src:///browser/components/qrcode/QRCodeWorker.sys.mjs"
     13 );
     14 
     15 add_task(async function test_worker_instantiation() {
     16  info("Testing QRCodeWorker can be instantiated");
     17 
     18  const worker = new QRCodeWorker();
     19  Assert.ok(worker, "QRCodeWorker instance should be created");
     20 
     21  // Clean up
     22  await worker.terminate();
     23 });
     24 
     25 add_task(async function test_worker_responds_to_ping() {
     26  info("Testing QRCodeWorker responds to ping message");
     27  const worker = new QRCodeWorker();
     28 
     29  // Test ping functionality
     30  const response = await worker.ping();
     31  Assert.equal(response, "pong", "Worker should respond with 'pong' to ping");
     32 
     33  // Clean up
     34  await worker.terminate();
     35 });
     36 
     37 add_task(async function test_worker_can_load_qrcode_library() {
     38  info("Testing QRCodeWorker can load QRCode library");
     39 
     40  const worker = new QRCodeWorker();
     41 
     42  // Test that the worker can check if the QRCode library is available
     43  const hasLibrary = await worker.hasQRCodeLibrary();
     44  Assert.ok(hasLibrary, "Worker should have access to QRCode library");
     45 
     46  // Clean up
     47  await worker.terminate();
     48 });
     49 
     50 add_task(async function test_worker_can_generate_simple_qrcode() {
     51  info("Testing QRCodeWorker can generate a simple QR code");
     52 
     53  const worker = new QRCodeWorker();
     54 
     55  // Test generating a very simple QR code
     56  const testUrl = "https://mozilla.org";
     57  const result = await worker.generateQRCode(testUrl);
     58 
     59  Assert.ok(result, "Should get a result from generateQRCode");
     60  Assert.ok(result.width, "Result should have a width");
     61  Assert.ok(result.height, "Result should have a height");
     62  Assert.ok(result.src, "Result should have a src data URI");
     63  Assert.ok(result.src.startsWith("data:image/"), "src should be a data URI");
     64 
     65  // Clean up
     66  await worker.terminate();
     67 });