Fix QuickTime plug-in replacement scripting bugs
authoreric.carlson@apple.com <eric.carlson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 16 Dec 2013 16:04:50 +0000 (16:04 +0000)
committereric.carlson@apple.com <eric.carlson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 16 Dec 2013 16:04:50 +0000 (16:04 +0000)
https://bugs.webkit.org/show_bug.cgi?id=125717

Reviewed by Sam Weinig.

Source/WebCore:

No new tests, existing test updated.

* Modules/plugins/QuickTimePluginReplacement.js:
(Replacement): Change '' to "" to avoid "Empty character constant" warning when creating
    Derived Sources.
(Replacement.prototype.createVideoElement): Handle qtsrc attribute. Remember base url.
(Replacement.prototype.setURL): Resolve urls relative to base.

LayoutTests:

* plugins/quicktime-plugin-replacement-expected.txt:
* plugins/quicktime-plugin-replacement.html: Update to test 'qtsrc' attribute, and to check
    that relative urls are resolved correctly.
* plugins/resources/yellow.mov: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@160640 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/plugins/quicktime-plugin-replacement-expected.txt
LayoutTests/plugins/quicktime-plugin-replacement.html
LayoutTests/plugins/resources/yellow.mov [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/Modules/plugins/QuickTimePluginReplacement.js

index a9bfe1d..9ea1844 100644 (file)
@@ -1,3 +1,15 @@
+2013-12-16  Eric Carlson  <eric.carlson@apple.com>
+
+        Fix QuickTime plug-in replacement scripting bugs
+        https://bugs.webkit.org/show_bug.cgi?id=125717
+
+        Reviewed by Sam Weinig.
+
+        * plugins/quicktime-plugin-replacement-expected.txt:
+        * plugins/quicktime-plugin-replacement.html: Update to test 'qtsrc' attribute, and to check
+            that relative urls are resolved correctly.
+        * plugins/resources/yellow.mov: Added.
+
 2013-12-16  Mario Sanchez Prada  <mario.prada@samsung.com>
 
         [ATK] Expose accessibility objects with ATK_ROLE_CHECK_MENU_ITEM
index 0d14d56..297b8c1 100644 (file)
@@ -1,4 +1,6 @@
 
+
+** Test 'qtsrc'. src = yellow.mov qtsrc = orange.mov, qtsrc should load.
 EVENT(qt_begin)
 EVENT(qt_validated)
 EVENT(qt_canplay)
@@ -33,7 +35,7 @@ PASS embed.GetAccessLog is a function.
 PASS embed.GetErrorLog is a function.
 
 ** Test overridden methods.
-PASS embed.GetURL().indexOf('resources/orange.mov') != -1 is true
+PASS embed.GetURL().indexOf('orange.mov') != -1 is true
 PASS embed.GetDuration() is 300000
 PASS embed.GetMovieSize() is 24962
 PASS embed.GetMaxTimeLoaded() is 300000
@@ -53,6 +55,15 @@ embed.Stop()
 EVENT(qt_pause)
 PASS embed.GetRate() is 0
 
+** SetURL expects a url relative to the original src, not to the document.
+embed.SetURL('yellow.mov')
+EVENT(qt_begin)
+EVENT(qt_validated)
+EVENT(qt_canplay)
+EVENT(qt_canplaythrough)
+PASS embed.GetURL().indexOf('yellow.mov') != -1 is true
+
+** SetURL to an empty string should generate an error.
 embed.SetURL('')
 EVENT(qt_begin)
 EVENT(qt_error)
index 9031178..bf2472d 100644 (file)
@@ -4,7 +4,8 @@
         <script src="../resources/js-test-pre.js"></script>
         <script>
             var embed;
-            var src = "resources/orange.mov";
+            var orangeURL = "orange.mov";
+            var yellowURL = "yellow.mov";
 
             function logEvent(event)
             {
 
             function playing(event)
             {
+                embed.removeEventListener("qt_play", playing, true);
                 debug("");
                 logEvent(event);
                 shouldEvaluateTo("embed.GetRate()", 1);
                 evalAndLog("embed.Stop()");
             }
             
+            function clearURL(event)
+            {
+                logEvent(event)
+
+                shouldBeTrue("embed.GetURL().indexOf('" + yellowURL + "') != -1");
+
+                debug("<br>** SetURL to an empty string should generate an error.");
+                evalAndLog("embed.SetURL('')");
+            }
+
             function paused(event)
             {
                 debug("");
                 logEvent(event)
                 shouldEvaluateTo("embed.GetRate()", 0);
 
-                debug("");
-                evalAndLog("embed.SetURL('')");
+                debug("<br>** SetURL expects a url relative to the original src, not to the document.");
+                embed.addEventListener("qt_canplaythrough", clearURL, true);
+                evalAndLog("embed.SetURL('" + yellowURL + "')");
             }
-            
+
             function error(event)
             {
                 logEvent(event)
                 if (window.testRunner)
                     testRunner.notifyDone();
             }
-            
-            function test(event)
+
+            function testElement(event)
             {
+                embed.removeEventListener("qt_canplaythrough", testElement, true);
                 logEvent(event)
 
                 if (window.internals) {
                 }
 
                 debug("<br>** Test overridden methods.");
-                shouldBeTrue("embed.GetURL().indexOf('" + src + "') != -1");
+                shouldBeTrue("embed.GetURL().indexOf('" + orangeURL + "') != -1");
                 shouldEvaluateTo("embed.GetDuration()", 300000);
                 shouldEvaluateTo("embed.GetMovieSize()", 24962);
                 shouldEvaluateTo("embed.GetMaxTimeLoaded()", 300000);
                 shouldEvaluateTo("embed.GetMaxBytesLoaded()", 24962);
                 shouldEvaluateTo("embed.GetMovieSize()", 24962);
                 shouldBeEqualToString("embed.GetPluginStatus()", "Playable");
-                
+
                 // "GetDate()" should return the current date, clear seconds and milliseconds 
                 var now = new Date();
                 shouldBeCloseTo("new Date(embed.GetDate()) - new Date()", 0, 100);
                     window.testRunner.dumpAsText()
                     window.internals.settings.setPluginReplacementEnabled(true);
                 }
+
                 div = document.getElementById("parent");
-                div.innerHTML = '<embed src="' + src + '" width="640" height="480" postdomevents=true>';
+
+                debug("<br>** Test 'qtsrc'. src = "  + yellowURL + " qtsrc = " + orangeURL + ", qtsrc should load.");
+                div.innerHTML = '<embed src="resources/' + yellowURL + '" qtsrc="' + orangeURL + '" width="640" height="480" postdomevents=true>';
                 
                 var events = [ "qt_begin", "qt_validated", "qt_enterfullscreen", "qt_exitfullscreen", 
                                 "qt_loadedmetada", "qt_canplay", "qt_ended", "qt_timedmetadataupdated" 
                 embed = div.firstChild;
                 for (i = 0; i < events.length; ++i)
                     embed.addEventListener(events[i], logEvent, true);
-                embed.addEventListener("qt_canplaythrough", test, true);
+                embed.addEventListener("qt_canplaythrough", testElement, true);
                 embed.addEventListener("qt_play", playing, true);
                 embed.addEventListener("qt_pause", paused, true);
                 embed.addEventListener("qt_error", error, true);
diff --git a/LayoutTests/plugins/resources/yellow.mov b/LayoutTests/plugins/resources/yellow.mov
new file mode 100644 (file)
index 0000000..1dcd000
Binary files /dev/null and b/LayoutTests/plugins/resources/yellow.mov differ
index 6b66097..eeea934 100644 (file)
@@ -1,3 +1,18 @@
+2013-12-16  Eric Carlson  <eric.carlson@apple.com>
+
+        Fix QuickTime plug-in replacement scripting bugs
+        https://bugs.webkit.org/show_bug.cgi?id=125717
+
+        Reviewed by Sam Weinig.
+
+        No new tests, existing test updated.
+
+        * Modules/plugins/QuickTimePluginReplacement.js:
+        (Replacement): Change '' to "" to avoid "Empty character constant" warning when creating
+            Derived Sources.
+        (Replacement.prototype.createVideoElement): Handle qtsrc attribute. Remember base url.
+        (Replacement.prototype.setURL): Resolve urls relative to base.
+
 2013-12-15  Darin Adler  <darin@apple.com>
 
         Catch callers who forget to use initializeStyle
index 59c4397..9ffd2a7 100644 (file)
@@ -16,11 +16,12 @@ function Replacement(root, parent, host, attributeNames, attributeValues)
     this.postEvents = false;
     this.height = 0;
     this.width = 0;
-    this.src = '';
+    this.src = "";
     this.autohref = false;
-    this.href = '';
-    this.qtsrc = '';
-    this.target = '';
+    this.href = "";
+    this.qtsrc = "";
+    this.baseUrl = "";
+    this.target = "";
 
     this.createVideoElement(attributeNames, attributeValues);
     this.createScriptInterface();
@@ -45,6 +46,7 @@ Replacement.prototype = {
         postdomevents: 'postEvents',
         height: 'height',
         width: 'width',
+        qtsrc: 'qtsrc',
         src: 'src',
         airplay: 'x-webkit-airplay=',
         href: 'href',
@@ -94,15 +96,24 @@ Replacement.prototype = {
         video.setAttribute('controls', 'controls');
         this.setStatus('Waiting');
 
-        var src = this.src;
+        var src = this.resolveRelativeToUrl(this.src, "");
+        this.baseUrl = src;
+
+        // The 'qtsrc' attribute is used when a page author wanted to always use the QuickTime plug-in
+        // to load a media type even if another plug-in was registered for that type. It tells the
+        // plug-in to ignore the 'src' url, and to load the 'qtsrc' url instead.
+        if (this.qtsrc)
+            src = this.resolveRelativeToUrl(this.qtsrc, this.src);
         if (this.href && this.target) {
             src = this.resolveRelativeToUrl(this.href, this.src);
             video.poster = this.src;
             video.setAttribute('preload', 'none');
         }
         
-        if (src.length)
-            this.setURL(src);
+        if (src.length) {
+            this.setStatus('Validating');
+            this.video.src = src;
+        }
 
         this.root.appendChild(video);
     },
@@ -212,6 +223,8 @@ Replacement.prototype = {
     setURL: function(url)
     {
         this.setStatus('Validating');
+        if (url.length)
+            url = this.resolveRelativeToUrl(url, this.baseUrl);
         this.video.src = url;
     },