test_input_datetime_focus_blur.html (2158B)
1 <!DOCTYPE HTML> 2 <html> 3 <!-- 4 https://bugzilla.mozilla.org/show_bug.cgi?id=1288591 5 --> 6 <head> 7 <title>Test focus/blur behaviour for date/time input types</title> 8 <script src="/tests/SimpleTest/SimpleTest.js"></script> 9 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> 10 </head> 11 <body> 12 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1288591">Mozilla Bug 1288591</a> 13 <p id="display"></p> 14 <div id="content"> 15 <input id="input_time" type="time"> 16 <input id="input_date" type="date"> 17 <input id="input_datetime-local" type="datetime-local"> 18 </div> 19 <pre id="test"> 20 <script type="application/javascript"> 21 22 /** 23 * Test for Bug 1288591. 24 * This test checks whether date/time input types' .focus()/.blur() works 25 * correctly. This test also checks when focusing on an date/time input element, 26 * the focus is redirected to the anonymous text control, but the 27 * document.activeElement still returns date/time input element. 28 */ 29 SimpleTest.waitForExplicitFinish(); 30 SimpleTest.waitForFocus(function() { 31 test(); 32 SimpleTest.finish(); 33 }); 34 35 function testFocusBlur(type) { 36 let input = document.getElementById("input_" + type); 37 input.focus(); 38 39 // The active element returns the date/time input element. 40 let activeElement = document.activeElement; 41 is(activeElement, input, "activeElement should be the date/time input element"); 42 is(activeElement.localName, "input", "activeElement should be an input element"); 43 is(activeElement.type, type, "activeElement should be of type " + type); 44 45 // Use FocusManager to check that the actual focus is on the anonymous 46 // text control. 47 let fm = SpecialPowers.Cc["@mozilla.org/focus-manager;1"] 48 .getService(SpecialPowers.Ci.nsIFocusManager); 49 let focusedElement = fm.focusedElement; 50 is(focusedElement.localName, "span", "focusedElement should be an span element"); 51 52 input.blur(); 53 isnot(document.activeElement, input, "activeElement should no longer be the datetime input element"); 54 } 55 56 function test() { 57 for (let inputType of ["time", "date", "datetime-local"]) { 58 testFocusBlur(inputType); 59 } 60 } 61 </script> 62 </pre> 63 </body> 64 </html>