tor-browser

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

web-extensions-helper.js (1282B)


      1 // testharness file with WebExtensions utilities
      2 
      3 /**
      4 * Loads the WebExtension at the path specified and runs the tests defined in the extension's resources.
      5 * Listens to messages sent from the user agent and converts the `browser.test` assertions
      6 * into testharness.js assertions.
      7 *
      8 * @param {string} extensionPath - a path to the extension's resources.
      9 */
     10 
     11 setup({ explicit_done: true })
     12 globalThis.runTestsWithWebExtension = function(extensionPath) {
     13    test_driver.install_web_extension({
     14        type: "path",
     15        path: extensionPath
     16    })
     17    .then((result) => {
     18        let test;
     19        browser.test.onTestStarted.addListener((data) => {
     20            test = async_test(data.testName)
     21        })
     22 
     23        browser.test.onTestFinished.addListener((data) => {
     24            test.step(() => {
     25                let description = data.message ? `${data.assertionDescription}. ${data.message}` : data.assertionDescription
     26                assert_true(data.result, description)
     27            })
     28 
     29            test.done()
     30 
     31            if (!data.result) {
     32                test.set_status(test.FAIL)
     33            }
     34 
     35            if (!data.remainingTests) {
     36                test_driver.uninstall_web_extension(result.extension).then(() => { done() })
     37            }
     38        })
     39    })
     40 }