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 | |
michael@0 | 5 | // This verifies that background updates & notifications work as expected |
michael@0 | 6 | |
michael@0 | 7 | // The test extension uses an insecure update url. |
michael@0 | 8 | Services.prefs.setBoolPref(PREF_EM_CHECK_UPDATE_SECURITY, false); |
michael@0 | 9 | |
michael@0 | 10 | Components.utils.import("resource://testing-common/httpd.js"); |
michael@0 | 11 | var testserver = new HttpServer(); |
michael@0 | 12 | testserver.start(-1); |
michael@0 | 13 | gPort = testserver.identity.primaryPort; |
michael@0 | 14 | const profileDir = gProfD.clone(); |
michael@0 | 15 | profileDir.append("extensions"); |
michael@0 | 16 | |
michael@0 | 17 | // register static files with server and interpolate port numbers in them |
michael@0 | 18 | mapFile("/data/test_backgroundupdate.rdf", testserver); |
michael@0 | 19 | |
michael@0 | 20 | function run_test() { |
michael@0 | 21 | createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2"); |
michael@0 | 22 | |
michael@0 | 23 | testserver.registerDirectory("/addons/", do_get_file("addons")); |
michael@0 | 24 | |
michael@0 | 25 | startupManager(); |
michael@0 | 26 | |
michael@0 | 27 | do_test_pending(); |
michael@0 | 28 | run_test_1(); |
michael@0 | 29 | } |
michael@0 | 30 | |
michael@0 | 31 | function end_test() { |
michael@0 | 32 | testserver.stop(do_test_finished); |
michael@0 | 33 | } |
michael@0 | 34 | |
michael@0 | 35 | // Verify that with no add-ons installed the background update notifications get |
michael@0 | 36 | // called |
michael@0 | 37 | function run_test_1() { |
michael@0 | 38 | AddonManager.getAddonsByTypes(["extension", "theme", "locale"], function(aAddons) { |
michael@0 | 39 | do_check_eq(aAddons.length, 0); |
michael@0 | 40 | |
michael@0 | 41 | Services.obs.addObserver(function() { |
michael@0 | 42 | Services.obs.removeObserver(arguments.callee, "addons-background-update-complete"); |
michael@0 | 43 | |
michael@0 | 44 | do_execute_soon(run_test_2); |
michael@0 | 45 | }, "addons-background-update-complete", false); |
michael@0 | 46 | |
michael@0 | 47 | AddonManagerPrivate.backgroundUpdateCheck(); |
michael@0 | 48 | }); |
michael@0 | 49 | } |
michael@0 | 50 | |
michael@0 | 51 | // Verify that with two add-ons installed both of which claim to have updates |
michael@0 | 52 | // available we get the notification after both updates attempted to start |
michael@0 | 53 | function run_test_2() { |
michael@0 | 54 | writeInstallRDFForExtension({ |
michael@0 | 55 | id: "addon1@tests.mozilla.org", |
michael@0 | 56 | version: "1.0", |
michael@0 | 57 | updateURL: "http://localhost:" + gPort + "/data/test_backgroundupdate.rdf", |
michael@0 | 58 | targetApplications: [{ |
michael@0 | 59 | id: "xpcshell@tests.mozilla.org", |
michael@0 | 60 | minVersion: "1", |
michael@0 | 61 | maxVersion: "1" |
michael@0 | 62 | }], |
michael@0 | 63 | name: "Test Addon 1", |
michael@0 | 64 | }, profileDir); |
michael@0 | 65 | |
michael@0 | 66 | writeInstallRDFForExtension({ |
michael@0 | 67 | id: "addon2@tests.mozilla.org", |
michael@0 | 68 | version: "1.0", |
michael@0 | 69 | updateURL: "http://localhost:" + gPort + "/data/test_backgroundupdate.rdf", |
michael@0 | 70 | targetApplications: [{ |
michael@0 | 71 | id: "xpcshell@tests.mozilla.org", |
michael@0 | 72 | minVersion: "1", |
michael@0 | 73 | maxVersion: "1" |
michael@0 | 74 | }], |
michael@0 | 75 | name: "Test Addon 2", |
michael@0 | 76 | }, profileDir); |
michael@0 | 77 | |
michael@0 | 78 | writeInstallRDFForExtension({ |
michael@0 | 79 | id: "addon3@tests.mozilla.org", |
michael@0 | 80 | version: "1.0", |
michael@0 | 81 | targetApplications: [{ |
michael@0 | 82 | id: "xpcshell@tests.mozilla.org", |
michael@0 | 83 | minVersion: "1", |
michael@0 | 84 | maxVersion: "1" |
michael@0 | 85 | }], |
michael@0 | 86 | name: "Test Addon 3", |
michael@0 | 87 | }, profileDir); |
michael@0 | 88 | |
michael@0 | 89 | // Background update uses a different pref, if set |
michael@0 | 90 | Services.prefs.setCharPref("extensions.update.background.url", |
michael@0 | 91 | "http://localhost:" + gPort +"/data/test_backgroundupdate.rdf"); |
michael@0 | 92 | restartManager(); |
michael@0 | 93 | |
michael@0 | 94 | // Do hotfix checks |
michael@0 | 95 | Services.prefs.setCharPref("extensions.hotfix.id", "hotfix@tests.mozilla.org"); |
michael@0 | 96 | Services.prefs.setCharPref("extensions.hotfix.url", "http://localhost:" + gPort + "/missing.rdf"); |
michael@0 | 97 | |
michael@0 | 98 | let installCount = 0; |
michael@0 | 99 | let completeCount = 0; |
michael@0 | 100 | let sawCompleteNotification = false; |
michael@0 | 101 | |
michael@0 | 102 | Services.obs.addObserver(function() { |
michael@0 | 103 | Services.obs.removeObserver(arguments.callee, "addons-background-update-complete"); |
michael@0 | 104 | |
michael@0 | 105 | do_check_eq(installCount, 3); |
michael@0 | 106 | sawCompleteNotification = true; |
michael@0 | 107 | }, "addons-background-update-complete", false); |
michael@0 | 108 | |
michael@0 | 109 | AddonManager.addInstallListener({ |
michael@0 | 110 | onNewInstall: function(aInstall) { |
michael@0 | 111 | installCount++; |
michael@0 | 112 | }, |
michael@0 | 113 | |
michael@0 | 114 | onDownloadFailed: function(aInstall) { |
michael@0 | 115 | completeCount++; |
michael@0 | 116 | if (completeCount == 3) { |
michael@0 | 117 | do_check_true(sawCompleteNotification); |
michael@0 | 118 | end_test(); |
michael@0 | 119 | } |
michael@0 | 120 | } |
michael@0 | 121 | }); |
michael@0 | 122 | |
michael@0 | 123 | AddonManagerPrivate.backgroundUpdateCheck(); |
michael@0 | 124 | } |