test_datetime.html (2587B)
1 <!doctype html> 2 <html> 3 <head> 4 <title>nsIAccessible value testing for datetime-local input element</title> 5 <link rel="stylesheet" 6 href="chrome://mochikit/content/tests/SimpleTest/test.css" /> 7 8 <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> 9 10 <script src="../common.js"></script> 11 <script src="../promisified-events.js"></script> 12 13 <script> 14 async function doTest() { 15 const dateTimeNode = getNode("datetime"); 16 const dateTime = getAccessible(dateTimeNode); 17 // We assume en-US for testing. However, the OS date format might 18 // override the en-US date format. 19 const monthFirst = dateTime.getChildAt(0).name == "Month"; 20 const month = dateTime.getChildAt(monthFirst ? 0 : 2); 21 const day = dateTime.getChildAt(monthFirst ? 2 : 0); 22 const year = dateTime.getChildAt(4); 23 const hour = dateTime.getChildAt(6); 24 const minute = dateTime.getChildAt(8); 25 const amPm = dateTime.getChildAt(10); 26 27 // We don't use testValue() because it also checks numeric value, but 28 // we don't support numeric value here because it isn't useful. 29 function assertIsClear() { 30 is(year.value, ""); 31 is(month.value, ""); 32 is(day.value, ""); 33 is(hour.value, ""); 34 is(minute.value, ""); 35 // Unlike the numeric fields, amPm is a textbox. Since textboxes take 36 // their a11y value from their text content and "--" is set as the text 37 // content, the a11y value is "--". 38 is(amPm.value, "--"); 39 } 40 41 info("Checking that input is initially clear"); 42 assertIsClear(); 43 44 // The container doesn't notify of value changes, so we wait for a value 45 // change on one of the fields to know when it's updated. 46 info("Setting value"); 47 let changed = waitForEvent(EVENT_TEXT_VALUE_CHANGE, month); 48 dateTimeNode.value = "2000-01-02T03:04"; 49 await changed; 50 is(year.value, "2000"); 51 is(month.value, "01"); 52 is(day.value, "02"); 53 is(hour.value, "03"); 54 is(minute.value, "04"); 55 // Again, the OS date format might override, so we might get "am" instead 56 // of "AM". 57 is(amPm.value.toLowerCase(), "am"); 58 59 info("Clearing value"); 60 changed = waitForEvent(EVENT_TEXT_VALUE_CHANGE, month); 61 dateTimeNode.value = ""; 62 await changed; 63 assertIsClear(); 64 65 SimpleTest.finish(); 66 } 67 68 SimpleTest.waitForExplicitFinish(); 69 addA11yLoadEvent(doTest); 70 </script> 71 </head> 72 73 <body> 74 <input type="datetime-local" id="datetime"> 75 </body> 76 </html>