summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/mediacapture-streams/MediaStream-MediaElement-preload-none.https.html
blob: 52a13af27287b9152c3e94ebcab39fde98f2d73e (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
81
82
83
84
<!DOCTYPE html>
<html>
    <head>
        <title>Test that the HTMLMediaElement preload 'none' attribute value is ignored for MediaStream used as srcObject and MediaStream object URLs used as src.</title>
        <link rel="author" title="Matthew Wolenetz" href="mailto:wolenetz@chromium.org"/>
        <script src="/resources/testharness.js"></script>
        <script src="/resources/testharnessreport.js"></script>
        <script src="/resources/testdriver.js"></script>
        <script src="/resources/testdriver-vendor.js"></script>
        <script src="permission-helper.js"></script>
    </head>
    <body>
        <p class="instructions">When prompted, accept to share your audio and video streams.</p>
        <p class="instructions">This test checks that the HTMLMediaElement preload 'none' attribute value is ignored for MediaStream used as srcObject and MediaStream object URLs used as src.</p>
        <div id=log></div>

        <audio preload="none"></audio>
        <video preload="none"></video>

        <script>
            async function testPreloadNone(mediaElement, stream)
            {
                let rejectSuspendedPromise, rejectErrorPromise, resolveDataLoadedPromise;
                const suspended = new Promise((r, rej) => {
                  rejectSuspendedPromise = rej;
                });
                const errored = new Promise((r, rej) => {
                  rejectErrorPromise = rej;
                });
                const loaded = new Promise(resolve => {
                  resolveDataLoadedPromise = resolve;
                });

                // The optional deferred load steps (for preload none) for MediaStream resources should be skipped.
                mediaElement.addEventListener("suspend", () => {
                  rejectSuspendedPromise("'suspend' should not be fired.")
                });
                mediaElement.addEventListener("error", () => {
                  rejectErrorPromise("'error' should not be fired, code=" + mediaElement.error.code);
                });

                mediaElement.addEventListener("loadeddata", () => {
                  assert_equals(mediaElement.networkState, mediaElement.NETWORK_LOADING);
                  resolveDataLoadedPromise();
                });

                mediaElement.srcObject = stream;
                assert_equals(mediaElement.networkState, mediaElement.NETWORK_NO_SOURCE); // Resource selection is active.
                try {
                  await Promise.race([suspended, errored, loaded]);
                } catch (msg) {
                  assert_unreached(msg);
                }
2            }

            promise_test(async () =>
            {
                const aud = document.querySelector("audio");
                // camera is needed for the next test, asking for both at once
                await setMediaPermission();
                let stream;
                try {
                  stream = await navigator.mediaDevices.getUserMedia({audio:true});
                } catch (e) {
                  assert_unreached("getUserMedia error callback was invoked.");
                }
                await testPreloadNone(aud, stream);
            }, "Test that preload 'none' is ignored for MediaStream object URL used as srcObject for audio");

            promise_test(async () =>
            {
                const vid = document.querySelector("video");
                let stream;
                try {
                  stream = await navigator.mediaDevices.getUserMedia({video:true});
                } catch (e) {
                  assert_unreached("getUserMedia error callback was invoked.")
                }
                await testPreloadNone(vid, stream);

            }, "Test that preload 'none' is ignored for MediaStream used as srcObject for video");
        </script>
    </body>
</html>