TextTrackLoader should use FetchOptions::mode according its crossOrigin attribute
[WebKit.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 = true;
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 0:
33                     log('Loading <b>without</b> Access-Control-Allow-Origin header, setting video.crossorigin to "anonymous"');
34                     url = "http://localhost:8000/security/resources/captions-with-access-control-headers.php?count=" + counter;
35                     videoElement.setAttribute('crossorigin', 'anonymous');
36                     trackElement.removeAttribute('src');
37                     trackElement.setAttribute('src', url);
38                     shouldLoad = false;
39                     ++counter;
40                     break;
41
42                 case 2:
43                     log('Loading <b>with</b> Access-Control-Allow-Origin and Access-Control-Allow-Credentials headers, setting video.crossorigin to "use-credentials"');
44                     url = "http://localhost:8000/security/resources/captions-with-access-control-headers.php?origin=1;credentials=1";
45                     trackElement.setAttribute('crossorigin', 'use-credentials');
46                     trackElement.setAttribute('src', url);
47                     ++counter;
48                     break;
49
50                 case 3:
51                     log("END OF TEST");
52                     if (window.testRunner)
53                         testRunner.notifyDone();
54                 defaut:
55                     if (window.testRunner)
56                         testRunner.notifyDone();
57                 }
58             }
59
60             function trackError()
61             {
62                 log('EVENT(error)');
63                 shouldBe('shouldLoad', false);
64
65                 trackElement = document.querySelectorAll('track')[0];
66                 videoElement = document.querySelectorAll('video')[0];
67                 shouldBe('event.target', trackElement);
68                 shouldBe('trackElement.readyState', HTMLTrackElement.ERROR);
69
70                 log('<br>');
71                 switch(counter) {
72                 case 1:
73                     log('Loading <b>with</b> Access-Control-Allow-Origin header, leaving video.crossorigin as "anonymous"');
74                     url = "http://localhost:8000/security/resources/captions-with-access-control-headers.php?origin=1";
75                     trackElement.setAttribute('src', url);
76                     shouldLoad = true;
77                     ++counter;
78                     break;
79                 defaut:
80                     if (window.testRunner)
81                         testRunner.notifyDone();
82                 }
83             }
84
85             function start()
86             {
87                 trackElement = document.querySelectorAll('track')[0];
88                 trackElement.track.mode = "hidden";
89                 log('Loading <b>without</b> Access-Control-Allow-Origin header, no "crossorigin" attribute on &lt;video&gt;');
90                 var url = "http://localhost:8000/security/resources/captions-with-access-control-headers.php"
91                 trackElement.setAttribute('src', url);
92             }
93
94         </script>
95     </head>
96     <body onload="start()">
97         <p>Tests loading cross-domain &lt;track&gt;.</p>
98         <video >
99             <track kind="captions" onerror="trackError()" onload="trackLoaded()" >
100         </video>
101         <div id="console"></div>
102     </body>
103 </html>