test_action-take-snapshot.js (1799B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 /** 7 * Tests the async reducer responding to the action `takeSnapshot(front)` 8 */ 9 10 const actions = require("resource://devtools/client/memory/actions/snapshot.js"); 11 const { 12 snapshotState: states, 13 } = require("resource://devtools/client/memory/constants.js"); 14 15 add_task(async function () { 16 const front = new StubbedMemoryFront(); 17 await front.attach(); 18 const store = Store(); 19 20 const unsubscribe = store.subscribe(checkState); 21 22 let foundPendingState = false; 23 let foundDoneState = false; 24 25 function checkState() { 26 const { snapshots } = store.getState(); 27 const lastSnapshot = snapshots[snapshots.length - 1]; 28 29 if (lastSnapshot.state === states.SAVING) { 30 foundPendingState = true; 31 ok( 32 foundPendingState, 33 "Got state change for pending heap snapshot request" 34 ); 35 ok(!lastSnapshot.path, "Snapshot does not yet have a path"); 36 ok(!lastSnapshot.census, "Has no census data when loading"); 37 } else if (lastSnapshot.state === states.SAVED) { 38 foundDoneState = true; 39 ok( 40 foundDoneState, 41 "Got state change for completed heap snapshot request" 42 ); 43 ok(foundPendingState, "SAVED state occurs after SAVING state"); 44 ok(lastSnapshot.path, "Snapshot fetched with a path"); 45 ok( 46 snapshots.every(s => s.selected === (s.id === lastSnapshot.id)), 47 "Only recent snapshot is selected" 48 ); 49 } 50 } 51 52 for (let i = 0; i < 4; i++) { 53 store.dispatch(actions.takeSnapshot(front)); 54 await waitUntilState(store, () => foundPendingState && foundDoneState); 55 56 // reset state trackers 57 foundDoneState = foundPendingState = false; 58 } 59 60 unsubscribe(); 61 });