dom/tests/mochitest/bugs/test_bug641552.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/tests/mochitest/bugs/test_bug641552.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,100 @@
     1.4 +<!DOCTYPE HTML>
     1.5 +<html>
     1.6 +<!--
     1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=641552
     1.8 +-->
     1.9 +<head>
    1.10 +  <title>Test for Bug 641552</title>
    1.11 +  <script type="application/javascript" src="/MochiKit/packed.js"></script>
    1.12 +  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
    1.13 +  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
    1.14 +</head>
    1.15 +<body>
    1.16 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=641552">Mozilla Bug 641552</a>
    1.17 +<p id="display"></p>
    1.18 +<pre id="test">
    1.19 +<script type="application/javascript">
    1.20 +
    1.21 +/** Test for Bug 641552 **/
    1.22 +
    1.23 +SimpleTest.waitForExplicitFinish();
    1.24 +
    1.25 +var contractId = "@mozilla.org/xmlextras/xmlhttprequest;1";
    1.26 +var categoryEntries = [
    1.27 +  {category: "JavaScript-global-property", entry: "randomname", contractId: contractId},
    1.28 +  {category: "JavaScript-navigator-property", entry: "randomname1", contractId: contractId},
    1.29 +  {category: "JavaScript-navigator-property", entry: "randomname2", contractId: contractId},
    1.30 +];
    1.31 +
    1.32 +function addCategoryEntries(func) {
    1.33 +  for (var categoryEntry of categoryEntries) {
    1.34 +    SpecialPowers.addCategoryEntry(categoryEntry.category, categoryEntry.entry, categoryEntry.contractId,
    1.35 +                                   false, true);
    1.36 +  }
    1.37 +  SimpleTest.executeSoon(func);
    1.38 +}
    1.39 +
    1.40 +function removeCategoryEntries(func) {
    1.41 +  for (var categoryEntry of categoryEntries) {
    1.42 +    SpecialPowers.deleteCategoryEntry(categoryEntry.category, categoryEntry.entry, false);
    1.43 +  }
    1.44 +  SimpleTest.executeSoon(func);
    1.45 +}
    1.46 +
    1.47 +function checkNamesPresent() {
    1.48 +  ok(window.randomname, "window.randomname should return an object");
    1.49 +  is(typeof(window.navigator.randomname1), 'object', "navigator.randomname1 should return an object");
    1.50 +  is(typeof(window.navigator.randomname2), 'object', "navigator.randomname1 should return an object");
    1.51 +}
    1.52 +
    1.53 +function checkNamesAbsent() {
    1.54 +  ok(!window.randomname, "window.randomname should return undefined");
    1.55 +  is(typeof(window.navigator.randomname1), 'undefined', "navigator.randomname1 should return undefined");
    1.56 +  is(typeof(window.navigator.randomname2), 'undefined', "navigator.randomname1 should return undefined");
    1.57 +}
    1.58 +
    1.59 +// Ensure the initial state
    1.60 +checkNamesAbsent();
    1.61 +
    1.62 +addCategoryEntries(function test1() {
    1.63 +  ok(window.randomname, "window.randomname should return an object");
    1.64 +  is(typeof(window.navigator.randomname1), 'object', "navigator.randomname1 should return an object");
    1.65 +  is(typeof(window.navigator.randomname2), 'object', "navigator.randomname1 should return an object");
    1.66 +
    1.67 +  delete window.randomname;
    1.68 +  delete window.navigator.randomname1;
    1.69 +  delete window.navigator.randomname2;
    1.70 +
    1.71 +  // The delete opertor should have no effect as long as the category entry is registered.
    1.72 +  checkNamesPresent();
    1.73 +
    1.74 +  removeCategoryEntries(test2);
    1.75 +});
    1.76 +
    1.77 +function test2() {
    1.78 +  // The object should be cached on the global/navigator object once accessed.
    1.79 +  checkNamesPresent();
    1.80 +
    1.81 +  delete window.randomname;
    1.82 +  delete window.navigator.randomname1;
    1.83 +  delete window.navigator.randomname2;
    1.84 +
    1.85 +  // Now the delete opertor should have the effect.
    1.86 +  checkNamesAbsent();
    1.87 +
    1.88 +  addCategoryEntries(function() {
    1.89 +    removeCategoryEntries(test3);
    1.90 +  });
    1.91 +}
    1.92 +
    1.93 +function test3() {
    1.94 +  // The object should not be cached until the first access.
    1.95 +  checkNamesAbsent();
    1.96 +
    1.97 +  SimpleTest.finish();
    1.98 +}
    1.99 +
   1.100 +</script>
   1.101 +</pre>
   1.102 +</body>
   1.103 +</html>

mercurial