michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: * http://creativecommons.org/publicdomain/zero/1.0/ michael@0: */ michael@0: michael@0: // This tests is modifying a file in an unpacked extension michael@0: // causes cache invalidation. michael@0: michael@0: // Disables security checking our updates which haven't been signed michael@0: Services.prefs.setBoolPref("extensions.checkUpdateSecurity", false); michael@0: // Allow the mismatch UI to show michael@0: Services.prefs.setBoolPref("extensions.showMismatchUI", true); michael@0: michael@0: const Ci = Components.interfaces; michael@0: const extDir = gProfD.clone(); michael@0: extDir.append("extensions"); michael@0: michael@0: var gCachePurged = false; michael@0: michael@0: // Override the window watcher michael@0: var WindowWatcher = { michael@0: openWindow: function(parent, url, name, features, arguments) { michael@0: do_check_false(gCachePurged); michael@0: }, michael@0: michael@0: QueryInterface: function(iid) { michael@0: if (iid.equals(Ci.nsIWindowWatcher) michael@0: || iid.equals(Ci.nsISupports)) michael@0: return this; michael@0: michael@0: throw Components.results.NS_ERROR_NO_INTERFACE; michael@0: } michael@0: } michael@0: michael@0: var WindowWatcherFactory = { michael@0: createInstance: function createInstance(outer, iid) { michael@0: if (outer != null) michael@0: throw Components.results.NS_ERROR_NO_AGGREGATION; michael@0: return WindowWatcher.QueryInterface(iid); michael@0: } michael@0: }; michael@0: michael@0: var registrar = Components.manager.QueryInterface(AM_Ci.nsIComponentRegistrar); michael@0: registrar.registerFactory(Components.ID("{1dfeb90a-2193-45d5-9cb8-864928b2af55}"), michael@0: "Fake Window Watcher", michael@0: "@mozilla.org/embedcomp/window-watcher;1", WindowWatcherFactory); michael@0: michael@0: /** michael@0: * Start the test by installing extensions. michael@0: */ michael@0: function run_test() { michael@0: do_test_pending(); michael@0: gCachePurged = false; michael@0: michael@0: let obs = AM_Cc["@mozilla.org/observer-service;1"]. michael@0: getService(AM_Ci.nsIObserverService); michael@0: obs.addObserver({ michael@0: observe: function(aSubject, aTopic, aData) { michael@0: gCachePurged = true; michael@0: } michael@0: }, "startupcache-invalidate", false); michael@0: createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1"); michael@0: michael@0: startupManager(); michael@0: // nsAppRunner takes care of clearing this when a new app is installed michael@0: do_check_false(gCachePurged); michael@0: michael@0: installAllFiles([do_get_addon("test_bug594058")], function() { michael@0: restartManager(); michael@0: do_check_true(gCachePurged); michael@0: gCachePurged = false; michael@0: michael@0: // Now, make it look like we've updated the file. First, start the EM michael@0: // so it records the bogus old time, then update the file and restart. michael@0: let extFile = extDir.clone(); michael@0: let pastTime = extFile.lastModifiedTime - 5000; michael@0: extFile.append("bug594058@tests.mozilla.org"); michael@0: setExtensionModifiedTime(extFile, pastTime); michael@0: let otherFile = extFile.clone(); michael@0: otherFile.append("directory"); michael@0: otherFile.lastModifiedTime = pastTime; michael@0: otherFile.append("file1"); michael@0: otherFile.lastModifiedTime = pastTime; michael@0: michael@0: restartManager(); michael@0: gCachePurged = false; michael@0: michael@0: otherFile.lastModifiedTime = pastTime + 5000; michael@0: restartManager(); michael@0: do_check_true(gCachePurged); michael@0: gCachePurged = false; michael@0: michael@0: restartManager(); michael@0: do_check_false(gCachePurged); michael@0: michael@0: // Upgrading the app should force a cache flush due to potentially showing michael@0: // the compatibility UI michael@0: restartManager("2"); michael@0: do_check_true(gCachePurged); michael@0: gCachePurged = false; michael@0: michael@0: do_test_finished(); michael@0: }); michael@0: }