tor-browser

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

tojson.html (2108B)


      1 <!doctype html>
      2 <html>
      3 <head>
      4 <meta charset="utf-8">
      5 <title>This test validates that PerformanceResourceTiming's toJSON method
      6       contains all of the entry's attributes.</title>
      7 <link rel="author" title="Google" href="http://www.google.com/" />
      8 <link rel="help"
      9      href="https://www.w3.org/TR/resource-timing-2/#dom-performanceresourcetiming-tojson">
     10 <script src="/resources/testharness.js"></script>
     11 <script src="/resources/testharnessreport.js"></script>
     12 </head>
     13 <body>
     14 <script>
     15 promise_test(() => {
     16  return new Promise((resolve, reject) => {
     17    const po = new PerformanceObserver(list => {
     18      const entries = list.getEntries();
     19      if (entries.length < 1) {
     20        throw new Error(`No entries to run the test with.`);
     21      }
     22      assert_greater_than_equal(entries.length, 1);
     23      const entry = entries[0];
     24      assert_equals(typeof(entry.toJSON), 'function');
     25      const json = entry.toJSON();
     26      assert_equals(typeof(json), 'object');
     27 
     28      const performanceResourceTimingKeys = [
     29        'name',
     30        'entryType',
     31        'startTime',
     32        'duration',
     33        'initiatorType',
     34        'nextHopProtocol',
     35        'workerStart',
     36        'redirectStart',
     37        'redirectEnd',
     38        'fetchStart',
     39        'domainLookupStart',
     40        'domainLookupEnd',
     41        'connectStart',
     42        'connectEnd',
     43        'secureConnectionStart',
     44        'requestStart',
     45        'responseStart',
     46        'responseEnd',
     47        'transferSize',
     48        'encodedBodySize',
     49        'decodedBodySize',
     50        'renderBlockingStatus',
     51        'responseStatus',
     52        'contentType',
     53      ];
     54      for (const key of performanceResourceTimingKeys) {
     55        try {
     56          assert_false(json[key] === undefined,
     57            `entry.toJSON().${key} is undefined`);
     58          assert_equals(json[key], entry[key],
     59            `entry.toJSON().${key} should match entry.${key}`);
     60        } catch(e) {
     61          reject(e);
     62        }
     63      }
     64      resolve();
     65    });
     66    po.observe({type: "resource", buffered: true});
     67  });
     68 }, 'Test toJSON() in PerformanceResourceTiming');
     69 </script>
     70 </body>
     71 </html>