perftest_http3_youtube_watch.js (2272B)
1 // This Source Code Form is subject to the terms of the Mozilla Public 2 // License, v. 2.0. If a copy of the MPL was not distributed with this 3 // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 /* eslint-env node */ 5 6 /* 7 Ensure the `--firefox.preference=network.http.http3.enable:true` is 8 set for this test. 9 */ 10 11 async function test(context, commands) { 12 let rootUrl = "https://www.youtube.com/watch?v=COU5T-Wafa4"; 13 let waitTime = 20000; 14 15 if ( 16 (typeof context.options.browsertime !== "undefined") & 17 (typeof context.options.browsertime.waitTime !== "undefined") 18 ) { 19 waitTime = context.options.browsertime.waitTime; 20 } 21 22 // Make firefox learn of HTTP/3 server 23 await commands.navigate(rootUrl); 24 25 let cycles = 1; 26 for (let cycle = 0; cycle < cycles; cycle++) { 27 await commands.measure.start("pageload"); 28 await commands.navigate(rootUrl); 29 30 // Make sure the video is running 31 if ( 32 await commands.js.run(`return document.querySelector("video").paused;`) 33 ) { 34 throw new Error("Video should be running but it's paused"); 35 } 36 37 // Disable youtube autoplay 38 await commands.click.byIdAndWait("toggleButton"); 39 40 // Start playback quality measurements 41 const start = await commands.js.run(`return performance.now();`); 42 while ( 43 !(await commands.js.run(` 44 return document.querySelector("video").ended; 45 `)) & 46 !(await commands.js.run(` 47 return document.querySelector("video").paused; 48 `)) & 49 ((await commands.js.run(`return performance.now();`)) - start < waitTime) 50 ) { 51 await commands.wait.byTime(5000); 52 context.log.info("playing..."); 53 } 54 55 // Video done, now gather metrics 56 const playbackQuality = await commands.js.run( 57 `return document.querySelector("video").getVideoPlaybackQuality();` 58 ); 59 await commands.measure.stop(); 60 61 commands.measure.result[0].browserScripts.pageinfo.droppedFrames = 62 playbackQuality.droppedVideoFrames; 63 commands.measure.result[0].browserScripts.pageinfo.decodedFrames = 64 playbackQuality.totalVideoFrames; 65 } 66 } 67 68 module.exports = { 69 test, 70 owner: "Network Team", 71 component: "netwerk", 72 name: "youtube-noscroll", 73 description: "Measures quality of the video being played.", 74 };