2009-04-15 Eric Carlson <eric.carlson@apple.com>
[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/resources/silence.mpg";
65
66             function loadedmetadata(evt) 
67             { 
68                 var src = video.currentSrc;
69                 var localFile = localMovie.substring(localMovie.lastIndexOf("/")+1, localMovie.length)
70                 var remoteFile = remoteUrl.substring(remoteUrl.lastIndexOf("/")+1, remoteUrl.length)
71
72                 logEvent(evt);
73                 consoleWrite("url " + src + " loaded.<br>");
74                 if (src.indexOf(localFile) > 0)
75                     logResult("local movie loaded", false);
76                 else if (src.indexOf(remoteFile) > 0)
77                     logResult("remote movie loaded, local movie failed to load", true);
78                 endTest();
79             }
80
81             if (window.layoutTestController) 
82             {
83                 localMovie = layoutTestController.pathToLocalResource(localMovie);
84                 layoutTestController.dumpAsText();
85                 layoutTestController.waitUntilDone();
86             }
87             setTimeout(hanged, 10000);
88
89             function test() 
90             {
91                 video = document.getElementById("vid");
92
93                 video.addEventListener("error", error);
94                 video.addEventListener('loadedmetadata', loadedmetadata);
95
96                 // Create two <source> children, the first with a local url and the second
97                 // with a remote url. The element should load the second.
98                 var src1 = document.createElement("source");
99                 src1.setAttribute("src", localMovie);
100
101                 var src2 = document.createElement("source");
102                 src2.setAttribute("src", remoteUrl);
103
104                 video.appendChild(src1);
105                 video.appendChild(src2);
106             }
107         </script>
108     
109     </head>
110
111     <body onLoad="test()">
112
113         <video id='vid' controls></video>
114
115         <p>Test that a remote video element will not use a local &lt;source&gt;, and will
116         use another remote &lt;source&gt;</p>
117
118         <p>This test only behaves correctly in DRT</p>
119
120     </body>
121 </html>