browser_memory_keyboard.js (4023B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 // Bug 1246570 - Check that when pressing on LEFT arrow, the parent tree node 5 // gets focused. 6 7 "use strict"; 8 9 const { viewState } = require("resource://devtools/client/memory/constants.js"); 10 const { 11 takeSnapshotAndCensus, 12 } = require("resource://devtools/client/memory/actions/snapshot.js"); 13 const { 14 changeView, 15 } = require("resource://devtools/client/memory/actions/view.js"); 16 17 const TEST_URL = 18 "http://example.com/browser/devtools/client/memory/test/browser/doc_steady_allocation.html"; 19 20 function waitUntilFocused(store, node) { 21 return waitUntilState( 22 store, 23 state => 24 state.snapshots.length === 1 && 25 state.snapshots[0].census && 26 state.snapshots[0].census.state === censusState.SAVED && 27 state.snapshots[0].census.focused && 28 state.snapshots[0].census.focused === node 29 ); 30 } 31 32 function waitUntilExpanded(store, node) { 33 return waitUntilState( 34 store, 35 state => 36 state.snapshots[0] && 37 state.snapshots[0].census && 38 state.snapshots[0].census.expanded.has(node.id) 39 ); 40 } 41 42 this.test = makeMemoryTest(TEST_URL, async function ({ panel }) { 43 const heapWorker = panel.panelWin.gHeapAnalysesClient; 44 const store = panel.panelWin.gStore; 45 const { getState, dispatch } = store; 46 const front = getState().front; 47 const doc = panel.panelWin.document; 48 49 dispatch(changeView(viewState.CENSUS)); 50 51 is(getState().censusDisplay.breakdown.by, "coarseType"); 52 53 await dispatch(takeSnapshotAndCensus(front, heapWorker)); 54 const census = getState().snapshots[0].census; 55 const root1 = census.report.children[0]; 56 const root2 = census.report.children[0]; 57 const root3 = census.report.children[0]; 58 const root4 = census.report.children[0]; 59 const child1 = root1.children[0]; 60 61 info("Click on first node."); 62 const firstNode = doc.querySelector(".tree .heap-tree-item-name"); 63 EventUtils.synthesizeMouseAtCenter(firstNode, {}, panel.panelWin); 64 await waitUntilFocused(store, root1); 65 ok(true, "First root is selected after click."); 66 67 info("Press DOWN key, expect second root focused."); 68 EventUtils.synthesizeKey("VK_DOWN", {}, panel.panelWin); 69 await waitUntilFocused(store, root2); 70 ok(true, "Second root is selected after pressing DOWN arrow."); 71 72 info("Press DOWN key, expect third root focused."); 73 EventUtils.synthesizeKey("VK_DOWN", {}, panel.panelWin); 74 await waitUntilFocused(store, root3); 75 ok(true, "Third root is selected after pressing DOWN arrow."); 76 77 info("Press DOWN key, expect fourth root focused."); 78 EventUtils.synthesizeKey("VK_DOWN", {}, panel.panelWin); 79 await waitUntilFocused(store, root4); 80 ok(true, "Fourth root is selected after pressing DOWN arrow."); 81 82 info("Press UP key, expect third root focused."); 83 EventUtils.synthesizeKey("VK_UP", {}, panel.panelWin); 84 await waitUntilFocused(store, root3); 85 ok(true, "Third root is selected after pressing UP arrow."); 86 87 info("Press UP key, expect second root focused."); 88 EventUtils.synthesizeKey("VK_UP", {}, panel.panelWin); 89 await waitUntilFocused(store, root2); 90 ok(true, "Second root is selected after pressing UP arrow."); 91 92 info("Press UP key, expect first root focused."); 93 EventUtils.synthesizeKey("VK_UP", {}, panel.panelWin); 94 await waitUntilFocused(store, root1); 95 ok(true, "First root is selected after pressing UP arrow."); 96 97 info("Press RIGHT key"); 98 EventUtils.synthesizeKey("VK_RIGHT", {}, panel.panelWin); 99 await waitUntilExpanded(store, root1); 100 ok(true, "Root node is expanded."); 101 102 info("Press RIGHT key, expect first child focused."); 103 EventUtils.synthesizeKey("VK_RIGHT", {}, panel.panelWin); 104 await waitUntilFocused(store, child1); 105 ok(true, "First child is selected after pressing RIGHT arrow."); 106 107 info("Press LEFT key, expect first root focused."); 108 EventUtils.synthesizeKey("VK_LEFT", {}, panel.panelWin); 109 await waitUntilFocused(store, root1); 110 ok(true, "First root is selected after pressing LEFT arrow."); 111 });