edit-context-execCommand.tentative.https.html (5217B)
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <title>EditContext: document.execCommand</title> 5 <script src="/resources/testharness.js"></script> 6 <script src="/resources/testharnessreport.js"></script> 7 <script src="/resources/testdriver.js"></script> 8 <script src="/resources/testdriver-actions.js"></script> 9 <script src="/resources/testdriver-vendor.js"></script> 10 <script src="../../clipboard-apis/resources/user-activation.js"></script> 11 </head> 12 <body> 13 <script> 14 promise_test(async function() { 15 const editContext = new EditContext(); 16 const test = document.createElement("div"); 17 document.body.appendChild(test); 18 let firedTextUpdate = false; 19 editContext.addEventListener("textupdate", e => { 20 firedTextUpdate = true; 21 }); 22 test.editContext = editContext; 23 test.focus(); 24 25 assert_true(document.queryCommandSupported("inserttext"), "'inserttext' should be supported regardless of focus position"); 26 assert_false(document.queryCommandEnabled("inserttext"), "'inserttext' should not be supported in EditContext"); 27 28 document.execCommand("inserttext", false, "a"); 29 assert_equals(test.innerHTML, "", "DOM should not be updated from execCommand('inserttext')"); 30 assert_false(firedTextUpdate, "textupdate should not fire for to execCommand('inserttext')"); 31 test.remove(); 32 }, 'document.execCommand("inserttext") should not change the DOM or fire textupdate'); 33 34 promise_test(async function() { 35 const editContext = new EditContext(); 36 const test = document.createElement("div"); 37 test.innerHTML = "abc"; 38 document.body.appendChild(test); 39 let firedTextUpdate = false; 40 editContext.addEventListener("textupdate", e => { 41 firedTextUpdate = true; 42 }); 43 test.editContext = editContext; 44 test.focus(); 45 46 assert_true(document.queryCommandSupported("bold"), "'bold' should be supported regardless of focus position"); 47 assert_false(document.queryCommandEnabled("bold"), "'bold' should not be supported in EditContext"); 48 49 document.execCommand("bold"); 50 assert_equals(test.innerHTML, "abc", "DOM should not be updated from execCommand('bold')"); 51 assert_false(firedTextUpdate, "textupdate should not fire for execCommand('bold')"); 52 test.remove(); 53 }, 'document.execCommand("bold") should not change the DOM or fire textupdate'); 54 55 promise_test(async function() { 56 const editContext = new EditContext(); 57 const test = document.createElement("div"); 58 test.innerHTML = "<b>ab</b>c"; 59 document.body.appendChild(test); 60 let firedTextUpdate = false; 61 editContext.addEventListener("textupdate", e => { 62 firedTextUpdate = true; 63 }); 64 test.editContext = editContext; 65 const selection = window.getSelection(); 66 selection.setBaseAndExtent(test.firstChild.firstChild, 0, test.firstChild.firstChild, 1); 67 68 assert_false(document.queryCommandState("bold"), "queryCommandState should always return false in EditContext"); 69 assert_equals(document.queryCommandValue("bold"), "false", "queryCommandValue should always return 'false' in EditContext for commands that return booleans"); 70 assert_equals(document.queryCommandValue("forecolor"), "", "queryCommandValue should always return empty string in EditContext for commands that return strings"); 71 72 selection.setBaseAndExtent(test.firstChild.firstChild, 1, test.lastChild, 1); 73 assert_false(document.queryCommandIndeterm("bold"), "'queryCommandInterm should always return false in EditContext"); 74 75 test.remove(); 76 }, 'queryCommandState, queryCommandvalue, and queryCommandInterm should always return false'); 77 78 promise_test(async function() { 79 const editContext = new EditContext(); 80 const test = document.createElement("div"); 81 test.innerHTML = "abc"; 82 document.body.appendChild(test); 83 let firedTextUpdate = false; 84 editContext.addEventListener("textupdate", e => { 85 firedTextUpdate = true; 86 }); 87 test.editContext = editContext; 88 test.focus(); 89 90 const selection = window.getSelection(); 91 selection.setBaseAndExtent(test.firstChild, 0, test.firstChild, 1); 92 93 await test_driver.set_permission({name: 'clipboard-read'}, 'granted'); 94 assert_true(document.execCommand("copy"), "'copy' always returns true regardless of whether it did anything"); 95 await waitForUserActivation(); 96 let clipboardText = await navigator.clipboard.readText(); 97 assert_equals(clipboardText, "a", "'copy' should work in EditContext"); 98 99 selection.setBaseAndExtent(test.firstChild, 1, test.firstChild, 2); 100 101 assert_true(document.execCommand("cut"), "'cut' always returns true regardless of whether it did anything"); 102 assert_equals(test.innerHTML, "abc", "DOM should not be updated from execCommand('cut')"); 103 await waitForUserActivation(); 104 clipboardText = await navigator.clipboard.readText(); 105 assert_equals(clipboardText, "a", "Failed 'cut' should not change clipboard"); 106 107 test.remove(); 108 }, 'document.execCommand("copy") should work but document.execCommand("cut") should not change the DOM or the clipboard'); 109 </script> 110 </body> 111 </html>