Skip to content

Instantly share code, notes, and snippets.

@gregglind
Created April 26, 2017 20:07
Show Gist options
  • Save gregglind/18d985d79c70a5fbefc0d471894d4c6b to your computer and use it in GitHub Desktop.
Save gregglind/18d985d79c70a5fbefc0d471894d4c6b to your computer and use it in GitHub Desktop.

Revisions

  1. gregglind created this gist Apr 26, 2017.
    62 changes: 62 additions & 0 deletions bootstrap.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,62 @@
    // https://github.com/gregglind/quantum-preference-telemetry-annotation-pretender/blob/master/index.js

    const CID = Cu.import('resource://gre/modules/ClientID.jsm');
    const { TelemetryController } = Cu.import('resource://gre/modules/TelemetryController.jsm');
    const { TelemetryEnvironment } = Cu.import('resource://gre/modules/TelemetryEnvironment.jsm');


    function generateTelemetryIdIfNeeded() {
    let id = TelemetryController.clientID;
    /* istanbul ignore next */
    if (id === undefined) {
    return CID.ClientIDImpl._doLoadClientID();
    } else {
    return Promise.resolve(id);
    }
    }

    const experimentName = "screenshots-rollout-test-1";
    const variations = ['control', 'screenshots-on'];

    function chooseVariation (clientId) {
    // do some hashing magic of the client id, such as:
    let last = clientId.substr(clientId.length-3);
    let which = parseInt(last,16) % variations.length;
    return variations[which];
    }

    function isEligible() {
    // check locales or whatever
    return true;
    }

    function markTelemetry (which) {

    }

    function unmarkTelemetry (which) {

    }

    function implement(variation) {
    markTelemetry(variation)

    switch (variation) {
    case "control":
    // don't set the pref to the value
    break;
    default:
    setThePref(someValue)
    }
    }


    function startup () {
    let variation = chooseVariation(clientId);
    impelement(variation)
    }


    function shutdown () {
    // blah blah
    }