browser_jsonview_copy_rawdata.js (1596B)
1 /* Any copyright is dedicated to the Public Domain. 2 * http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 const TEST_JSON_URL = URL_ROOT + "simple_json.json"; 7 8 const jsonText = '{ "name": "value" }\n'; 9 const prettyJson = '{\n "name": "value"\n}'; 10 11 add_task(async function () { 12 info("Test copy raw data started"); 13 14 await addJsonViewTab(TEST_JSON_URL); 15 16 // Select the RawData tab 17 await selectJsonViewContentTab("rawdata"); 18 19 // Check displayed JSON 20 const text = await getElementText(".textPanelBox .data"); 21 is(text, jsonText, "Proper JSON must be displayed in DOM"); 22 23 const browser = gBrowser.selectedBrowser; 24 25 // Verify JSON copy into the clipboard. 26 await waitForClipboardPromise(function setup() { 27 BrowserTestUtils.synthesizeMouseAtCenter( 28 ".textPanelBox .toolbar button.copy", 29 {}, 30 browser 31 ); 32 }, jsonText); 33 34 // Click 'Pretty Print' button 35 await BrowserTestUtils.synthesizeMouseAtCenter( 36 ".textPanelBox .toolbar button.prettyprint", 37 {}, 38 browser 39 ); 40 41 let prettyText = await getElementText(".textPanelBox .data"); 42 prettyText = normalizeNewLines(prettyText); 43 ok( 44 prettyText.startsWith(prettyJson), 45 "Pretty printed JSON must be displayed" 46 ); 47 48 // Verify JSON copy into the clipboard. 49 await waitForClipboardPromise( 50 function setup() { 51 BrowserTestUtils.synthesizeMouseAtCenter( 52 ".textPanelBox .toolbar button.copy", 53 {}, 54 browser 55 ); 56 }, 57 function validator(value) { 58 const str = normalizeNewLines(value); 59 return str == prettyJson; 60 } 61 ); 62 });