forked from web-platform-tests/wpt
-
Notifications
You must be signed in to change notification settings - Fork 2
/
common.js
38 lines (35 loc) · 1.32 KB
/
common.js
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
// Create an anonymous iframe. The new document will execute any scripts sent
// toward the token it returns.
const newAnonymousIframe = (child_origin) => {
const sub_document_token = token();
let iframe = document.createElement('iframe');
iframe.src = child_origin + executor_path + `&uuid=${sub_document_token}`;
iframe.anonymous = true;
document.body.appendChild(iframe);
return sub_document_token;
};
// Create a normal iframe. The new document will execute any scripts sent
// toward the token it returns.
const newIframe = (child_origin) => {
const sub_document_token = token();
let iframe = document.createElement('iframe');
iframe.src = child_origin + executor_path + `&uuid=${sub_document_token}`;
iframe.anonymous = false
document.body.appendChild(iframe);
return sub_document_token;
};
// Create a popup. The new document will execute any scripts sent toward the
// token it returns.
const newPopup = (origin) => {
const popup_token = token();
const popup = window.open(origin + executor_path + `&uuid=${popup_token}`);
return popup_token;
};
const importScript = (url) => {
const script = document.createElement("script");
script.type = "text/javascript";
script.src = url;
const loaded = new Promise(resolve => script.onload = resolve);
document.body.appendChild(script);
return loaded;
}