Bug 1068336 - Part 2: Add a slug and headers to avoid caching test JavaScript files. r=mcomella
authorNick Alexander <nalexander@mozilla.com>
Fri, 19 Sep 2014 11:17:54 -0700
changeset 206256 d75c3d4ba074a041465f4af34cf13d499e0d0c99
parent 206255 2192dc45e484b1ba551396a640393d66506b1cfa
child 206257 42f7ab962b3145cf40c9d4377654084b472bfe0e
push id27519
push userkwierso@gmail.com
push dateFri, 19 Sep 2014 23:56:39 +0000
treeherdermozilla-central@a85324dfc960 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmcomella
bugs1068336
milestone35.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1068336 - Part 2: Add a slug and headers to avoid caching test JavaScript files. r=mcomella
mobile/android/base/tests/robocop_testharness.js
--- a/mobile/android/base/tests/robocop_testharness.js
+++ b/mobile/android/base/tests/robocop_testharness.js
@@ -13,17 +13,21 @@ function _evalURI(uri, sandbox) {
   let req = SpecialPowers.Cc["@mozilla.org/xmlextras/xmlhttprequest;1"]
                          .createInstance();
 
   let baseURI = SpecialPowers.Services.io
                              .newURI(window.document.baseURI, window.document.characterSet, null);
   let theURI = SpecialPowers.Services.io
                             .newURI(uri, window.document.characterSet, baseURI);
 
-  req.open('GET', theURI.spec, false);
+  // We append a random slug to avoid caching: see
+  // https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/Using_XMLHttpRequest#Bypassing_the_cache.
+  req.open('GET', theURI.spec + ((/\?/).test(theURI.spec) ? "&slug=" : "?slug=") + (new Date()).getTime(), false);
+  req.setRequestHeader('Cache-Control', 'no-cache');
+  req.setRequestHeader('Pragma', 'no-cache');
   req.send();
 
   return SpecialPowers.Cu.evalInSandbox(req.responseText, sandbox, "1.8", uri, 1);
 }
 
 /**
  * Execute the Javascript file at `uri` in a testing sandbox populated
  * with the Javascript test harness.