Add unit test for find/replace in dirty document.
Plus another attempt to fix flaky unit test.