diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:22:09 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:22:09 +0000 |
commit | 43a97878ce14b72f0981164f87f2e35e14151312 (patch) | |
tree | 620249daf56c0258faa40cbdcf9cfba06de2a846 /devtools/client/memory/test/xpcshell/test_action-take-snapshot.js | |
parent | Initial commit. (diff) | |
download | firefox-43a97878ce14b72f0981164f87f2e35e14151312.tar.xz firefox-43a97878ce14b72f0981164f87f2e35e14151312.zip |
Adding upstream version 110.0.1.upstream/110.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'devtools/client/memory/test/xpcshell/test_action-take-snapshot.js')
-rw-r--r-- | devtools/client/memory/test/xpcshell/test_action-take-snapshot.js | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/devtools/client/memory/test/xpcshell/test_action-take-snapshot.js b/devtools/client/memory/test/xpcshell/test_action-take-snapshot.js new file mode 100644 index 0000000000..2e91c04909 --- /dev/null +++ b/devtools/client/memory/test/xpcshell/test_action-take-snapshot.js @@ -0,0 +1,61 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +/** + * Tests the async reducer responding to the action `takeSnapshot(front)` + */ + +const actions = require("resource://devtools/client/memory/actions/snapshot.js"); +const { + snapshotState: states, +} = require("resource://devtools/client/memory/constants.js"); + +add_task(async function() { + const front = new StubbedMemoryFront(); + await front.attach(); + const store = Store(); + + const unsubscribe = store.subscribe(checkState); + + let foundPendingState = false; + let foundDoneState = false; + + function checkState() { + const { snapshots } = store.getState(); + const lastSnapshot = snapshots[snapshots.length - 1]; + + if (lastSnapshot.state === states.SAVING) { + foundPendingState = true; + ok( + foundPendingState, + "Got state change for pending heap snapshot request" + ); + ok(!lastSnapshot.path, "Snapshot does not yet have a path"); + ok(!lastSnapshot.census, "Has no census data when loading"); + } else if (lastSnapshot.state === states.SAVED) { + foundDoneState = true; + ok( + foundDoneState, + "Got state change for completed heap snapshot request" + ); + ok(foundPendingState, "SAVED state occurs after SAVING state"); + ok(lastSnapshot.path, "Snapshot fetched with a path"); + ok( + snapshots.every(s => s.selected === (s.id === lastSnapshot.id)), + "Only recent snapshot is selected" + ); + } + } + + for (let i = 0; i < 4; i++) { + store.dispatch(actions.takeSnapshot(front)); + await waitUntilState(store, () => foundPendingState && foundDoneState); + + // reset state trackers + foundDoneState = foundPendingState = false; + } + + unsubscribe(); +}); |