|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 * http://creativecommons.org/publicdomain/zero/1.0/ |
|
3 */ |
|
4 |
|
5 // This verifies that AddonRepository correctly fills in the |
|
6 // %COMPATIBILITY_MODE% token in the Search API URL. |
|
7 |
|
8 const PREF_GETADDONS_GETSEARCHRESULTS = "extensions.getAddons.search.url"; |
|
9 |
|
10 Components.utils.import("resource://testing-common/httpd.js"); |
|
11 var gServer = new HttpServer(); |
|
12 gServer.start(-1); |
|
13 gPort = gServer.identity.primaryPort; |
|
14 var COMPATIBILITY_PREF; |
|
15 |
|
16 // register static files with server and interpolate port numbers in them |
|
17 mapFile("/data/test_AddonRepository_compatmode_ignore.xml", gServer); |
|
18 mapFile("/data/test_AddonRepository_compatmode_normal.xml", gServer); |
|
19 mapFile("/data/test_AddonRepository_compatmode_strict.xml", gServer); |
|
20 |
|
21 function run_test() { |
|
22 do_test_pending(); |
|
23 createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2"); |
|
24 |
|
25 Services.prefs.setCharPref(PREF_GETADDONS_GETSEARCHRESULTS, |
|
26 "http://localhost:" + gPort + "/data/test_AddonRepository_compatmode_%COMPATIBILITY_MODE%.xml"); |
|
27 startupManager(); |
|
28 run_test_1(); |
|
29 } |
|
30 |
|
31 function end_test() { |
|
32 gServer.stop(do_test_finished); |
|
33 } |
|
34 |
|
35 // Strict compatibility checking disabled. |
|
36 function run_test_1() { |
|
37 do_print("Testing with strict compatibility checking disabled"); |
|
38 Services.prefs.setBoolPref(PREF_EM_STRICT_COMPATIBILITY, false); |
|
39 |
|
40 AddonRepository.searchAddons("test", 6, { |
|
41 searchSucceeded: function(aAddons) { |
|
42 do_check_neq(aAddons, null); |
|
43 do_check_eq(aAddons.length, 1); |
|
44 do_check_eq(aAddons[0].id, "compatmode-normal@tests.mozilla.org"); |
|
45 |
|
46 run_test_2(); |
|
47 }, |
|
48 searchFailed: function() { |
|
49 do_throw("Search should not have failed"); |
|
50 } |
|
51 }); |
|
52 } |
|
53 |
|
54 // Strict compatibility checking enabled. |
|
55 function run_test_2() { |
|
56 do_print("Testing with strict compatibility checking enabled"); |
|
57 Services.prefs.setBoolPref(PREF_EM_STRICT_COMPATIBILITY, true); |
|
58 |
|
59 AddonRepository.searchAddons("test", 6, { |
|
60 searchSucceeded: function(aAddons) { |
|
61 do_check_neq(aAddons, null); |
|
62 do_check_eq(aAddons.length, 1); |
|
63 do_check_eq(aAddons[0].id, "compatmode-strict@tests.mozilla.org"); |
|
64 |
|
65 run_test_3(); |
|
66 }, |
|
67 searchFailed: function() { |
|
68 do_throw("Search should not have failed"); |
|
69 } |
|
70 }); |
|
71 } |
|
72 |
|
73 // Compatibility checking disabled. |
|
74 function run_test_3() { |
|
75 do_print("Testing with all compatibility checking disabled"); |
|
76 AddonManager.checkCompatibility = false; |
|
77 |
|
78 AddonRepository.searchAddons("test", 6, { |
|
79 searchSucceeded: function(aAddons) { |
|
80 do_check_neq(aAddons, null); |
|
81 do_check_eq(aAddons.length, 1); |
|
82 do_check_eq(aAddons[0].id, "compatmode-ignore@tests.mozilla.org"); |
|
83 |
|
84 end_test(); |
|
85 }, |
|
86 searchFailed: function() { |
|
87 do_throw("Search should not have failed"); |
|
88 } |
|
89 }); |
|
90 } |