dom/tests/mochitest/bugs/test_bug641552.html

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 <!DOCTYPE HTML>
     2 <html>
     3 <!--
     4 https://bugzilla.mozilla.org/show_bug.cgi?id=641552
     5 -->
     6 <head>
     7   <title>Test for Bug 641552</title>
     8   <script type="application/javascript" src="/MochiKit/packed.js"></script>
     9   <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
    10   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
    11 </head>
    12 <body>
    13 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=641552">Mozilla Bug 641552</a>
    14 <p id="display"></p>
    15 <pre id="test">
    16 <script type="application/javascript">
    18 /** Test for Bug 641552 **/
    20 SimpleTest.waitForExplicitFinish();
    22 var contractId = "@mozilla.org/xmlextras/xmlhttprequest;1";
    23 var categoryEntries = [
    24   {category: "JavaScript-global-property", entry: "randomname", contractId: contractId},
    25   {category: "JavaScript-navigator-property", entry: "randomname1", contractId: contractId},
    26   {category: "JavaScript-navigator-property", entry: "randomname2", contractId: contractId},
    27 ];
    29 function addCategoryEntries(func) {
    30   for (var categoryEntry of categoryEntries) {
    31     SpecialPowers.addCategoryEntry(categoryEntry.category, categoryEntry.entry, categoryEntry.contractId,
    32                                    false, true);
    33   }
    34   SimpleTest.executeSoon(func);
    35 }
    37 function removeCategoryEntries(func) {
    38   for (var categoryEntry of categoryEntries) {
    39     SpecialPowers.deleteCategoryEntry(categoryEntry.category, categoryEntry.entry, false);
    40   }
    41   SimpleTest.executeSoon(func);
    42 }
    44 function checkNamesPresent() {
    45   ok(window.randomname, "window.randomname should return an object");
    46   is(typeof(window.navigator.randomname1), 'object', "navigator.randomname1 should return an object");
    47   is(typeof(window.navigator.randomname2), 'object', "navigator.randomname1 should return an object");
    48 }
    50 function checkNamesAbsent() {
    51   ok(!window.randomname, "window.randomname should return undefined");
    52   is(typeof(window.navigator.randomname1), 'undefined', "navigator.randomname1 should return undefined");
    53   is(typeof(window.navigator.randomname2), 'undefined', "navigator.randomname1 should return undefined");
    54 }
    56 // Ensure the initial state
    57 checkNamesAbsent();
    59 addCategoryEntries(function test1() {
    60   ok(window.randomname, "window.randomname should return an object");
    61   is(typeof(window.navigator.randomname1), 'object', "navigator.randomname1 should return an object");
    62   is(typeof(window.navigator.randomname2), 'object', "navigator.randomname1 should return an object");
    64   delete window.randomname;
    65   delete window.navigator.randomname1;
    66   delete window.navigator.randomname2;
    68   // The delete opertor should have no effect as long as the category entry is registered.
    69   checkNamesPresent();
    71   removeCategoryEntries(test2);
    72 });
    74 function test2() {
    75   // The object should be cached on the global/navigator object once accessed.
    76   checkNamesPresent();
    78   delete window.randomname;
    79   delete window.navigator.randomname1;
    80   delete window.navigator.randomname2;
    82   // Now the delete opertor should have the effect.
    83   checkNamesAbsent();
    85   addCategoryEntries(function() {
    86     removeCategoryEntries(test3);
    87   });
    88 }
    90 function test3() {
    91   // The object should not be cached until the first access.
    92   checkNamesAbsent();
    94   SimpleTest.finish();
    95 }
    97 </script>
    98 </pre>
    99 </body>
   100 </html>

mercurial