browser_changes_copy_declaration.js (2038B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 // Test that the Changes panel Copy Declaration context menu item will populate the 7 // clipboard with the changed declaration. 8 9 const TEST_URI = ` 10 <style type='text/css'> 11 div { 12 color: red; 13 margin: 0; 14 } 15 </style> 16 <div></div> 17 `; 18 19 const EXPECTED_CLIPBOARD_REMOVED = `/* color: red; */`; 20 const EXPECTED_CLIPBOARD_ADDED = `color: green;`; 21 22 add_task(async function () { 23 await addTab("data:text/html;charset=utf-8," + encodeURIComponent(TEST_URI)); 24 const { inspector, view: ruleView } = await openRuleView(); 25 const changesView = selectChangesView(inspector); 26 const { document: panelDoc, store } = changesView; 27 28 await selectNode("div", inspector); 29 const onTrackChange = waitForDispatch(store, "TRACK_CHANGE"); 30 await updateDeclaration(ruleView, 1, { color: "red" }, { color: "green" }); 31 await onTrackChange; 32 33 info( 34 "Click the Copy Declaration context menu item for the removed declaration" 35 ); 36 const removeDecl = getRemovedDeclarations(panelDoc); 37 const addDecl = getAddedDeclarations(panelDoc); 38 39 let menu = await getChangesContextMenu(changesView, removeDecl[0].element); 40 let menuItem = menu.items.find( 41 item => item.id === "changes-contextmenu-copy-declaration" 42 ); 43 await waitForClipboardPromise( 44 () => menuItem.click(), 45 () => checkClipboardData(EXPECTED_CLIPBOARD_REMOVED) 46 ); 47 48 info("Hiding menu"); 49 menu.hide(document); 50 51 info( 52 "Click the Copy Declaration context menu item for the added declaration" 53 ); 54 menu = await getChangesContextMenu(changesView, addDecl[0].element); 55 menuItem = menu.items.find( 56 item => item.id === "changes-contextmenu-copy-declaration" 57 ); 58 await waitForClipboardPromise( 59 () => menuItem.click(), 60 () => checkClipboardData(EXPECTED_CLIPBOARD_ADDED) 61 ); 62 }); 63 64 function checkClipboardData(expected) { 65 const actual = SpecialPowers.getClipboardData("text/plain"); 66 return actual.trim() === expected.trim(); 67 }