tor-browser

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

imagecapture-helpers.js (1787B)


      1 'use strict';
      2 
      3 // These tests rely on the User Agent providing an implementation of
      4 // platform image capture backends.
      5 //
      6 // In Chromium-based browsers this implementation is provided by a polyfill
      7 // in order to reduce the amount of test-only code shipped to users. To enable
      8 // these tests the browser must be run with these options:
      9 //
     10 //   --enable-blink-features=MojoJS,MojoJSTest
     11 
     12 async function loadChromiumResources() {
     13  await import('/resources/chromium/mock-imagecapture.js');
     14 }
     15 
     16 async function initialize_image_capture_tests() {
     17  if (typeof ImageCaptureTest === 'undefined') {
     18    const script = document.createElement('script');
     19    script.src = '/resources/test-only-api.js';
     20    script.async = false;
     21    const p = new Promise((resolve, reject) => {
     22      script.onload = () => { resolve(); };
     23      script.onerror = e => { reject(e); };
     24    })
     25    document.head.appendChild(script);
     26    await p;
     27 
     28    if (isChromiumBased) {
     29      await loadChromiumResources();
     30    }
     31  }
     32  assert_implements(ImageCaptureTest, 'ImageCaptureTest is unavailable');
     33  let imageCaptureTest = new ImageCaptureTest();
     34  await imageCaptureTest.initialize();
     35  return imageCaptureTest;
     36 }
     37 
     38 function image_capture_test(func, name, properties) {
     39  promise_test(async (t) => {
     40    let imageCaptureTest = await initialize_image_capture_tests();
     41    try {
     42      await func(t, imageCaptureTest);
     43    } finally {
     44      await imageCaptureTest.reset();
     45    };
     46  }, name, properties);
     47 }
     48 
     49 function assert_point2d_array_approx_equals(actual, expected, epsilon) {
     50  assert_equals(actual.length, expected.length, 'length');
     51  for (var i = 0; i < actual.length; ++i) {
     52    assert_approx_equals(actual[i].x, expected[i].x, epsilon, 'x');
     53    assert_approx_equals(actual[i].y, expected[i].y, epsilon, 'y');
     54  }
     55 }