Bug 1602991 - Fix intermittent browser/components/urlbar/tests/browser/browser_urlbar_locationchange_urlbar_edit_dos.js r=Gijs

The test messages the content script to trigger a web-progress change and waits for the change. The problem is that those two actions race each other. In the intermittent failures, the web-progress change happens before the test adds a listener for it.

The test first should add its listener and then message the content script to trigger the change. This try run is all green with many retriggers: https://treeherder.mozilla.org/#/jobs?repo=try&revision=6990ce980eff124ef28c41195ae57e0fd2b1f25b&group_state=expanded

Differential Revision: https://phabricator.services.mozilla.com/D59976

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Drew Willcoxon 2020-01-15 18:27:10 +00:00
Родитель 5f443f7001
Коммит 02ffd74c11
2 изменённых файлов: 15 добавлений и 13 удалений

Просмотреть файл

@ -18,7 +18,13 @@ async function checkURLBarValueStays(browser) {
); );
gBrowser.selectedBrowser.removeProgressListener(filter); gBrowser.selectedBrowser.removeProgressListener(filter);
filter = null; filter = null;
resolve(); // Wait an extra tick before resolving. We want to make sure that other
// web progress listeners queued after this one are called before we
// continue the test, in case the remainder of the test depends on those
// listeners. That should happen anyway since promises are resolved on
// the next tick, but do this to be a little safer. In particular we
// want to avoid having the test pass when it should fail.
executeSoon(resolve);
}, },
}; };
let filter = Cc[ let filter = Cc[
@ -46,15 +52,16 @@ add_task(async function() {
url: TEST_URL, url: TEST_URL,
}, },
async function(browser) { async function(browser) {
await SpecialPowers.spawn(browser, [""], function() { let promise1 = checkURLBarValueStays(browser);
SpecialPowers.spawn(browser, [""], function() {
content.wrappedJSObject.dos_hash(); content.wrappedJSObject.dos_hash();
}); });
await checkURLBarValueStays(browser); await promise1;
await SpecialPowers.spawn(browser, [""], function() { let promise2 = checkURLBarValueStays(browser);
content.clearTimeout(content.wrappedJSObject.dos_timeout); SpecialPowers.spawn(browser, [""], function() {
content.wrappedJSObject.dos_pushState(); content.wrappedJSObject.dos_pushState();
}); });
await checkURLBarValueStays(browser); await promise2;
} }
); );
}); });

Просмотреть файл

@ -6,17 +6,12 @@
</head> </head>
<body> <body>
<script> <script>
var dos_timeout = null;
function dos_hash() { function dos_hash() {
dos_timeout = setTimeout(function() {
location.hash = "#"; location.hash = "#";
}, 50);
} }
function dos_pushState() { function dos_pushState() {
dos_timeout = setTimeout(function() {
history.pushState({}, "Some title", ""); history.pushState({}, "Some title", "");
}, 50);
} }
</script> </script>
</body> </body>