Bug 1371395 Part 5: 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 643433 2edf3f37818fc9da4e24ce40bd3c07553e0681ca
parent 643432 b99c89204b3b998c2463c08b554984defb3e1c82
child 725300 05d495086d5a31467a0b5b8b1c280fb884769692
push id73096
push userbwerth@mozilla.com
push dateWed, 09 Aug 2017 18:48:00 +0000
bugs1371395
milestone57.0a1
Bug 1371395 Part 5: 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,53 @@
+<!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 AAAAA {}
+  @media ZZZZZ {}
+
+  @media NotAValidMediaType_!000 {}
+  @media NotAValidMediaType_!000, AlsoInvalid!!!! {}
+
+  @media PrInT, GARbAGE7, notAValidMediaType_!000 {}
+</style>
+<script type="application/javascript">
+
+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."],
+  ["aaaaa", "Ascii conversion handles 'A' correctly."],
+  ["zzzzz", "Ascii conversion handles 'Z' correctly."],
+
+  // 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]);
+});
+
+</script>
+</head>
+<body>
+</body>
+</html>