tenfourfox/dom/tests/mochitest/bugs/test_bug641552.html
Cameron Kaiser c9b2922b70 hello FPR
2017-04-19 00:56:45 -07:00

101 lines
3.2 KiB
HTML

<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=641552
-->
<head>
<title>Test for Bug 641552</title>
<script type="application/javascript" src="/MochiKit/packed.js"></script>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=641552">Mozilla Bug 641552</a>
<p id="display"></p>
<pre id="test">
<script type="application/javascript">
/** Test for Bug 641552 **/
SimpleTest.waitForExplicitFinish();
var contractId = "@mozilla.org/xmlextras/xmlhttprequest;1";
var categoryEntries = [
{category: "JavaScript-global-property", entry: "randomname", contractId: contractId},
{category: "JavaScript-navigator-property", entry: "randomname1", contractId: contractId},
{category: "JavaScript-navigator-property", entry: "randomname2", contractId: contractId},
];
function addCategoryEntries(func) {
for (var categoryEntry of categoryEntries) {
SpecialPowers.addCategoryEntry(categoryEntry.category, categoryEntry.entry, categoryEntry.contractId,
false, true);
}
SimpleTest.executeSoon(func);
}
function removeCategoryEntries(func) {
for (var categoryEntry of categoryEntries) {
SpecialPowers.deleteCategoryEntry(categoryEntry.category, categoryEntry.entry, false);
}
SimpleTest.executeSoon(func);
}
function checkNamesPresent() {
ok(window.randomname, "window.randomname should return an object");
is(typeof(window.navigator.randomname1), 'object', "navigator.randomname1 should return an object");
is(typeof(window.navigator.randomname2), 'object', "navigator.randomname1 should return an object");
}
function checkNamesAbsent() {
ok(!window.randomname, "window.randomname should return undefined");
is(typeof(window.navigator.randomname1), 'undefined', "navigator.randomname1 should return undefined");
is(typeof(window.navigator.randomname2), 'undefined', "navigator.randomname1 should return undefined");
}
// Ensure the initial state
checkNamesAbsent();
addCategoryEntries(function test1() {
ok(window.randomname, "window.randomname should return an object");
is(typeof(window.navigator.randomname1), 'object', "navigator.randomname1 should return an object");
is(typeof(window.navigator.randomname2), 'object', "navigator.randomname1 should return an object");
delete window.randomname;
delete window.navigator.randomname1;
delete window.navigator.randomname2;
// The delete opertor should have no effect as long as the category entry is registered.
checkNamesPresent();
removeCategoryEntries(test2);
});
function test2() {
// The object should be cached on the global/navigator object once accessed.
checkNamesPresent();
delete window.randomname;
delete window.navigator.randomname1;
delete window.navigator.randomname2;
// Now the delete opertor should have the effect.
checkNamesAbsent();
addCategoryEntries(function() {
removeCategoryEntries(test3);
});
}
function test3() {
// The object should not be cached until the first access.
checkNamesAbsent();
SimpleTest.finish();
}
</script>
</pre>
</body>
</html>