OLD | NEW |
| (Empty) |
1 // include resources/js-test.js before this file. | |
2 | |
3 function getCounterValues(callback) { | |
4 testRunner.resetTestHelperControllers(); | |
5 asyncGC(function() { | |
6 var ret = { | |
7 'numberOfLiveDocuments': window.internals.numberOfLiveDocuments(), | |
8 'numberOfLiveAXObjects': window.internals.numberOfLiveAXObjects() | |
9 }; | |
10 | |
11 var refCountedInstances = JSON.parse(window.internals.dumpRefCountedInst
anceCounts()); | |
12 for (typename in refCountedInstances) | |
13 ret['numberOfInstances-'+typename] = refCountedInstances[typename]; | |
14 | |
15 callback(ret); | |
16 }); | |
17 | |
18 } | |
19 | |
20 function compareValues(countersBefore, countersAfter, tolerance) { | |
21 for (type in tolerance) { | |
22 var before = countersBefore[type]; | |
23 var after = countersAfter[type]; | |
24 | |
25 if (after - before <= tolerance[type]) | |
26 testPassed('The difference of counter "'+type+'" before and after th
e cycle is under the threshold of '+tolerance[type]+'.'); | |
27 else | |
28 testFailed('counter "'+type+'" was '+before+' before and now '+after
+' after the cycle. This exceeds the threshold of '+tolerance[type]+'.'); | |
29 } | |
30 } | |
31 | |
32 function doLeakTest(src, tolerance) { | |
33 var frame = document.createElement('iframe'); | |
34 document.body.appendChild(frame); | |
35 function loadSourceIntoIframe(src, callback) { | |
36 var originalSrc = frame.src; | |
37 | |
38 frame.onload = function() { | |
39 if (frame.src === originalSrc) | |
40 return true; | |
41 | |
42 callback(); | |
43 return true; | |
44 }; | |
45 frame.src = src; | |
46 } | |
47 | |
48 jsTestIsAsync = true; | |
49 if (!window.internals) { | |
50 debug("This test only runs on DumpRenderTree, as it requires existence o
f window.internals and cross-domain resource access check disabled."); | |
51 finishJSTest(); | |
52 } | |
53 | |
54 loadSourceIntoIframe('about:blank', function() { | |
55 // blank document loaded... | |
56 getCounterValues(function(countersBefore) { | |
57 loadSourceIntoIframe(src, function() { | |
58 // target document loaded... | |
59 | |
60 loadSourceIntoIframe('about:blank', function() { | |
61 // target document unloaded... | |
62 | |
63 // Measure counter values on next timer event. This is neede
d | |
64 // to correctly handle deref cycles for some ActiveDOMObject
s | |
65 // such as XMLHttpRequest. | |
66 setTimeout(function() { | |
67 getCounterValues(function(countersAfter) { | |
68 compareValues(countersBefore, countersAfter, toleran
ce); | |
69 finishJSTest(); | |
70 }); | |
71 }, 0); | |
72 }); | |
73 }); | |
74 }); | |
75 }); | |
76 } | |
77 | |
78 function htmlToUrl(html) { | |
79 return 'data:text/html;charset=utf-8,' + html; | |
80 } | |
81 | |
82 function grabScriptText(id) { | |
83 return document.getElementById(id).innerText; | |
84 } | |
85 | |
86 // include fast/js/resources/js-test-post.js after this file. | |
OLD | NEW |