69d8578038a8c2191ab4134c2628d04626e84368
[WebKit-https.git] / LayoutTests / http / tests / security / text-track-crossorigin.html
1 <!DOCTYPE html>
2 <html>
3     <head>
4         <script src="resources/cross-frame-access.js"></script>
5         <script>
6
7             var shouldLoad = false;
8             var counter = 0;
9
10             if (window.testRunner) {
11                 testRunner.dumpAsText();
12                 testRunner.waitUntilDone();
13             }
14
15             function log(msg)
16             {
17                 document.getElementById('console').innerHTML += msg + "<br>";
18             }
19
20             function trackLoaded()
21             {
22                 log('EVENT(load)');
23                 shouldBe('shouldLoad', true);
24
25                 trackElement = document.querySelectorAll('track')[0];
26                 videoElement = document.querySelectorAll('video')[0];
27                 shouldBe('event.target', trackElement);
28                 shouldBe('trackElement.readyState', HTMLTrackElement.LOADED);
29
30                 log('<br>');
31                 switch(counter) {
32                 case 2:
33                     log('Loading <b>with</b> Access-Control-Allow-Origin and Access-Control-Allow-Credentials headers, setting video.crossorigin to "use-credentials"');
34                     url = "http://localhost:8000/security/resources/captions-with-access-control-headers.php?origin=1;credentials=1";
35                     trackElement.setAttribute('crossorigin', 'use-credentials');
36                     trackElement.setAttribute('src', url);
37                     ++counter;
38                     break;
39
40                 case 3:
41                     log("END OF TEST");
42                     if (window.testRunner)
43                         testRunner.notifyDone();
44                 }
45             }
46
47             function trackError()
48             {
49                 log('EVENT(error)');
50                 shouldBe('shouldLoad', false);
51
52                 trackElement = document.querySelectorAll('track')[0];
53                 videoElement = document.querySelectorAll('video')[0];
54                 shouldBe('event.target', trackElement);
55                 shouldBe('trackElement.readyState', HTMLTrackElement.ERROR);
56
57                 log('<br>');
58                 switch(counter) {
59                 case 0:
60                     log('Loading <b>without</b> Access-Control-Allow-Origin header, setting video.crossorigin to "anonymous"');
61                     url = "http://localhost:8000/security/resources/captions-with-access-control-headers.php?count=" + counter;
62                     videoElement.setAttribute('crossorigin', 'anonymous');
63                     trackElement.removeAttribute('src');
64                     trackElement.setAttribute('src', url);
65                     ++counter;
66                     break;
67
68                 case 1:
69                     log('Loading <b>with</b> Access-Control-Allow-Origin header, leaving video.crossorigin as "anonymous"');
70                     url = "http://localhost:8000/security/resources/captions-with-access-control-headers.php?origin=1";
71                     trackElement.setAttribute('src', url);
72                     shouldLoad = true;
73                     ++counter;
74                     break;
75                 }
76
77             }
78
79             function start()
80             {
81                 trackElement = document.querySelectorAll('track')[0];
82                 log('Loading <b>without</b> Access-Control-Allow-Origin header, no "crossorigin" attribute on &lt;video&gt;');
83                 var url = "http://localhost:8000/security/resources/captions-with-access-control-headers.php"
84                 trackElement.setAttribute('src', url);
85             }
86
87         </script>
88     </head>
89     <body onload="start()">
90         <p>Tests loading cross-domain &lt;track&gt;.</p>
91         <video >
92             <track kind="captions" onerror="trackError()" onload="trackLoaded()" >
93         </video>
94         <div id="console"></div>
95     </body>
96 </html>