Adding stricter checks for state change logic.

 * Never allow leaving of POSTED state.
 * onload can get called multiple times, ignore all accept the first one.
 * message can arrive when test is in pretty much any state.
 * Clear tests which have timed out.
Extending timeout to 30 seconds because travis can be slow.
Merge pull request #435 from mithro/state-fixes-2

Another attempt at making the state transitions more reliable