From c0cce73db5ee77885c65f7294e828eadbd41788c Mon Sep 17 00:00:00 2001 From: "bclary%bclary.com" Date: Wed, 14 Jun 2006 18:52:00 +0000 Subject: [PATCH] JavaScript Test Library - add support for browser tests which complete after page load, bug 341550, a=bsmedberg for checkin to closed tree --- js/tests/e4x/Regress/regress-327697.js | 16 ++++++++-- js/tests/e4x/browser.js | 17 ++++++++++- js/tests/ecma/browser.js | 22 ++++++++++++-- js/tests/ecma_2/browser.js | 21 +++++++++++-- js/tests/ecma_3/browser.js | 17 ++++++++++- js/tests/js-test-driver-begin.js | 1 + js/tests/js-test-driver-end.js | 34 +++++++++++++++++----- js/tests/js1_1/browser.js | 21 +++++++++++-- js/tests/js1_2/browser.js | 21 +++++++++++-- js/tests/js1_3/browser.js | 20 +++++++++++-- js/tests/js1_4/browser.js | 21 +++++++++++-- js/tests/js1_5/Regress/regress-127243.js | 18 ++++++++++-- js/tests/js1_5/Regress/regress-233483-2.js | 6 ++++ js/tests/js1_5/Regress/regress-233483.js | 9 ++++++ js/tests/js1_5/Regress/regress-327608.js | 9 ++++-- js/tests/js1_5/browser.js | 17 ++++++++++- js/tests/js1_6/browser.js | 17 ++++++++++- 17 files changed, 251 insertions(+), 36 deletions(-) diff --git a/js/tests/e4x/Regress/regress-327697.js b/js/tests/e4x/Regress/regress-327697.js index 53088848ece..d30bdff88c3 100755 --- a/js/tests/e4x/Regress/regress-327697.js +++ b/js/tests/e4x/Regress/regress-327697.js @@ -49,14 +49,26 @@ printStatus('This test runs in the browser only'); function init() { - var sel = document.getElementsByTagName("select")[0]; - sel.add(document.createElement('foo'), ); + try + { + var sel = document.getElementsByTagName("select")[0]; + sel.add(document.createElement('foo'), ); + } + catch(ex) + { + printStatus(ex + ''); + } TEST(1, expect, actual); END(); + gDelayTestDriverEnd = false; + jsTestDriverEnd(); } if (typeof window != 'undefined') { + // delay test driver end + gDelayTestDriverEnd = true; + document.write(''); window.addEventListener("load", init, false); } diff --git a/js/tests/e4x/browser.js b/js/tests/e4x/browser.js index b122043f16a..f4f5007f954 100644 --- a/js/tests/e4x/browser.js +++ b/js/tests/e4x/browser.js @@ -59,10 +59,25 @@ function htmlesc(str) { return str; } +function DocumentWrite(s) +{ + try + { + var msgDiv = document.createElement('div'); + msgDiv.innerHTML = s; + document.body.appendChild(msgDiv); + msgDiv = null; + } + catch(excp) + { + document.write(s + "
\n"); + } +} + function writeLineToLog( string ) { string = String(string); string = string.replace(/[<>&]/g, htmlesc); - document.write( string + "
\n"); + DocumentWrite( string + "
\n"); } function print( string ) { diff --git a/js/tests/ecma/browser.js b/js/tests/ecma/browser.js index 26bd9d872e2..a4d5081e65e 100644 --- a/js/tests/ecma/browser.js +++ b/js/tests/ecma/browser.js @@ -62,16 +62,32 @@ function htmlesc(str) { return str; } +function DocumentWrite(s) +{ + try + { + var msgDiv = document.createElement('div'); + msgDiv.innerHTML = s; + document.body.appendChild(msgDiv); + msgDiv = null; + } + catch(excp) + { + document.write(s + "
\n"); + } +} + function writeLineToLog( string ) { string = String(string); string = string.replace(/[<>&]/g, htmlesc); - document.write( string + "
\n"); + DocumentWrite( string + "
\n"); + } function writeHeaderToLog( string ) { string = String(string); string = string.replace(/[<>&]/g, htmlesc); - document.write( "

" + string + "

" ); + DocumentWrite( "

" + string + "

" ); } function writeFormattedResult( expect, actual, string, passed ) { @@ -81,7 +97,7 @@ function writeFormattedResult( expect, actual, string, passed ) { s += "" ; s += ( passed ) ? "  " + PASSED : " " + FAILED + expect + ""; - document.write( s + "
" ); + DocumentWrite( s + "

" ); return passed; } diff --git a/js/tests/ecma_2/browser.js b/js/tests/ecma_2/browser.js index 4f9dd63c9c2..dbb972209db 100644 --- a/js/tests/ecma_2/browser.js +++ b/js/tests/ecma_2/browser.js @@ -62,15 +62,30 @@ function htmlesc(str) { return str; } +function DocumentWrite(s) +{ + try + { + var msgDiv = document.createElement('div'); + msgDiv.innerHTML = s; + document.body.appendChild(msgDiv); + msgDiv = null; + } + catch(excp) + { + document.write(s + "
\n"); + } +} + function writeLineToLog( string ) { string = String(string); string = string.replace(/[<>&]/g, htmlesc); - document.write( string + "
\n"); + DocumentWrite( string + "
\n"); } function writeHeaderToLog( string ) { string = String(string); string = string.replace(/[<>&]/g, htmlesc); - document.write( "

" + string + "

" ); + DocumentWrite( "

" + string + "

" ); } function writeFormattedResult( expect, actual, string, passed ) { @@ -80,7 +95,7 @@ function writeFormattedResult( expect, actual, string, passed ) { s += "" ; s += ( passed ) ? "  " + PASSED : " " + FAILED + expect + ""; - document.write( s + "
" ); + DocumentWrite( s + "

" ); return passed; } diff --git a/js/tests/ecma_3/browser.js b/js/tests/ecma_3/browser.js index df56e13c190..1b3f33f5caf 100755 --- a/js/tests/ecma_3/browser.js +++ b/js/tests/ecma_3/browser.js @@ -60,10 +60,25 @@ function htmlesc(str) { return str; } +function DocumentWrite(s) +{ + try + { + var msgDiv = document.createElement('div'); + msgDiv.innerHTML = s; + document.body.appendChild(msgDiv); + msgDiv = null; + } + catch(excp) + { + document.write(s + "
\n"); + } +} + function writeLineToLog( string ) { string = String(string); string = string.replace(/[<>&]/g, htmlesc); - document.write( string + "
\n"); + DocumentWrite( string + "
\n"); } var testcases = new Array(); diff --git a/js/tests/js-test-driver-begin.js b/js/tests/js-test-driver-begin.js index 6414c79717b..14d7055e980 100644 --- a/js/tests/js-test-driver-begin.js +++ b/js/tests/js-test-driver-begin.js @@ -2,6 +2,7 @@ var gVersion = 150; var gTestName = ''; var gTestPath = ''; +var gDelayTestDriverEnd = false; function init() { diff --git a/js/tests/js-test-driver-end.js b/js/tests/js-test-driver-end.js index 568830f6700..a09b5ac01c4 100644 --- a/js/tests/js-test-driver-end.js +++ b/js/tests/js-test-driver-end.js @@ -1,14 +1,32 @@ -if (window.opener && window.opener.runNextTest) +function jsTestDriverEnd() { - if (window.opener.reportCallBack) + // gDelayTestDriverEnd is used to + // delay collection of the test result and + // signal to Spider so that tests can continue + // to run after page load has fired. They are + // responsible for setting gDelayTestDriverEnd = true + // then when completed, setting gDelayTestDriverEnd = false + // then calling jsTestDriverEnd() + + if (gDelayTestDriverEnd) { - window.opener.reportCallBack(window.opener.gWindow); + return; + } + + if (window.opener && window.opener.runNextTest) + { + if (window.opener.reportCallBack) + { + window.opener.reportCallBack(window.opener.gWindow); + } + setTimeout('window.opener.runNextTest()', 250); + } + else + { + gPageCompleted = true; } - setTimeout('window.opener.runNextTest()', 250); -} -else -{ - gPageCompleted = true; } +jsTestDriverEnd(); + diff --git a/js/tests/js1_1/browser.js b/js/tests/js1_1/browser.js index cf41d2b6fd8..77c3220d1ec 100644 --- a/js/tests/js1_1/browser.js +++ b/js/tests/js1_1/browser.js @@ -62,13 +62,28 @@ function htmlesc(str) { return str; } +function DocumentWrite(s) +{ + try + { + var msgDiv = document.createElement('div'); + msgDiv.innerHTML = s; + document.body.appendChild(msgDiv); + msgDiv = null; + } + catch(excp) + { + document.write(s + "
\n"); + } +} + function writeLineToLog( string ) { string = string.replace(/[<>&]/g, htmlesc); - document.write( string + "
\n"); + DocumentWrite( string + "
\n"); } function writeHeaderToLog( string ) { string = string.replace(/[<>&]/g, htmlesc); - document.write( "

" + string + "

" ); + DocumentWrite( "

" + string + "

" ); } function writeFormattedResult( expect, actual, string, passed ) { @@ -77,7 +92,7 @@ function writeFormattedResult( expect, actual, string, passed ) { s += "" ; s += ( passed ) ? "  " + PASSED : " " + FAILED + expect + ""; - document.write( s + "
" ); + DocumentWrite( s + "

" ); return passed; } diff --git a/js/tests/js1_2/browser.js b/js/tests/js1_2/browser.js index fc3ed8ecd7b..cb5887d7279 100644 --- a/js/tests/js1_2/browser.js +++ b/js/tests/js1_2/browser.js @@ -62,16 +62,31 @@ function htmlesc(str) { return str; } +function DocumentWrite(s) +{ + try + { + var msgDiv = document.createElement('div'); + msgDiv.innerHTML = s; + document.body.appendChild(msgDiv); + msgDiv = null; + } + catch(excp) + { + document.write(s + "
\n"); + } +} + function writeLineToLog( string ) { string = String(string); string = string.replace(/[<>&]/g, htmlesc); - document.write( string + "
\n"); + DocumentWrite( string + "
\n"); } function writeHeaderToLog( string ) { string = String(string); string = string.replace(/[<>&]/g, htmlesc); - document.write( "

" + string + "

" ); + DocumentWrite( "

" + string + "

" ); } function writeFormattedResult( expect, actual, string, passed ) { @@ -81,7 +96,7 @@ function writeFormattedResult( expect, actual, string, passed ) { s += "" ; s += ( passed ) ? "  " + PASSED : " " + FAILED + expect + ""; - document.write( s + "
" ); + DocumentWrite( s + "

" ); return passed; } diff --git a/js/tests/js1_3/browser.js b/js/tests/js1_3/browser.js index b618590d723..24213fb6923 100644 --- a/js/tests/js1_3/browser.js +++ b/js/tests/js1_3/browser.js @@ -62,15 +62,31 @@ function htmlesc(str) { return str; } +function DocumentWrite(s) +{ + try + { + var msgDiv = document.createElement('div'); + msgDiv.innerHTML = s; + document.body.appendChild(msgDiv); + msgDiv = null; + } + catch(excp) + { + document.write(s + "
\n"); + } +} + function writeLineToLog( string ) { string = String(string); string = string.replace(/[<>&]/g, htmlesc); string = string.replace(/[<>&]/g, htmlesc); document.write( string + "
\n"); } + function writeHeaderToLog( string ) { string = String(string); - document.write( "

" + string + "

" ); + DocumentWrite( "

" + string + "

" ); } function writeFormattedResult( expect, actual, string, passed ) { string = String(string); @@ -79,7 +95,7 @@ function writeFormattedResult( expect, actual, string, passed ) { s += "" ; s += ( passed ) ? "  " + PASSED : " " + FAILED + expect + ""; - document.write( s + "
" ); + DocumentWrite( s + "

" ); return passed; } diff --git a/js/tests/js1_4/browser.js b/js/tests/js1_4/browser.js index 232beef898a..29ba18bbce2 100644 --- a/js/tests/js1_4/browser.js +++ b/js/tests/js1_4/browser.js @@ -62,15 +62,30 @@ function htmlesc(str) { return str; } +function DocumentWrite(s) +{ + try + { + var msgDiv = document.createElement('div'); + msgDiv.innerHTML = s; + document.body.appendChild(msgDiv); + msgDiv = null; + } + catch(excp) + { + document.write(s + "
\n"); + } +} + function writeLineToLog( string ) { string = String(string); string = string.replace(/[<>&]/g, htmlesc); - document.write( string + "
\n"); + DocumentWrite( string + "
\n"); } function writeHeaderToLog( string ) { string = String(string); string = string.replace(/[<>&]/g, htmlesc); - document.write( "

" + string + "

" ); + DocumentWrite( "

" + string + "

" ); } function writeFormattedResult( expect, actual, string, passed ) { @@ -80,7 +95,7 @@ function writeFormattedResult( expect, actual, string, passed ) { s += "" ; s += ( passed ) ? "  " + PASSED : " " + FAILED + expect + ""; - document.write( s + "
" ); + DocumentWrite( s + "

" ); return passed; } diff --git a/js/tests/js1_5/Regress/regress-127243.js b/js/tests/js1_5/Regress/regress-127243.js index ba21d72ae65..5f7249a51f9 100755 --- a/js/tests/js1_5/Regress/regress-127243.js +++ b/js/tests/js1_5/Regress/regress-127243.js @@ -46,14 +46,16 @@ printStatus (summary); if (typeof window != 'undefined' && typeof document != 'undefined') { + // delay test driver end + gDelayTestDriverEnd = true; window.addEventListener('load', handleLoad, false); } else { printStatus('This test must be run in the browser'); -} + reportCompare(expect, actual, summary); -reportCompare(expect, actual, summary); +} var div; @@ -76,7 +78,7 @@ function handleLoad() div.watch('scrollTop', wee); - setTimeout('div.scrollTop = 42', 1000); + setTimeout('setScrollTop()', 1000); } function wee(id, oldval, newval) @@ -92,3 +94,13 @@ function wee(id, oldval, newval) return newval; } +function setScrollTop() +{ + div.scrollTop = 42; + + reportCompare(expect, actual, summary); + + gDelayTestDriverEnd = false; + jsTestDriverEnd(); + +} diff --git a/js/tests/js1_5/Regress/regress-233483-2.js b/js/tests/js1_5/Regress/regress-233483-2.js index 9ef7754b7dd..ea2ef932510 100755 --- a/js/tests/js1_5/Regress/regress-233483-2.js +++ b/js/tests/js1_5/Regress/regress-233483-2.js @@ -51,6 +51,9 @@ if (typeof document == 'undefined') } else { + // delay test driver end + gDelayTestDriverEnd = true; + actual = 'Crash'; window.onload = onLoad; } @@ -75,6 +78,9 @@ function onLoad() actual = 'No Crash'; reportCompare(expect, actual, summary); + + gDelayTestDriverEnd = false; + jsTestDriverEnd(); } function setform() diff --git a/js/tests/js1_5/Regress/regress-233483.js b/js/tests/js1_5/Regress/regress-233483.js index 7da54d0e5e2..db0b871e44e 100755 --- a/js/tests/js1_5/Regress/regress-233483.js +++ b/js/tests/js1_5/Regress/regress-233483.js @@ -47,8 +47,15 @@ printStatus (summary); if (typeof document != 'undefined') { + // delay test driver end + gDelayTestDriverEnd = true; window.onload = onLoad; } +else +{ + actual = 'No Crash'; + reportCompare(expect, actual, summary); +} function onLoad() { setform(); @@ -60,6 +67,8 @@ function onLoad() { actual = 'No Crash'; reportCompare(expect, actual, summary); + gDelayTestDriverEnd = false; + jsTestDriverEnd(); } diff --git a/js/tests/js1_5/Regress/regress-327608.js b/js/tests/js1_5/Regress/regress-327608.js index 6f48be62efe..54ea0f26ad9 100755 --- a/js/tests/js1_5/Regress/regress-327608.js +++ b/js/tests/js1_5/Regress/regress-327608.js @@ -42,7 +42,7 @@ var expect = 'No Crash'; printBugNumber (bug); printStatus (summary); -printStatus('This test runs only in the browser'); +writeLineToLog('This test runs only in the browser'); function countProps(obj) { @@ -56,15 +56,20 @@ function init() { var inp = document.getElementsByTagName("input")[0]; countProps(inp); - window.open().close(); // force gc? + gc(); var blurfun = inp.blur; blurfun.__proto__ = null; countProps(blurfun); reportCompare(expect, actual, summary); + gDelayTestDriverEnd = false; + jsTestDriverEnd(); } if (typeof window != 'undefined') { + // delay test driver end + gDelayTestDriverEnd = true; + document.write(''); window.addEventListener("load", init, false); } diff --git a/js/tests/js1_5/browser.js b/js/tests/js1_5/browser.js index eed3ff4f2f2..70abeee0d89 100755 --- a/js/tests/js1_5/browser.js +++ b/js/tests/js1_5/browser.js @@ -59,10 +59,25 @@ function htmlesc(str) { return str; } +function DocumentWrite(s) +{ + try + { + var msgDiv = document.createElement('div'); + msgDiv.innerHTML = s; + document.body.appendChild(msgDiv); + msgDiv = null; + } + catch(excp) + { + document.write(s + "
\n"); + } +} + function writeLineToLog( string ) { string = String(string); string = string.replace(/[<>&]/g, htmlesc); - document.write( string + "
\n"); + DocumentWrite(string); } var testcases = new Array(); diff --git a/js/tests/js1_6/browser.js b/js/tests/js1_6/browser.js index 600b0904481..da22e177e43 100755 --- a/js/tests/js1_6/browser.js +++ b/js/tests/js1_6/browser.js @@ -60,10 +60,25 @@ function htmlesc(str) { return str; } +function DocumentWrite(s) +{ + try + { + var msgDiv = document.createElement('div'); + msgDiv.innerHTML = s; + document.body.appendChild(msgDiv); + msgDiv = null; + } + catch(excp) + { + document.write(s + "
\n"); + } +} + function writeLineToLog( string ) { string = String(string); string = string.replace(/[<>&]/g, htmlesc); - document.write( string + "
\n"); + DocumentWrite( string + "
\n"); } var testcases = new Array();