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