Bug 1686029 [wpt PR 27131] - Mark performance.measureMemory web-platform tests as...
[gecko.git] / testing / web-platform / tests / measure-memory / detached.https.window.js
blob179e5e727adfd9b12e82b84b0c39a7c682a6689d
1 // META: script=/common/get-host-info.sub.js
2 // META: script=./resources/common.js
3 // META: timeout=long
4 'use strict';
6 assert_true(self.crossOriginIsolated);
8 promise_test(async testCase => {
9   const {iframes, windows} = await build([
10     {
11       id: 'cross-site-1',
12       children: [
13         {
14           id: 'same-origin-2',
15         },
16         {
17           id: 'same-origin-11',
18           window_open: true,
19         },
20       ],
21     },
22     {
23       id: 'same-origin-3',
24       children: [
25         {
26           id: 'same-origin-4',
27         },
28         {
29           id: 'same-origin-12',
30           window_open: true,
31         },
32       ],
33     },
34     {
35       id: 'cross-origin-5',
36       children: [
37         {
38           id: 'same-origin-6',
39         },
40         {
41           id: 'same-origin-13',
42           window_open: true,
43         },
44       ],
45     },
46     {
47       id: 'same-origin-7',
48       window_open: true,
49       children: [
50         {
51           id: 'same-origin-8',
52         }
53       ],
54     },
55     {
56       id: 'cross-origin-9',
57       window_open: true,
58       children: [
59         {
60           id: 'same-origin-10',
61         }
62       ],
63     },
64   ]);
65   const expected = [
66     {
67       url: window.location.href,
68       scope: 'Window',
69       container: null,
70     },
71     {
72       url: 'cross-origin-url',
73       scope: 'cross-origin-aggregated',
74       container: {
75         id: 'cross-site-1',
76         src: iframes['cross-site-1'].src,
77       },
78     },
79     {
80       url: windows['same-origin-2'].location.href,
81       scope: 'Window',
82       container: {
83         id: 'cross-site-1',
84         src: iframes['cross-site-1'].src,
85       },
86     },
87     {
88       url: windows['same-origin-3'].location.href,
89       scope: 'Window',
90       container: {
91         id: 'same-origin-3',
92         src: iframes['same-origin-3'].src,
93       },
94     },
95     {
96       url: windows['same-origin-4'].location.href,
97       scope: 'Window',
98       container: {
99         id: 'same-origin-4',
100         src: iframes['same-origin-4'].src,
101       },
102     },
103     {
104       url: 'cross-origin-url',
105       scope: 'cross-origin-aggregated',
106       container: {
107         id: 'cross-origin-5',
108         src: iframes['cross-origin-5'].src,
109       },
110     },
111     {
112       url: windows['same-origin-6'].location.href,
113       scope: 'Window',
114       container: {
115         id: 'cross-origin-5',
116         src: iframes['cross-origin-5'].src,
117       },
118     },
119     {
120       url: windows['same-origin-8'].location.href,
121       scope: 'Window',
122       container: {
123         id: 'same-origin-8',
124         src: iframes['same-origin-8'].src,
125       },
126     },
127     {
128       url: windows['same-origin-7'].location.href,
129       scope: 'Window',
130       container: null,
131     },
132     {
133       url: windows['same-origin-11'].location.href,
134       scope: 'Window',
135       container: null,
136     },
137     {
138       url: windows['same-origin-12'].location.href,
139       scope: 'Window',
140       container: null,
141     },
142     {
143       url: windows['same-origin-13'].location.href,
144       scope: 'Window',
145       container: null,
146     },
147   ];
148   const keep = sameOriginContexts(frames).concat(sameOriginContexts(windows));
149   // Detach iframes:
150   // 1) By setting src attribute:
151   iframes['cross-site-1'].src =
152       iframes['cross-site-1'].src.replace('iframe.sub', 'iframe.secret.sub');
153   // 2) By setting location attribute:
154   let url = iframes['same-origin-3'].contentWindow.location.href;
155   url = url.replace('iframe.sub', 'iframe.secret.sub');
156   iframes['same-origin-3'].contentWindow.location.href = url;
157   // 3) By removing from the DOM tree:
158   iframes['cross-origin-5'].parentNode.removeChild(iframes['cross-origin-5']);
160   // Detach windows:
161   // 1) By setting document.location attribute:
162   url = windows['same-origin-7'].location.href;
163   url = url.replace('window.sub', 'window.secret.sub');
164   windows['same-origin-7'].location.href = url;
165   // 2) By closing the window:
166   windows['same-origin-10'].parent.close();
168   await waitForMessage('cross-site-1');
169   await waitForMessage('same-origin-3');
170   await waitForMessage('same-origin-7');
172   expected.push({
173     url: 'cross-origin-url',
174     scope: 'cross-origin-aggregated',
175     container: {
176       id: 'cross-site-1',
177       src: iframes['cross-site-1'].src,
178     },
179   });
181   expected.push({
182     url: windows['same-origin-3'].location.href,
183     scope: 'Window',
184     container: {
185       id: 'same-origin-3',
186       src: iframes['same-origin-3'].src,
187     },
188   });
189   expected.push({
190     url: windows['same-origin-7'].location.href,
191     scope: 'Window',
192     container: null,
193   });
194   const result = await performance.measureMemory();
195   checkMeasureMemory(result, expected);
196 }, 'performance.measureMemory URLs within a cross-site iframe.');