|
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=673468 |
|
6 --> |
|
7 <window title="Mozilla Bug " |
|
8 xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> |
|
9 <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/> |
|
10 |
|
11 <!-- test results are displayed in the html:body --> |
|
12 <body xmlns="http://www.w3.org/1999/xhtml"> |
|
13 <a id="testelem" href="https://bugzilla.mozilla.org/show_bug.cgi?id=" |
|
14 target="_blank">Mozilla Bug 673468</a> |
|
15 </body> |
|
16 |
|
17 <!-- test code goes here --> |
|
18 <script type="application/javascript"> |
|
19 <![CDATA[ |
|
20 /** Test for Bug 673468 **/ |
|
21 |
|
22 let Cc = Components.classes; |
|
23 let Cu = Components.utils; |
|
24 let Ci = Components.interfaces; |
|
25 |
|
26 SpecialPowers.DOMWindowUtils.garbageCollect(); |
|
27 |
|
28 let get_live_dom = function () { |
|
29 return document.getElementById("testelem"); |
|
30 }; |
|
31 |
|
32 let wrappers_as_keys_test = function () { |
|
33 let e = new MessageEvent("foo", { bubbles: false, cancellable: false, |
|
34 data: { dummy: document.createElement("foo") }}); |
|
35 window.eeeevent = e; |
|
36 |
|
37 let live_dom = e.data.dummy; |
|
38 let dead_dom = document.createElement("div"); |
|
39 let dead_child = document.createElement("div"); |
|
40 dead_dom.appendChild(dead_child); |
|
41 is(dead_dom.children.length, 1, "children have wrong length"); |
|
42 let wrappee = new Object(); |
|
43 |
|
44 dead_dom.abcxyz = wrappee; |
|
45 |
|
46 let system = Cc["@mozilla.org/systemprincipal;1"].createInstance(); |
|
47 let sandbox = Cu.Sandbox(system); |
|
48 |
|
49 sandbox.wrapper = wrappee; |
|
50 sandbox.value = dead_dom; |
|
51 let map = Cu.evalInSandbox("wm = new WeakMap(); wm.set(wrapper, value); wm", sandbox); |
|
52 sandbox.wrapper = null; |
|
53 sandbox.value = null; |
|
54 |
|
55 live_dom.xyzabc = {wrappee: wrappee, m: map, sb: sandbox}; |
|
56 |
|
57 let key = Cu.nondeterministicGetWeakMapKeys(map)[0]; |
|
58 let value = map.get(key); |
|
59 is(value.children.length, 1, "children have wrong length"); |
|
60 } |
|
61 |
|
62 wrappers_as_keys_test(); |
|
63 |
|
64 let check_wrappers_as_keys = function () { |
|
65 let live_dom = window.eeeevent.data.dummy; |
|
66 let live_map = live_dom.xyzabc.m; |
|
67 let sandbox = live_dom.xyzabc.sb; |
|
68 is(Cu.nondeterministicGetWeakMapKeys(live_map).length, 1, |
|
69 "Map should not be empty."); |
|
70 let key = Cu.nondeterministicGetWeakMapKeys(live_map)[0]; |
|
71 let value = live_map.get(key); |
|
72 is(value.children.length, 1, "children have wrong length"); |
|
73 } |
|
74 |
|
75 Cu.schedulePreciseGC(function () { |
|
76 SpecialPowers.DOMWindowUtils.cycleCollect(); |
|
77 SpecialPowers.DOMWindowUtils.garbageCollect(); |
|
78 |
|
79 check_wrappers_as_keys(); |
|
80 }); |
|
81 |
|
82 ]]> |
|
83 </script> |
|
84 </window> |