Test case: http://dvcs.w3.org/hg/editing/raw-file/6aaa4b8455c9/selecttest/unload.html
Mozilla bug: https://bugzilla.mozilla.org/show_bug.cgi?id=717339
The editing spec was just changed to require this. Neither Mozilla nor WebKit do this currently, but IE/Opera do and I think it makes sense.
Safari 5.1 says Pass. When did this regress?
After discussion with Boris Zbarsky and Ian Hickson: actually, the Selection object is supposed to be replaced with a new one. This is specified in HTML as part of the document.open() algorithm:
New test: http://dvcs.w3.org/hg/editing/raw-file/56c83bbaa44c/selecttest/Document-open.html
The new test shows that Gecko does replace the selection with a new object, but that object has the same ranges as the old one. WebKit (Chrome 17 dev) is the same object as before. Opera clears the ranges but I can't tell if it's the same object, because getSelection() != getSelection() in Opera. IE returns a different object and clears the ranges, so it's the only one that passes the new test.
This is specific to document.open(), not a general unloading thing.
Regressed in <http://trac.webkit.org/changeset/96257>.