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

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 /* Any copyright is dedicated to the Public Domain.
     2  * http://creativecommons.org/publicdomain/zero/1.0/
     3  */
     5 // This tests is modifying a file in an unpacked extension
     6 // causes cache invalidation.
     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);
    13 const Ci = Components.interfaces;
    14 const extDir = gProfD.clone();
    15 extDir.append("extensions");
    17 var gCachePurged = false;
    19 // Override the window watcher
    20 var WindowWatcher = {
    21   openWindow: function(parent, url, name, features, arguments) {
    22     do_check_false(gCachePurged);
    23   },
    25   QueryInterface: function(iid) {
    26     if (iid.equals(Ci.nsIWindowWatcher)
    27      || iid.equals(Ci.nsISupports))
    28       return this;
    30     throw Components.results.NS_ERROR_NO_INTERFACE;
    31   }
    32 }
    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 };
    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);
    47 /**
    48  * Start the test by installing extensions.
    49  */
    50 function run_test() {
    51   do_test_pending();
    52   gCachePurged = false;
    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");
    63   startupManager();
    64   // nsAppRunner takes care of clearing this when a new app is installed
    65   do_check_false(gCachePurged);
    67   installAllFiles([do_get_addon("test_bug594058")], function() {
    68     restartManager();
    69     do_check_true(gCachePurged);
    70     gCachePurged = false;
    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;
    84     restartManager();
    85     gCachePurged = false;
    87     otherFile.lastModifiedTime = pastTime + 5000;
    88     restartManager();
    89     do_check_true(gCachePurged);
    90     gCachePurged = false;
    92     restartManager();
    93     do_check_false(gCachePurged);
    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;
   101     do_test_finished();
   102   });  
   103 }

mercurial