Bug 1371395 Part 4: Add a test of media query list serialization of valid, invalid, and malformed types. draft
authorBrad Werth <bwerth@mozilla.com>
Mon, 07 Aug 2017 12:42:03 -0700
changeset 642161 73486b0d541049267fbfacd4a16491f984348085
parent 642160 e5aea588ccaf529ea9062a848a6066bf3c3f33f9
child 724919 1fcdf5cf84b2546d1958dbe0b82f120012e0e276
push id72664
push userbwerth@mozilla.com
push dateMon, 07 Aug 2017 19:42:56 +0000
bugs1371395
milestone57.0a1
Bug 1371395 Part 4: Add a test of media query list serialization of valid, invalid, and malformed types. MozReview-Commit-ID: IzKmbIuCZ5c
layout/style/test/mochitest.ini
layout/style/test/test_media_query_serialization.html
--- a/layout/style/test/mochitest.ini
+++ b/layout/style/test/mochitest.ini
@@ -235,16 +235,17 @@ skip-if = !stylo
 [test_keyframes_vendor_prefix.html]
 [test_load_events_on_stylesheets.html]
 [test_logical_properties.html]
 [test_media_queries.html]
 skip-if = android_version == '18' #debug-only failure; timed out #Android 4.3 aws only; bug 1030419
 [test_media_queries_dynamic.html]
 [test_media_queries_dynamic_xbl.html]
 [test_media_query_list.html]
+[test_media_query_serialization.html]
 [test_moz_device_pixel_ratio.html]
 [test_namespace_rule.html]
 [test_of_type_selectors.xhtml]
 [test_page_parser.html]
 [test_parse_eof.html]
 [test_parse_ident.html]
 [test_parse_rule.html]
 [test_parse_url.html]
new file mode 100644
--- /dev/null
+++ b/layout/style/test/test_media_query_serialization.html
@@ -0,0 +1,55 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+<title>Test media query list serialization</title>
+<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+<style>
+  @media PrInT {}
+  @media screen, PrInT, SPEECH {}
+
+  @media GARbAGE7 {}
+
+  @media NotAValidMediaType_!000 {}
+  @media NotAValidMediaType_!000, AlsoInvalid!!!! {}
+
+  @media PrInT, GARbAGE7, notAValidMediaType_!000 {}
+</style>
+<script type="application/javascript">
+
+SimpleTest.waitForExplicitFinish();
+
+function run() {
+  let expectedValues = [
+    // Valid types
+    ["print", "Valid media types are ascii lowercased."],
+    ["screen, print, speech", "Media query lists with only valid types are ascii lowercased."],
+
+    // Invalid types
+    ["garbage7", "Invalid media types are ascii lowercased."],
+
+    // Malformed types
+    ["not all", "Malformed media types are serialized to 'not all'."],
+    ["not all, not all", "Multiple malformed media types are each serialized to 'not all'."],
+
+    // Mixes
+    ["print, garbage7, not all", "Media query lists with a mix of valid, invalid, and malformed types serialize " +
+                                 "as lowercase with malformed types changed to 'not all'."],
+  ];
+
+  let sheet = document.styleSheets[1];
+
+  expectedValues.forEach(function (entry, index) {
+    let rule = sheet.cssRules[index];
+    let serializedList = rule.media.mediaText;
+    is(serializedList, entry[0], entry[1]);
+  });
+
+  SimpleTest.finish();
+}
+
+</script>
+</head>
+<body onload="run()">
+</body>
+</html>