Bug 863456: Report failures for tests that leave unexpected tabs or windows behind

The important part is the unit-test code that checks for remaining windows/tabs. Tests are expected to completely close (and wait for the close to complete) before calling done. There are a lot of tests that don't do that now and fixes for them.

The tabs API in particular has a problem, the callback from tab.close calls before the next tab has been selected so lots of tabs can try to use tabs.activeTab and end up with the wrong thing. I worked around this by only calling the callback when a new tab has been selected.