Bug 1172562 - Clear QuotaManager storage when uninstalling an app. Test. r=bkelly

This commit is contained in:
Fernando Jimenez 2015-07-02 11:17:01 +02:00
parent 7509cdc68b
commit f1d1db8162
9 changed files with 306 additions and 0 deletions

View File

@ -0,0 +1,29 @@
<!DOCTYPE html>
<html>
<head>
<title>Test app for bug 1172562</title>
<script src='test.js'></script>
<script type='application/javascript;version=1.7'>
function runTests() {
return Promise.resolve()
.then(() => { return navigator.serviceWorker.ready })
.then((registration) => {
return new Promise((resolve) => {
var worker = registration.waiting || registration.active;
worker.postMessage('read');
navigator.serviceWorker.onmessage = (message) => {
if (message.data.type == 'done') {
ok(!message.data.cached, 'No cached data');
resolve();
}
};
});
})
.then(done);
}
</script>
</head>
<body onload='runTests()'>
</body>
</html>

View File

@ -0,0 +1,31 @@
<!DOCTYPE html>
<html>
<head>
<title>Test app for bug 1172562</title>
<script src='test.js'></script>
<script type='application/javascript;version=1.7'>
function runTests() {
return Promise.resolve()
.then(() => { return navigator.serviceWorker.ready })
.then((registration) => {
return new Promise((resolve) => {
var worker = registration.waiting || registration.active;
worker.postMessage('write');
navigator.serviceWorker.onmessage = (message) => {
if (message.data.type == 'written') {
worker.postMessage('read');
} else if (message.data.type == 'done') {
ok(message.data.cached, 'Write success');
resolve();
}
};
});
})
.then(done);
}
</script>
</head>
<body onload='runTests()'>
</body>
</html>

41
dom/cache/test/mochitest/app/index.html vendored Normal file
View File

@ -0,0 +1,41 @@
<!DOCTYPE html>
<html>
<head>
<title>Test app for bug 1172562</title>
<script type='application/javascript;version=1.7'>
function ok(aCondition, aMessage) {
if (aCondition) {
alert('OK: ' + aMessage);
} else {
alert('KO: ' + aMessage);
}
}
function ready() {
alert('READY');
}
function registerServiceWorker() {
return new Promise((resolve, reject) => {
navigator.serviceWorker.ready.then(() => {
ready();
resolve();
});
navigator.serviceWorker.register('sw.js', {scope: '.'})
.then(registration => {
ok(true, 'service worker registered');
})
.catch(reject);
});
}
function runTests() {
return Promise.resolve()
.then(registerServiceWorker)
.then(ready)
}
</script>
</head>
<body onload='runTests()'>
</body>
</html>

View File

@ -0,0 +1,5 @@
{
"name": "App",
"launch_path": "/index.html",
"description": "Test app for bug 1172562"
}

View File

@ -0,0 +1 @@
Content-Type: application/manifest+json

18
dom/cache/test/mochitest/app/sw.js vendored Normal file
View File

@ -0,0 +1,18 @@
self.addEventListener('message', (message) => {
caches.open('acache').then((cache) => {
if(message.data == 'write') {
cache.add('aurl').then(() => {
message.source.postMessage({
type: 'written'
});
});
} else if (message.data == 'read') {
cache.match('aurl').then((result) => {
message.source.postMessage({
type: 'done',
cached: !!result
});
});
}
});
});

15
dom/cache/test/mochitest/app/test.js vendored Normal file
View File

@ -0,0 +1,15 @@
function ok(aCondition, aMessage) {
if (aCondition) {
alert('OK: ' + aMessage);
} else {
alert('KO: ' + aMessage);
}
}
function ready() {
alert('READY');
}
function done() {
alert('DONE');
}

View File

