зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1178233 - [non-e10s] The update process doesn't work within about:serviceworkers in non-e10s mode. Test. r=baku
This commit is contained in:
Родитель
4351767879
Коммит
0f6d49432e
|
@ -0,0 +1,17 @@
|
|||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<head>
|
||||
<title>Test app for bug 1178233</title>
|
||||
<script type='application/javascript;version=1.7'>
|
||||
|
||||
function onLoad() {
|
||||
navigator.serviceWorker.ready.then(function(swr) {
|
||||
parent.postMessage({status: "callback", data: "ready"}, '*');
|
||||
});
|
||||
}
|
||||
|
||||
</script>
|
||||
</head>
|
||||
<body onload='onLoad()'>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,77 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Test app for bug 1178233</title>
|
||||
<script type='application/javascript;version=1.7'>
|
||||
|
||||
function ok(aCondition, aMessage) {
|
||||
if (aCondition) {
|
||||
alert('OK: ' + aMessage);
|
||||
} else {
|
||||
alert('KO: ' + aMessage);
|
||||
}
|
||||
}
|
||||
|
||||
function done() {
|
||||
alert('DONE');
|
||||
}
|
||||
|
||||
function testFrame(src) {
|
||||
return new Promise(function(resolve, reject) {
|
||||
var iframe = document.createElement("iframe");
|
||||
iframe.src = src;
|
||||
window.onmessage = function(e) {
|
||||
if (e.data.status == "callback") {
|
||||
window.onmessage = null;
|
||||
var result = e.data.data;
|
||||
iframe.src = "about:blank";
|
||||
document.body.removeChild(iframe);
|
||||
iframe = null;
|
||||
resolve(result);
|
||||
}
|
||||
};
|
||||
document.body.appendChild(iframe);
|
||||
});
|
||||
}
|
||||
|
||||
function registerServiceWorker() {
|
||||
return navigator.serviceWorker.register('sw.sjs', {scope: '.'});
|
||||
}
|
||||
|
||||
function runTests() {
|
||||
var lastSeenVersion;
|
||||
return Promise.resolve()
|
||||
.then(function() {
|
||||
// Check whether the service worker is already registered and save its
|
||||
// version.
|
||||
return navigator.serviceWorker.getRegistration(".").then(function(swr) {
|
||||
if (!swr) {
|
||||
lastSeenVersion = 0;
|
||||
return registerServiceWorker();
|
||||
}
|
||||
return testFrame('version.html').then(function(body) {
|
||||
lastSeenVersion = parseInt(body);
|
||||
return Promise.resolve();
|
||||
});
|
||||
});
|
||||
})
|
||||
.then(function() {
|
||||
// Wait until the service worker start controlling the client.
|
||||
return testFrame('client.html');
|
||||
})
|
||||
.then(function() {
|
||||
// Fetch current version. It should be greater than the last seen version.
|
||||
return testFrame('version.html').then(function(body) {
|
||||
var currentVersion = parseInt(body);
|
||||
ok(lastSeenVersion < currentVersion, "New service worker version seen");
|
||||
return Promise.resolve();
|
||||
});
|
||||
})
|
||||
.then(done);
|
||||
}
|
||||
|
||||
</script>
|
||||
</head>
|
||||
<body onload='runTests()'>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"name": "App",
|
||||
"launch_path": "/index.html",
|
||||
"description": "Test app for bug 1178233"
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
Content-Type: application/manifest+json
|
|
@ -0,0 +1,22 @@
|
|||
function handleRequest(request, response) {
|
||||
var stateName = request.scheme + 'counter';
|
||||
if (!getState(stateName)) {
|
||||
setState(stateName, '1');
|
||||
} else {
|
||||
// Make sure that we pass a string value to setState!
|
||||
setState(stateName, "" + (parseInt(getState(stateName)) + 1));
|
||||
}
|
||||
response.setHeader("Content-Type", "application/javascript", false);
|
||||
response.write(getScript(stateName));
|
||||
}
|
||||
|
||||
function getScript(stateName) {
|
||||
return "oninstall = function(evt) {" +
|
||||
"evt.waitUntil(self.skipWaiting());" +
|
||||
"}; " +
|
||||
"onfetch = function(evt) {" +
|
||||
"if (evt.request.url.indexOf('get-sw-version') > -1) {" +
|
||||
"evt.respondWith(new Response('" + getState(stateName) + "'));" +
|
||||
"}" +
|
||||
"};";
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<head>
|
||||
<title>Test app for bug 1178233</title>
|
||||
<script type='application/javascript;version=1.7'>
|
||||
|
||||
function onLoad() {
|
||||
fetch("get-sw-version").then(function(r) {
|
||||
return r.text();
|
||||
}).then(function(body) {
|
||||
parent.postMessage({status: "callback", data: body}, "*");
|
||||
});
|
||||
}
|
||||
|
||||
</script>
|
||||
</head>
|
||||
<body onload='onLoad()'>
|
||||
</body>
|
||||
</html>
|
|
@ -2,6 +2,8 @@
|
|||
skip-if = buildapp == 'b2g'
|
||||
support-files =
|
||||
app/*
|
||||
app2/*
|
||||
|
||||
[test_app_installation.html]
|
||||
[test_privateBrowsing.html]
|
||||
[test_aboutserviceworkers.html]
|
||||
|
|
|
@ -0,0 +1,161 @@
|
|||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<!--
|
||||
https://bugzilla.mozilla.org/show_bug.cgi?id=1178233
|
||||
-->
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Test for Bug 1178233</title>
|
||||
<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"/>
|
||||
<script type="application/javascript;version=1.7">
|
||||
|
||||
const { classes: Cc, interfaces: Ci, utils: Cu } = Components;
|
||||
|
||||
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||
XPCOMUtils.defineLazyServiceGetter(this, "gServiceWorkerManager",
|
||||
"@mozilla.org/serviceworkers/manager;1",
|
||||
"nsIServiceWorkerManager");
|
||||
|
||||
XPCOMUtils.defineLazyServiceGetter(this, "gAppsService",
|
||||
"@mozilla.org/AppsService;1",
|
||||
"nsIAppsService");
|
||||
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
|
||||
const gOrigin = 'http://test/chrome/dom/workers/test/serviceworkers/app2';
|
||||
const appManifestURL = gOrigin + '/manifest.webapp';
|
||||
let gApp;
|
||||
|
||||
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 update() {
|
||||
return new Promise((resolve, reject) => {
|
||||
let registrations = [];
|
||||
registrations = gServiceWorkerManager.getAllRegistrations();
|
||||
|
||||
ok(registrations.length === 1, "The registration shows up in about:serviceworker page");
|
||||
|
||||
for (let i = 0; i < registrations.length; i++) {
|
||||
let registration = registrations.queryElementAt(i, Ci.nsIServiceWorkerInfo);
|
||||
if (!registration) {
|
||||
reject();
|
||||
return;
|
||||
}
|
||||
gServiceWorkerManager.propagateSoftUpdate(
|
||||
registration.principal.originAttributes,
|
||||
registration.scope
|
||||
);
|
||||
}
|
||||
resolve();
|
||||
});
|
||||
}
|
||||
|
||||
function testApp() {
|
||||
if (!gApp) {
|
||||
ok(false, 'No test application to launch');
|
||||
return Promise.reject();
|
||||
}
|
||||
return new Promise((resolve, reject) => {
|
||||
let iframe = document.createElement('iframe');
|
||||
let domParent = document.getElementById('container');
|
||||
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, "Message from app: " + message);
|
||||
iframe.src = "about:blank";
|
||||
domParent.removeChild(iframe);
|
||||
iframe = null;
|
||||
resolve();
|
||||
}
|
||||
}, false);
|
||||
domParent.appendChild(iframe);
|
||||
ok(true, "origin " + gOrigin + gApp.manifest.launch_path);
|
||||
SpecialPowers.wrap(iframe.contentWindow).location =
|
||||
gOrigin + gApp.manifest.launch_path;
|
||||
});
|
||||
}
|
||||
|
||||
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 setup() {
|
||||
info('Setting up');
|
||||
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]
|
||||
]}, () => {
|
||||
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 go() {
|
||||
setup()
|
||||
.then(installApp)
|
||||
.then(testApp)
|
||||
.then(update)
|
||||
.then(testApp)
|
||||
.then(uninstallApp)
|
||||
.then(SimpleTest.finish)
|
||||
.catch(function(e) {
|
||||
ok(false, 'Unexpected error ' + e);
|
||||
SimpleTest.finish();
|
||||
});
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
<body onload="go()">
|
||||
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1171917">Mozilla Bug 1178233</a>
|
||||
<p id="display"></p>
|
||||
<div id="content" style="display: none">
|
||||
</div>
|
||||
<pre id="test">
|
||||
</pre>
|
||||
<div id="container"></div>
|
||||
</body>
|
||||
</html>
|
Загрузка…
Ссылка в новой задаче