gecko/js/xpconnect/tests/chrome/test_paris_weakmap_keys.xul
Ehsan Akhgari 94b2981ab9 Bug 833631 - Unprefix mozAudioContext; r=roc
--HG--
extra : rebase_source : 3c477a97ea842a806f6fad6f5c3a81d6e50b27c3
2013-01-22 20:12:21 -05:00

84 lines
2.5 KiB
XML

<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="chrome://global/skin"?>
<?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=777385
-->
<window title="Mozilla Bug 777385"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<div></div>
<div id="mydivname"></div>
<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
<!-- test results are displayed in the html:body -->
<body xmlns="http://www.w3.org/1999/xhtml">
<a href="https://bugzilla.mozilla.org/show_bug.cgi?id="
target="_blank">Mozilla Bug 777385</a>
</body>
<!-- test code goes here -->
<script type="application/javascript">
<![CDATA[
/** Test for Bug 777385 **/
let Cu = Components.utils;
let live_map = new WeakMap;
let get_div_style = function () {
return document.getElementById("mydivname").style;
}
let make_live_map = function () {
let my_div_style = get_div_style();
let div_fail = false;
try {
live_map.set(my_div_style, 12345);
} catch (e) {
div_fail = true;
}
ok(!div_fail, "Using elem.style as a weak map key should not produce an exception.");
is(live_map.get(get_div_style()), 12345, "Live map should have live style with right value before GC.");
}
make_live_map();
// AudioContext is the only Paris bindings non-nsISupports refCounted class.
SpecialPowers.setBoolPref("media.webaudio.enabled", true);
// non-nsISupports cycle-collected classes should fail as weak map keys.
let context = new AudioContext();
let contextFail = false;
try {
live_map.set(context, 2);
} catch (e) {
contextFail = true;
}
ok(contextFail, "Cycle collected non-nsISupports classes aren't allowed as weak map keys.");
/* Set up for running precise GC/CC then check the results. */
SimpleTest.waitForExplicitFinish();
Cu.schedulePreciseGC(function () {
SpecialPowers.DOMWindowUtils.cycleCollect();
SpecialPowers.DOMWindowUtils.garbageCollect();
SpecialPowers.DOMWindowUtils.garbageCollect();
is(Cu.nondeterministicGetWeakMapKeys(live_map).length, 1,
"Live nsISupports new DOM bindings wrappercached native weak map key should not be removed.");
is(live_map.get(get_div_style()), 12345, "Live map should have live style with right value after GC.");
SpecialPowers.clearUserPref("media.webaudio.enabled");
SimpleTest.finish();
});
]]>
</script>
</window>