Skip to content
Permalink
Browse files
Bug #16315: Test spoofed media queries in picture elements
  • Loading branch information
arthuredelstein committed Jun 21, 2015
1 parent 5602274 commit 930a4c9a701ffd137bed058ddf948ca2cd12fcf2
Showing with 35 additions and 6 deletions.
  1. BIN tbb-tests/match.png
  2. BIN tbb-tests/mismatch.png
  3. +3 −0 tbb-tests/mochitest.ini
  4. +32 −6 tbb-tests/test_tor_bug2875.html
BIN +1.18 KB tbb-tests/match.png
Binary file not shown.
BIN +1.54 KB tbb-tests/mismatch.png
Binary file not shown.
@@ -1,4 +1,7 @@
[DEFAULT]
support-files =
match.png
mismatch.png

[test_tor_bug2874.html]
[test_tor_bug2875.html]
@@ -9,7 +9,11 @@
<title>Test for Tor Bug #2875: Limit device and system specific CSS Media Queries</title>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
<script type="application/javascript">
<script type="application/javascript;version=1.7">
let test = function () {

SimpleTest.waitForExplicitFinish();

var keyValMatches = ([key, val]) => matchMedia("(" + key + ":" + val +")").matches;

// Default spoofed values by Tor Browser:
@@ -51,23 +55,45 @@
];

tor_suppressed_toggles.map(key => ok(!keyValMatches([key, 0]) && !keyValMatches([key, 1]),
key + " should not exist."));
key + " should not exist."));

var foundOSVersion = false;
["windows-xp", "windows-vista", "windows-win7", "windows-win8"].map(function (val) {
foundOSVersion = foundOSVersion || keyValMatches(["-moz-os-version", val]);
});
ok(!foundOSVersion, "-moz-os-version should have no match");


// Test media queries in picture elements (Tor Bug #16315)
let lines = "";
for (let [query, expected] of tor_defaults) {
lines += "<picture>\n";
lines += " <source srcset='match.png' media='(" + query + ": " + expected + ")'>\n";
lines += " <img class='testImage' src='mismatch.png' alt='" + query + "'>\n";
lines += "</picture><br>\n";
}
document.getElementById("content").innerHTML += lines;
var testImages = document.getElementsByClassName("testImage");
window.setTimeout(function () {
for (let testImage of testImages) {
ok(testImage.currentSrc.endsWith("/match.png"), "Media query in picture should match.");
}
SimpleTest.finish();
}, 0);

};

</script>
</head>
<body>
<a target="_blank" href="https://trac.torproject.org/projects/tor/ticket/2875">Tor Bug 2875</a>
<p id="display"></p>
<div id="content" style="display: none">

</div>
<div id="content"></div>
<pre id="test">
</pre>
<script>
window.onload = function () {
test();
}
</script>
</body>
</html>

0 comments on commit 930a4c9

Please sign in to comment.