Hand picking relevant logic into FetchLoaderManager
DO NOT SUBMIT
Change-Id: I1cf2171641ac3aca72d524ad2028197693503e16
diff --git a/fetch/fetch-later/basic.tentative.https.window.js b/fetch/fetch-later/basic.tentative.https.window.js
index 55bdbc9..61a5f1c 100644
--- a/fetch/fetch-later/basic.tentative.https.window.js
+++ b/fetch/fetch-later/basic.tentative.https.window.js
@@ -33,3 +33,11 @@
assert_throws_dom(
'AbortError', () => fetchLater('/', {signal: controller.signal}));
}, `fetchLater() throws AbortError when its initial abort signal is aborted.`);
+
+test(() => {
+ const controller = new AbortController();
+ const result = fetchLater('/', {signal: controller.signal});
+ assert_false(result.activated);
+ controller.abort();
+ assert_false(result.activated);
+}, `fetchLater() does not throw error when it is aborted before sending.`);
diff --git a/fetch/fetch-later/send-on-deactivate.tentative.https.window.js b/fetch/fetch-later/send-on-deactivate.tentative.https.window.js
index 4ea9d2e..6e14a18 100644
--- a/fetch/fetch-later/send-on-deactivate.tentative.https.window.js
+++ b/fetch/fetch-later/send-on-deactivate.tentative.https.window.js
@@ -38,3 +38,36 @@
await expectBeacon(uuid, {count: 0});
}, `fetchLater() does not send on page entering BFCache.`);
+
+parallelPromiseTest(async t => {
+ const uuid = token();
+ const url = generateSetBeaconURL(uuid);
+ // Sets no option to test the default behavior when a document gets discarded
+ // on navigated away.
+ const helper = new RemoteContextHelper();
+ // Opens a window without BFCache.
+ const rc1 = await helper.addWindow();
+
+ // Creates 2 fetchLater requests in remote, and one of them is aborted
+ // immediately. The other one should only be sent right on navigating away.
+ await rc1.executeScript(url => {
+ const controller = new AbortController();
+ fetchLater(url, {signal: controller.signal});
+ fetchLater(url);
+ controller.abort();
+ // Add a pageshow listener to stash the BFCache event.
+ window.addEventListener('pageshow', e => {
+ window.pageshowEvent = e;
+ });
+ }, [url]);
+ // Navigates away to trigger request sending.
+ const rc2 = await rc1.navigateToNew();
+ // Navigate back.
+ await rc2.historyBack();
+ // Verify that the page was NOT BFCached.
+ assert_equals(undefined, await rc1.executeScript(() => {
+ return window.pageshowEvent;
+ }));
+
+ await expectBeacon(uuid, {count: 1});
+}, `fetchLater() does not send aborted request on navigating away a page w/o BFCache.`);