6537b69ee90370e6b82d5c9d0c9c1b60ff9a3e62
[WebKit-https.git] / LayoutTests / http / tests / security / local-video-source-from-remote.html
1 <html lang="en">
2     <head>
3         <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
4         <title>remote &lt;video&gt; with local &lt;source&gt;</title>
5
6         <script>
7
8             var video = null;
9             var console = null;
10             var testEnded = false;
11
12             function endTest()
13             {
14                 consoleWrite("<br>END OF TEST");
15                 testEnded = true;
16                 if (window.layoutTestController)
17                     layoutTestController.notifyDone();     
18             }
19             function hanged()
20             {
21                 consoleWrite("FAIL: timed out");
22                 if (window.layoutTestController)
23                     layoutTestController.notifyDone();  
24             }
25
26             function logConsole()
27             {
28                 if (!console && document.body) {
29                     console = document.createElement('div');
30                     document.body.appendChild(console);
31                 }
32                 return console;
33             }
34             
35             function consoleWrite(text)
36             {
37                 if (testEnded)
38                     return;
39                 logConsole().innerHTML += text + "<br>";
40             }
41
42             function logEvent(evt)
43             {
44                 consoleWrite("EVENT(" + evt.type + ")");
45             }
46
47             function logResult(msg, success)
48             {
49                 if (success)
50                     consoleWrite("<span style='color:green'>SUCCESS: " + msg + "</span>");
51                 else
52                     consoleWrite("<span style='color:red'>FAIL: " + msg + "</span>");
53             }
54
55             function error(evt)
56             {
57                 logEvent(evt)
58                 consoleWrite("");
59                 logResult("failed trying to load " + video.currentSrc, false);
60                 endTest();
61             }
62
63             var localMovie = "file:///tmp/LayoutTests/media/content/scaled-matrix.mov";
64             var remoteUrl = "http://localhost:8000/security/resources/load-media.cgi?url=/../../media/content/test.mp4";
65             function loadedmetadata(evt) 
66             { 
67                 var src = video.currentSrc;
68                 var localFile = localMovie.substring(localMovie.lastIndexOf("/")+1, localMovie.length)
69                 var remoteFile = remoteUrl.substring(remoteUrl.lastIndexOf("/")+1, remoteUrl.length)
70
71                 logEvent(evt);
72                 consoleWrite("url " + src + " loaded.<br>");
73                 if (src.indexOf(localFile) > 0)
74                     logResult("local movie loaded", false);
75                 else if (src.indexOf(remoteFile) > 0)
76                     logResult("remote movie loaded, local movie failed to load", true);
77                 endTest();
78             }
79
80             if (window.layoutTestController) 
81             {
82                 localMovie = layoutTestController.pathToLocalResource(localMovie);
83                 layoutTestController.dumpAsText();
84                 layoutTestController.waitUntilDone();
85             }
86             setTimeout(hanged, 10000);
87
88             function test() 
89             {
90                 video = document.getElementById("vid");
91
92                 video.addEventListener("error", error);
93                 video.addEventListener('loadedmetadata', loadedmetadata);
94
95                 // Create two <source> children, the first with a local url and the second
96                 // with a remote url. The element should load the second.
97                 var src1 = document.createElement("source");
98                 src1.setAttribute("src", localMovie);
99
100                 var src2 = document.createElement("source");
101                 src2.setAttribute("src", remoteUrl);
102
103                 video.appendChild(src1);
104                 video.appendChild(src2);
105             }
106         </script>
107     
108     </head>
109
110     <body onLoad="test()">
111
112         <video id='vid' controls></video>
113
114         <p>Test that a remote video element will not use a local &lt;source&gt;, and will
115         use another remote &lt;source&gt;</p>
116
117         <p>This test only works in DRT</p>
118
119     </body>
120 </html>