Bug 44642

Summary: js-test-post.js is not robust for asynchronous tests
Product: WebKit Reporter: Steve Block <steveblock>
Component: Tools / TestsAssignee: Nobody <webkit-unassigned>
Status: RESOLVED FIXED    
Severity: Normal CC: abarth, benm, commit-queue, darin, eric, mjs, steveblock, webkit.review.bot
Priority: P2    
Version: 528+ (Nightly build)   
Hardware: All   
OS: All   
Attachments:
Description Flags
Patch darin: review+

Description Steve Block 2010-08-25 15:44:08 PDT
LayoutTests that use the script-tests pattern use a standard HTML template. This includes fast/js/resources/js-test-pre.js, followed by the script for the test itself, followed by fast/js/resources/js-test-post.js.

If window.jsTestIsAsync has been set by the test, js-test-post.js calls layoutTestController.waitUntilDone(). The test should then call finishJSTest() when it completes. finishJSTest() is defined in js-test-post.js and calls layoutTestController.notifyDone().

However, it's possible for an asynchronous test to complete before js-test-post.js has been parsed. This can occur when the loading of this script is slow, causing WebCore to yield during loading and process asynchronous callbacks from the test. In this case, finishJSTest() is not yet defined, causing the test to fail.

One solution would be to update all such asynchronous tests to delay any testing until onload has fired. A less intrusive alternative is to move finishJSTest() to js-test-pre.js and add logic to js-test-post.js to handle the case of finishJSTest() having already been called.
Comment 1 Steve Block 2010-08-25 16:11:02 PDT
Created attachment 65493 [details]
Patch
Comment 2 Darin Adler 2010-08-26 11:30:20 PDT
Comment on attachment 65493 [details]
Patch

The change seems fine.

> +isAllScriptParsed = true;

I think that adding this new window property might affect tests that dump everything on the window object. Did you run all the scripts to test?

I would name this variable postTestScriptWasParsed or wasPostTestScriptParsed.

> +    if (window.isFinishJSTestCalled)

I would name this variable finishJSTestWasCalled or wasFinishJSTestCalled.
Comment 3 Steve Block 2010-08-27 01:31:10 PDT
> I think that adding this new window property might affect tests that dump everything on the window
> object. Did you run all the scripts to test?
Yes, I ran all tests. I guess none of them dump the window object asynchronously, ie after js-test-post.js has been parsed.

> I would name this variable postTestScriptWasParsed or wasPostTestScriptParsed.
> I would name this variable finishJSTestWasCalled or wasFinishJSTestCalled.
Will do
Comment 4 Steve Block 2010-08-27 04:15:58 PDT
Committed r66201: <http://trac.webkit.org/changeset/66201>
Comment 5 WebKit Review Bot 2010-08-27 04:40:04 PDT
http://trac.webkit.org/changeset/66201 might have broken GTK Linux 32-bit Release
Comment 6 Steve Block 2010-08-27 05:35:12 PDT
Added GTK, Qt and Win expected results in http://trac.webkit.org/changeset/66212