1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/mozapps/extensions/test/xpcshell/test_bug594058.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,103 @@ 1.4 +/* Any copyright is dedicated to the Public Domain. 1.5 + * http://creativecommons.org/publicdomain/zero/1.0/ 1.6 + */ 1.7 + 1.8 +// This tests is modifying a file in an unpacked extension 1.9 +// causes cache invalidation. 1.10 + 1.11 +// Disables security checking our updates which haven't been signed 1.12 +Services.prefs.setBoolPref("extensions.checkUpdateSecurity", false); 1.13 +// Allow the mismatch UI to show 1.14 +Services.prefs.setBoolPref("extensions.showMismatchUI", true); 1.15 + 1.16 +const Ci = Components.interfaces; 1.17 +const extDir = gProfD.clone(); 1.18 +extDir.append("extensions"); 1.19 + 1.20 +var gCachePurged = false; 1.21 + 1.22 +// Override the window watcher 1.23 +var WindowWatcher = { 1.24 + openWindow: function(parent, url, name, features, arguments) { 1.25 + do_check_false(gCachePurged); 1.26 + }, 1.27 + 1.28 + QueryInterface: function(iid) { 1.29 + if (iid.equals(Ci.nsIWindowWatcher) 1.30 + || iid.equals(Ci.nsISupports)) 1.31 + return this; 1.32 + 1.33 + throw Components.results.NS_ERROR_NO_INTERFACE; 1.34 + } 1.35 +} 1.36 + 1.37 +var WindowWatcherFactory = { 1.38 + createInstance: function createInstance(outer, iid) { 1.39 + if (outer != null) 1.40 + throw Components.results.NS_ERROR_NO_AGGREGATION; 1.41 + return WindowWatcher.QueryInterface(iid); 1.42 + } 1.43 +}; 1.44 + 1.45 +var registrar = Components.manager.QueryInterface(AM_Ci.nsIComponentRegistrar); 1.46 +registrar.registerFactory(Components.ID("{1dfeb90a-2193-45d5-9cb8-864928b2af55}"), 1.47 + "Fake Window Watcher", 1.48 + "@mozilla.org/embedcomp/window-watcher;1", WindowWatcherFactory); 1.49 + 1.50 +/** 1.51 + * Start the test by installing extensions. 1.52 + */ 1.53 +function run_test() { 1.54 + do_test_pending(); 1.55 + gCachePurged = false; 1.56 + 1.57 + let obs = AM_Cc["@mozilla.org/observer-service;1"]. 1.58 + getService(AM_Ci.nsIObserverService); 1.59 + obs.addObserver({ 1.60 + observe: function(aSubject, aTopic, aData) { 1.61 + gCachePurged = true; 1.62 + } 1.63 + }, "startupcache-invalidate", false); 1.64 + createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1"); 1.65 + 1.66 + startupManager(); 1.67 + // nsAppRunner takes care of clearing this when a new app is installed 1.68 + do_check_false(gCachePurged); 1.69 + 1.70 + installAllFiles([do_get_addon("test_bug594058")], function() { 1.71 + restartManager(); 1.72 + do_check_true(gCachePurged); 1.73 + gCachePurged = false; 1.74 + 1.75 + // Now, make it look like we've updated the file. First, start the EM 1.76 + // so it records the bogus old time, then update the file and restart. 1.77 + let extFile = extDir.clone(); 1.78 + let pastTime = extFile.lastModifiedTime - 5000; 1.79 + extFile.append("bug594058@tests.mozilla.org"); 1.80 + setExtensionModifiedTime(extFile, pastTime); 1.81 + let otherFile = extFile.clone(); 1.82 + otherFile.append("directory"); 1.83 + otherFile.lastModifiedTime = pastTime; 1.84 + otherFile.append("file1"); 1.85 + otherFile.lastModifiedTime = pastTime; 1.86 + 1.87 + restartManager(); 1.88 + gCachePurged = false; 1.89 + 1.90 + otherFile.lastModifiedTime = pastTime + 5000; 1.91 + restartManager(); 1.92 + do_check_true(gCachePurged); 1.93 + gCachePurged = false; 1.94 + 1.95 + restartManager(); 1.96 + do_check_false(gCachePurged); 1.97 + 1.98 + // Upgrading the app should force a cache flush due to potentially showing 1.99 + // the compatibility UI 1.100 + restartManager("2"); 1.101 + do_check_true(gCachePurged); 1.102 + gCachePurged = false; 1.103 + 1.104 + do_test_finished(); 1.105 + }); 1.106 +}