|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 * http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 "use strict"; |
|
5 |
|
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"); |
|
10 |
|
11 let gProfileDir = null; |
|
12 let gHttpServer = null; |
|
13 let gHttpRoot = null; |
|
14 let gPolicy = new Experiments.Policy(); |
|
15 |
|
16 function run_test() { |
|
17 loadAddonManager(); |
|
18 gProfileDir = do_get_profile(); |
|
19 |
|
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(() => {})); |
|
26 |
|
27 disableCertificateChecks(); |
|
28 |
|
29 Services.prefs.setBoolPref(PREF_EXPERIMENTS_ENABLED, true); |
|
30 Services.prefs.setIntPref(PREF_LOGGING_LEVEL, 0); |
|
31 Services.prefs.setBoolPref(PREF_LOGGING_DUMP, true); |
|
32 |
|
33 patchPolicy(gPolicy, { |
|
34 updatechannel: () => "nightly", |
|
35 }); |
|
36 |
|
37 run_next_test(); |
|
38 } |
|
39 |
|
40 add_task(function* test_fetchAndCache() { |
|
41 Services.prefs.setCharPref(PREF_MANIFEST_URI, gHttpRoot + "experiments_1.manifest"); |
|
42 let ex = new Experiments.Experiments(gPolicy); |
|
43 |
|
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."); |
|
47 |
|
48 yield ex.uninit(); |
|
49 }); |
|
50 |
|
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."); |
|
55 |
|
56 yield ex.uninit(); |
|
57 }); |
|
58 |
|
59 add_task(function* test_fetchInvalid() { |
|
60 yield removeCacheFile(); |
|
61 |
|
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"); |
|
66 |
|
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."); |
|
70 |
|
71 yield ex.uninit(); |
|
72 }); |
|
73 |