Bug 1413754: Add tests for parsing of non-content-exposed media queries. r?xidorn
MozReview-Commit-ID: 4B8EPLboM4G
--- a/layout/style/test/chrome/chrome.ini
+++ b/layout/style/test/chrome/chrome.ini
@@ -10,16 +10,17 @@ support-files =
mismatch.png
[test_bug1346623.html]
[test_bug1371453.html]
[test_bug418986-2.xul]
[test_bug1157097.html]
[test_bug1160724.xul]
[test_bug535806.xul]
+[test_chrome_only_media_queries.html]
[test_display_mode.html]
tags = fullscreen
[test_display_mode_reflow.html]
tags = fullscreen
[test_hover.html]
skip-if = stylo # bug 1346353
[test_moz_document_rules.html]
[test_stylesheet_clone_import_rule.html]
new file mode 100644
--- /dev/null
+++ b/layout/style/test/chrome/test_chrome_only_media_queries.html
@@ -0,0 +1,85 @@
+<!doctype html>
+<title>Test for parsing of non-content-exposed media-queries.</title>
+<script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
+<style></style>
+<script>
+const SHEET = document.querySelector('style');
+
+function expect(q, shouldBeParseable) {
+ const NOT_PARSEABLE_TEXT = "@media screen, not all {\n}";
+
+ let text = "@media screen, " + q + " {\n}";
+ SHEET.textContent = text;
+
+ let rules = SHEET.sheet.cssRules;
+ is(rules.length, 1, `Rule not parsed for ${q}`);
+ is(rules[0].cssText,
+ shouldBeParseable ? text : NOT_PARSEABLE_TEXT,
+ `Serialization for ${q}`);
+}
+
+function expectParseable(q) {
+ expect(q, true);
+}
+
+function expectNonParseable(q) {
+ expect(q, false);
+}
+
+// Test a toggle that should always match for `1` or `0`.
+function testToggle(toggle) {
+ expectParseable(`(${toggle})`);
+ expectParseable(`(${toggle}: 1)`);
+ expectParseable(`(${toggle}: 0)`);
+
+ expectNonParseable(`(${toggle}: foo)`);
+ expectNonParseable(`(min-${toggle}: 0)`);
+ expectNonParseable(`(max-${toggle}: 0)`);
+ expectNonParseable(`(max-${toggle})`);
+ expectNonParseable(`(min-${toggle})`);
+
+ let matches_1 = matchMedia(`(${toggle}: 1)`).matches;
+ let matches_0 = matchMedia(`(${toggle}: 0)`).matches;
+ isnot(matches_0, matches_1, `Should not match both true and false: ${toggle}`);
+ is(matches_0 || matches_1, true, `Should match at least one: ${toggle}`);
+}
+
+const TOGGLES = [
+ "-moz-is-glyph",
+ "-moz-scrollbar-start-backward",
+ "-moz-scrollbar-start-forward",
+ "-moz-scrollbar-end-backward",
+ "-moz-scrollbar-end-forward",
+ "-moz-overlay-scrollbars",
+ "-moz-windows-default-theme",
+ "-moz-mac-graphite-theme",
+ "-moz-mac-yosemite-theme",
+ "-moz-windows-accent-color-in-titlebar",
+ "-moz-windows-compositor",
+ "-moz-windows-classic",
+ "-moz-windows-glass",
+ "-moz-swipe-animation-enabled",
+ "-moz-touch-enabled",
+];
+
+for (let i = 0; i < TOGGLES.length; ++i) {
+ testToggle(TOGGLES[i])
+}
+
+expectParseable("(-moz-windows-theme: aero)");
+expectParseable("(-moz-windows-theme: aero-lite)");
+expectParseable("(-moz-windows-theme: luna-blue)");
+expectParseable("(-moz-windows-theme: luna-olive)");
+expectParseable("(-moz-windows-theme: luna-silver)");
+expectParseable("(-moz-windows-theme: royale)");
+expectParseable("(-moz-windows-theme: generic)");
+expectParseable("(-moz-windows-theme: zune)");
+expectParseable("(-moz-windows-theme: garbage)");
+expectNonParseable("(-moz-windows-theme: '')");
+expectNonParseable("(-moz-windows-theme: )");
+
+expectParseable("(-moz-os-version: windows-win7)");
+expectParseable("(-moz-os-version: windows-win8)");
+expectParseable("(-moz-os-version: windows-win10)");
+expectNonParseable("(-moz-os-version: )");
+</script>