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