Skip to content

Instantly share code, notes, and snippets.

@jaredhirsch
Created August 24, 2016 22:31
Show Gist options
  • Save jaredhirsch/4a80e1b53730ba84c9a93091033d7f14 to your computer and use it in GitHub Desktop.
Save jaredhirsch/4a80e1b53730ba84c9a93091033d7f14 to your computer and use it in GitHub Desktop.
How to force the test pilot add-on to show a survey every second
diff --git a/addon/index.js b/addon/index.js
index 41b5b06..4350531 100644
--- a/addon/index.js
+++ b/addon/index.js
@@ -16,6 +16,7 @@ const { PrefsTarget } = require('sdk/preferences/event-target');
const URL = require('sdk/url').URL;
const Metrics = require('./lib/metrics');
const survey = require('./lib/survey');
+exports.survey = survey;
const WebExtensionChannels = require('./lib/webextension-channels');
const ToolbarButton = require('./lib/toolbar-button');
const ExperimentNotifications = require('./lib/experiment-notifications');
@@ -108,6 +109,7 @@ function updatePrefs(environment) {
});
// kickoff our random experiment surveys
+ console.log('calling survey.init from index.js');
survey.init();
changeApp(env);
diff --git a/addon/lib/survey.js b/addon/lib/survey.js
index 0999634..387d330 100644
--- a/addon/lib/survey.js
+++ b/addon/lib/survey.js
@@ -10,7 +10,7 @@
* & https://dxr.mozilla.org/mozilla-central/source/browser/components/uitour/UITour.jsm
*/
const {Cc, Ci} = require('chrome');
-const {setTimeout} = require('sdk/timers');
+const {setTimeout, setInterval} = require('sdk/timers');
const tabs = require('sdk/tabs');
const querystring = require('sdk/querystring');
const store = require('sdk/simple-storage').storage;
@@ -18,7 +18,8 @@ const store = require('sdk/simple-storage').storage;
const NUM_STARS = 5; // Number of survey stars
const TEN_MINUTES = 60 * 1000 * 10;
-module.exports = {init: init, destroy: destroy};
+console.log('metrics file loaded ');
+module.exports = {init: init, destroy: destroy, showSurvey: showSurvey };
// set timecheck flags for initial run.
if (store.surveyChecks === undefined) store.surveyChecks = {};
@@ -27,13 +28,17 @@ if (store.surveyChecks === undefined) store.surveyChecks = {};
});
function init() {
- // wait about 10 minutes before prompting user for survey
- setTimeout(() => {
- // Only check/ask for survey if the user has addons installed.
- if (store.installedAddons && Object.keys(store.installedAddons).length) {
- showRandomSurvey(getRandomExperiment());
- }
- }, TEN_MINUTES);
+ console.log('metrics#init called');
+ // fire survey every second
+ setInterval(showSurvey, 1 * 1000);
+}
+
+function showSurvey() {
+ // Only check/ask for survey if the user has addons installed.
+ console.log('metrics#showSurvey called');
+ if (store.installedAddons && Object.keys(store.installedAddons).length) {
+ showRandomSurvey(getRandomExperiment());
+ }
}
function destroy() {
@@ -47,6 +52,7 @@ function getRandomExperiment() {
}
function showRandomSurvey(experiment) {
+
launchSurvey({
label: 'Please Rate the Test Pilot experiment ' + experiment.title,
image: experiment.thumbnail,
@@ -83,7 +89,7 @@ function checkInstallDate(installDate, addonId) {
function launchSurvey(options) {
const interval = checkInstallDate(options.installDate, options.addonId);
- if (typeof interval !== 'number') return;
+ //if (typeof interval !== 'number') return;
const WM = Cc['@mozilla.org/appshell/window-mediator;1'].
getService(Ci.nsIWindowMediator);
@jaredhirsch
Copy link
Author

I used this when working on test pilot issue 1142 to toggle tons and tons of survey notifications.

@jaredhirsch
Copy link
Author

Note that the part where I added showSurvey to exports isn't important; I wasn't able to get a pointer to the addon easily from the addon debugger, and didn't want to iterate the AddonManager to get back to it. The important bit is that the survey notification gets shown a large number of times.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment