Ajax tests: Refactor tests and fix bugs.

cc @jaubourg  @gibson042