throttled_pageload.js (1670B)
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 5 /* eslint-env node */ 6 7 const fs = require("fs"); 8 const path = require("path"); 9 const { logTest } = require("./utils/profiling"); 10 11 module.exports = logTest( 12 "throttled pageload", 13 async function (context, commands) { 14 context.log.info( 15 "Starting a pageload for which we will first enable the dev tools network throttler" 16 ); 17 18 const url = "https://en.wikipedia.org/wiki/Barack_Obama"; 19 20 await commands.navigate("about:blank"); 21 await commands.wait.byTime(1000); 22 23 // Load the throttling script 24 let throttler_script = null; 25 let throttlerScriptPath = path.join( 26 `${path.resolve(__dirname)}`, 27 "utils", 28 "NetworkThrottlingUtils.js" 29 ); 30 try { 31 throttler_script = fs.readFileSync(throttlerScriptPath, "utf8"); 32 } catch (error) { 33 throw Error( 34 `Failed to load network throttler script ${throttlerScriptPath}` 35 ); 36 } 37 38 // Create a throttler and configure the network 39 let usage = ` 40 let networkThrottler = new NetworkThrottler(); 41 let throttleData = { 42 latencyMean: 50, 43 latencyMax: 50, 44 downloadBPSMean: 250000, 45 downloadBPSMax: 250000, 46 uploadBPSMean: 250000, 47 uploadBPSMax: 250000 48 }; 49 networkThrottler.start(throttleData); 50 `; 51 52 throttler_script += usage; 53 commands.js.runPrivileged(throttler_script); 54 55 await commands.measure.start(url); 56 57 context.log.info("Throttled pageload test finished."); 58 return true; 59 } 60 );