I've fixed the `beforeunload` case, since it happens during `load_nsuri`. I added tests for both it and `unload`, but unfortunately the new tests are somewhat hackish, as we have to release the View without actually closing it to test this, because closing the view sends those events (this is already tested by existing tests), and we want to test if releasing the doc obj sends those events. As for why we have to release the View, it's because it holds a ref to the doc obj.
So I placed the test last now since it doesn't close the view properly. If you think the test is too hackish I can remove it.