Bug 1383122 - P3. Don't set src attribute to null. r?jwwang draft
authorJean-Yves Avenard <jyavenard@mozilla.com>
Fri, 21 Jul 2017 19:05:54 +0200
changeset 613121 0dff5036a0f76e13f8c353826f8c7de91a52308c
parent 613120 f1bee1c978ccbbaafd6b5e25d9e569479c8e6223
child 638624 684181cf9fd15ff9ba39714164777340cfb13532
push id69740
push userbmo:jyavenard@mozilla.com
push dateFri, 21 Jul 2017 17:44:57 +0000
reviewersjwwang
bugs1383122
milestone56.0a1
Bug 1383122 - P3. Don't set src attribute to null. r?jwwang Setting the src attribute to null was incorrect, per spec https://www.w3.org/TR/WebIDL-1/#es-DOMString, if null is passed, this is to be treated as ToString(null), which is "null" (https://tc39.github.io/ecma262/#sec-tostring). Hence setting src to null will cause a 404 error as it attempts to load "null". To unload the element, recommended practice is: Per spec: https://html.spec.whatwg.org/multipage/media.html#best-practices-for-authors-using-media-elements "by removing the element's src attribute and any source element descendants, and invoking the element's load() method." MozReview-Commit-ID: 5Lq13CeDCSZ
dom/media/mediasource/test/mediasource.js
dom/media/test/eme.js
dom/media/test/file_access_controls.html
--- a/dom/media/mediasource/test/mediasource.js
+++ b/dom/media/mediasource/test/mediasource.js
@@ -19,17 +19,18 @@ function runWithMSE(testFunction) {
     el.src = URL.createObjectURL(ms);
     el.preload = "auto";
 
     document.body.appendChild(el);
     SimpleTest.registerCleanupFunction(function () {
       el.remove();
       // Don't trigger load algorithm to prevent 'error' events.
       el.preload = "none";
-      el.src = null;
+      el.removeAttribute("src");
+      el.load();
     });
 
     testFunction(ms, el);
   }
 
   addLoadEvent(function () {
     SpecialPowers.pushPrefEnv({"set": gMSETestPrefs}, bootstrapTest);
   });
--- a/dom/media/test/eme.js
+++ b/dom/media/test/eme.js
@@ -376,17 +376,18 @@ function ProcessInitData(v, test, token,
 
 /*
  * Clean up the |v| element.
  */
 function CleanUpMedia(v) {
   v.setMediaKeys(null);
   v.remove();
   v.onerror = null;
-  v.src = null;
+  v.removeAttribute("src");
+  v.load();
 }
 
 /*
  * Close all sessions and clean up the |v| element.
  */
 function CloseSessions(v, sessions) {
   return Promise.all(sessions.map(s => s.close()))
   .then(CleanUpMedia(v));
--- a/dom/media/test/file_access_controls.html
+++ b/dom/media/test/file_access_controls.html
@@ -118,35 +118,36 @@ function nextTest() {
       window.close();
       return;
     }
   }
 
   if (gVideo) {
     gVideo.remove();
     gVideo.preload = "none"; // Don't trigger load algorithm.
-    gVideo.src = null;
+    gVideo.removeAttribute("src");
+    gVideo.load();
   }
 
   gVideo = null;
-  SpecialPowers.forceGC();  
-  
+  SpecialPowers.forceGC();
+
   gVideo = createVideo();
   gVideo.expectedResult = gTests[gTestNum].result;
   gVideo.testDescription = gTests[gTestNum].description;
   // Uniquify the resource URL to ensure that the resources loaded by earlier or subsequent tests
   // don't overlap with the resources we load here, which are loaded with non-default preferences set.
   // We also want to make sure that an HTTP fetch actually happens for each testcase.
   var url = gTests[gTestNum].url;
   var random = Math.floor(Math.random()*1000000000);
   url += (url.search(/\?/) < 0 ? "?" : "&") + "rand=" + random;
   gVideo.src = url;
   //dump("Starting test " + gTestNum + " at " + gVideo.src + " expecting:" + gVideo.expectedResult + "\n");
   if (!gTestedRemoved) {
-    document.body.appendChild(gVideo); 
+    document.body.appendChild(gVideo);
     // Will cause load() to be invoked.
   } else {
     gVideo.load();
   }
   gTestNum++;
 }
 
 function done() {