Skip to content

Commit

Permalink
use a timeout instead
Browse files Browse the repository at this point in the history
  • Loading branch information
TimothyGu committed Aug 31, 2018
1 parent d37257a commit 6353140
Showing 1 changed file with 17 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,18 @@ async_test(t => {
const img = frame.contentDocument.createElement("img");
img.src = new URL("resources/slow-png.py", document.URL);
img.onload = t.unreached_func("Image loading should have errored");
img.onerror = t.step_func_done(() => {
assert_true(happened);
});
// The image fetch starts in a microtask, so let's be sure to test after
// the fetch has started.
t.step_timeout(() => {
frame.contentWindow.location.href = new URL("resources/dummy.html", document.URL);
frame.contentDocument.open();
happened = true;
});
// If 3 seconds have passed and the image has still not loaded, we consider
// it aborted. slow-png.py only sleeps for 2 wallclock seconds.
t.step_timeout(t.step_func_done(() => {
assert_true(happened);
}), 3000);
});
}, "document.open() aborts documents that are navigating through Location (image loading)");

Expand All @@ -79,6 +81,8 @@ async_test(t => {
frame.contentDocument.open();
}, "document.open() aborts documents that are navigating through iframe loading (fetch())");

// We use resources/slow.py here, to prevent the situation where when
// document.open() is called the initial document has already become inactive.
async_test(t => {
const div = document.body.appendChild(document.createElement("div"));
t.add_cleanup(() => div.remove());
Expand All @@ -88,15 +92,17 @@ async_test(t => {
const img = frame.contentDocument.createElement("img");
img.src = new URL("resources/slow-png.py", document.URL);
img.onload = t.unreached_func("Image loading should have errored");
img.onerror = t.step_func_done(() => {
assert_true(happened);
});
// The image fetch starts in a microtask, so let's be sure to test after
// the fetch has started.
t.step_timeout(() => {
frame.contentDocument.open();
happened = true;
});
// If 3 seconds have passed and the image has still not loaded, we consider
// it aborted. slow-png.py only sleeps for 2 wallclock seconds.
t.step_timeout(t.step_func_done(() => {
assert_true(happened);
}), 3000);
}, "document.open() aborts documents that are navigating through iframe loading (image loading)");

async_test(t => {
Expand Down Expand Up @@ -149,15 +155,17 @@ async_test(t => {
const img = frame.contentDocument.createElement("img");
img.src = new URL("resources/slow-png.py", document.URL);
img.onload = t.unreached_func("Image loading should have errored");
img.onerror = t.step_func_done(() => {
assert_true(happened);
});
// The image fetch starts in a microtask, so let's be sure to test after
// the fetch has started.
t.step_timeout(() => {
link.click();
frame.contentDocument.open();
happened = true;
});
// If 3 seconds have passed and the image has still not loaded, we consider
// it aborted. slow-png.py only sleeps for 2 wallclock seconds.
t.step_timeout(t.step_func_done(() => {
assert_true(happened);
}), 3000);
});
}, "document.open() aborts documents that are queued for navigation through .click() (image loading)");

0 comments on commit 6353140

Please sign in to comment.