Bug 1005696 - Make sure test blocklist.xml isn't overwritten before use. r=Unfocused, a=test-only
authorBill McCloskey <wmccloskey@mozilla.com>
Fri, 20 Jun 2014 17:46:02 -0700
changeset 207338 de320a360e704d991d8194bdc04a365ad455644a
parent 207337 fbdfb0c35e8ecdae2b65ed197d1262ff289c226c
child 207339 444dc23190f4d0bfdcdf69378531dcb1abb22569
push id3741
push userasasaki@mozilla.com
push dateMon, 21 Jul 2014 20:25:18 +0000
treeherdermozilla-beta@4d6f46f5af68 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersUnfocused, test-only
bugs1005696
milestone32.0a2
Bug 1005696 - Make sure test blocklist.xml isn't overwritten before use. r=Unfocused, a=test-only
browser/modules/test/unit/social/head.js
toolkit/components/social/test/xpcshell/head.js
toolkit/mozapps/extensions/test/xpcshell/head_addons.js
toolkit/mozapps/extensions/test/xpcshell/test_bug455906.js
toolkit/mozapps/extensions/test/xpcshell/test_bug468528.js
toolkit/mozapps/extensions/test/xpcshell/test_bug514327_1.js
toolkit/mozapps/extensions/test/xpcshell/test_bug514327_2.js
toolkit/mozapps/extensions/test/xpcshell/test_bug514327_3.js
--- a/browser/modules/test/unit/social/head.js
+++ b/browser/modules/test/unit/social/head.js
@@ -80,16 +80,17 @@ function initApp() {
   createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9");
   // prepare a blocklist file for the blocklist service
   var blocklistFile = gProfD.clone();
   blocklistFile.append("blocklist.xml");
   if (blocklistFile.exists())
     blocklistFile.remove(false);
   var source = do_get_file("blocklist.xml");
   source.copyTo(gProfD, "blocklist.xml");
+  blocklistFile.lastModifiedTime = Date.now();
 
 
   let internalManager = Cc["@mozilla.org/addons/integration;1"].
                      getService(Ci.nsIObserver).
                      QueryInterface(Ci.nsITimerCallback);
 
   internalManager.observe(null, "addons-startup", null);
 }
