Fix two bugs with spurious dirtyFlagChange events:
- Document ctor always fires it, even though isDirty stays false whole time
- Calling refreshText() always fires a pair of isDirty->true,->false
  (causing bug #502)

Add unit tests for various cases around Document dirty/undo state
Merge branch 'master' into pflynn/spurious-dirtyflag
reuse test window in Document-test
add check for dangling documents
Merge pull request #4994 from adobe/pflynn/spurious-dirtyflag

Fix bugs with spurious dirtyFlagChange events