Hi, I think the difference between real applications and browsertest is whether the main document can be closed directly.
For real applications, we can't directly close main runtime object, therefore, we need this patch to check whether main document is the last one. 
While for testing, things are different, it is able to delete all Runtime objects from RuntimeRegistry, including main runtime. Also it doesn't guarantee the main runtime is the last to close. 

Seems both cases are reasonable. Though this looks a bit weired here, it maybe the most simplest solution to cover both cases.
What do you think?