browser_computed_select-and-copy-styles-01.js (2036B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 // Tests that properties can be selected and copied from the computed view. 7 8 const TEST_URI = ` 9 <style type="text/css"> 10 span { 11 font-variant-caps: small-caps; 12 color: #000000; 13 } 14 .nomatches { 15 color: #ff0000; 16 } 17 </style> 18 <div id="first" style="margin: 10em; 19 font-size: 14pt; font-family: helvetica, sans-serif; color: #AAA"> 20 <h1>Some header text</h1> 21 <p id="salutation" style="font-size: 12pt">hi.</p> 22 <p id="body" style="font-size: 12pt">I am a test-case. This text exists 23 solely to provide some things to <span style="color: yellow"> 24 highlight</span> and <span style="font-weight: bold">count</span> 25 style list-items in the box at right. If you are reading this, 26 you should go do something else instead. Maybe read a book. Or better 27 yet, write some test-cases for another bit of code. 28 <span style="font-style: italic">some text</span></p> 29 <p id="closing">more text</p> 30 <p>even more text</p> 31 </div> 32 `; 33 34 add_task(async function () { 35 await addTab("data:text/html;charset=utf-8," + encodeURIComponent(TEST_URI)); 36 const { inspector, view } = await openComputedView(); 37 await selectNode("span", inspector); 38 39 await testCopySome(view); 40 await testCopyAll(view); 41 }); 42 43 async function testCopySome(view) { 44 const expectedPattern = 45 "font-family: helvetica, sans-serif;[\\r\\n]+" + 46 "font-size: 16px;[\\r\\n]+" + 47 "font-variant-caps: small-caps;[\\r\\n]*"; 48 49 await copySomeTextAndCheckClipboard( 50 view, 51 { 52 start: { prop: 1, offset: 0 }, 53 end: { prop: 3, offset: 3 }, 54 }, 55 expectedPattern 56 ); 57 } 58 59 async function testCopyAll(view) { 60 const expectedPattern = 61 "color: rgb\\(255, 255, 0\\);[\\r\\n]+" + 62 "font-family: helvetica, sans-serif;[\\r\\n]+" + 63 "font-size: 16px;[\\r\\n]+" + 64 "font-variant-caps: small-caps;[\\r\\n]*"; 65 66 await copyAllAndCheckClipboard(view, expectedPattern); 67 }