browser_changes_copy_rule.js (1941B)
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 Rule button and context menu will populate the 7 // clipboard with the entire contents of the changed rule, including unchanged properties. 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 // Indentation is important. A strict check will be done against the clipboard content. 20 const EXPECTED_CLIPBOARD = ` 21 div { 22 color: green; 23 margin: 0; 24 } 25 `; 26 27 add_task(async function () { 28 await addTab("data:text/html;charset=utf-8," + encodeURIComponent(TEST_URI)); 29 const { inspector, view: ruleView } = await openRuleView(); 30 const changesView = selectChangesView(inspector); 31 const { document: panelDoc, store } = changesView; 32 33 await selectNode("div", inspector); 34 const onTrackChange = waitForDispatch(store, "TRACK_CHANGE"); 35 await updateDeclaration(ruleView, 1, { color: "red" }, { color: "green" }); 36 await onTrackChange; 37 38 info("Click the Copy Rule button and expect the changed rule on clipboard"); 39 const button = panelDoc.querySelector(".changes__copy-rule-button"); 40 await waitForClipboardPromise( 41 () => button.click(), 42 () => checkClipboardData(EXPECTED_CLIPBOARD) 43 ); 44 45 emptyClipboard(); 46 47 info( 48 "Click the Copy Rule context menu item and expect the changed rule on the clipboard" 49 ); 50 const addDecl = getAddedDeclarations(panelDoc); 51 const menu = await getChangesContextMenu(changesView, addDecl[0].element); 52 const menuItem = menu.items.find( 53 item => item.id === "changes-contextmenu-copy-rule" 54 ); 55 await waitForClipboardPromise( 56 () => menuItem.click(), 57 () => checkClipboardData(EXPECTED_CLIPBOARD) 58 ); 59 }); 60 61 function checkClipboardData(expected) { 62 const actual = SpecialPowers.getClipboardData("text/plain"); 63 return actual.trim() === expected.trim(); 64 }