Giter VIP home page Giter VIP logo

webext-experiment-utils's Introduction

WebExtension Experiment Utils

Tools for rapid development of WebExtension Experiments based on a schema.json API definition.

  • generateStubApi - generates a stub api.js based on schema.json
  • documentSchema - generates documentation in Markdown based on schema.json
  • verifyWeeSchema - verifies that schema.json is a valid WebExtension Experiments schema

For a usage example, see the npm run generate command in ./package.json and the example files in ./example/.

Installation

npm install --save-dev mozilla/webext-experiment-utils#develop

Hints

  1. Put all the privileged code of your add-on in src/privileged as a best practice
  2. The 'Firefox privileged' modules cannot use WebExtension apis (browserAction, management, etc.). Use a background.js script (using messages and events) to co-ordinate multiple privileged modules.

A note on automatic testing of WebExtension Experiments

WebExtension Experiments can not be automatically tested in the same manner as the official (in-tree) WebExtension APIs. Partially, such testing could work by copying over source files into the Firefox source tree and then building from source, but doing so would not let us catch the specific issues associated with bundling WebExtension Experiments (which have different life-cycle behavior than in-tree WebExtension APIs).

Instead, we can leverage Selenium for functional testing in a way that mimics unit testing of our experiment APIs.

The SHIELD utils test add-on currently accomplishes this by opening an extension page, switching to that tab/window and executing javascript using driver.executeAsyncScript().

Check this helper method for more information and an initial implementation: https://github.com/mozilla/shield-studies-addon-utils/blob/develop/testUtils/executeJs.js

Tests can then be written as such:

  it("should be able to access window.browser from the extension page for tests", async () => {
    const hasAccessToWebExtensionApi = await utils.executeJs.executeAsyncScriptInExtensionPageForTests(
      driver,
      async callback => {
        callback(typeof browser === "object");
      },
    );
    assert(hasAccessToWebExtensionApi);
  });

This way, WebExtension APIs that are only exposed in background scripts can be accessed directly in automated tests.

For an example of such a testing set-up, see https://github.com/mozilla/shield-studies-addon-utils/blob/master/test/functional/browser.study.api.js

webext-experiment-utils's People

Contributors

motin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

webext-experiment-utils's Issues

Update readme to reflect the current state of Mozilla extension testing

@biancadanforth mentioned in mozilla/preparatory-survey-for-naar-study-addon@dc47d20#r34225341:

I noticed a section in the README that does not reflect the current state of testing extensions in Firefox that rhelmer published earlier this year.

In particular, you don't have to install the extension as a built-in -- you can just copy it to a particular test directory to have it installed with the testing profile. You can also now write custom extension tests (xpcshell and mochitests) and run them using Mozilla CI. This may not be quite the same for folks who are not familiar with Mozilla test frameworks, but some may find it useful.

This should be reflected in the README of this repo.

CODE_OF_CONDUCT.md file missing

As of January 1 2019, Mozilla requires that all GitHub projects include this CODE_OF_CONDUCT.md file in the project root. The file has two parts:

  1. Required Text - All text under the headings Community Participation Guidelines and How to Report, are required, and should not be altered.
  2. Optional Text - The Project Specific Etiquette heading provides a space to speak more specifically about ways people can work effectively and inclusively together. Some examples of those can be found on the Firefox Debugger project, and Common Voice. (The optional part is commented out in the raw template file, and will not be visible until you modify and uncomment that part.)

If you have any questions about this file, or Code of Conduct policies and procedures, please see Mozilla-GitHub-Standards or email [email protected].

(Message COC001)

Wiki changes

FYI: The following changes were made to this repository's wiki:

These were made as the result of a recent automated defacement of publically writeable wikis.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.