Create DOM wrapper and rewrite tests to simplify stubbing.

Also, #108 used XMLHttpRequest directly, which works from PhantomJS but
not from Chrome (unless started with special command line argument).
XMLHttpRequest is now a mock to enable tests to run in both environments.