Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
1 <?xml version="1.0"?>
2 <?xml-stylesheet type="text/css" href="chrome://global/skin"?>
3 <?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?>
4 <!--
5 https://bugzilla.mozilla.org/show_bug.cgi?id=777385
6 -->
7 <window title="Mozilla Bug 777385"
8 xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
9 <div></div>
10 <div id="mydivname"></div>
11 <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
13 <!-- test results are displayed in the html:body -->
14 <body xmlns="http://www.w3.org/1999/xhtml">
15 <a href="https://bugzilla.mozilla.org/show_bug.cgi?id="
16 target="_blank">Mozilla Bug 777385</a>
17 </body>
19 <!-- test code goes here -->
20 <script type="application/javascript">
21 <![CDATA[
22 /** Test for Bug 777385 **/
24 let Cu = Components.utils;
26 let live_map = new WeakMap;
28 let get_div_style = function () {
29 return document.getElementById("mydivname").style;
30 }
32 let make_live_map = function () {
33 let my_div_style = get_div_style();
34 let div_fail = false;
35 try {
36 live_map.set(my_div_style, 12345);
37 } catch (e) {
38 div_fail = true;
39 }
40 ok(!div_fail, "Using elem.style as a weak map key should not produce an exception.");
42 is(live_map.get(get_div_style()), 12345, "Live map should have live style with right value before GC.");
44 }
46 make_live_map();
48 // RGBColor is a non-nsISupports refCounted class using WebIDL bindings.
50 // non-nsISupports cycle-collected classes should fail as weak map keys.
51 let context = window.getComputedStyle(document.documentElement, null).getPropertyCSSValue("color").getRGBColorValue();
52 let contextFail = false;
53 try {
54 live_map.set(context, 2);
55 } catch (e) {
56 contextFail = true;
57 }
59 ok(contextFail, "Cycle collected non-nsISupports classes aren't allowed as weak map keys.");
61 /* Set up for running precise GC/CC then check the results. */
63 SimpleTest.waitForExplicitFinish();
65 Cu.schedulePreciseGC(function () {
66 SpecialPowers.DOMWindowUtils.cycleCollect();
67 SpecialPowers.DOMWindowUtils.garbageCollect();
68 SpecialPowers.DOMWindowUtils.garbageCollect();
70 is(Cu.nondeterministicGetWeakMapKeys(live_map).length, 1,
71 "Live nsISupports new DOM bindings wrappercached native weak map key should not be removed.");
73 is(live_map.get(get_div_style()), 12345, "Live map should have live style with right value after GC.");
75 SimpleTest.finish();
76 });
78 ]]>
79 </script>
80 </window>