Break pluginReplacementEnabled into youTubeFlashPluginReplacementEnabled and quickTim...
[WebKit-https.git] / LayoutTests / plugins / quicktime-plugin-replacement.html
1 <!DOCTYPE html>
2 <html>
3     <head>
4         <script src="../resources/js-test-pre.js"></script>
5         <script>
6             var embed;
7             var orangeURL = "orange.mov";
8             var yellowURL = "yellow.mov";
9
10             function logEvent(event)
11             {
12                 debug("<i>EVENT(" + event.type + ")</i>");
13             }
14             
15             function seeked()
16             {
17                 debug("");
18                 shouldEvaluateTo("embed.GetTime()", embed.GetTimeScale() * 2);
19                 evalAndLog("embed.Play()");
20             }
21
22             function playing(event)
23             {
24                 embed.removeEventListener("qt_play", playing, true);
25                 debug("");
26                 logEvent(event);
27                 shouldEvaluateTo("embed.GetRate()", 1);
28                 evalAndLog("embed.Stop()");
29             }
30             
31             function clearURL(event)
32             {
33                 logEvent(event)
34
35                 shouldBeTrue("embed.GetURL().indexOf('" + yellowURL + "') != -1");
36
37                 debug("<br>** SetURL to an empty string should generate an error.");
38                 evalAndLog("embed.SetURL('')");
39             }
40
41             function paused(event)
42             {
43                 debug("");
44                 logEvent(event)
45                 shouldEvaluateTo("embed.GetRate()", 0);
46
47                 debug("<br>** SetURL expects a url relative to the original src, not to the document.");
48                 embed.addEventListener("qt_canplaythrough", clearURL, true);
49                 evalAndLog("embed.SetURL('" + yellowURL + "')");
50             }
51
52             function error(event)
53             {
54                 logEvent(event)
55                 shouldBeEqualToString("embed.GetURL()", "");
56                 shouldBeEqualToString("embed.GetPluginStatus()", "Error");
57                 debug("<br>END TEST.");
58                 if (window.testRunner)
59                     testRunner.notifyDone();
60             }
61
62             function testElement(event)
63             {
64                 embed.removeEventListener("qt_canplaythrough", testElement, true);
65                 logEvent(event)
66
67                 if (window.internals) {
68                     debug("<br>** Test to make sure &lt;video&gt; element is in the shadow DOM.");
69                     evalAndLog("shadowElement = internals.shadowRoot(embed).firstChild");
70                     shouldBeEqualToString("shadowElement.tagName", "VIDEO");
71                     shouldBeEqualToString("internals.shadowPseudoId(shadowElement)", "-webkit-plugin-replacement");
72                 } else {
73                     debug("");
74                     testFailed("This test must be run in DRT.");
75                     debug("");
76                 }
77
78                 debug("<br>** Test for the presence of overridden methods.");
79                 var methods = [ "SetURL", "GetURL", "Play", "Stop", "GetRate", "SetRate", "IsFullScreen", 
80                                 "ExitFullScreen", "GetPluginStatus", "GetTime", "SetTime", "SeekToDate", "GetDate", 
81                                 "GetDuration", "GetTimeScale", "GetMaxTimeLoaded", "GetMaxBytesLoaded", 
82                                 "GetMovieSize", "GetTimedMetadataUpdates", "GetAccessLog", "GetErrorLog"
83                               ];
84                 for (i = 0; i < methods.length; ++i) {
85                     var type = typeof embed[methods[i]];
86                     if (type == "function")
87                         testPassed("embed." + methods[i] + " is a function.");
88                     else
89                         testFailed("embed." + methods[i] + " should be a function but is \"" + type + "\".");
90                 }
91
92                 debug("<br>** Test overridden methods.");
93                 shouldBeTrue("embed.GetURL().indexOf('" + orangeURL + "') != -1");
94                 shouldEvaluateTo("embed.GetDuration()", 300000);
95                 shouldEvaluateTo("embed.GetMovieSize()", 24962);
96                 shouldEvaluateTo("embed.GetMaxTimeLoaded()", 300000);
97                 shouldEvaluateTo("embed.GetMaxBytesLoaded()", 24962);
98                 shouldEvaluateTo("embed.GetMovieSize()", 24962);
99                 shouldBeEqualToString("embed.GetPluginStatus()", "Playable");
100
101                 // "GetDate()" should return the current date, clear seconds and milliseconds 
102                 var now = new Date();
103                 shouldBeCloseTo("new Date(embed.GetDate()) - new Date()", 0, 100);
104
105                 evalAndLog("embed.SetTime(embed.GetTimeScale() * 2)");
106                 setTimeout(seeked, 500);
107             }
108             
109             function setup()
110             {
111                 if (window.testRunner) {
112                     window.testRunner.waitUntilDone();
113                     window.testRunner.dumpAsText()
114                     window.internals.settings.setQuickTimePluginReplacementEnabled(true);
115                 }
116
117                 div = document.getElementById("parent");
118
119                 debug("<br>** Test 'qtsrc'. src = "  + yellowURL + " qtsrc = " + orangeURL + ", qtsrc should load.");
120                 div.innerHTML = '<embed src="resources/' + yellowURL + '" qtsrc="' + orangeURL + '" width="640" height="480" postdomevents=true>';
121                 
122                 var events = [ "qt_begin", "qt_validated", "qt_enterfullscreen", "qt_exitfullscreen", 
123                                 "qt_loadedmetada", "qt_canplay", "qt_ended", "qt_timedmetadataupdated" 
124                               ];
125                 embed = div.firstChild;
126                 for (i = 0; i < events.length; ++i)
127                     embed.addEventListener(events[i], logEvent, true);
128                 embed.addEventListener("qt_canplaythrough", testElement, true);
129                 embed.addEventListener("qt_play", playing, true);
130                 embed.addEventListener("qt_pause", paused, true);
131                 embed.addEventListener("qt_error", error, true);
132             }
133         </script>
134     </head>
135
136     <body onload="setup()">
137         <div id=parent></div>
138         <p>
139         <div id=console></div>
140     </body>
141 </html>