browser_compatibility_event_panel-select.js (4916B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 // Test the behavior when the panel is selected. 7 8 const TEST_URI = "<body style='background-color: lime;'><div>test</div></body>"; 9 const TEST_ANOTHER_URI = "<body></body>"; 10 11 const { 12 COMPATIBILITY_UPDATE_SELECTED_NODE_START, 13 COMPATIBILITY_UPDATE_TOP_LEVEL_TARGET_START, 14 } = require("resource://devtools/client/inspector/compatibility/actions/index.js"); 15 16 add_task(async function () { 17 info( 18 "Check that the panel does not update when no changes occur while hidden" 19 ); 20 21 await pushPref("devtools.inspector.activeSidebar", ""); 22 23 const tab = await addTab(_toDataURL(TEST_URI)); 24 const { inspector } = await openCompatibilityView(); 25 26 info("Select another sidebar panel"); 27 await _selectSidebarPanel(inspector, "changesview"); 28 29 info("Select the compatibility panel again"); 30 let isSelectedNodeUpdated = false; 31 let isTopLevelTargetUpdated = false; 32 waitForDispatch( 33 inspector.store, 34 COMPATIBILITY_UPDATE_SELECTED_NODE_START 35 ).then(() => { 36 isSelectedNodeUpdated = true; 37 }); 38 waitForDispatch( 39 inspector.store, 40 COMPATIBILITY_UPDATE_TOP_LEVEL_TARGET_START 41 ).then(() => { 42 isTopLevelTargetUpdated = true; 43 }); 44 45 await _selectSidebarPanel(inspector, "compatibilityview"); 46 47 // Check above both flags after taking enough time. 48 await wait(1000); 49 50 ok(!isSelectedNodeUpdated, "Avoid updating the selected node pane"); 51 ok(!isTopLevelTargetUpdated, "Avoid updating the top level target pane"); 52 53 await removeTab(tab); 54 }); 55 56 add_task(async function () { 57 info( 58 "Check that the panel only updates for the selected node when the node is changed while the panel is hidden" 59 ); 60 61 await pushPref("devtools.inspector.activeSidebar", ""); 62 63 const tab = await addTab(_toDataURL(TEST_URI)); 64 const { inspector } = await openCompatibilityView(); 65 66 info("Select another sidebar panel"); 67 await _selectSidebarPanel(inspector, "changesview"); 68 69 info("Select another node"); 70 await selectNode("div", inspector); 71 72 info("Select the compatibility panel again"); 73 const onSelectedNodePaneUpdated = waitForUpdateSelectedNodeAction( 74 inspector.store 75 ); 76 let isTopLevelTargetUpdated = false; 77 waitForDispatch( 78 inspector.store, 79 COMPATIBILITY_UPDATE_TOP_LEVEL_TARGET_START 80 ).then(() => { 81 isTopLevelTargetUpdated = true; 82 }); 83 84 await _selectSidebarPanel(inspector, "compatibilityview"); 85 86 await onSelectedNodePaneUpdated; 87 ok(true, "Update the selected node pane"); 88 ok(!isTopLevelTargetUpdated, "Avoid updating the top level target pane"); 89 90 await removeTab(tab); 91 }); 92 93 add_task(async function () { 94 info( 95 "Check that both panes update when the top-level target changed while the panel is hidden" 96 ); 97 98 await pushPref("devtools.inspector.activeSidebar", ""); 99 100 const tab = await addTab(_toDataURL(TEST_URI)); 101 const { inspector } = await openCompatibilityView(); 102 103 info("Select another sidebar panel"); 104 await _selectSidebarPanel(inspector, "changesview"); 105 106 info("Navigate to another page"); 107 BrowserTestUtils.startLoadingURIString( 108 tab.linkedBrowser, 109 _toDataURL(TEST_ANOTHER_URI) 110 ); 111 112 info("Select the compatibility panel again"); 113 const onSelectedNodePaneUpdated = waitForUpdateSelectedNodeAction( 114 inspector.store 115 ); 116 const onTopLevelTargetPaneUpdated = waitForUpdateTopLevelTargetAction( 117 inspector.store 118 ); 119 120 await _selectSidebarPanel(inspector, "compatibilityview"); 121 122 await onSelectedNodePaneUpdated; 123 await onTopLevelTargetPaneUpdated; 124 ok(true, "Update both panes"); 125 126 await removeTab(tab); 127 }); 128 129 add_task(async function () { 130 info( 131 "Check that both panes update when a rule is changed changed while the panel is hidden" 132 ); 133 134 await pushPref("devtools.inspector.activeSidebar", ""); 135 136 info("Disable 3 pane mode"); 137 await pushPref("devtools.inspector.three-pane-enabled", false); 138 139 const tab = await addTab(_toDataURL(TEST_URI)); 140 const { inspector } = await openCompatibilityView(); 141 142 info("Select rule view"); 143 await _selectSidebarPanel(inspector, "ruleview"); 144 145 info("Change a rule"); 146 await togglePropStatusOnRuleView(inspector, 0, 0); 147 148 info("Select the compatibility panel again"); 149 const onSelectedNodePaneUpdated = waitForUpdateSelectedNodeAction( 150 inspector.store 151 ); 152 const onTopLevelTargetPaneUpdated = waitForUpdateTopLevelTargetAction( 153 inspector.store 154 ); 155 156 await _selectSidebarPanel(inspector, "compatibilityview"); 157 158 await onSelectedNodePaneUpdated; 159 await onTopLevelTargetPaneUpdated; 160 ok(true, "Update both panes"); 161 162 await removeTab(tab); 163 }); 164 165 async function _selectSidebarPanel(inspector, toolId) { 166 const onSelected = inspector.sidebar.once(`${toolId}-selected`); 167 inspector.sidebar.select(toolId); 168 await onSelected; 169 } 170 171 function _toDataURL(content) { 172 return "data:text/html;charset=utf-8," + encodeURIComponent(content); 173 }