@ -23,6 +23,7 @@ support-files =
test_cache_https.js
large_url_list.js
empty.html
app/*
[test_cache.html]
[test_cache_add.html]
@ -40,6 +41,8 @@ support-files =
skip-if = buildapp == 'b2g' # bug 1162353
[test_cache_restart.html]
[test_cache_shrink.html]
[test_cache_clear_on_app_uninstall.html]
skip-if = e10s || buildapp == 'b2g' # bug 1178685
[test_cache_orphaned_cache.html]
[test_cache_orphaned_body.html]
[test_cache_untrusted.html]

View File

@ -0,0 +1,163 @@
<!--
Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/
-->
<!DOCTYPE HTML>
<html>
<head>
<title>Bug 1172562 - Clear QuotaManager storage when uninstalling an app</title>
<script type='text/javascript' src='/tests/SimpleTest/SimpleTest.js'></script>
<link rel='stylesheet' type='text/css' href='/tests/SimpleTest/test.css' />
</head>
<body onload='runTests()'>
<p id='display'></p>
<div id='content' style='display: none'></div>
<pre id='test'></pre>
<script class='testbody' type='application/javascript;version=1.7'>
SimpleTest.waitForExplicitFinish();
const gOrigin = 'http://mochi.test:8888/tests/dom/cache/test/mochitest/app';
const appManifestURL = gOrigin + '/manifest.webapp';
let gApp;
function setup() {
return new Promise((resolve, reject) => {
SpecialPowers.setAllAppsLaunchable(true);
SpecialPowers.pushPrefEnv({'set': [
['dom.mozBrowserFramesEnabled', true],
['dom.serviceWorkers.exemptFromPerDomainMax', true],
['dom.serviceWorkers.enabled', true],
['dom.serviceWorkers.testing.enabled', true],
['dom.caches.enabled', true],
]}, () => {
SpecialPowers.pushPermissions([
{ 'type': 'webapps-manage', 'allow': 1, 'context': document },
{ 'type': 'browser', 'allow': 1, 'context': document },
{ 'type': 'embed-apps', 'allow': 1, 'context': document }
], () => {
SpecialPowers.autoConfirmAppInstall(() => {
SpecialPowers.autoConfirmAppUninstall(resolve);
});
});
});
});
}
function installApp() {
return new Promise((resolve, reject) => {
let req = navigator.mozApps.install(appManifestURL);
req.onsuccess = function() {
gApp = req.result;
is(req.result.manifestURL, appManifestURL, 'app installed');
if (req.result.installState == 'installed') {
is(req.result.installState, 'installed', 'app downloaded');
resolve()
} else {
req.result.ondownloadapplied = function() {
is(req.result.installState, 'installed', 'app downloaded');
resolve();
}
}
}
req.onerror = reject;
});
}
function launchApp() {
if (!gApp) {
ok(false, 'No test application to launch');
return Promise.reject();
}
return new Promise((resolve, reject) => {
let iframe = document.createElement('iframe');
iframe.setAttribute('mozbrowser', 'true');
iframe.setAttribute('mozapp', gApp.manifestURL);
iframe.addEventListener('mozbrowsershowmodalprompt', function listener(e) {
let message = e.detail.message;
if (/OK/.exec(message)) {
ok(true, "Message from app: " + message);
} else if (/KO/.exec(message)) {
ok(false, "Message from app: " + message);
} else if (/READY/.exec(message)) {
ok(true, "Message from app: " + message);
resolve();
} else {
ok(false, "Unexpected message received: " + message);
}
}, false);
let domParent = document.getElementById('container');
domParent.appendChild(iframe);
SpecialPowers.wrap(iframe.contentWindow).location =
gOrigin + gApp.manifest.launch_path;
});
}
function loadControlled(aUrl) {
return new Promise((resolve, reject) => {
let iframe = document.createElement('iframe');
iframe.setAttribute('mozbrowser', 'true');
iframe.setAttribute('mozapp', gApp.manifestURL);
iframe.addEventListener('mozbrowsershowmodalprompt', function listener(e) {
let message = e.detail.message;
if (/OK/.exec(message)) {
ok(true, "Message from app: " + message);
} else if (/KO/.exec(message)) {
ok(false, "Message from app: " + message);
} else if (/DONE/.exec(message)) {
ok(true, "Messaging from app complete");
iframe.removeEventListener('mozbrowsershowmodalprompt', listener);
let domParent = document.getElementById('container');
domParent.removeChild(iframe);
resolve();
} else {
ok(false, "Unexpected message received: " + message);
}
}, false);
let domParent = document.getElementById('container');
domParent.appendChild(iframe);
SpecialPowers.wrap(iframe.contentWindow).location =
gOrigin + aUrl;
});
}
function loadBeforeClear() {
return loadControlled('/before_clear.html');
}
function loadAfterClear() {
return loadControlled('/after_clear.html');
}
function uninstallApp() {
return new Promise((resolve, reject) => {
if (!gApp) {
return reject();
}
let req = navigator.mozApps.mgmt.uninstall(gApp);
req.onsuccess = resolve;
req.onerror = reject;
});
}
function runTests() {
setup()
.then(installApp)
.then(launchApp)
.then(loadBeforeClear)
.then(uninstallApp)
.then(installApp)
.then(launchApp)
.then(loadAfterClear)
.then(uninstallApp)
.then(SimpleTest.finish)
.catch((e) => {
ok(false, 'Unexpected error ' + e.target.error.name);
SimpleTest.finish();
});
}
</script>
<div id='container'></div>
</body>
</html>