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 | Components.utils.import("resource://gre/modules/Services.jsm"); |
michael@0 | 6 | |
michael@0 | 7 | // restartManager() mucks with XPIProvider.jsm importing, so we hack around. |
michael@0 | 8 | this.__defineGetter__("XPIProvider", function () { |
michael@0 | 9 | let scope = {}; |
michael@0 | 10 | return Components.utils.import("resource://gre/modules/addons/XPIProvider.jsm", scope) |
michael@0 | 11 | .XPIProvider; |
michael@0 | 12 | }); |
michael@0 | 13 | |
michael@0 | 14 | const addonId = "addon1@tests.mozilla.org"; |
michael@0 | 15 | |
michael@0 | 16 | function run_test() { |
michael@0 | 17 | Services.prefs.setBoolPref("extensions.checkUpdateSecurity", false); |
michael@0 | 18 | |
michael@0 | 19 | createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9"); |
michael@0 | 20 | startupManager(); |
michael@0 | 21 | |
michael@0 | 22 | run_next_test(); |
michael@0 | 23 | } |
michael@0 | 24 | |
michael@0 | 25 | add_test(function test_getter_and_setter() { |
michael@0 | 26 | // Our test add-on requires a restart. |
michael@0 | 27 | let listener = { |
michael@0 | 28 | onInstallEnded: function onInstallEnded() { |
michael@0 | 29 | AddonManager.removeInstallListener(listener); |
michael@0 | 30 | // never restart directly inside an onInstallEnded handler! |
michael@0 | 31 | do_execute_soon(function getter_setter_install_ended() { |
michael@0 | 32 | restartManager(); |
michael@0 | 33 | |
michael@0 | 34 | AddonManager.getAddonByID(addonId, function(addon) { |
michael@0 | 35 | |
michael@0 | 36 | do_check_neq(addon, null); |
michael@0 | 37 | do_check_neq(addon.syncGUID, null); |
michael@0 | 38 | do_check_true(addon.syncGUID.length >= 9); |
michael@0 | 39 | |
michael@0 | 40 | let oldGUID = addon.SyncGUID; |
michael@0 | 41 | let newGUID = "foo"; |
michael@0 | 42 | |
michael@0 | 43 | addon.syncGUID = newGUID; |
michael@0 | 44 | do_check_eq(newGUID, addon.syncGUID); |
michael@0 | 45 | |
michael@0 | 46 | // Verify change made it to DB. |
michael@0 | 47 | AddonManager.getAddonByID(addonId, function(newAddon) { |
michael@0 | 48 | do_check_neq(newAddon, null); |
michael@0 | 49 | do_check_eq(newGUID, newAddon.syncGUID); |
michael@0 | 50 | }); |
michael@0 | 51 | |
michael@0 | 52 | run_next_test(); |
michael@0 | 53 | }); |
michael@0 | 54 | }); |
michael@0 | 55 | } |
michael@0 | 56 | }; |
michael@0 | 57 | |
michael@0 | 58 | AddonManager.addInstallListener(listener); |
michael@0 | 59 | |
michael@0 | 60 | AddonManager.getInstallForFile(do_get_addon("test_install1"), |
michael@0 | 61 | function(install) { |
michael@0 | 62 | install.install(); |
michael@0 | 63 | }); |
michael@0 | 64 | }); |
michael@0 | 65 | |
michael@0 | 66 | add_test(function test_fetch_by_guid_unknown_guid() { |
michael@0 | 67 | XPIProvider.getAddonBySyncGUID("XXXX", function(addon) { |
michael@0 | 68 | do_check_eq(null, addon); |
michael@0 | 69 | run_next_test(); |
michael@0 | 70 | }); |
michael@0 | 71 | }); |
michael@0 | 72 | |
michael@0 | 73 | // Ensure setting an extension to an existing syncGUID results in error. |
michael@0 | 74 | add_test(function test_error_on_duplicate_syncguid_insert() { |
michael@0 | 75 | const installNames = ["test_install1", "test_install2_1"]; |
michael@0 | 76 | const installIDs = ["addon1@tests.mozilla.org", "addon2@tests.mozilla.org"]; |
michael@0 | 77 | |
michael@0 | 78 | let installCount = 0; |
michael@0 | 79 | |
michael@0 | 80 | let listener = { |
michael@0 | 81 | onInstallEnded: function onInstallEnded() { |
michael@0 | 82 | installCount++; |
michael@0 | 83 | |
michael@0 | 84 | if (installCount == installNames.length) { |
michael@0 | 85 | AddonManager.removeInstallListener(listener); |
michael@0 | 86 | do_execute_soon(function duplicate_syncguid_install_ended() { |
michael@0 | 87 | restartManager(); |
michael@0 | 88 | |
michael@0 | 89 | AddonManager.getAddonsByIDs(installIDs, callback_soon(function(addons) { |
michael@0 | 90 | let initialGUID = addons[1].syncGUID; |
michael@0 | 91 | |
michael@0 | 92 | try { |
michael@0 | 93 | addons[1].syncGUID = addons[0].syncGUID; |
michael@0 | 94 | do_throw("Should not get here."); |
michael@0 | 95 | } |
michael@0 | 96 | catch (e) { |
michael@0 | 97 | do_check_true(e.message.startsWith("Addon sync GUID conflict")); |
michael@0 | 98 | restartManager(); |
michael@0 | 99 | |
michael@0 | 100 | AddonManager.getAddonByID(installIDs[1], function(addon) { |
michael@0 | 101 | do_check_eq(initialGUID, addon.syncGUID); |
michael@0 | 102 | run_next_test(); |
michael@0 | 103 | }); |
michael@0 | 104 | } |
michael@0 | 105 | })); |
michael@0 | 106 | }); |
michael@0 | 107 | } |
michael@0 | 108 | } |
michael@0 | 109 | }; |
michael@0 | 110 | |
michael@0 | 111 | AddonManager.addInstallListener(listener); |
michael@0 | 112 | let getInstallCB = function(install) { install.install(); }; |
michael@0 | 113 | |
michael@0 | 114 | for each (let name in installNames) { |
michael@0 | 115 | AddonManager.getInstallForFile(do_get_addon(name), getInstallCB); |
michael@0 | 116 | } |
michael@0 | 117 | }); |
michael@0 | 118 | |
michael@0 | 119 | add_test(function test_fetch_by_guid_known_guid() { |
michael@0 | 120 | AddonManager.getAddonByID(addonId, function(addon) { |
michael@0 | 121 | do_check_neq(null, addon); |
michael@0 | 122 | do_check_neq(null, addon.syncGUID); |
michael@0 | 123 | |
michael@0 | 124 | let syncGUID = addon.syncGUID; |
michael@0 | 125 | |
michael@0 | 126 | XPIProvider.getAddonBySyncGUID(syncGUID, function(newAddon) { |
michael@0 | 127 | do_check_neq(null, newAddon); |
michael@0 | 128 | do_check_eq(syncGUID, newAddon.syncGUID); |
michael@0 | 129 | |
michael@0 | 130 | run_next_test(); |
michael@0 | 131 | }); |
michael@0 | 132 | }); |
michael@0 | 133 | }); |
michael@0 | 134 | |
michael@0 | 135 | add_test(function test_addon_manager_get_by_sync_guid() { |
michael@0 | 136 | AddonManager.getAddonByID(addonId, function(addon) { |
michael@0 | 137 | do_check_neq(null, addon.syncGUID); |
michael@0 | 138 | |
michael@0 | 139 | let syncGUID = addon.syncGUID; |
michael@0 | 140 | |
michael@0 | 141 | AddonManager.getAddonBySyncGUID(syncGUID, function(newAddon) { |
michael@0 | 142 | do_check_neq(null, newAddon); |
michael@0 | 143 | do_check_eq(addon.id, newAddon.id); |
michael@0 | 144 | do_check_eq(syncGUID, newAddon.syncGUID); |
michael@0 | 145 | |
michael@0 | 146 | AddonManager.getAddonBySyncGUID("DOES_NOT_EXIST", function(missing) { |
michael@0 | 147 | do_check_eq(undefined, missing); |
michael@0 | 148 | |
michael@0 | 149 | run_next_test(); |
michael@0 | 150 | }); |
michael@0 | 151 | }); |
michael@0 | 152 | }); |
michael@0 | 153 | }); |
michael@0 | 154 |