Bug 1719855 - Take over preventDefaulted infomation for long-tap events to the origin...
[gecko.git] / dom / performance / tests / test_performance_user_timing_dying_global.html
blob18e4a54684d6f93b95ce125a2e4434aeeb139b64
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');
13 testDoesNotCrash(dyingWindow);
14 SimpleTest.finish();
15 });
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;
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'});
30 // Send the global to a dying state.
31 iframe.remove();
33 return iframeWindow;
36 function testDoesNotCrash(dyingWindow) {
37 ok(true, 'Running testDoesNotCrash');
39 dyingWindow.newPerformanceMark();
40 ok(true, 'new PerformanceMark() on dying global did not crash');
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');
47 ok(true, 'performance.mark on dying global did not crash');
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');
54 ok(true, 'performance.measure on dying global did not crash');
56 </script>
57 </head>
58 <body>
59 <iframe width="200" height="200" src="about:blank"></iframe>
60 </body>
61 </html>