Fix back button behavior in modern browsers

The problem here was we were storing the page state before we updated
it. So you would get a stale cache when you used the back button.

Added a test which highlighted non-determanistic behavior due to the way
we were 'mocking' in a different test. Made sure that those tests reset
the global objects back to how they should be when the test exited.

https://www.pivotaltracker.com/story/show/46889523