mathml-html-serializtion-on-copy.html (2388B)
1 <!doctype html> 2 <meta charset=utf-8> 3 <title>MathML HTML serialization on copy</title> 4 <script src="/resources/testharness.js"></script> 5 <script src="/resources/testharnessreport.js"></script> 6 <script src="/resources/testdriver.js"></script> 7 <script src="/resources/testdriver-vendor.js"></script> 8 <script src="/resources/testdriver-actions.js"></script> 9 <script src="../include/editor-test-utils.js"></script> 10 11 <div id="source" contenteditable="true"> 12 <math xmlns="http://www.w3.org/1998/Math/MathML"> 13 <mrow> 14 <mi>x</mi> 15 <mo>+</mo> 16 <mn>1</mn> 17 </mrow> 18 <msup> 19 <mi>a</mi> 20 <mn>2</mn> 21 </msup> 22 <msub> 23 <mi>b</mi> 24 <mn>1</mn> 25 </msub> 26 <mfrac> 27 <mn>1</mn> 28 <mn>2</mn> 29 </mfrac> 30 <msqrt> 31 <mi>x</mi> 32 </msqrt> 33 <mtable> 34 <mtr> 35 <mtd> 36 <mtext>text</mtext> 37 </mtd> 38 <mtd> 39 <ms>string</ms> 40 </mtd> 41 </mtr> 42 </mtable> 43 </math> 44 </div> 45 46 <div id="target" contenteditable="true"></div> 47 48 <script> 49 promise_test(async t => { 50 const sourceDiv = document.getElementById("source"); 51 await test_driver.click(sourceDiv); 52 53 const utils = new EditorTestUtils(sourceDiv); 54 await utils.sendSelectAllShortcutKey(); 55 await utils.sendCopyShortcutKey(); 56 57 const targetDiv = document.getElementById("target"); 58 await test_driver.click(targetDiv); 59 const targetUtils = new EditorTestUtils(targetDiv); 60 await targetUtils.sendPasteShortcutKey(); 61 62 const pastedMath = targetDiv.querySelector("math"); 63 assert_not_equals(pastedMath, null, "MathML element should be pasted"); 64 assert_equals(pastedMath.namespaceURI, "http://www.w3.org/1998/Math/MathML", 65 "Pasted MathML should have correct namespace"); 66 67 // Check that the entire MathML structure and content is preserved 68 const expectedInnerHTML = "<mrow><mi>x</mi><mo>+</mo><mn>1</mn></mrow>" + 69 "<msup><mi>a</mi><mn>2</mn></msup><msub><mi>b</mi><mn>1</mn></msub>" + 70 "<mfrac><mn>1</mn><mn>2</mn></mfrac><msqrt><mi>x</mi></msqrt>" + 71 "<mtable><mtr><mtd><mtext>text</mtext></mtd><mtd><ms>string</ms>" + 72 "</mtd></mtr></mtable>"; 73 assert_equals(pastedMath.innerHTML, expectedInnerHTML, 74 "Pasted MathML should preserve all structure and content"); 75 }, "MathML elements should preserve structure and content during copy-paste"); 76 </script>