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 flushing the zipreader cache happens when appropriate |
michael@0 | 6 | |
michael@0 | 7 | var gExpectedFile = null; |
michael@0 | 8 | var gCacheFlushed = false; |
michael@0 | 9 | |
michael@0 | 10 | var CacheFlushObserver = { |
michael@0 | 11 | observe: function(aSubject, aTopic, aData) { |
michael@0 | 12 | if (aTopic != "flush-cache-entry") |
michael@0 | 13 | return; |
michael@0 | 14 | |
michael@0 | 15 | do_check_true(gExpectedFile != null); |
michael@0 | 16 | do_check_true(aSubject instanceof AM_Ci.nsIFile); |
michael@0 | 17 | do_check_eq(aSubject.path, gExpectedFile.path); |
michael@0 | 18 | gCacheFlushed = true; |
michael@0 | 19 | gExpectedFile = null; |
michael@0 | 20 | } |
michael@0 | 21 | }; |
michael@0 | 22 | |
michael@0 | 23 | function run_test() { |
michael@0 | 24 | // This test only makes sense when leaving extensions packed |
michael@0 | 25 | if (Services.prefs.getBoolPref("extensions.alwaysUnpack")) |
michael@0 | 26 | return; |
michael@0 | 27 | |
michael@0 | 28 | do_test_pending(); |
michael@0 | 29 | Services.obs.addObserver(CacheFlushObserver, "flush-cache-entry", false); |
michael@0 | 30 | createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "2"); |
michael@0 | 31 | |
michael@0 | 32 | startupManager(); |
michael@0 | 33 | |
michael@0 | 34 | run_test_1(); |
michael@0 | 35 | } |
michael@0 | 36 | |
michael@0 | 37 | // Tests that the cache is flushed when cancelling a pending install |
michael@0 | 38 | function run_test_1() { |
michael@0 | 39 | AddonManager.getInstallForFile(do_get_addon("test_cacheflush1"), function(aInstall) { |
michael@0 | 40 | completeAllInstalls([aInstall], function() { |
michael@0 | 41 | // We should flush the staged XPI when cancelling the install |
michael@0 | 42 | gExpectedFile = gProfD.clone(); |
michael@0 | 43 | gExpectedFile.append("extensions"); |
michael@0 | 44 | gExpectedFile.append("staged"); |
michael@0 | 45 | gExpectedFile.append("addon1@tests.mozilla.org.xpi"); |
michael@0 | 46 | aInstall.cancel(); |
michael@0 | 47 | |
michael@0 | 48 | do_check_true(gCacheFlushed); |
michael@0 | 49 | gCacheFlushed = false; |
michael@0 | 50 | |
michael@0 | 51 | run_test_2(); |
michael@0 | 52 | }); |
michael@0 | 53 | }); |
michael@0 | 54 | } |
michael@0 | 55 | |
michael@0 | 56 | // Tests that the cache is flushed when uninstalling an add-on |
michael@0 | 57 | function run_test_2() { |
michael@0 | 58 | installAllFiles([do_get_addon("test_cacheflush1")], function() { |
michael@0 | 59 | // Installing will flush the staged XPI during startup |
michael@0 | 60 | gExpectedFile = gProfD.clone(); |
michael@0 | 61 | gExpectedFile.append("extensions"); |
michael@0 | 62 | gExpectedFile.append("staged"); |
michael@0 | 63 | gExpectedFile.append("addon1@tests.mozilla.org.xpi"); |
michael@0 | 64 | restartManager(); |
michael@0 | 65 | do_check_true(gCacheFlushed); |
michael@0 | 66 | gCacheFlushed = false; |
michael@0 | 67 | |
michael@0 | 68 | AddonManager.getAddonByID("addon1@tests.mozilla.org", function(a1) { |
michael@0 | 69 | // We should flush the installed XPI when uninstalling |
michael@0 | 70 | gExpectedFile = gProfD.clone(); |
michael@0 | 71 | gExpectedFile.append("extensions"); |
michael@0 | 72 | gExpectedFile.append("addon1@tests.mozilla.org.xpi"); |
michael@0 | 73 | |
michael@0 | 74 | do_check_true(a1 != null); |
michael@0 | 75 | a1.uninstall(); |
michael@0 | 76 | do_check_false(gCacheFlushed); |
michael@0 | 77 | do_execute_soon(run_test_3); |
michael@0 | 78 | }); |
michael@0 | 79 | }); |
michael@0 | 80 | } |
michael@0 | 81 | |
michael@0 | 82 | // Tests that the cache is flushed when installing a restartless add-on |
michael@0 | 83 | function run_test_3() { |
michael@0 | 84 | restartManager(); |
michael@0 | 85 | |
michael@0 | 86 | AddonManager.getInstallForFile(do_get_addon("test_cacheflush2"), function(aInstall) { |
michael@0 | 87 | aInstall.addListener({ |
michael@0 | 88 | onInstallStarted: function(aInstall) { |
michael@0 | 89 | // We should flush the staged XPI when completing the install |
michael@0 | 90 | gExpectedFile = gProfD.clone(); |
michael@0 | 91 | gExpectedFile.append("extensions"); |
michael@0 | 92 | gExpectedFile.append("staged"); |
michael@0 | 93 | gExpectedFile.append("addon2@tests.mozilla.org.xpi"); |
michael@0 | 94 | }, |
michael@0 | 95 | |
michael@0 | 96 | onInstallEnded: function(aInstall) { |
michael@0 | 97 | do_check_true(gCacheFlushed); |
michael@0 | 98 | gCacheFlushed = false; |
michael@0 | 99 | |
michael@0 | 100 | do_execute_soon(run_test_4); |
michael@0 | 101 | } |
michael@0 | 102 | }); |
michael@0 | 103 | |
michael@0 | 104 | aInstall.install(); |
michael@0 | 105 | }); |
michael@0 | 106 | } |
michael@0 | 107 | |
michael@0 | 108 | // Tests that the cache is flushed when uninstalling a restartless add-on |
michael@0 | 109 | function run_test_4() { |
michael@0 | 110 | AddonManager.getAddonByID("addon2@tests.mozilla.org", function(a2) { |
michael@0 | 111 | // We should flush the installed XPI when uninstalling |
michael@0 | 112 | gExpectedFile = gProfD.clone(); |
michael@0 | 113 | gExpectedFile.append("extensions"); |
michael@0 | 114 | gExpectedFile.append("addon2@tests.mozilla.org.xpi"); |
michael@0 | 115 | |
michael@0 | 116 | a2.uninstall(); |
michael@0 | 117 | do_check_true(gCacheFlushed); |
michael@0 | 118 | gCacheFlushed = false; |
michael@0 | 119 | |
michael@0 | 120 | do_execute_soon(do_test_finished); |
michael@0 | 121 | }); |
michael@0 | 122 | } |