Fixed tests to use document.addEventListener instead of window.addEventListener