Bug 1101790 - setTreatmentTag API for UITour. r=felipe a=gavin
authorGavin Sharp <gavin@gavinsharp.com>
Wed, 19 Nov 2014 17:52:23 -0500
changeset 226105 659ccf9aac7a59e18d076a164ded1744e150f8f0
parent 226104 8cadcfdc846a68628a9786c7371c5fd552f8da51
child 226106 166866d8cfcfb1b37cc079239992bb0021873439
push id4155
push userfelipc@gmail.com
push dateThu, 20 Nov 2014 20:21:58 +0000
treeherdermozilla-beta@0bcee2fc8e0b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfelipe, gavin
bugs1101790
milestone34.0
Bug 1101790 - setTreatmentTag API for UITour. r=felipe a=gavin
browser/modules/UITour.jsm
browser/modules/test/browser_UITour.js
browser/modules/test/uitour.js
--- a/browser/modules/UITour.jsm
+++ b/browser/modules/UITour.jsm
@@ -486,16 +486,38 @@ this.UITour = {
         break;
       }
 
       case "setDefaultSearchEngine": {
         let enginePromise = this.selectSearchEngine(data.identifier);
         enginePromise.catch(Cu.reportError);
         break;
       }
+
+      case "setTreatmentTag": {
+        let name = data.name;
+        let value = data.value;
+        let string = Cc["@mozilla.org/supports-string;1"].createInstance(Ci.nsISupportsString);
+        string.data = value;
+        Services.prefs.setComplexValue("browser.uitour.treatment." + name,
+                                       Ci.nsISupportsString, string);
+        UITourHealthReport.recordTreatmentTag(name, value);
+        break;
+      }
+
+      case "getTreatmentTag": {
+        let name = data.name;
+        let value;
+        try {
+          value = Services.prefs.getComplexValue("browser.uitour.treatment." + name,
+                                                 Ci.nsISupportsString).data;
+        } catch (ex) {}
+        this.sendPageCallback(contentDocument, data.callbackID, { value: value });
+        break;
+      }
     }
 
     if (!this.originTabs.has(window))
       this.originTabs.set(window, new Set());
 
     this.originTabs.get(window).add(tab);
     tab.addEventListener("TabClose", this);
     tab.addEventListener("TabBecomingWindow", this);
--- a/browser/modules/test/browser_UITour.js
+++ b/browser/modules/test/browser_UITour.js
@@ -370,14 +370,22 @@ let tests = [
           Services.search.defaultEngine = defaultEngine;
         });
 
         gContentAPI.setDefaultSearchEngine(someOtherEngineID);
       });
     });
   },
 
+  function test_treatment_tag(done) {
+    gContentAPI.setTreatmentTag("foobar", "baz");
+    gContentAPI.getTreatmentTag("foobar", (data) => {
+      is(data.value, "baz", "set and retrieved treatmentTag");
+      done();
+    });
+  },
+
   // Make sure this test is last in the file so the appMenu gets left open and done will confirm it got tore down.
   function cleanupMenus(done) {
     gContentAPI.showMenu("appMenu");
     done();
   },
 ];
--- a/browser/modules/test/uitour.js
+++ b/browser/modules/test/uitour.js
@@ -204,9 +204,23 @@ if (typeof Mozilla == 'undefined') {
 	};
 
 	Mozilla.UITour.setDefaultSearchEngine = function(identifier) {
 		_sendEvent('setDefaultSearchEngine', {
 			identifier: identifier,
 		});
 	};
 
+	Mozilla.UITour.setTreatmentTag = function(name, value) {
+		_sendEvent('setTreatmentTag', {
+			name: name,
+			value: value
+		});
+	};
+
+	Mozilla.UITour.getTreatmentTag = function(name, callback) {
+		_sendEvent('getTreatmentTag', {
+			name: name,
+			callbackID: _waitForCallback(callback)
+		});
+	};
+
 })();