summaryrefslogtreecommitdiffstats
path: root/dom/performance/tests/test_performance_user_timing_dying_global.html
blob: 18e4a54684d6f93b95ce125a2e4434aeeb139b64 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<!DOCTYPE html>
<html>
    <head>
        <title>Test for User Timing APIs on dying globals</title>
        <script src="/tests/SimpleTest/SimpleTest.js"></script>
        <script type="text/javascript">
            // We must wait for the iframe to load.
            SimpleTest.waitForExplicitFinish();
            window.addEventListener('load', () => {
                const dyingWindow = initTest();
                ok(true, 'Initialization complete');

                testDoesNotCrash(dyingWindow);
                SimpleTest.finish();
            });

            function initTest() {
                // We create a dying global by creating an iframe, keeping a
                // reference to it, and removing it.
                const iframe = document.querySelector('iframe');
                const iframeWindow = iframe.contentWindow;

                // We want to call the User Timing functions in the context of
                // the dying global. However, we can't call constructors
                // directly on a reference to a window so we have to wrap it.
                iframeWindow.newPerformanceMark = () => {
                  new PerformanceMark('constructor', {detail: 'constructorDetail'});
                };

                // Send the global to a dying state.
                iframe.remove();

                return iframeWindow;
            }

            function testDoesNotCrash(dyingWindow) {
                ok(true, 'Running testDoesNotCrash');

                dyingWindow.newPerformanceMark();
                ok(true, 'new PerformanceMark() on dying global did not crash');

                try {
                    dyingWindow.performance.mark('markMethod', {detail: 'markMethodDetail'});
                } catch (e) {
                    is(e.code, e.INVALID_STATE_ERR, 'performance.mark on dying global threw expected exception');
                }
                ok(true, 'performance.mark on dying global did not crash');

                try {
                    dyingWindow.performance.measure('measureMethod');
                } catch (e) {
                    is(e.code, e.INVALID_STATE_ERR, 'performance.measure on dying global threw expected exception');
                }
                ok(true, 'performance.measure on dying global did not crash');
            }
        </script>
    </head>
    <body>
        <iframe width="200" height="200" src="about:blank"></iframe>
    </body>
</html>