indexeddb_open.js (3544B)
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 { logTest } = require("./utils/profiling"); 8 9 module.exports = logTest( 10 "IndexedDB open test", 11 async function (context, commands) { 12 context.log.info("Starting an IndexedDB open test"); 13 14 const post_startup_delay = context.options.browsertime.post_startup_delay; 15 const url = context.options.browsertime.url; 16 const iterations = context.options.browsertime.iterations; 17 const parallel = context.options.browsertime.parallel; 18 19 await commands.navigate(url); 20 21 context.log.info( 22 "Waiting for %d ms (post_startup_delay)", 23 post_startup_delay 24 ); 25 await commands.wait.byTime(post_startup_delay); 26 27 await commands.measure.start(); 28 29 const open_duration = await context.selenium.driver.executeAsyncScript(` 30 const notifyDone = arguments[arguments.length - 1]; 31 32 const iterations = ${iterations}; 33 const parallel = ${parallel}; 34 35 function startOpen() { 36 return new Promise((resolve, reject) => { 37 try { 38 const openRequest = indexedDB.open("rootsdb"); 39 openRequest.onsuccess = () => resolve(openRequest.result); 40 openRequest.onerror = () => reject(openRequest.error); 41 } catch (e) { 42 reject(e); 43 } 44 }); 45 } 46 47 async function openInSequence() { 48 const result = []; 49 50 for (let index = 0; index < iterations; index++) { 51 const database = await startOpen(); 52 result.push(database); 53 } 54 55 return result; 56 } 57 58 async function openInParallel() { 59 const openPromises = []; 60 61 for (let index = 0; index < iterations; index++) { 62 openPromises.push(startOpen()); 63 } 64 65 return Promise.all(openPromises); 66 } 67 68 async function main() { 69 const databases = 70 parallel ? await openInParallel() : await openInSequence(); 71 72 for (const database of databases) { 73 database.close(); 74 } 75 } 76 77 const startTime = performance.now(); 78 main().then(() => { 79 notifyDone(performance.now() - startTime); 80 }); 81 `); 82 console.log("Open duration ", open_duration); 83 84 const delete_duration = await context.selenium.driver.executeAsyncScript(` 85 const notifyDone = arguments[arguments.length - 1]; 86 87 function startDelete() { 88 return new Promise((resolve, reject) => { 89 try { 90 const openRequest = indexedDB.deleteDatabase("rootsdb"); 91 openRequest.onsuccess = () => resolve(); 92 openRequest.onerror = () => reject(openRequest.error); 93 } catch (e) { 94 reject(e); 95 } 96 }); 97 } 98 99 const startTime = performance.now(); 100 startDelete().then(() => { 101 notifyDone(performance.now() - startTime); 102 }); 103 `); 104 console.log("Delete duration ", delete_duration); 105 106 const time_duration = open_duration + delete_duration; 107 console.log("Time duration ", time_duration); 108 109 await commands.measure.stop(); 110 111 await commands.measure.addObject({ 112 custom_data: { open_duration, delete_duration, time_duration }, 113 }); 114 115 context.log.info("IndexedDB open test ended"); 116 117 return true; 118 } 119 );