/* Any copyright is dedicated to the Public Domain. * http://creativecommons.org/publicdomain/zero/1.0/ */ "use strict"; Cu.import("resource:///modules/experiments/Experiments.jsm"); Cu.import("resource://gre/modules/TelemetryController.jsm", this); const SEC_IN_ONE_DAY = 24 * 60 * 60; var gPolicy = null; function ManifestEntry(data) { this.id = EXPERIMENT1_ID; this.xpiURL = "http://localhost:1/dummy.xpi"; this.xpiHash = EXPERIMENT1_XPI_SHA1; this.startTime = new Date(2010, 0, 1, 12).getTime() / 1000; this.endTime = new Date(9001, 0, 1, 12).getTime() / 1000; this.maxActiveSeconds = SEC_IN_ONE_DAY; this.appName = ["XPCShell"]; this.channel = ["nightly"]; data = data || {}; for (let k of Object.keys(data)) { this[k] = data[k]; } if (!this.endTime) { this.endTime = this.startTime + 5 * SEC_IN_ONE_DAY; } } function applicableFromManifestData(data, policy) { let manifestData = new ManifestEntry(data); let entry = new Experiments.ExperimentEntry(policy); entry.initFromManifestData(manifestData); return entry.isApplicable(); } function run_test() { run_next_test(); } add_task(function* test_setup() { createAppInfo(); do_get_profile(); startAddonManagerOnly(); yield TelemetryController.testSetup(); gPolicy = new Experiments.Policy(); patchPolicy(gPolicy, { updatechannel: () => "nightly", locale: () => "en-US", random: () => 0.5, }); Services.prefs.setBoolPref(PREF_EXPERIMENTS_ENABLED, true); Services.prefs.setIntPref(PREF_LOGGING_LEVEL, 0); Services.prefs.setBoolPref(PREF_LOGGING_DUMP, true); }); function arraysEqual(a, b) { if (a.length !== b.length) { return false; } for (let i=0; i applicable = value, value => { applicable = false; reason = value; } ); Assert.equal(applicable, entry[0], "Experiment entry applicability should match for test " + i + ": " + JSON.stringify([entry[2], entry[3]])); if (!applicable && entry[1]) { Assert.equal(reason, entry[1], "Experiment rejection reason should match for test " + i); } } }); add_task(function* test_shutdown() { yield TelemetryController.testShutdown(); });