Bug 1198438, having a JS implemented nsIContentPolicy shouldn't break srcset and picture tests, r=johns
authorOlli Pettay <Olli.Pettay@helsinki.fi>
Fri, 25 Sep 2015 03:20:31 +0300
changeset 264304 2b5a7e0e2082f72e9bab6f879c5a74ff7d590450
parent 264303 0ab67cace54fdce557e2156106d30b1e4ac94883
child 264305 619a486559623a2aa176ad0489c674f819351364
push id65591
push useropettay@mozilla.com
push dateFri, 25 Sep 2015 00:23:30 +0000
treeherdermozilla-inbound@2b5a7e0e2082 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjohns
bugs1198438
milestone44.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1198438, having a JS implemented nsIContentPolicy shouldn't break srcset and picture tests, r=johns
dom/tests/mochitest/general/test_picture_pref.html
dom/tests/mochitest/general/test_srcset_pref.html
--- a/dom/tests/mochitest/general/test_picture_pref.html
+++ b/dom/tests/mochitest/general/test_picture_pref.html
@@ -66,26 +66,27 @@ https://bugzilla.mozilla.org/show_bug.cg
       });
       document.body.appendChild(iframe);
       iframe.src = "data:text/html;base64," + btoa(container.innerHTML);
     });
   }
 
   function runTest(iframe) {
     var doc = iframe.contentDocument;
+    var win = iframe.contentWindow;
     var img = doc.querySelector("img");
     var source = doc.querySelector("source");
 
     is(img.sizes, undefined, "sizes should not be visible on <img>");
     is(source.sizes, undefined, "sizes should not be visible on <source>");
     is(source.srcset, undefined, "srcset should not be visible on <source>");
 
-    var imgSizesDesc = Object.getOwnPropertyDescriptor(HTMLImageElement.prototype, "sizes");
-    var sourceSizesDesc = Object.getOwnPropertyDescriptor(HTMLSourceElement.prototype, "sizes");
-    var sourceSrcsetDesc = Object.getOwnPropertyDescriptor(HTMLSourceElement.prototype, "srcset");
+    var imgSizesDesc = Object.getOwnPropertyDescriptor(win.HTMLImageElement.prototype, "sizes");
+    var sourceSizesDesc = Object.getOwnPropertyDescriptor(win.HTMLSourceElement.prototype, "sizes");
+    var sourceSrcsetDesc = Object.getOwnPropertyDescriptor(win.HTMLSourceElement.prototype, "srcset");
     is(imgSizesDesc, undefined, "HTMLImageElement should know nothing of sizes");
     is(sourceSizesDesc, undefined, "HTMLSourceElement should know nothing of sizes");
     is(sourceSrcsetDesc, undefined, "HTMLSourceElement should know nothing of srcset");
 
     // Make sure the test images loaded red.png, which is 1x1, not big.png
     for (var id of [ 'img1', 'img2' ]) {
       var testImg = doc.getElementById(id);
       is(testImg.naturalWidth, 1, "Image should have loaded small source");
--- a/dom/tests/mochitest/general/test_srcset_pref.html
+++ b/dom/tests/mochitest/general/test_srcset_pref.html
@@ -7,36 +7,35 @@ https://bugzilla.mozilla.org/show_bug.cg
   <title>Test for dom.image.srcset.enabled (Bug 870021)</title>
   <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
 </head>
 <body onload="setupTest()">
 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=870021">Mozilla Bug 870021</a>
 
 <div id="imgContainer">
-<img src="http://example.com/tests/image/test/mochitest/blue.png"
-     srcset="http://example.com/tests/image/test/mochitest/big.png">
 </div>
 
 <script type="application/javascript">
 
   const srcsetPref = 'dom.image.srcset.enabled';
 
   SimpleTest.waitForExplicitFinish();
 
   is(SpecialPowers.getBoolPref(srcsetPref), true, "srcset should be enabled by default");
 
   function setupTest() {
     // Ensure that disabling the pref works as expected
     SpecialPowers.pushPrefEnv({'set': [[ "dom.image.srcset.enabled", false ]] }, function() {
       var container = document.querySelector("#imgContainer");
-      // We want to re-create the element with the pref disabled to ensure
-      // webIDL attributes are not attached
-      container.innerHTML = container.innerHTML + " ";
-      var img = container.querySelector("img");
+
+      var img = document.createElement("img");
+      img.setAttribute("src", "http://example.com/tests/image/test/mochitest/blue.png");
+      img.setAttribute("srcset", "http://example.com/tests/image/test/mochitest/big.png");
+      container.insertBefore(img, container.firstChild);
       img.addEventListener("load", function imgLoad() {
         img.removeEventListener("load", imgLoad);
         runTest();
       });
     });
   }
 
   function runTest() {