Bug 1172629 - Use the caches global property from an iframe loaded after setting the pref in order to make the tests pass with the pref disabled; r=bkelly a=RyanVM
authorEhsan Akhgari <ehsan@mozilla.com>
Tue, 09 Jun 2015 10:20:01 -0400
changeset 247742 72c67850a705f986ef14b6a037f0a043196b3ad0
parent 247741 f6a0792e62591363b96683fc2d3c157096994f43
child 247743 f98f1e0f40fe35792db7f5207c65f5afe3ca9b0f
push id28881
push userkwierso@gmail.com
push dateWed, 10 Jun 2015 01:59:03 +0000
treeherdermozilla-central@d9156ad9b7a2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbkelly, RyanVM
bugs1172629
milestone41.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 1172629 - Use the caches global property from an iframe loaded after setting the pref in order to make the tests pass with the pref disabled; r=bkelly a=RyanVM
dom/cache/test/mochitest/empty.html
dom/cache/test/mochitest/mochitest.ini
dom/cache/test/mochitest/test_cache_restart.html
dom/cache/test/mochitest/test_cache_shrink.html
new file mode 100644
--- /dev/null
+++ b/dom/cache/test/mochitest/empty.html
@@ -0,0 +1,2 @@
+<!DOCTYPE html>
+<!-- This is only used to give us access to the caches global after setting the pref. -->
--- a/dom/cache/test/mochitest/mochitest.ini
+++ b/dom/cache/test/mochitest/mochitest.ini
@@ -17,16 +17,17 @@ support-files =
   test_caches.js
   test_cache_keys.js
   test_cache_put.js
   test_cache_requestCache.js
   test_cache_delete.js
   test_cache_put_reorder.js
   test_cache_https.js
   large_url_list.js
+  empty.html
 
 [test_cache.html]
 [test_cache_add.html]
 [test_cache_match_request.html]
 [test_cache_matchAll_request.html]
 [test_cache_overwrite.html]
 [test_cache_match_vary.html]
 [test_caches.html]
--- a/dom/cache/test/mochitest/test_cache_restart.html
+++ b/dom/cache/test/mochitest/test_cache_restart.html
@@ -4,16 +4,28 @@
 <html>
 <head>
   <title>Test Cache with QuotaManager Restart</title>
   <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
 </head>
 <body>
 <script class="testbody" type="text/javascript">
+function setupTestIframe() {
+  return new Promise(function(resolve) {
+    var iframe = document.createElement("iframe");
+    iframe.src = "empty.html";
+    iframe.onload = function() {
+      window.caches = iframe.contentWindow.caches;
+      resolve();
+    };
+    document.body.appendChild(iframe);
+  });
+}
+
 function resetStorage() {
   return new Promise(function(resolve, reject) {
     var principal = SpecialPowers.wrap(document).nodePrincipal;
     var appId, inBrowser;
     var nsIPrincipal = SpecialPowers.Components.interfaces.nsIPrincipal;
     if (principal.appId != nsIPrincipal.UNKNOWN_APP_ID &&
         principal.appId != nsIPrincipal.NO_APP_ID) {
       appId = principal.appId;
@@ -27,17 +39,19 @@ function resetStorage() {
 SimpleTest.waitForExplicitFinish();
 SpecialPowers.pushPrefEnv({
   "set": [["dom.caches.enabled", true],
           ["dom.quotaManager.testing", true]],
 }, function() {
   var name = 'foo';
   var url = './test_cache_add.js';
   var cache;
-  caches.open(name).then(function(c) {
+  setupTestIframe().then(function() {
+    return caches.open(name);
+  }).then(function(c) {
     cache = c;
     return cache.add(url);
   }).then(function() {
     return resetStorage();
   }).then(function() {
     return cache.match(url).then(function(resp) {
       ok(false, 'old cache reference should not work after reset');
     }).catch(function(err) {
--- a/dom/cache/test/mochitest/test_cache_shrink.html
+++ b/dom/cache/test/mochitest/test_cache_shrink.html
@@ -5,16 +5,28 @@
 <head>
   <title>Test Cache with QuotaManager Restart</title>
   <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
   <script type="text/javascript" src="large_url_list.js"></script>
   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
 </head>
 <body>
 <script class="testbody" type="text/javascript">
+function setupTestIframe() {
+  return new Promise(function(resolve) {
+    var iframe = document.createElement("iframe");
+    iframe.src = "empty.html";
+    iframe.onload = function() {
+      window.caches = iframe.contentWindow.caches;
+      resolve();
+    };
+    document.body.appendChild(iframe);
+  });
+}
+
 function clearStorage() {
   return new Promise(function(resolve, reject) {
     var principal = SpecialPowers.wrap(document).nodePrincipal;
     var appId, inBrowser;
     var nsIPrincipal = SpecialPowers.Components.interfaces.nsIPrincipal;
     if (principal.appId != nsIPrincipal.UNKNOWN_APP_ID &&
         principal.appId != nsIPrincipal.NO_APP_ID) {
       appId = principal.appId;
@@ -68,17 +80,19 @@ SpecialPowers.pushPrefEnv({
 }, function() {
   var name = 'foo';
   var cache = null;
   var initialUsage = 0;
   var fullUsage = 0;
   var endUsage = 0;
   // start from a fresh origin directory so other tests do not influence our
   // results
-  clearStorage().then(function() {
+  setupTestIframe().then(function() {
+    return clearStorage();
+  }).then(function() {
     return storageUsage();
   }).then(function(usage) {
     is(0, usage, 'disk usage should be zero to start');
     return caches.open(name);
   }).then(function(c) {
     cache = c;
     return storageUsage();
   }).then(function(usage) {