Port newer version of WebTestCase from master