medialist-interfaces-001.html (2803B)
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <title>CSS Test: CSSOM Media Query List Serialization</title> 5 <link rel="author" title="Ben Sheldon" href="mailto:ben@codeforamerica.org"> 6 <link rel="author" title="Chapman Shoop" href="mailto:chapman.shoop@gmail.com"> 7 <link rel="help" href="http://www.w3.org/TR/cssom-1/#the-medialist-interface"> 8 <link rel="help" href="http://www.w3.org/TR/cssom-1/#serializing-media-queries"> 9 <link rel="help" href="http://www.w3.org/TR/cssom-1/#serialize-a-media-query-list"> 10 <meta name="flags" content="dom"> 11 <meta name="assert" content="MediaLists are serialized according to the specification"> 12 <script src="/resources/testharness.js" type="text/javascript"></script> 13 <script src="/resources/testharnessreport.js" type="text/javascript"></script> 14 </head> 15 <body> 16 <noscript>Test not run - javascript required.</noscript> 17 <div id="log"></div> 18 <script type="text/javascript"> 19 20 var styleElement; 21 var styleSheet; 22 var mediaList; 23 24 // Setup 25 function setup() { 26 styleElement = document.getElementById("styleElement"); 27 28 if (styleElement) { 29 // teardown 30 document.getElementsByTagName("head")[0].removeChild(styleElement); 31 styleElement = undefined; 32 styleSheet = undefined; 33 mediaList = undefined; 34 } 35 36 styleElement = document.createElement("style"); 37 styleElement.id = "styleElement"; 38 styleElement.type = "text/css"; 39 styleElement.media = "all"; 40 document.getElementsByTagName("head")[0].appendChild(styleElement); 41 styleSheet = styleElement.sheet; 42 mediaList = styleSheet.media; 43 } 44 45 // MediaList.mediaText equals the 'media' value of the initial 'style' element. 46 test(function() { 47 setup(); 48 49 assert_equals(mediaList.mediaText, "all"); 50 51 }, "mediatest_medialist_serialize_element"); 52 53 // To serialize a comma-separated list concatenate all items of the list in list order while separating them by \",\" (U+002C), followed by a space (U+0020). 54 test(function() { 55 setup(); 56 57 mediaList.appendMedium('screen'); 58 assert_equals(mediaList.mediaText, "all, screen"); 59 60 }, "mediatest_medialist_serialize_comma"); 61 62 // If the media query list is empty return the empty string. 63 test(function() { 64 setup(); 65 66 mediaList.deleteMedium('all'); 67 assert_equals(mediaList.mediaText, ""); 68 69 }, "mediatest_medialist_serialize_empty"); 70 71 // Each media query should be sorted in the same order as they appear in the list of media queries. 72 test(function() { 73 setup(); 74 75 mediaList.appendMedium('screen'); 76 mediaList.appendMedium('print'); 77 assert_equals(mediaList.mediaText, "all, screen, print"); 78 79 }, "mediatest_medialist_serialize_order"); 80 81 </script> 82 </body> 83 </html>