зеркало из https://github.com/mozilla/gecko-dev.git
99 строки
3.2 KiB
HTML
99 строки
3.2 KiB
HTML
<!DOCTYPE HTML>
|
|
<html>
|
|
<!--
|
|
https://bugzilla.mozilla.org/show_bug.cgi?id=1265279
|
|
-->
|
|
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<title>Test for Bug 1265279 - Web Manifest: Implement window.oninstall</title>
|
|
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
|
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css">
|
|
<script>
|
|
"use strict";
|
|
SimpleTest.waitForExplicitFinish();
|
|
const finish = SimpleTest.finish.bind(SimpleTest);
|
|
enableOnInstallPref()
|
|
.then(createIframe)
|
|
.then(checkImplementation)
|
|
.then(checkOnInstallEventFires)
|
|
.then(checkAddEventListenerFires)
|
|
.then(finish)
|
|
.catch(err => {
|
|
ok(false, err.stack);
|
|
finish();
|
|
});
|
|
|
|
function enableOnInstallPref() {
|
|
const ops = {
|
|
"set": [
|
|
["dom.manifest.oninstall", true],
|
|
],
|
|
};
|
|
return SpecialPowers.pushPrefEnv(ops);
|
|
}
|
|
|
|
// WebIDL conditional annotations for an interface are evaluate once per
|
|
// global, so we need to create an iframe to see the effects of calling
|
|
// enableOnInstallPref().
|
|
function createIframe() {
|
|
return new Promise((resolve) => {
|
|
const iframe = document.createElement("iframe");
|
|
iframe.src = "about:blank";
|
|
iframe.onload = () => resolve(iframe.contentWindow);
|
|
document.body.appendChild(iframe);
|
|
});
|
|
}
|
|
|
|
// Check that the WebIDL is as expected.
|
|
function checkImplementation(ifrWindow) {
|
|
return new Promise((resolve, reject) => {
|
|
const hasOnInstallProp = ifrWindow.hasOwnProperty("oninstall");
|
|
ok(hasOnInstallProp, "window has own oninstall property");
|
|
|
|
// no point in continuing
|
|
if (!hasOnInstallProp) {
|
|
const err = new Error("No 'oninstall' IDL attribute. Aborting early.");
|
|
return reject(err);
|
|
}
|
|
is(ifrWindow.oninstall, null, "window install is initially set to null");
|
|
|
|
// Check that enumerable, configurable, and has a getter and setter.
|
|
const objDescriptor = Object.getOwnPropertyDescriptor(ifrWindow, "oninstall");
|
|
ok(objDescriptor.enumerable, "is enumerable");
|
|
ok(objDescriptor.configurable, "is configurable");
|
|
ok(objDescriptor.hasOwnProperty("get"), "has getter");
|
|
ok(objDescriptor.hasOwnProperty("set"), "has setter");
|
|
resolve(ifrWindow);
|
|
});
|
|
}
|
|
|
|
// Checks that .oninstall receives an event.
|
|
function checkOnInstallEventFires(ifrWindow) {
|
|
const customEv = new CustomEvent("install");
|
|
return new Promise((resolve) => {
|
|
// Test is we receive the event on `oninstall`
|
|
ifrWindow.oninstall = ev => {
|
|
ifrWindow.oninstall = null;
|
|
is(ev, customEv, "The events should be the same event object");
|
|
resolve(ifrWindow);
|
|
};
|
|
ifrWindow.dispatchEvent(customEv);
|
|
});
|
|
}
|
|
|
|
// Checks that .addEventListener("install") receives an event.
|
|
function checkAddEventListenerFires(ifrWindow) {
|
|
const customEv = new CustomEvent("install");
|
|
return new Promise((resolve) => {
|
|
ifrWindow.addEventListener("install", function handler(ev) {
|
|
ifrWindow.removeEventListener("install", handler);
|
|
is(ev, customEv, "The events should be the same");
|
|
resolve(ifrWindow);
|
|
});
|
|
ifrWindow.dispatchEvent(customEv);
|
|
});
|
|
}
|
|
</script>
|
|
</head>
|