Skip to content
This repository has been archived by the owner on Oct 14, 2020. It is now read-only.

Commit

Permalink
WIP to make fakeApi
Browse files Browse the repository at this point in the history
  • Loading branch information
gregglind committed Apr 10, 2018
1 parent dfa2ec0 commit 0412f2e
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,5 @@ ADDON_SRC_PATH="examples/small-study/src"
# bundle the study web extension experiment
mkdir -p $ADDON_SRC_PATH/privileged/study
cp $WEBEXTAPIS_PATH/study/api.js $ADDON_SRC_PATH/privileged/study/api.js
cp $WEBEXTAPIS_PATH/study/fakeApi.js $ADDON_SRC_PATH/privileged/study/fakeApi.js
cp $WEBEXTAPIS_PATH/study/schema.json $ADDON_SRC_PATH/privileged/study/schema.json

# bundle the prefs web extension experiment
mkdir -p $ADDON_SRC_PATH/privileged/prefs
cp $WEBEXTAPIS_PATH/prefs/api.js $ADDON_SRC_PATH/privileged/prefs/api.js
cp $WEBEXTAPIS_PATH/prefs/schema.json $ADDON_SRC_PATH/privileged/prefs/schema.json
2 changes: 1 addition & 1 deletion examples/small-study/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@
"browser_action": {
"browser_style": true,
"default_icon": "icons/shield-icon.svg",
"default_title": "Test"
"default_title": "Send A Ping"
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"url": "git://github.com/mozilla/shield-studies-addon-utils.git"
},
"scripts": {
"build": "cd webExtensionApis/study && webpack && yaml2json schema.yaml -p > schema.json",
"build": "cd webExtensionApis/study && webpack && yaml2json schema.yaml -p > schema.json ; node ../../bin/schemaToInterface.js ./schema.json > fakeApi.js ",
"docformat": "doctoc --title '**Contents**' docs/*.md && prettier '**/*.md' --write",
"eslint": "eslint src --ext jsm --ext js --ext json",
"eslint-fix": "npm run eslint -- --fix",
Expand Down
63 changes: 63 additions & 0 deletions webExtensionApis/study/fakeApi.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@

this.study = class extends ExtensionAPI {
getAPI(context) {
return {

async configure ( studySetup ) {
return undefined;
}

async simpleDeterministicVariation ( weightedVariations, fraction ) {
return "styleA";
}

async endStudy ( anEnding ) {
return "endingName";
}

async permissions ( ) {
return {"shield":true,"pioneer":false};
}

async userInfo ( ) {
return undefined;
}

async sendTelemetry ( payload, type ) {
return "undefined";
}

async getTelemetry ( telemetrySelectionOptions ) {
return [{"pingType":"main"}];
}

async setActiveExperiment ( ) {
return undefined;
}

async unsetActiveExperiment ( ) {
return undefined;
}

async getPref ( prefName ) {
return "someValue";
}

async setPref ( prefName, prefType ) {
return "someValue";
}

async watchPref ( prefName, prefType ) {
return "[A function]";
}

async surveyUrl ( baseUrl ) {
return "https://example.com?version=59.0";
}

async validateJSON ( anObject, schema ) {
return {"isValid":true};
}
}
}
}
30 changes: 26 additions & 4 deletions webExtensionApis/study/schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,16 @@
type: function
description: Configure the study. Most things can't work without this
async: true
fakereturn:
parameters:
- name: studySetup
type: object
# with a variation included.
# expiration?

# expiration? -- TODO No, this should be with usual webExt timers.
#

- name: simpleDeterministicVariation
defaultReturn: "styleA"
returns: Name of a variation from weightedVariations
async: true
parameters:
Expand All @@ -50,14 +52,16 @@
type: Number

- name: endStudy
defaultReturn: "endingName"
parameters:
- name: anEnding
- type: object
type: object
# should be anEnding Object
returns: none

## informational things
- name: permissions
defaultReturn: {shield: true, pioneer: false}
async: true
# I don't like this name!
# TODO: should there be an arg to just ask for pioneer? shield?
Expand All @@ -74,15 +78,18 @@
type: object # TODO copy existing?

- name: type
defaultReturn: undefined
returns: Nothing

- name: getTelemetry
async: true
defaultReturn: [{pingType: 'main'}]
returns: Array of Telemetry pings
parameters:
- name: telemetrySelectionOptions
description: `{ type, n, minTimestamp, headersOnly }`

# btw, these might not need to be public
- name: setActiveExperiment
async: true
returns: Nothing
Expand All @@ -95,24 +102,39 @@
## prefs
# TODO: userBranch, default branch complications
- name: getPref
parameters: []
defaultReturn: 'someValue'
parameters:
- name: prefName
type: string

- name: setPref
defaultReturn: 'someValue'
returns: Value. Unclear for edge cases
parameters:
- name: prefName
type: string
- name: prefType
type: string # from prefTypes

- name: watchPref
defaultReturn: '[A function]'
returns: a watcher for a pref
parameters:
- name: prefName
type: string
- name: prefType
type: function # does this work?

# utilities
- name: surveyUrl
defaultReturn: 'https://example.com?version=59.0'
parameters:
- name: baseUrl
type: string
returns: a url with queryArgs appended / mixed

- name: validateJSON
defaultReturn: {isValid: true}
returns: a validation
parameters:
- name: anObject
Expand Down

0 comments on commit 0412f2e

Please sign in to comment.