summaryrefslogtreecommitdiffstats
path: root/tests/auto/wasm/selenium/tst_qwasmwindow_harness.html
blob: 8c2457f3022e868e623b4a823fdcfa244621a16e (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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<!doctype html>

<head>
    <script type="text/javascript" src="tst_qwasmwindow_harness.js"></script>
    <script>
        (async () => {
            const instance = await tst_qwasmwindow_harness_entry({});
            window.instance = instance;

            const testSandbox = document.createElement('div');
            testSandbox.id = 'test-sandbox';
            let nextScreenId = 1;
            document.body.appendChild(testSandbox);

            const eventList = [];

            const makeSizedDiv = (left, top, width, height) => {
                const screenDiv = document.createElement('div');

                screenDiv.style.left = `${left}px`;
                screenDiv.style.top = `${top}px`;
                screenDiv.style.width = `${width}px`;
                screenDiv.style.height = `${height}px`;
                screenDiv.style.backgroundColor = 'lightblue';
                screenDiv.id = `test-screen-${nextScreenId++}`;

                return screenDiv;
            };

            window.testSupport = {
                initializeScreenWithFixedPosition: (left, top, width, height) => {
                    const screenDiv = makeSizedDiv(left, top, width, height);
                    testSandbox.appendChild(screenDiv);

                    screenDiv.style.position = 'fixed';
                    instance.qtAddContainerElement(screenDiv);

                    return screenDiv;
                },
                initializeScreenWithRelativePosition: (left, top, width, height) => {
                    const screenDiv = makeSizedDiv(left, top, width, height);
                    testSandbox.appendChild(screenDiv);

                    screenDiv.style.position = 'relative';
                    instance.qtAddContainerElement(screenDiv);

                    return screenDiv;
                },
                initializeScreenInScrollContainer:
                    (scrollWidth, scrollHeight, left, top, width, height) => {
                        const scrollContainer = document.createElement('div');
                        scrollContainer.style.height = `${scrollHeight}px`;
                        scrollContainer.style.width = `${scrollWidth}px`;
                        testSandbox.appendChild(scrollContainer);

                        const screenDiv = makeSizedDiv(left, top, width, height);
                        scrollContainer.appendChild(screenDiv);
                        screenDiv.style.position = 'relative';

                        instance.qtAddContainerElement(screenDiv);

                        return [scrollContainer, screenDiv];
                    },
                reportEvent: event => {
                    eventList.push(event);
                },
                events: () => eventList,
                hitTestPoint: (x, y, screenId) => {
                    return document
                        .querySelector(`#${screenId}`)
                        .querySelector('#qt-shadow-container')
                        .shadowRoot.elementsFromPoint(x, y);
                }
            };
        })();
    </script>
</head>

<body>
</body>