diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5db7383 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +node_modules +*xpi diff --git a/code/.jpmignore b/code/.jpmignore new file mode 100644 index 0000000..f0dceed --- /dev/null +++ b/code/.jpmignore @@ -0,0 +1,5 @@ +.* +node_modules +!/node_modules/shield-studies-addon-utils +!/lib +!/test diff --git a/code/README.md b/code/README.md new file mode 100644 index 0000000..7b837e7 --- /dev/null +++ b/code/README.md @@ -0,0 +1,2 @@ +#My Jetpack Addon +A basic add-on \ No newline at end of file diff --git a/code/bootstrap.js b/code/bootstrap.orig.js similarity index 100% rename from code/bootstrap.js rename to code/bootstrap.orig.js diff --git a/code/content/BrowserListener.jsm b/code/content/BrowserListener.js similarity index 93% rename from code/content/BrowserListener.jsm rename to code/content/BrowserListener.js index c725556..416ec42 100755 --- a/code/content/BrowserListener.jsm +++ b/code/content/BrowserListener.js @@ -1,16 +1,14 @@ -this.EXPORTED_SYMBOLS = [ - "BrowserListener", -]; +const {Ci, Cu, Cc} = require("chrome"); -const STYLE_URL = "chrome://unified-urlbar/content/style.css"; +const STYLE_URL = require("sdk/self").data.url("style.css"); const SEARCH_BAR_WIDGET_ID = "search-container"; const XHTML_NS = "http://www.w3.org/1999/xhtml"; -const { classes: Cc, interfaces: Ci, utils: Cu } = Components; Cu.import("resource://gre/modules/XPCOMUtils.jsm"); Cu.import("resource://gre/modules/Services.jsm"); Cu.import("resource:///modules/CustomizableUI.jsm"); -Cu.import("chrome://unified-urlbar/content/Panel.jsm"); + +const { Panel } = require("./Panel.js"); var gBranch = "control"; var gBrowsers = null; @@ -151,3 +149,6 @@ function whenWindowLoaded(win, callback) { } }, true); } + +// require-ify +exports.BrowserListener = BrowserListener; diff --git a/code/content/Panel.jsm b/code/content/Panel.js similarity index 99% rename from code/content/Panel.jsm rename to code/content/Panel.js index e92b5a4..afb81c9 100755 --- a/code/content/Panel.jsm +++ b/code/content/Panel.js @@ -1,13 +1,10 @@ -this.EXPORTED_SYMBOLS = [ - "Panel", -]; +const {Ci, Cu, Cc} = require("chrome"); const EXISTING_FOOTER_ID = "urlbar-search-footer"; const XUL_NS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"; -const { classes: Cc, interfaces: Ci, utils: Cu } = Components; Cu.import("resource://gre/modules/Services.jsm"); -Cu.import("chrome://unified-urlbar/content/Telemetry.jsm"); +const { Telemetry } = require("./Telemetry"); this.Panel = function (panelElt) { this.panelElement = panelElt; @@ -536,3 +533,5 @@ this.Panel.prototype = { this._selectedButton = null; }, }; + +exports.Panel = Panel; diff --git a/code/content/Telemetry.jsm b/code/content/Telemetry.js similarity index 97% rename from code/content/Telemetry.jsm rename to code/content/Telemetry.js index d293b81..b7daf86 100755 --- a/code/content/Telemetry.jsm +++ b/code/content/Telemetry.js @@ -1,11 +1,8 @@ -this.EXPORTED_SYMBOLS = [ - "Telemetry", -]; +const {Ci, Cu, Cc} = require("chrome"); const SEARCH_SUGGESTIONS_OPT_IN_CHOICE_PREF = "browser.urlbar.userMadeSearchSuggestionsChoice"; -const { classes: Cc, interfaces: Ci, utils: Cu } = Components; Cu.import("resource://gre/modules/XPCOMUtils.jsm"); Cu.import("resource://gre/modules/Preferences.jsm"); Cu.import("resource:///modules/BrowserUITelemetry.jsm"); @@ -135,3 +132,7 @@ function addSearchSuggestionsOptInTelemetry() { let optedIn = Preferences.get("browser.urlbar.suggest.searches"); Telemetry.setValue("suggestionsEnabled", optedIn); } + + +exports.Telemetry = Telemetry; + diff --git a/code/content/gear.svg b/code/data/gear.svg similarity index 100% rename from code/content/gear.svg rename to code/data/gear.svg diff --git a/code/content/style.css b/code/data/style.css similarity index 91% rename from code/content/style.css rename to code/data/style.css index 4903b6c..cb880e1 100755 --- a/code/content/style.css +++ b/code/data/style.css @@ -64,13 +64,13 @@ } #urlbar-search-settings2 { - list-style-image: url("chrome://unified-urlbar/content/gear.svg#gear"); + list-style-image: url("./gear.svg#gear"); background-position: left center; border-bottom: none; } #urlbar-search-settings2:hover { - list-style-image: url("chrome://unified-urlbar/content/gear.svg#gear-inverted"); + list-style-image: url("./gear.svg#gear-inverted"); background-color: Highlight; } diff --git a/code/index.js b/code/index.js new file mode 100644 index 0000000..259518d --- /dev/null +++ b/code/index.js @@ -0,0 +1,51 @@ +//BUG: Call ryanvm to get person to test addon + +/* 1. the modules needed to turn this into a STUDY */ +const xutils = require("shield-studies-addon-utils"); +const variationsMod = require("./variations"); + +const addonPrefs = require("sdk/simple-prefs").prefs; + +/* 2. configuration / setup constants for the study. + * These are only ones needed, or supported + */ +const forSetup = { + name: "Unified Urlbar Shield Study 1", // unique for Telemetry + choices: Object.keys(variationsMod.variations), // names of branches. + duration: 7, // in days, + /* Get surveyUrl from Strategy + Insights */ + surveyUrl: "https://qsurvey.mozilla.com/s3/Shield-Study-Example-Survey" +}; + +// 3. Study Object (module singleton); +var ourConfig = xutils.xsetup(forSetup); +let thisStudy = new xutils.Study(ourConfig,variationsMod); + +// 3a (optional). Watch for changes and reporting +xutils.Reporter.on("report",(d)=>console.debug("telemetry", d)); +thisStudy.on("change",(newState)=>console.debug("newState:", newState)); + +/* 4. usual bootstrap / jetpack main function */ +function main (options, callback) { + // TURN ON TELEMETRY, using an indirect pref!!! + xutils.generateTelemetryIdIfNeeded().then(function () { + xutils.handleStartup(options, thisStudy); + }) + // addon specific load code should go here, if there is additional. + console.debug(`special addon loading code: ${options.loadReason}`) + console.debug(JSON.stringify(addonPrefs, null, 2)) +} + +function onUnload (reason) { + console.debug(`special addon unloading code: ${reason}`) + xutils.handleOnUnload(reason, thisStudy); + + // special unload code, specific to addon if any. + console.debug(`special addon unloading code: ${reason}`) + console.debug(JSON.stringify(addonPrefs, null, 2)) +} + + +/* 5. usual bootstrap addon exports */ +exports.main = main; +exports.onUnload = onUnload diff --git a/code/install.rdf b/code/install.rdf index 72ce290..a80298a 100755 --- a/code/install.rdf +++ b/code/install.rdf @@ -2,9 +2,9 @@ - unified-urlbar@experiments.mozilla.org + unified-urlbar-shield-study-1@experiments.mozilla.org 1.0.0 - 128 + 2 true false @@ -13,11 +13,11 @@ {ec8030f7-c20a-464f-9b0e-13a3a9e97384} 43.0 - 47.0 + 49.0 - Unified Urlbar Experiment + Unified Urlbar Experiment Shield Study An experimental add-on testing the unified urlbar experience. diff --git a/code/package.json b/code/package.json new file mode 100644 index 0000000..c2e4836 --- /dev/null +++ b/code/package.json @@ -0,0 +1,21 @@ +{ + "title": "X-Unified-Urlbar-Study", + "name": "code", + "version": "0.0.1", + "description": "A basic add-on", + "main": "index.js", + "author": "", + "engines": { + "firefox": ">=38.0a1", + "fennec": ">=38.0a1" + }, + "license": "MIT", + "keywords": [ + "jetpack" + ], + "devDependencies": { + "chai": "^3.5.0", + "jpm": "^1.0.7", + "shield-studies-addon-utils": "^1.0.1" + } +} diff --git a/code/test/test-index.js b/code/test/test-index.js new file mode 100644 index 0000000..b3ad6e8 --- /dev/null +++ b/code/test/test-index.js @@ -0,0 +1,19 @@ +var main = require("../"); + +exports["test main"] = function(assert) { + assert.pass("Unit test running!"); +}; + +exports["test main async"] = function(assert, done) { + assert.pass("async Unit test running!"); + done(); +}; + +exports["test dummy"] = function(assert, done) { + main.dummy("foo", function(text) { + assert.ok((text === "foo"), "Is the text actually 'foo'"); + done(); + }); +}; + +require("sdk/test").run(exports); diff --git a/code/variations.js b/code/variations.js new file mode 100644 index 0000000..56ff517 --- /dev/null +++ b/code/variations.js @@ -0,0 +1,104 @@ +// facade for enumerated urlbar variations + +const { BrowserListener } = require("./content/BrowserListener"); +const { Telemetry } = require("./content/Telemetry"); + +/* Telemetry Pref needs to be on to record searches */ +const TEL_PREF = "toolkit.telemetry.enabled"; +const SUGGEST_PREF = "browser.urlbar.suggest.searches"; + +let prefSvc = require("sdk/preferences/service"); +let prefs = require("sdk/simple-prefs").prefs; + +// BUG, are these robust *enough*? Generalize to prefs in general. +function setShadowPref (name, value) { + let shadow = name + ".shadow"; + if (!prefSvc.isSet(shadow)) { + let original = prefSvc.get(name); + prefSvc.set(shadow, original); + prefSvc.set(name, value); + } +} + +function resetShadowPref (name) { + let shadow = name + ".shadow"; + if (prefSvc.isSet(shadow)) { + let original = prefSvc.get(shadow); + prefSvc.set(name, original); + prefSvc.reset(shadow); + } +} + +// BUG: should control arm arm turn on suggestions? +// BUG: should having suggestions on include/exclude? + +/* create a safe, multi-callable, idempotent modification */ +let isCalled = false; +function modify (branch) { + if (!isCalled) { + setShadowPref(TEL_PREF, true); + setShadowPref(SUGGEST_PREF, true); + isCalled = true; + BrowserListener.init(branch); + Telemetry.init(branch); + } +}; + + +let variations = { + "unified": () => modify("unified"), + //- modify placement + //- Orientation note (onboarding) (BUG!) + + "control": () => modify("control") + //"customized": // trash this from the study +}; + +function isEligible () { + /* BUG + eligible: { + is not customized the search bar already. + AND version < 50 + }*/ + return true; +}; + +function cleanup () { + resetTelemetry(); + BrowserListener.destroy(); + Telemetry.destroy(); + return true; +}; + + +module.exports = { + isEligible: isEligible, + cleanup: cleanup, + variations: variations, +}; + + +/* TODO: tests +- after destroy... + - telemetry is reset + - searchbar is back + +*/ +/* + +everyoneSetup : + - force extended telemetry on + - onboarding check or show + - turn on seach suggestions + `browser.urlbar.suggest.searches` ?? + + +cleanup: + # restore telemetry from indirect pref + # `browser.urlbar.suggest.searches` ?? + + # remove indirect pref + # searchbar restore? "placement" + BrowserListener.destroy(); + Telemetry.destroy(); +*/ diff --git a/code/x-prefs.json b/code/x-prefs.json new file mode 100644 index 0000000..c6c99df --- /dev/null +++ b/code/x-prefs.json @@ -0,0 +1,5 @@ +{ + "extensions.unified-urlbar-shield-study-1@experiments.mozilla.org.variation": "unified", + "extensions.sdk.console.logLevel": "debug", + "general.warnOnAboutConfig": false +}