--- a/toolkit/components/social/test/xpcshell/head.js
+++ b/toolkit/components/social/test/xpcshell/head.js
@@ -66,16 +66,17 @@ function initApp() {
   createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9");
   // prepare a blocklist file for the blocklist service
   var blocklistFile = gProfD.clone();
   blocklistFile.append("blocklist.xml");
   if (blocklistFile.exists())
     blocklistFile.remove(false);
   var source = do_get_file("blocklist.xml");
   source.copyTo(gProfD, "blocklist.xml");
+  blocklistFile.lastModifiedTime = Date.now();
 }
 
 function AsyncRunner() {
   do_test_pending();
   do_register_cleanup((function () this.destroy()).bind(this));
 
   this._callbacks = {
     done: do_test_finished,
--- a/toolkit/mozapps/extensions/test/xpcshell/head_addons.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/head_addons.js
@@ -1333,16 +1333,26 @@ stream.init(blockFile, FileUtils.MODE_WR
             FileUtils.PERMS_FILE, 0);
 
 var data = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
            "<blocklist xmlns=\"http://www.mozilla.org/2006/addons-blocklist\">\n" +
            "</blocklist>\n";
 stream.write(data, data.length);
 stream.close();
 
+// Copies blocklistFile (an nsIFile) to gProfD/blocklist.xml.
+function copyBlocklistToProfile(blocklistFile) {
+  var dest = gProfD.clone();
+  dest.append("blocklist.xml");
+  if (dest.exists())
+    dest.remove(false);
+  blocklistFile.copyTo(gProfD, "blocklist.xml");
+  dest.lastModifiedTime = Date.now();
+}
+
 // Throw a failure and attempt to abandon the test if it looks like it is going
 // to timeout
 function timeout() {
   timer = null;
   do_throw("Test ran longer than " + TIMEOUT_MS + "ms");
 
   // Attempt to bail out of the test
   do_test_finished();
--- a/toolkit/mozapps/extensions/test/xpcshell/test_bug455906.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_bug455906.js
@@ -242,22 +242,17 @@ function run_test() {
   dump("Setting up tests\n");
   // Rather than keeping lots of identical add-ons in version control, just
   // write them into the profile.
   for (let addon of ADDONS)
     create_addon(addon);
 
   // Copy the initial blocklist into the profile to check add-ons start in the
   // right state.
-  var blocklistFile = gProfD.clone();
-  blocklistFile.append("blocklist.xml");
-  if (blocklistFile.exists())
-    blocklistFile.remove(false);
-  var blocklist = do_get_file("data/bug455906_start.xml")
-  blocklist.copyTo(gProfD, "blocklist.xml");
+  copyBlocklistToProfile(do_get_file("data/bug455906_start.xml"));
 
   createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "3", "8");
   startupManager();
 
   do_test_pending();
   check_test_pt1();
 }
 
--- a/toolkit/mozapps/extensions/test/xpcshell/test_bug468528.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_bug468528.js
@@ -33,22 +33,17 @@ var PLUGINS = [{
   blocklisted: false
 }];
 
 
 function run_test() {
   createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9");
 
   // We cannot force the blocklist to update so just copy our test list to the profile
-  var blocklistFile = gProfD.clone();
-  blocklistFile.append("blocklist.xml");
-  if (blocklistFile.exists())
-    blocklistFile.remove(false);
-  var source = do_get_file("data/test_bug468528.xml");
-  source.copyTo(gProfD, "blocklist.xml");
+  copyBlocklistToProfile(do_get_file("data/test_bug468528.xml"));
 
   var blocklist = Components.classes["@mozilla.org/extensions/blocklist;1"]
                             .getService(nsIBLS);
 
   // blocked (sanity check)
   do_check_true(blocklist.getPluginBlocklistState(PLUGINS[0], "1", "1.9") == nsIBLS.STATE_BLOCKED);
 
   // not blocked - won't match due to invalid regexp
--- a/toolkit/mozapps/extensions/test/xpcshell/test_bug514327_1.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_bug514327_1.js
@@ -36,22 +36,17 @@ var PLUGINS = [{
   blocklisted: false,
   outdated: false
 }];
 
 
 function run_test() {
   createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9");
 
-  var blocklistFile = gProfD.clone();
-  blocklistFile.append("blocklist.xml");
-  if (blocklistFile.exists())
-    blocklistFile.remove(false);
-  var source = do_get_file("data/test_bug514327_1.xml");
-  source.copyTo(gProfD, "blocklist.xml");
+  copyBlocklistToProfile(do_get_file("data/test_bug514327_1.xml"));
 
   var blocklist = Cc["@mozilla.org/extensions/blocklist;1"].getService(nsIBLS);
 
   // blocked (sanity check)
   do_check_true(blocklist.getPluginBlocklistState(PLUGINS[0], "1", "1.9") == nsIBLS.STATE_BLOCKED);
 
   // outdated
   do_check_true(blocklist.getPluginBlocklistState(PLUGINS[1], "1", "1.9") == nsIBLS.STATE_OUTDATED);
--- a/toolkit/mozapps/extensions/test/xpcshell/test_bug514327_2.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_bug514327_2.js
@@ -16,22 +16,17 @@ function get_test_plugintag() {
       return tag;
   }
   return null;
 }
 
 function run_test() {
   createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9");
 
-  var blocklistFile = gProfD.clone();
-  blocklistFile.append("blocklist.xml");
-  if (blocklistFile.exists())
-    blocklistFile.remove(false);
-  var source = do_get_file("data/test_bug514327_2.xml");
-  source.copyTo(gProfD, "blocklist.xml");
+  copyBlocklistToProfile(do_get_file("data/test_bug514327_2.xml"));
 
   var blocklist = Cc["@mozilla.org/extensions/blocklist;1"].getService(nsIBLS);
   var prefs = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch);
 
   var plugin = get_test_plugintag();
   if (!plugin)
     do_throw("Plugin tag not found");
 
--- a/toolkit/mozapps/extensions/test/xpcshell/test_bug514327_3.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_bug514327_3.js
@@ -120,22 +120,17 @@ function run_test() {
   gTestserver = new HttpServer();
   gTestserver.registerDirectory("/data/", do_get_file("data"));
   gTestserver.start(-1);
   gPort = gTestserver.identity.primaryPort;
 
   startupManager();
 
   // initialize the blocklist with no entries
-  var blocklistFile = gProfD.clone();
-  blocklistFile.append("blocklist.xml");
-  if (blocklistFile.exists())
-    blocklistFile.remove(false);
-  var source = do_get_file("data/test_bug514327_3_empty.xml");
-  source.copyTo(gProfD, "blocklist.xml");
+  copyBlocklistToProfile(do_get_file("data/test_bug514327_3_empty.xml"));
   
   gPrefs = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch);
   gBlocklist = Cc["@mozilla.org/extensions/blocklist;1"].getService(nsIBLS);
   
   // should NOT be marked as outdated by the blocklist
   do_check_true(gBlocklist.getPluginBlocklistState(PLUGINS[0], "1", "1.9") == nsIBLS.STATE_NOT_BLOCKED);
   
   do_test_pending();