Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
1 /* Any copyright is dedicated to the Public Domain.
2 * http://creativecommons.org/publicdomain/zero/1.0/ */
4 "use strict";
6 Cu.import("resource://testing-common/httpd.js");
7 Cu.import("resource://gre/modules/Services.jsm");
8 Cu.import("resource://gre/modules/osfile.jsm");
9 Cu.import("resource:///modules/experiments/Experiments.jsm");
11 let gProfileDir = null;
12 let gHttpServer = null;
13 let gHttpRoot = null;
14 let gPolicy = new Experiments.Policy();
16 function run_test() {
17 loadAddonManager();
18 gProfileDir = do_get_profile();
20 gHttpServer = new HttpServer();
21 gHttpServer.start(-1);
22 let port = gHttpServer.identity.primaryPort;
23 gHttpRoot = "http://localhost:" + port + "/";
24 gHttpServer.registerDirectory("/", do_get_cwd());
25 do_register_cleanup(() => gHttpServer.stop(() => {}));
27 disableCertificateChecks();
29 Services.prefs.setBoolPref(PREF_EXPERIMENTS_ENABLED, true);
30 Services.prefs.setIntPref(PREF_LOGGING_LEVEL, 0);
31 Services.prefs.setBoolPref(PREF_LOGGING_DUMP, true);
33 patchPolicy(gPolicy, {
34 updatechannel: () => "nightly",
35 });
37 run_next_test();
38 }
40 add_task(function* test_fetchAndCache() {
41 Services.prefs.setCharPref(PREF_MANIFEST_URI, gHttpRoot + "experiments_1.manifest");
42 let ex = new Experiments.Experiments(gPolicy);
44 Assert.equal(ex._experiments, null, "There should be no cached experiments yet.");
45 yield ex.updateManifest();
46 Assert.notEqual(ex._experiments.size, 0, "There should be cached experiments now.");
48 yield ex.uninit();
49 });
51 add_task(function* test_checkCache() {
52 let ex = new Experiments.Experiments(gPolicy);
53 yield ex.notify();
54 Assert.notEqual(ex._experiments.size, 0, "There should be cached experiments now.");
56 yield ex.uninit();
57 });
59 add_task(function* test_fetchInvalid() {
60 yield removeCacheFile();
62 Services.prefs.setCharPref(PREF_MANIFEST_URI, gHttpRoot + "experiments_1.manifest");
63 let ex = new Experiments.Experiments(gPolicy);
64 yield ex.updateManifest();
65 Assert.notEqual(ex._experiments.size, 0, "There should be experiments");
67 Services.prefs.setCharPref(PREF_MANIFEST_URI, gHttpRoot + "invalid.manifest");
68 yield ex.updateManifest()
69 Assert.notEqual(ex._experiments.size, 0, "There should still be experiments: fetch failure shouldn't remove them.");
71 yield ex.uninit();
72 });