Index: LayoutTests/fast/dom/resources/leak-check.js |
diff --git a/LayoutTests/fast/dom/resources/leak-check.js b/LayoutTests/fast/dom/resources/leak-check.js |
new file mode 100644 |
index 0000000000000000000000000000000000000000..1db4cb3a43526cd8baa22dd42c94afac5519d842 |
--- /dev/null |
+++ b/LayoutTests/fast/dom/resources/leak-check.js |
@@ -0,0 +1,69 @@ |
+// include ../../js/resources/js-test-pre.js before this file. |
haraken
2013/08/02 03:47:59
../../js/resources/js-test-pre.js => fast/js/resou
kouhei (in TOK)
2013/08/02 04:04:25
Done.
|
+ |
+function doLeakTest(src, tolerance) { |
+ function getCounterValues() { |
+ gc(); |
+ return {'numberOfLiveDocuments': window.internals.numberOfLiveDocuments()}; |
+ } |
+ |
+ var frame = document.createElement('frame'); |
+ document.body.appendChild(frame); |
+ function loadSourceIntoIframe(src, callback) { |
+ var originalSrc = frame.src; |
+ |
+ frame.onload = function() { |
+ if (frame.src === originalSrc) return true; |
+ |
+ callback(); |
+ }; |
+ frame.src = src; |
+ } |
+ |
+ function cyclePage(src, continuation) { |
+ } |
+ |
+ function compareValues(countersBefore, countersAfter, tolerance) { |
+ for (type in tolerance) { |
+ var before = countersBefore[type]; |
+ var after = countersAfter[type]; |
+ |
+ if(after - before <= tolerance[type]) |
+ testPassed('counter "'+type+'" was '+before+' before and now '+after+' after the cycle. This is under threshold of '+tolerance[type]+'.'); |
+ else |
+ testFailed('counter "'+type+'" was '+before+' before and now '+after+' after the cycle. This exceeds threshold of '+tolerance[type]+'.'); |
+ } |
+ } |
+ |
+ jsTestIsAsync = true; |
+ if (!window.internals) { |
+ console.log("This test only runs on DumpRenderTree, as it requires existence of window.internals and cross-domain resource access check disabled."); |
haraken
2013/08/02 03:47:59
Nit: We prefer debug("...") instead of console.log
kouhei (in TOK)
2013/08/02 04:04:25
Done.
|
+ finishJSTest(); |
+ } |
+ |
+ loadSourceIntoIframe('about:blank', function() { |
+ // blank document loaded... |
+ var countersBefore = getCounterValues(); |
+ |
+ loadSourceIntoIframe(src, function() { |
+ // target document loaded... |
+ |
+ loadSourceIntoIframe('about:blank', function() { |
+ // target document unloaded... |
+ |
+ var countersAfter = getCounterValues(); |
+ compareValues(countersBefore, countersAfter, tolerance); |
+ finishJSTest(); |
+ }); |
+ }); |
+ }); |
+} |
+ |
+function htmlToUrl(html) { |
+ return 'data:text/html;charset=utf-8,'+html; |
haraken
2013/08/02 03:47:59
Nit: Spaces are needed around '+'.
kouhei (in TOK)
2013/08/02 04:04:25
Done.
|
+} |
+ |
+function grabScriptText(id) { |
+ document.getElementById(id).innerText; |
+} |
+ |
+// include ../../js/resources/js-test-post.js after this file. |
haraken
2013/08/02 03:47:59
../../js/resources/js-test-post.js => fast/js/reso
kouhei (in TOK)
2013/08/02 04:04:25
Done.
|