tor-browser

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

test_performance_user_timing_dying_global.html (2455B)


      1 <!DOCTYPE html>
      2 <html>
      3    <head>
      4        <title>Test for User Timing APIs on dying globals</title>
      5        <script src="/tests/SimpleTest/SimpleTest.js"></script>
      6        <script type="text/javascript">
      7            // We must wait for the iframe to load.
      8            SimpleTest.waitForExplicitFinish();
      9            window.addEventListener('load', () => {
     10                const dyingWindow = initTest();
     11                ok(true, 'Initialization complete');
     12 
     13                testDoesNotCrash(dyingWindow);
     14                SimpleTest.finish();
     15            });
     16 
     17            function initTest() {
     18                // We create a dying global by creating an iframe, keeping a
     19                // reference to it, and removing it.
     20                const iframe = document.querySelector('iframe');
     21                const iframeWindow = iframe.contentWindow;
     22 
     23                // We want to call the User Timing functions in the context of
     24                // the dying global. However, we can't call constructors
     25                // directly on a reference to a window so we have to wrap it.
     26                iframeWindow.newPerformanceMark = () => {
     27                  new PerformanceMark('constructor', {detail: 'constructorDetail'});
     28                };
     29 
     30                // Send the global to a dying state.
     31                iframe.remove();
     32 
     33                return iframeWindow;
     34            }
     35 
     36            function testDoesNotCrash(dyingWindow) {
     37                ok(true, 'Running testDoesNotCrash');
     38 
     39                dyingWindow.newPerformanceMark();
     40                ok(true, 'new PerformanceMark() on dying global did not crash');
     41 
     42                try {
     43                    dyingWindow.performance.mark('markMethod', {detail: 'markMethodDetail'});
     44                } catch (e) {
     45                    is(e.code, e.INVALID_STATE_ERR, 'performance.mark on dying global threw expected exception');
     46                }
     47                ok(true, 'performance.mark on dying global did not crash');
     48 
     49                try {
     50                    dyingWindow.performance.measure('measureMethod');
     51                } catch (e) {
     52                    is(e.code, e.INVALID_STATE_ERR, 'performance.measure on dying global threw expected exception');
     53                }
     54                ok(true, 'performance.measure on dying global did not crash');
     55            }
     56        </script>
     57    </head>
     58    <body>
     59        <iframe width="200" height="200" src="about:blank"></iframe>
     60    </body>
     61 </html>