summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/html/browsers/origin/cross-origin-objects/cross-origin-objects-function-common.js
blob: 3b93b498a26cbd7213179dba7254eeb843173d2d (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
"use strict";

const crossOriginWindowMethods = [
    {key: "close", length: 0},
    {key: "focus", length: 0},
    {key: "blur", length: 0},
    {key: "postMessage", length: 1},
];

const crossOriginWindowAccessors = [
    "window",
    "self",
    "location",
    "closed",
    "frames",
    "length",
    "top",
    "opener",
    "parent",
].map(key => ({key}));

const makeCrossOriginWindow = t => {
    const iframe = document.createElement("iframe");
    const path = location.pathname.slice(0, location.pathname.lastIndexOf("/")) + "/frame.html";
    iframe.src = get_host_info().HTTP_REMOTE_ORIGIN + path;

    return new Promise((resolve, reject) => {
        iframe.onload = () => { resolve(iframe.contentWindow); };
        iframe.onerror = reject;

        document.body.append(iframe);
        t.add_cleanup(() => { iframe.remove(); });
    });
};