forked from mozilla/gecko-dev
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug 1392408 Part 6 - Add test for capturing worker stacks in net moni…
…tor, r=ochameau. --HG-- extra : rebase_source : 4d4c0e454dbe607462875a655aa407cfc9d57075
- Loading branch information
1 parent
0a2217b
commit 239349e
Showing
7 changed files
with
192 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletions
100
devtools/client/netmonitor/test/browser_net_worker_stacks.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
/* Any copyright is dedicated to the Public Domain. | ||
http://creativecommons.org/publicdomain/zero/1.0/ */ | ||
|
||
"use strict"; | ||
|
||
// Test that we get stack traces for the network requests made when starting or | ||
// running worker threads. | ||
|
||
const TOP_FILE_NAME = "html_worker-test-page.html"; | ||
const TOP_URL = EXAMPLE_URL + TOP_FILE_NAME; | ||
const WORKER_FILE_NAME = "js_worker-test.js"; | ||
const WORKER_URL = EXAMPLE_URL + WORKER_FILE_NAME; | ||
|
||
const EXPECTED_REQUESTS = [ | ||
{ | ||
method: "GET", | ||
url: TOP_URL, | ||
causeType: "document", | ||
causeUri: null, | ||
stack: true, | ||
}, | ||
{ | ||
method: "GET", | ||
url: WORKER_URL, | ||
causeType: "script", | ||
causeUri: TOP_URL, | ||
stack: [ | ||
{ fn: "startWorkerInner", file: TOP_FILE_NAME, line: 11 }, | ||
{ fn: "startWorker", file: TOP_FILE_NAME, line: 8 }, | ||
{ file: TOP_FILE_NAME, line: 4 }, | ||
], | ||
}, | ||
{ | ||
method: "GET", | ||
url: EXAMPLE_URL + "missing1.js", | ||
causeType: "script", | ||
causeUri: TOP_URL, | ||
stack: [ | ||
{ fn: "importScriptsFromWorker", file: WORKER_FILE_NAME, line: 14 }, | ||
{ file: WORKER_FILE_NAME, line: 10 }, | ||
], | ||
}, | ||
{ | ||
method: "GET", | ||
url: EXAMPLE_URL + "missing2.js", | ||
causeType: "script", | ||
causeUri: TOP_URL, | ||
stack: [ | ||
{ fn: "importScriptsFromWorker", file: WORKER_FILE_NAME, line: 14 }, | ||
{ file: WORKER_FILE_NAME, line: 10 }, | ||
], | ||
}, | ||
{ | ||
method: "GET", | ||
url: EXAMPLE_URL + "js_worker-test2.js", | ||
causeType: "script", | ||
causeUri: TOP_URL, | ||
stack: [ | ||
{ fn: "startWorkerFromWorker", file: WORKER_FILE_NAME, line: 7 }, | ||
{ file: WORKER_FILE_NAME, line: 3 }, | ||
], | ||
}, | ||
{ | ||
method: "GET", | ||
url: EXAMPLE_URL + "missing.json", | ||
causeType: "xhr", | ||
causeUri: TOP_URL, | ||
stack: [ | ||
{ fn: "createJSONRequest", file: WORKER_FILE_NAME, line: 22 }, | ||
{ file: WORKER_FILE_NAME, line: 18 }, | ||
], | ||
}, | ||
]; | ||
|
||
add_task(async function() { | ||
// Load a different URL first to instantiate the network monitor before we | ||
// load the page we're really interested in. | ||
const { tab, monitor } = await initNetMonitor(SIMPLE_URL); | ||
|
||
const { store, windowRequire, connector } = monitor.panelWin; | ||
const { | ||
getSortedRequests, | ||
} = windowRequire("devtools/client/netmonitor/src/selectors/index"); | ||
|
||
BrowserTestUtils.loadURI(tab.linkedBrowser, TOP_URL); | ||
|
||
await waitForNetworkEvents(monitor, EXPECTED_REQUESTS.length); | ||
|
||
is(store.getState().requests.requests.size, EXPECTED_REQUESTS.length, | ||
"All the page events should be recorded."); | ||
|
||
// Wait for stack traces from all requests. | ||
const requests = getSortedRequests(store.getState()); | ||
await Promise.all(requests.map(requestItem => | ||
connector.requestData(requestItem.id, "stackTrace"))); | ||
|
||
validateRequests(EXPECTED_REQUESTS, monitor); | ||
|
||
await teardown(monitor); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
devtools/client/netmonitor/test/html_worker-test-page.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<script> | ||
/* eslint-disable no-unused-vars */ | ||
"use strict"; | ||
startWorker(); | ||
|
||
var w; | ||
function startWorker() { | ||
startWorkerInner(); | ||
} | ||
function startWorkerInner() { | ||
w = new Worker("js_worker-test.js"); | ||
} | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* eslint-disable no-unused-vars, no-undef */ | ||
"use strict"; | ||
startWorkerFromWorker(); | ||
|
||
var w; | ||
function startWorkerFromWorker() { | ||
w = new Worker("js_worker-test2.js"); | ||
} | ||
|
||
importScriptsFromWorker(); | ||
|
||
function importScriptsFromWorker() { | ||
try { | ||
importScripts("missing1.js", "missing2.js"); | ||
} catch (e) {} | ||
} | ||
|
||
createJSONRequest(); | ||
|
||
function createJSONRequest() { | ||
const request = new XMLHttpRequest(); | ||
request.open("GET", "missing.json", true); | ||
request.send(null); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
"use strict"; | ||
|
||
console.log("I AM A WORKER"); |