browser_grids_restored-after-reload.js (3425B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 // Tests that the grid highlighter is re-displayed after reloading a page and the grid 7 // item is highlighted. 8 9 const TEST_URI = ` 10 <style type='text/css'> 11 #grid { 12 display: grid; 13 } 14 </style> 15 <div id="grid"> 16 <div id="cell1">cell1</div> 17 <div id="cell2">cell2</div> 18 </div> 19 `; 20 21 const OTHER_URI = ` 22 <style type='text/css'> 23 #grid { 24 display: grid; 25 } 26 </style> 27 <div id="grid"> 28 <div id="cell1">cell1</div> 29 <div id="cell2">cell2</div> 30 <div id="cell3">cell3</div> 31 </div> 32 `; 33 34 add_task(async function () { 35 await addTab("data:text/html;charset=utf-8," + encodeURIComponent(TEST_URI)); 36 const { gridInspector, inspector } = await openLayoutView(); 37 const { document: doc } = gridInspector; 38 const { highlighters, store } = inspector; 39 const HIGHLIGHTER_TYPE = inspector.highlighters.TYPES.GRID; 40 const { waitForHighlighterTypeRestored, waitForHighlighterTypeDiscarded } = 41 getHighlighterTestHelpers(inspector); 42 43 await selectNode("#grid", inspector); 44 const gridList = doc.getElementById("grid-list"); 45 const checkbox = gridList.children[0].querySelector("input"); 46 47 info("Toggling ON the CSS grid highlighter from the layout panel."); 48 const onHighlighterShown = highlighters.once("grid-highlighter-shown"); 49 const onCheckboxChange = waitUntilState( 50 store, 51 state => state.grids.length == 1 && state.grids[0].highlighted 52 ); 53 checkbox.click(); 54 await onHighlighterShown; 55 await onCheckboxChange; 56 57 info( 58 "Check that the CSS grid highlighter is created and the saved grid state." 59 ); 60 is(highlighters.gridHighlighters.size, 1, "CSS grid highlighter is shown."); 61 is( 62 highlighters.state.grids.size, 63 1, 64 "There's a saved grid state to be restored." 65 ); 66 67 info( 68 "Reload the page, expect the highlighter to be displayed once again and " + 69 "grid is checked" 70 ); 71 const onRestored = waitForHighlighterTypeRestored(HIGHLIGHTER_TYPE); 72 let onGridListRestored = waitUntilState( 73 store, 74 state => state.grids.length == 1 && state.grids[0].highlighted 75 ); 76 77 const onReloaded = inspector.once("reloaded"); 78 await reloadBrowser(); 79 info("Wait for inspector to be reloaded after page reload"); 80 await onReloaded; 81 82 await onRestored; 83 await onGridListRestored; 84 85 info( 86 "Check that the grid highlighter can be displayed after reloading the page" 87 ); 88 is(highlighters.gridHighlighters.size, 1, "CSS grid highlighter is shown."); 89 is( 90 highlighters.state.grids.size, 91 1, 92 "The saved grid state has the correct number of saved states." 93 ); 94 95 info( 96 "Navigate to another URL, and check that the highlighter is hidden and " + 97 "grid is unchecked" 98 ); 99 const otherUri = 100 "data:text/html;charset=utf-8," + encodeURIComponent(OTHER_URI); 101 const onDiscarded = waitForHighlighterTypeDiscarded(HIGHLIGHTER_TYPE); 102 onGridListRestored = waitUntilState( 103 store, 104 state => state.grids.length == 1 && !state.grids[0].highlighted 105 ); 106 await navigateTo(otherUri); 107 await onDiscarded; 108 await onGridListRestored; 109 110 info( 111 "Check that the grid highlighter is hidden after navigating to a different page" 112 ); 113 ok(!highlighters.gridHighlighters.size, "CSS grid highlighter is hidden."); 114 ok(!highlighters.state.grids.size, "No grids to be restored on page reload."); 115 });