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

This commit is contained in:
Ehsan Akhgari 2015-06-09 10:20:01 -04:00
parent fe6d5a35cb
commit 1d3ef5533c
4 changed files with 33 additions and 2 deletions

2
dom/cache/test/mochitest/empty.html vendored Normal file
View File

@ -0,0 +1,2 @@
<!DOCTYPE html>
<!-- This is only used to give us access to the caches global after setting the pref. -->

View File

@ -22,6 +22,7 @@ support-files =
test_cache_put_reorder.js
test_cache_https.js
large_url_list.js
empty.html
[test_cache.html]
[test_cache_add.html]

View File

@ -9,6 +9,18 @@
</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;
@ -32,7 +44,9 @@ SpecialPowers.pushPrefEnv({
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() {

View File

@ -10,6 +10,18 @@
</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;
@ -73,7 +85,9 @@ SpecialPowers.pushPrefEnv({
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');