tor-browser

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

test_registration.html (2746B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <head>
      4  <title>Service worker performance test: registration</title>
      5 </head>
      6 <script src="/tests/SimpleTest/SimpleTest.js"></script>
      7 <script src="../utils.js"></script>
      8 <script src="perfutils.js"></script>
      9 <script>
     10 
     11  "use strict";
     12 
     13  // "Total" register() time, including process startup.  We don't cause it all,
     14  // but we're affected by it.
     15  const REGISTRATION = "Registration";
     16 
     17  // Targeted timing of regristration machinery.
     18  const REGISTRATION_INTERNALS = "Registration Internals";
     19 
     20  const ACTIVATION = "Activation";
     21 
     22  const UNREGISTRATION = "Unregistration";
     23 
     24  var journal = {};
     25  journal[REGISTRATION] = [];
     26  journal[REGISTRATION_INTERNALS] = [];
     27  journal[ACTIVATION] = [];
     28  journal[UNREGISTRATION] = [];
     29 
     30  const ITERATIONS = 11;
     31 
     32  var perfMetadata = {
     33    owner: "DOM LWS",
     34    name: "Service Worker Registration",
     35    description: "Test registration, activation, and unregistration.",
     36    options: {
     37      default: {
     38        perfherder: true,
     39        perfherder_metrics: [
     40          // Here, we can't use the constants defined above because perfherder
     41          // grabs data from the parse tree.
     42          { name: "Registration", unit: "ms", shouldAlert: true },
     43          { name: "Registration Internals", unit: "ms", shouldAlert: true },
     44          { name: "Activation", unit: "ms", shouldAlert: true },
     45          { name: "Unregistration", unit: "ms", shouldAlert: true },
     46        ],
     47        verbose: true,
     48        manifest: "perftest.toml",
     49        manifest_flavor: "plain",
     50      },
     51    },
     52  };
     53 
     54  add_task(async () => {
     55    await SpecialPowers.pushPrefEnv({
     56      set: [["dom.serviceWorkers.testing.enabled", true]]
     57    });
     58 
     59    async function measure() {
     60      await startProfiler();
     61 
     62      let begin_ts = performance.now();
     63      let reg = await navigator.serviceWorker.register("sw_empty.js");
     64      let reg_ts = performance.now();
     65      await waitForState(reg.installing, "activated");
     66      let act_ts = performance.now();
     67      await reg.unregister();
     68      let unreg_ts = performance.now();
     69 
     70      let pdata = await stopProfiler();
     71      let duration_ms = inspectProfile(pdata, [
     72        "SWM Register",
     73        "SWRJ AsyncExecute",
     74        "InitServiceWorkerRegistrationParent",
     75        "SWC Register",
     76        "SWC Register (inner)"
     77      ]);
     78 
     79      journal[REGISTRATION].push(reg_ts - begin_ts);
     80      journal[REGISTRATION_INTERNALS].push(duration_ms);
     81      journal[ACTIVATION].push(act_ts - reg_ts);
     82      journal[UNREGISTRATION].push(unreg_ts - act_ts);
     83    }
     84 
     85    for (let i = 0; i < ITERATIONS; i++) {
     86      await measure();
     87    }
     88 
     89    await SpecialPowers.popPrefEnv();
     90 
     91    ok(true);
     92  });
     93 
     94  add_task(() => {
     95    reportMetrics(journal);
     96  });
     97 
     98 </script>
     99 <body>
    100 </body>
    101 </html>