Smarter MockUI

This fixes test failures I'm seeing on master by avoiding arbitrary
setTimeouts.
Merge pull request #2762 from ef4/mock-ui

Smarter MockUI