browser_net_post-data-json-payloads.js (3244B)
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 if the POST requests display the correct information in the UI, 8 * for JSON payloads. 9 */ 10 11 add_task(async function () { 12 const { 13 L10N, 14 } = require("resource://devtools/client/netmonitor/src/utils/l10n.js"); 15 16 const { tab, monitor } = await initNetMonitor(POST_JSON_URL, { 17 requestCount: 1, 18 }); 19 info("Starting test... "); 20 21 const { document, store, windowRequire } = monitor.panelWin; 22 const Actions = windowRequire("devtools/client/netmonitor/src/actions/index"); 23 24 store.dispatch(Actions.batchEnable(false)); 25 26 // Execute requests. 27 await performRequests(monitor, tab, 1); 28 29 // Wait for header and properties view to be displayed 30 const wait = waitForDOM(document, "#request-panel .data-header"); 31 let waitForContent = waitForDOM(document, "#request-panel .properties-view"); 32 store.dispatch(Actions.toggleNetworkDetails()); 33 clickOnSidebarTab(document, "request"); 34 await Promise.all([wait, waitForContent]); 35 36 const tabpanel = document.querySelector("#request-panel"); 37 38 ok( 39 tabpanel.querySelector(".treeTable"), 40 "The request params doesn't have the indended visibility." 41 ); 42 is( 43 tabpanel.querySelector(".cm-content") === null, 44 true, 45 "The request post data doesn't have the indended visibility." 46 ); 47 is( 48 tabpanel.querySelectorAll(".raw-data-toggle") !== null, 49 true, 50 "The raw request data toggle should be displayed in this tabpanel." 51 ); 52 is( 53 tabpanel.querySelectorAll(".empty-notice").length, 54 0, 55 "The empty notice should not be displayed in this tabpanel." 56 ); 57 58 is( 59 tabpanel.querySelector(".data-label").textContent, 60 L10N.getStr("jsonScopeName"), 61 "The post section doesn't have the correct title." 62 ); 63 64 const labels = tabpanel.querySelectorAll("tr .treeLabelCell .treeLabel"); 65 const values = tabpanel.querySelectorAll("tr .treeValueCell .objectBox"); 66 67 is(labels[0].textContent, "a", "The JSON var name was incorrect."); 68 is(values[0].textContent, "1", "The JSON var value was incorrect."); 69 70 // Toggle the raw data display. This should hide the formatted display. 71 waitForContent = waitForDOM(document, "#request-panel .cm-content"); 72 const rawDataToggle = document.querySelector( 73 "#request-panel .raw-data-toggle-input .devtools-checkbox-toggle" 74 ); 75 clickElement(rawDataToggle, monitor); 76 await waitForContent; 77 78 is( 79 tabpanel.querySelector(".data-label").textContent, 80 L10N.getStr("paramsPostPayload"), 81 "The post section doesn't have the correct title." 82 ); 83 is( 84 tabpanel.querySelector(".raw-data-toggle-input .devtools-checkbox-toggle") 85 .checked, 86 true, 87 "The raw request toggle should be on." 88 ); 89 is( 90 tabpanel.querySelector(".properties-view") === null, 91 true, 92 "The formatted display should be hidden." 93 ); 94 // Bug 1514750 - Show JSON request in plain text view also 95 ok( 96 tabpanel.querySelector(".cm-content"), 97 "The request post data doesn't have the indended visibility." 98 ); 99 ok( 100 getCodeMirrorValue(monitor).includes('{"a":1}'), 101 "The text shown in the source editor is incorrect." 102 ); 103 104 return teardown(monitor); 105 });