1 // include resources/js-test.js before this file.
3 function getCounterValues(callback) {
4 testRunner.resetTestHelperControllers();
6 var ret = {'numberOfLiveDocuments': window.internals.numberOfLiveDocuments()};
8 var refCountedInstances = JSON.parse(window.internals.dumpRefCountedInstanceCounts());
9 for (typename in refCountedInstances)
10 ret['numberOfInstances-'+typename] = refCountedInstances[typename];
17 function compareValues(countersBefore, countersAfter, tolerance) {
18 for (type in tolerance) {
19 var before = countersBefore[type];
20 var after = countersAfter[type];
22 if (after - before <= tolerance[type])
23 testPassed('The difference of counter "'+type+'" before and after the cycle is under the threshold of '+tolerance[type]+'.');
25 testFailed('counter "'+type+'" was '+before+' before and now '+after+' after the cycle. This exceeds the threshold of '+tolerance[type]+'.');
29 function doLeakTest(src, tolerance) {
30 var frame = document.createElement('iframe');
31 document.body.appendChild(frame);
32 function loadSourceIntoIframe(src, callback) {
33 var originalSrc = frame.src;
35 frame.onload = function() {
36 if (frame.src === originalSrc)
46 if (!window.internals) {
47 debug("This test only runs on DumpRenderTree, as it requires existence of window.internals and cross-domain resource access check disabled.");
51 loadSourceIntoIframe('about:blank', function() {
52 // blank document loaded...
53 getCounterValues(function(countersBefore) {
54 loadSourceIntoIframe(src, function() {
55 // target document loaded...
57 loadSourceIntoIframe('about:blank', function() {
58 // target document unloaded...
60 // Measure counter values on next timer event. This is needed
61 // to correctly handle deref cycles for some ActiveDOMObjects
62 // such as XMLHttpRequest.
63 setTimeout(function() {
64 getCounterValues(function(countersAfter) {
65 compareValues(countersBefore, countersAfter, tolerance);
75 function htmlToUrl(html) {
76 return 'data:text/html;charset=utf-8,' + html;
79 function grabScriptText(id) {
80 return document.getElementById(id).innerText;
83 // include fast/js/resources/js-test-post.js after this file.