OLD | NEW |
(Empty) | |
| 1 <!doctype html> |
| 2 <html> |
| 3 <head> |
| 4 <meta charset=utf-8> |
| 5 <title>HTML time element API</title> |
| 6 <style> |
| 7 #time { visibility: hidden; } |
| 8 </style> |
| 9 <link rel="help" href="https://html.spec.whatwg.org/multipage/#the-time-elem
ent"> |
| 10 <script src="../../../../../../resources/testharness.js"></script> |
| 11 <script src="../../../../../../resources/testharnessreport.js"></script> |
| 12 </head> |
| 13 <body> |
| 14 <div id="log"></div> |
| 15 <!-- intentionally nested to test parsing rules --> |
| 16 <p id="time"><time pubdate datetime="2000-02-01T03:04:05Z">Dummy text <time>
2001-06-07T<time>08:09<time></time></time>Z</time></time></p> |
| 17 <script type="text/javascript"> |
| 18 function makeTime(dateTime,contents,dateTimeProp) { |
| 19 var timeEl = document.createElement('time'); |
| 20 if( dateTime ) { |
| 21 timeEl.setAttribute('datetime',dateTime); |
| 22 } |
| 23 if( contents ) { |
| 24 timeEl.innerHTML = contents; |
| 25 } |
| 26 if( dateTimeProp ) { |
| 27 timeEl.dateTime = dateTimeProp; |
| 28 } |
| 29 return timeEl; |
| 30 } |
| 31 |
| 32 var timep = document.getElementById('time'); |
| 33 var times = timep.getElementsByTagName('time'); |
| 34 |
| 35 //TIME elements |
| 36 test(function () { |
| 37 assert_equals( times.length, 4 ); |
| 38 }, 'HTML parsing should locate 4 time elements in this document'); |
| 39 test(function () { |
| 40 assert_true( !!window.HTMLTimeElement ); |
| 41 }, 'HTMLTimeElement should be exposed for prototyping'); |
| 42 test(function () { |
| 43 assert_true( makeTime() instanceof window.HTMLTimeElement, 'createElement vari
ant' ); |
| 44 assert_true( times[0] instanceof window.HTMLTimeElement, 'HTML parsing variant
' ); |
| 45 }, 'the time elements should be instanceof HTMLTimeElement'); |
| 46 |
| 47 //dateTime |
| 48 test(function () { |
| 49 assert_equals( makeTime('2000-02-01T03:04:05Z','2001-02-01T03:04:05Z').dateTim
e, '2000-02-01T03:04:05Z' ); |
| 50 }, 'the datetime attribute should be reflected by the .dateTime property'); |
| 51 test(function () { |
| 52 assert_equals( typeof makeTime().dateTime, 'string', 'typeof test' ); |
| 53 assert_equals( makeTime().dateTime, '', 'value test' ); |
| 54 }, 'the dateTime IDL property should default to an empty string'); |
| 55 test(function () { |
| 56 assert_equals( makeTime(false,false,'2000-02-01T03:04:05Z').dateTime, '2000-02
-01T03:04:05Z' ); |
| 57 }, 'the dateTime property should be read/write'); |
| 58 test(function () { |
| 59 assert_equals( makeTime('go fish').dateTime, 'go fish' ); |
| 60 }, 'the datetime attribute should be reflected by the .dateTime property even if
it is invalid'); |
| 61 test(function () { |
| 62 assert_equals( makeTime(false,'2000-02-01T03:04:05Z').dateTime, '' ); |
| 63 }, 'the datetime attribute should not reflect the textContent'); |
| 64 |
| 65 </script> |
| 66 |
| 67 </body> |
| 68 </html> |
OLD | NEW |