toolkit/mozapps/extensions/test/xpcshell/test_bug594058.js

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

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 tests is modifying a file in an unpacked extension
michael@0 6 // causes cache invalidation.
michael@0 7
michael@0 8 // Disables security checking our updates which haven't been signed
michael@0 9 Services.prefs.setBoolPref("extensions.checkUpdateSecurity", false);
michael@0 10 // Allow the mismatch UI to show
michael@0 11 Services.prefs.setBoolPref("extensions.showMismatchUI", true);
michael@0 12
michael@0 13 const Ci = Components.interfaces;
michael@0 14 const extDir = gProfD.clone();
michael@0 15 extDir.append("extensions");
michael@0 16
michael@0 17 var gCachePurged = false;
michael@0 18
michael@0 19 // Override the window watcher
michael@0 20 var WindowWatcher = {
michael@0 21 openWindow: function(parent, url, name, features, arguments) {
michael@0 22 do_check_false(gCachePurged);
michael@0 23 },
michael@0 24
michael@0 25 QueryInterface: function(iid) {
michael@0 26 if (iid.equals(Ci.nsIWindowWatcher)
michael@0 27 || iid.equals(Ci.nsISupports))
michael@0 28 return this;
michael@0 29
michael@0 30 throw Components.results.NS_ERROR_NO_INTERFACE;
michael@0 31 }
michael@0 32 }
michael@0 33
michael@0 34 var WindowWatcherFactory = {
michael@0 35 createInstance: function createInstance(outer, iid) {
michael@0 36 if (outer != null)
michael@0 37 throw Components.results.NS_ERROR_NO_AGGREGATION;
michael@0 38 return WindowWatcher.QueryInterface(iid);
michael@0 39 }
michael@0 40 };
michael@0 41
michael@0 42 var registrar = Components.manager.QueryInterface(AM_Ci.nsIComponentRegistrar);
michael@0 43 registrar.registerFactory(Components.ID("{1dfeb90a-2193-45d5-9cb8-864928b2af55}"),
michael@0 44 "Fake Window Watcher",
michael@0 45 "@mozilla.org/embedcomp/window-watcher;1", WindowWatcherFactory);
michael@0 46
michael@0 47 /**
michael@0 48 * Start the test by installing extensions.
michael@0 49 */
michael@0 50 function run_test() {
michael@0 51 do_test_pending();
michael@0 52 gCachePurged = false;
michael@0 53
michael@0 54 let obs = AM_Cc["@mozilla.org/observer-service;1"].
michael@0 55 getService(AM_Ci.nsIObserverService);
michael@0 56 obs.addObserver({
michael@0 57 observe: function(aSubject, aTopic, aData) {
michael@0 58 gCachePurged = true;
michael@0 59 }
michael@0 60 }, "startupcache-invalidate", false);
michael@0 61 createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1");
michael@0 62
michael@0 63 startupManager();
michael@0 64 // nsAppRunner takes care of clearing this when a new app is installed
michael@0 65 do_check_false(gCachePurged);
michael@0 66
michael@0 67 installAllFiles([do_get_addon("test_bug594058")], function() {
michael@0 68 restartManager();
michael@0 69 do_check_true(gCachePurged);
michael@0 70 gCachePurged = false;
michael@0 71
michael@0 72 // Now, make it look like we've updated the file. First, start the EM
michael@0 73 // so it records the bogus old time, then update the file and restart.
michael@0 74 let extFile = extDir.clone();
michael@0 75 let pastTime = extFile.lastModifiedTime - 5000;
michael@0 76 extFile.append("bug594058@tests.mozilla.org");
michael@0 77 setExtensionModifiedTime(extFile, pastTime);
michael@0 78 let otherFile = extFile.clone();
michael@0 79 otherFile.append("directory");
michael@0 80 otherFile.lastModifiedTime = pastTime;
michael@0 81 otherFile.append("file1");
michael@0 82 otherFile.lastModifiedTime = pastTime;
michael@0 83
michael@0 84 restartManager();
michael@0 85 gCachePurged = false;
michael@0 86
michael@0 87 otherFile.lastModifiedTime = pastTime + 5000;
michael@0 88 restartManager();
michael@0 89 do_check_true(gCachePurged);
michael@0 90 gCachePurged = false;
michael@0 91
michael@0 92 restartManager();
michael@0 93 do_check_false(gCachePurged);
michael@0 94
michael@0 95 // Upgrading the app should force a cache flush due to potentially showing
michael@0 96 // the compatibility UI
michael@0 97 restartManager("2");
michael@0 98 do_check_true(gCachePurged);
michael@0 99 gCachePurged = false;
michael@0 100
michael@0 101 do_test_finished();
michael@0 102 });
michael@0 103 }

mercurial