tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

indexeddb_getkeyrange.js (2709B)


      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, logTask } = require("./utils/profiling");
      8 
      9 module.exports = logTest(
     10  "indexedDB getkeyrange test",
     11  async function (context, commands) {
     12    context.log.info("Starting a indexedDB getkeyrange");
     13 
     14    const test_url = context.options.browsertime.url;
     15    let page_cycles = context.options.browsertime.page_cycles;
     16    let page_cycle_delay = context.options.browsertime.page_cycle_delay;
     17    let post_startup_delay = context.options.browsertime.post_startup_delay;
     18 
     19    context.log.info(
     20      "Waiting for %d ms (post_startup_delay)",
     21      post_startup_delay
     22    );
     23    await commands.wait.byTime(post_startup_delay);
     24 
     25    await commands.navigate(test_url);
     26 
     27    for (let count = 0; count < page_cycles; count++) {
     28      await logTask(context, "cycle " + count, async function () {
     29        context.log.info(
     30          "Cycle %d, waiting for %d ms",
     31          count,
     32          page_cycle_delay
     33        );
     34        await commands.wait.byTime(page_cycle_delay);
     35 
     36        context.log.info("Cycle %d, starting the measure", count);
     37        await commands.measure.start();
     38        await commands.js.run(`
     39        const notifyDone = arguments[arguments.length - 1];
     40        async function resPromise() {
     41          return new Promise((resolve, reject) => {
     42            const results = {};
     43            const request = indexedDB.open('get-keyrange', 1);
     44 
     45            request.onsuccess = () => {
     46              const db = request.result;
     47              const start = Date.now();
     48              const keyRange = IDBKeyRange.bound(0, 99);
     49              const transaction = db.transaction('entries', 'readonly');
     50              const store = transaction.objectStore('entries');
     51              const index = store.index('index');
     52              const getAllRequest = index.getAll(keyRange);
     53              getAllRequest.onsuccess = () => {
     54                const items = getAllRequest.result;
     55                items.forEach((item) => {
     56                  results[item.key] = item;
     57                });
     58                const end = Date.now();
     59                db.close();
     60                resolve(end - start);
     61              };
     62              getAllRequest.onerror = () => {
     63                reject(getAllRequest.error);
     64              };
     65            };
     66 
     67          });
     68        }
     69        resPromise().then(() => {
     70          notifyDone();
     71        });
     72      `);
     73        await commands.measure.stop();
     74      });
     75    }
     76 
     77    context.log.info("IndexedDB getkeyrange ended.");
     78    return true;
     79  }
     80 );