typing-space-in-editable-button.tentative.html (3369B)
1 <!doctype html> 2 <head> 3 <meta charset="utf-8"> 4 <title>Tests for pressing space in editable button element</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-vendor.js"></script> 9 <script src="/resources/testdriver-actions.js"></script> 10 </head> 11 <body> 12 <button contenteditable>HelloWorld</button> 13 <div contenteditable><button>HelloWorld</button></div> 14 <button><div contenteditable>HelloWorld</div></button> 15 <script> 16 "use strict"; 17 18 promise_test(async () => { 19 await new Promise(resolve => { 20 addEventListener("load", resolve, {once: true}); 21 }); 22 const button = document.querySelector("button[contenteditable]"); 23 getSelection().collapse(button.firstChild, "Hello".length); 24 let clickEvent = null; 25 button.addEventListener("click", event => clickEvent = event, {once: true}); 26 await new this.window.test_driver.Actions() 27 .keyDown("\uE00D") 28 .keyUp("\uE00D") 29 .send(); 30 assert_equals(button.textContent, "HelloWorld", "The button label shouldn't be changed"); 31 assert_not_equals(clickEvent, null, "Click event should be fired on the <button>"); 32 }, "Type space key in <button contenteditable> should be handled by the <button>"); 33 34 promise_test(async () => { 35 document.querySelector("div[contenteditable]").focus(); 36 const button = document.querySelector("div[contenteditable] > button"); 37 getSelection().collapse(button.firstChild, "Hello".length); 38 let clickEvent = null; 39 button.addEventListener("click", event => clickEvent = event, {once: true}); 40 await new this.window.test_driver.Actions() 41 .keyDown("\uE00D") 42 .keyUp("\uE00D") 43 .send(); 44 assert_equals(button.textContent, "Hello World", "A space should be inserted into the button label"); 45 assert_equals(clickEvent, null, "Click event should not be fired on the <button>"); 46 }, "Type space key in editable <button> shouldn't be handled by the <button> when it's not focused"); 47 48 promise_test(async () => { 49 const button = document.querySelector("div[contenteditable] > button"); 50 button.textContent = "HelloWorld"; 51 button.focus(); 52 let clickEvent = null; 53 button.addEventListener("click", event => clickEvent = event, {once: true}); 54 await new this.window.test_driver.Actions() 55 .keyDown("\uE00D") 56 .keyUp("\uE00D") 57 .send(); 58 assert_equals(button.textContent, "HelloWorld", "The button label shouldn't be changed"); 59 assert_not_equals(clickEvent, null, "Click event should be fired on the <button>"); 60 }, "Type space key in editable <button> should be handled by the <button> when it's focused"); 61 62 promise_test(async () => { 63 const div = document.querySelector("button > div[contenteditable]"); 64 div.focus(); 65 getSelection().collapse(div.firstChild, "Hello".length); 66 let clickEvent = null; 67 div.parentElement.addEventListener("click", event => clickEvent = event, {once: true}); 68 await new this.window.test_driver.Actions() 69 .keyDown("\uE00D") 70 .keyUp("\uE00D") 71 .send(); 72 assert_equals(div.textContent, "Hello World", "A space should be inserted into the button label"); 73 assert_equals(clickEvent, null, "Click event should not be fired on the <button>"); 74 }, "Type space key in editable element in <button> shouldn't be handled by the <button>"); 75 </script> 76 </body> 77 </html>