tor-browser

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

longtask-tojson.html (2870B)


      1 <!doctype html>
      2 <html>
      3 <head>
      4 <script src="/resources/testharness.js"></script>
      5 <script src="/resources/testharnessreport.js"></script>
      6 </head>
      7 <body>
      8 <script>
      9  async_test(function (t) {
     10    assert_implements(window.PerformanceLongTaskTiming, 'Longtasks are not supported.');
     11    const observer = new PerformanceObserver(
     12      t.step_func(function (entryList) {
     13        const entries = entryList.getEntries();
     14        assert_greater_than_equal(entries.length, 1);
     15        const entry = entries[0];
     16        assert_equals(typeof(entry.toJSON), 'function');
     17        const entryJSON = entry.toJSON();
     18        assert_equals(typeof(entryJSON), 'object');
     19        // Check attributes inheritted from PerformanceEntry.
     20        const performanceEntryKeys = [
     21            'name',
     22            'entryType',
     23            'startTime',
     24            'duration'
     25        ];
     26        for (const key of performanceEntryKeys) {
     27            assert_equals(entryJSON[key], entry[key],
     28                `entry.toJSON().${key} should match entry.${key}`);
     29        }
     30 
     31        // Check PerformanceLongTaskTiming specific entries.
     32        assert_equals(typeof(entryJSON.attribution), 'object');
     33        const entryJsonAttribution = entryJSON.attribution[0];
     34        assert_equals(typeof(entryJsonAttribution), 'object');
     35        assert_equals(entryJSON.attribution.length, entry.attribution.length);
     36 
     37        // Check TaskAttributionTiming toJSON.
     38        const entryAttribution = entry.attribution[0];
     39        assert_equals(typeof(entryAttribution.toJSON), 'function');
     40        const entryAttributionJSON = entryAttribution.toJSON();
     41        assert_equals(typeof(entryAttributionJSON), 'object');
     42        // Check TaskAttributionTiming attributes, from both:
     43        // 1) |entryJsonAttribution| from  PerformanceLongTaskTiming.
     44        // 2) |entryAttributionJSON| from TaskAttributionTiming.
     45        const taskAttributionTimingKeys = [
     46            'name',
     47            'entryType',
     48            'startTime',
     49            'duration',
     50            'containerType',
     51            'containerSrc',
     52            'containerId',
     53            'containerName'
     54        ];
     55        for (const key of taskAttributionTimingKeys) {
     56            assert_equals(entryAttributionJSON[key], entryAttribution[key],
     57                `attribution.toJSON().${key} should match attribution.${key}`);
     58            assert_equals(entryJsonAttribution[key], entryAttribution[key],
     59                `entry.toJSON().attribution[0].${key} should match attribution.${key}`);
     60        }
     61        t.done();
     62      })
     63    );
     64    observer.observe({entryTypes: ['longtask']});
     65 
     66    window.onload = () => {
     67        // Trigger a long task.
     68        const begin = window.performance.now();
     69        while (window.performance.now() < begin + 60);
     70    };
     71  }, 'Test toJSON() in PerformanceLongTaskTiming and TaskAttributionTiming');
     72 </script>
     73 </body>
     74 </html>