Bug 1444132 - Fix the order of requests done by html_cause-test-page.html test. r=jdescottes

MozReview-Commit-ID: IY8TLzqjrnT

--HG--
extra : rebase_source : b01a5cd462d920fe52eadb6b4ba8222d08898972
This commit is contained in:
Alexandre Poirot 2018-07-31 07:33:04 -07:00
Родитель 57ca676e5a
Коммит d41a01a8c9
2 изменённых файлов: 37 добавлений и 22 удалений

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

@ -38,14 +38,14 @@ const EXPECTED_REQUESTS = [
url: EXAMPLE_URL + "xhr_request", url: EXAMPLE_URL + "xhr_request",
causeType: "xhr", causeType: "xhr",
causeUri: CAUSE_URL, causeUri: CAUSE_URL,
stack: [{ fn: "performXhrRequest", file: CAUSE_FILE_NAME, line: 24 }] stack: [{ fn: "performXhrRequestCallback", file: CAUSE_FILE_NAME, line: 26 }]
}, },
{ {
method: "GET", method: "GET",
url: EXAMPLE_URL + "fetch_request", url: EXAMPLE_URL + "fetch_request",
causeType: "fetch", causeType: "fetch",
causeUri: CAUSE_URL, causeUri: CAUSE_URL,
stack: [{ fn: "performFetchRequest", file: CAUSE_FILE_NAME, line: 28 }] stack: [{ fn: "performFetchRequest", file: CAUSE_FILE_NAME, line: 31 }]
}, },
{ {
method: "GET", method: "GET",
@ -53,8 +53,9 @@ const EXPECTED_REQUESTS = [
causeType: "fetch", causeType: "fetch",
causeUri: CAUSE_URL, causeUri: CAUSE_URL,
stack: [ stack: [
{ fn: "performPromiseFetchRequest", file: CAUSE_FILE_NAME, line: 40 }, { fn: "performPromiseFetchRequestCallback", file: CAUSE_FILE_NAME, line: 37 },
{ fn: null, file: CAUSE_FILE_NAME, line: 39, asyncCause: "promise callback" }, { fn: "performPromiseFetchRequest", file: CAUSE_FILE_NAME, line: 36,
asyncCause: "promise callback" },
] ]
}, },
{ {
@ -63,8 +64,8 @@ const EXPECTED_REQUESTS = [
causeType: "fetch", causeType: "fetch",
causeUri: CAUSE_URL, causeUri: CAUSE_URL,
stack: [ stack: [
{ fn: "performTimeoutFetchRequest", file: CAUSE_FILE_NAME, line: 42 }, { fn: "performTimeoutFetchRequestCallback2", file: CAUSE_FILE_NAME, line: 44 },
{ fn: "performPromiseFetchRequest", file: CAUSE_FILE_NAME, line: 41, { fn: "performTimeoutFetchRequestCallback1", file: CAUSE_FILE_NAME, line: 43,
asyncCause: "setTimeout handler" }, asyncCause: "setTimeout handler" },
] ]
}, },
@ -73,7 +74,7 @@ const EXPECTED_REQUESTS = [
url: EXAMPLE_URL + "beacon_request", url: EXAMPLE_URL + "beacon_request",
causeType: "beacon", causeType: "beacon",
causeUri: CAUSE_URL, causeUri: CAUSE_URL,
stack: [{ fn: "performBeaconRequest", file: CAUSE_FILE_NAME, line: 32 }] stack: [{ fn: "performBeaconRequest", file: CAUSE_FILE_NAME, line: 50 }]
}, },
]; ];

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

@ -17,34 +17,48 @@
<img src="img_request" /> <img src="img_request" />
<script type="text/javascript"> <script type="text/javascript">
"use strict"; "use strict";
function performXhrRequest() { function performXhrRequest() {
const xhr = new XMLHttpRequest(); const xhr = new XMLHttpRequest();
xhr.open("GET", "xhr_request", true); xhr.open("GET", "xhr_request", true);
xhr.send(); return new Promise(function performXhrRequestCallback(resolve) {
xhr.onload = resolve;
xhr.send();
});
} }
function performFetchRequest() { function performFetchRequest() {
fetch("fetch_request"); return fetch("fetch_request");
}
// Perform some requests with async stacks
function performPromiseFetchRequest() {
return Promise.resolve().then(function performPromiseFetchRequestCallback() {
return fetch("promise_fetch_request");
});
}
function performTimeoutFetchRequest() {
return new Promise(function performTimeoutFetchRequestCallback1(resolve) {
setTimeout(function performTimeoutFetchRequestCallback2() {
resolve(fetch("timeout_fetch_request"));
}, 0);
});
} }
function performBeaconRequest() { function performBeaconRequest() {
navigator.sendBeacon("beacon_request"); navigator.sendBeacon("beacon_request");
} }
performXhrRequest(); (async function() {
performFetchRequest(); await performXhrRequest();
await performFetchRequest();
await performPromiseFetchRequest();
await performTimeoutFetchRequest();
// Perform some requests with async stacks // Finally, send a beacon request
Promise.resolve().then(function performPromiseFetchRequest() { performBeaconRequest();
fetch("promise_fetch_request"); })();
setTimeout(function performTimeoutFetchRequest() {
fetch("timeout_fetch_request");
// Finally, send a beacon request
performBeaconRequest();
}, 0);
});
</script> </script>
</body> </body>
</html> </html>