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.
michael@0 | 1 | /* Any copyright is dedicated to the Public Domain. |
michael@0 | 2 | * http://creativecommons.org/publicdomain/zero/1.0/ */ |
michael@0 | 3 | |
michael@0 | 4 | "use strict"; |
michael@0 | 5 | |
michael@0 | 6 | Cu.import("resource://testing-common/httpd.js"); |
michael@0 | 7 | Cu.import("resource://gre/modules/Services.jsm"); |
michael@0 | 8 | Cu.import("resource://gre/modules/osfile.jsm"); |
michael@0 | 9 | Cu.import("resource:///modules/experiments/Experiments.jsm"); |
michael@0 | 10 | |
michael@0 | 11 | let gProfileDir = null; |
michael@0 | 12 | let gHttpServer = null; |
michael@0 | 13 | let gHttpRoot = null; |
michael@0 | 14 | let gPolicy = new Experiments.Policy(); |
michael@0 | 15 | |
michael@0 | 16 | function run_test() { |
michael@0 | 17 | loadAddonManager(); |
michael@0 | 18 | gProfileDir = do_get_profile(); |
michael@0 | 19 | |
michael@0 | 20 | gHttpServer = new HttpServer(); |
michael@0 | 21 | gHttpServer.start(-1); |
michael@0 | 22 | let port = gHttpServer.identity.primaryPort; |
michael@0 | 23 | gHttpRoot = "http://localhost:" + port + "/"; |
michael@0 | 24 | gHttpServer.registerDirectory("/", do_get_cwd()); |
michael@0 | 25 | do_register_cleanup(() => gHttpServer.stop(() => {})); |
michael@0 | 26 | |
michael@0 | 27 | disableCertificateChecks(); |
michael@0 | 28 | |
michael@0 | 29 | Services.prefs.setBoolPref(PREF_EXPERIMENTS_ENABLED, true); |
michael@0 | 30 | Services.prefs.setIntPref(PREF_LOGGING_LEVEL, 0); |
michael@0 | 31 | Services.prefs.setBoolPref(PREF_LOGGING_DUMP, true); |
michael@0 | 32 | |
michael@0 | 33 | patchPolicy(gPolicy, { |
michael@0 | 34 | updatechannel: () => "nightly", |
michael@0 | 35 | }); |
michael@0 | 36 | |
michael@0 | 37 | run_next_test(); |
michael@0 | 38 | } |
michael@0 | 39 | |
michael@0 | 40 | add_task(function* test_fetchAndCache() { |
michael@0 | 41 | Services.prefs.setCharPref(PREF_MANIFEST_URI, gHttpRoot + "experiments_1.manifest"); |
michael@0 | 42 | let ex = new Experiments.Experiments(gPolicy); |
michael@0 | 43 | |
michael@0 | 44 | Assert.equal(ex._experiments, null, "There should be no cached experiments yet."); |
michael@0 | 45 | yield ex.updateManifest(); |
michael@0 | 46 | Assert.notEqual(ex._experiments.size, 0, "There should be cached experiments now."); |
michael@0 | 47 | |
michael@0 | 48 | yield ex.uninit(); |
michael@0 | 49 | }); |
michael@0 | 50 | |
michael@0 | 51 | add_task(function* test_checkCache() { |
michael@0 | 52 | let ex = new Experiments.Experiments(gPolicy); |
michael@0 | 53 | yield ex.notify(); |
michael@0 | 54 | Assert.notEqual(ex._experiments.size, 0, "There should be cached experiments now."); |
michael@0 | 55 | |
michael@0 | 56 | yield ex.uninit(); |
michael@0 | 57 | }); |
michael@0 | 58 | |
michael@0 | 59 | add_task(function* test_fetchInvalid() { |
michael@0 | 60 | yield removeCacheFile(); |
michael@0 | 61 | |
michael@0 | 62 | Services.prefs.setCharPref(PREF_MANIFEST_URI, gHttpRoot + "experiments_1.manifest"); |
michael@0 | 63 | let ex = new Experiments.Experiments(gPolicy); |
michael@0 | 64 | yield ex.updateManifest(); |
michael@0 | 65 | Assert.notEqual(ex._experiments.size, 0, "There should be experiments"); |
michael@0 | 66 | |
michael@0 | 67 | Services.prefs.setCharPref(PREF_MANIFEST_URI, gHttpRoot + "invalid.manifest"); |
michael@0 | 68 | yield ex.updateManifest() |
michael@0 | 69 | Assert.notEqual(ex._experiments.size, 0, "There should still be experiments: fetch failure shouldn't remove them."); |
michael@0 | 70 | |
michael@0 | 71 | yield ex.uninit(); |
michael@0 | 72 | }); |
michael@0 | 73 |