test_video_stats_resistfingerprinting.html (3828B)
1 <!DOCTYPE HTML> 2 <html> 3 <!-- 4 Mozilla Bug: 5 https://bugzilla.mozilla.org/show_bug.cgi?id=1369309 6 Tor Ticket: 7 https://trac.torproject.org/projects/tor/ticket/15757 8 --> 9 <head> 10 <meta charset="utf-8"> 11 <title>Test for Bug 1369309</title> 12 <script src="/tests/SimpleTest/SimpleTest.js"></script> 13 <script type="application/javascript" src="manifest.js"></script> 14 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> 15 </head> 16 <body> 17 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=682299">Mozilla Bug 1369309</a> 18 <a target="_blank" href="https://trac.torproject.org/projects/tor/ticket/15757">Tor Ticket 15757</a> 19 20 <!-- The main testing script --> 21 <script class="testbody" type="text/javascript"> 22 var manager = new MediaTestManager; 23 const SPOOFED_FRAMES_PER_SECOND = 30; 24 const SPOOFED_DROPPED_RATIO = 0.01; 25 const MS_PER_TIME_ATOM = 100; // Not the default anymore, but what we test here. 26 // Push the setting of 'privacy.resistFingerprinting' into gTestPrefs, which 27 // will be set during MediaTestManager.runTests(). 28 gTestPrefs.push( 29 ["privacy.resistFingerprinting", true], 30 ["privacy.resistFingerprinting.reduceTimerPrecision.microseconds", MS_PER_TIME_ATOM * 1000], 31 ["privacy.resistFingerprinting.reduceTimerPrecision.jitter", false], 32 // We use 240p as the target resolution since 1080p is greater than every video 33 // source in our test suite, so we need to use 240p here for allowing us to 34 // test dropped rate here. 35 ["privacy.resistFingerprinting.target_video_res", 240] 36 ); 37 var testCases = [ 38 { name:"seek.webm", type:"video/webm", width:320, height:240, duration:3.966, drop: false }, 39 { name:"gizmo.mp4", type:"video/mp4", width:560, height:320, duration:5.56, drop: true } 40 ]; 41 42 function checkStats(v, shouldDrop) { 43 // Rounding the current time to 100ms. 44 const secondsPerAtom = MS_PER_TIME_ATOM / 1000; 45 const currentTimeAtoms = Math.floor(v.currentTime / secondsPerAtom); 46 const currentTime = currentTimeAtoms * secondsPerAtom; 47 let dropRate = 0; 48 49 if (shouldDrop) { 50 dropRate = SPOOFED_DROPPED_RATIO; 51 } 52 53 is(v.mozParsedFrames, parseInt(currentTime * SPOOFED_FRAMES_PER_SECOND, 10), 54 "mozParsedFrames should be spoofed if fingerprinting resistance is enabled"); 55 is(v.mozDecodedFrames, parseInt(currentTime * SPOOFED_FRAMES_PER_SECOND, 10), 56 "mozDecodedFrames should be spoofed if fingerprinting resistance is enabled"); 57 is(v.mozPresentedFrames, 58 parseInt(currentTime * SPOOFED_FRAMES_PER_SECOND * (1 - dropRate), 10), 59 "mozPresentedFrames should be spoofed if fingerprinting resistance is enabled"); 60 is(v.mozPaintedFrames, 61 parseInt(currentTime * SPOOFED_FRAMES_PER_SECOND * (1 - dropRate), 10), 62 "mozPaintedFrames should be spoofed if fingerprinting resistance is enabled"); 63 is(v.mozFrameDelay, 0.0, 64 "mozFrameDelay should be 0.0 if fingerprinting resistance is enabled"); 65 let playbackQuality = v.getVideoPlaybackQuality(); 66 is(playbackQuality.totalVideoFrames, parseInt(currentTime * SPOOFED_FRAMES_PER_SECOND, 10), 67 "VideoPlaybackQuality.totalVideoFrames should be spoofed if fingerprinting resistance is enabled"); 68 is(playbackQuality.droppedVideoFrames, parseInt(currentTime * SPOOFED_FRAMES_PER_SECOND * dropRate, 10), 69 "VideoPlaybackQuality.droppedVideoFrames should be spoofed if fingerprinting resistance is enabled"); 70 } 71 72 function startTest(test, token) { 73 let v = document.createElement("video"); 74 v.token = token; 75 v.src = test.name; 76 manager.started(token); 77 once(v, "ended", () => { 78 checkStats(v, test.drop); 79 removeNodeAndSource(v); 80 manager.finished(v.token); 81 }); 82 v.play(); 83 } 84 85 manager.runTests(testCases, startTest); 86 87 </script> 88 </body> 89 </html>