Adds tests and slight refactoring to the code

Uses Jasmine and a spy to ensure the callback is only executed when
the browser is in compatibility mode. The logic for determining
compatibility mode is wrapped in a function so it can be stubbed out in
tests.