summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/fetch/metadata/track.https.sub.html
blob: 346798fdc0e5ae0a94515786e2b8e7e7578a3cfb (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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
<!DOCTYPE html>

<link rel="author" href="mtrzos@google.com" title="Maciek Trzos">
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src=/fetch/metadata/resources/helper.js></script>
<script src=/common/utils.js></script>
<body>
</body>
<script>
  let nonce = token();

  function createVideoElement() {
    let el = document.createElement('video');
    el.src = "/media/movie_5.mp4";
    el.setAttribute("controls", "");
    el.setAttribute("crossorigin", "");
    return el;
  }

  function createTrack() {
    let el = document.createElement("track");
    el.setAttribute("default", "");
    el.setAttribute("kind", "captions");
    el.setAttribute("srclang", "en");
    return el;
  }

  promise_test(t => {
    return new Promise((resolve, reject) => {
      let key = "track-same-origin" + nonce;
      let video = createVideoElement();
      let el = createTrack();
      el.src = "https://{{host}}:{{ports[https][0]}}/fetch/metadata/resources/record-header.py?file=" + key;
      el.onload = t.step_func(_ => {
        expected = {
          "site": "same-origin",
          "user": "",
          "mode": "cors", // Because the `video` element has `crossorigin`
          "dest": "track"
        };
        validate_expectations(key, expected, "Same-Origin track")
            .then(_ => resolve());
      });
      video.appendChild(el);
      document.body.appendChild(video);
    });
  }, "Same-Origin track");

  promise_test(t => {
    return new Promise((resolve, reject) => {
      let key = "track-same-site" + nonce;
      let video = createVideoElement();
      let el = createTrack();
      el.src = "https://{{hosts[][www]}}:{{ports[https][0]}}/fetch/metadata/resources/record-header.py?file=" + key;
      el.onload = t.step_func(_ => {
        expected = {
          "site": "same-site",
          "user": "",
          "mode": "cors", // Because the `video` element has `crossorigin`
          "dest": "track"
        };
        validate_expectations(key, expected, "Same-Site track")
            .then(resolve)
            .catch(reject);

      });
      video.appendChild(el);
      document.body.appendChild(video);
    });
  }, "Same-Site track");

  promise_test(t => {
    return new Promise((resolve, reject) => {
      let key = "track-cross-site" + nonce;
      let video = createVideoElement();
      let el = createTrack();
      el.src = "https://{{hosts[alt][www]}}:{{ports[https][0]}}/fetch/metadata/resources/record-header.py?file=" + key;
      el.onload = t.step_func(_ => {
        expected = {
          "site": "cross-site",
          "user": "",
          "mode": "cors", // Because the `video` element has `crossorigin`
          "dest": "track"
        };
        validate_expectations(key, expected,"Cross-Site track")
            .then(resolve)
            .catch(reject);
      });
      video.appendChild(el);
      document.body.appendChild(video);
    });
  }, "Cross-Site track");

  promise_test(t => {
    return new Promise((resolve, reject) => {
      let key = "track-same-origin-cors" + nonce;
      let video = createVideoElement();

      // Unset `crossorigin` to change the CORS mode:
      video.crossOrigin = undefined;

      let el = createTrack();
      el.src = "https://{{host}}:{{ports[https][0]}}/fetch/metadata/resources/record-header.py?file=" + key;
      el.onload = t.step_func(_ => {
        expected = {
          "site":"same-origin",
          "user":"",
          "mode": "same-origin",
          "dest": "track"
        };
        validate_expectations(key, expected, "Same-Origin, CORS track")
            .then(_ => resolve());
      });
      video.appendChild(el);
      document.body.appendChild(video);
    });
  }, "Same-Origin, CORS track");
</script>