Bug 1017875 - Pref on <picture> element and update test
authorJohn Schoenick <jschoenick@mozilla.com>
Wed, 10 Dec 2014 18:54:00 -0500
changeset 229470 de043394a41dc8ae43911644a0ad6c435aadf345
parent 229469 f8cb71f5eda1dcb29a8faf6327082c7db7cb607c
child 229471 2bb299df4c331486538496c3de283798543e8996
push id11352
push userryanvm@gmail.com
push dateTue, 17 Feb 2015 19:29:37 +0000
treeherderfx-team@b6c56fab513d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs1017875
milestone38.0a1
Bug 1017875 - Pref on <picture> element and update test
dom/tests/mochitest/general/test_picture_pref.html
modules/libpref/init/all.js
--- a/dom/tests/mochitest/general/test_picture_pref.html
+++ b/dom/tests/mochitest/general/test_picture_pref.html
@@ -3,25 +3,26 @@
 <!--
 https://bugzilla.mozilla.org/show_bug.cgi?id=870022
 -->
 <head>
   <title>Test for dom.image.picture.enabled (Bug 870022)</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="runTest()">
+<body onload="setupTest()">
 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=870022">Mozilla Bug 870022</a>
 
-<!-- Tests that the picture pref is off pending bug 1017875, accounting
+<!-- Tests that the picture pref can still be disabled, accounting
      for dom.images.srcset.enabled being flipped on in the mean time. -->
 
-
 <!-- these should all load red.png (naturalWidth 1) not big.png (natural
      width 3000) regardless of dom.images.srcset.enabled being on or off -->
+
+<div id="testContainer">
 <picture>
   <source srcset="http://example.com/tests/image/test/mochitest/big.png">
   <img id="img1" src="http://example.com/tests/image/test/mochitest/red.png">
 </picture>
 
 <picture>
   <source srcset="http://example.com/tests/image/test/mochitest/big.png 500w"
           sizes="500w">
@@ -35,55 +36,71 @@ https://bugzilla.mozilla.org/show_bug.cg
 <img id="img-srcset-only"
      srcset="http://example.com/tests/image/test/mochitest/big.png 500w, http://example.com/tests/image/test/mochitest/red.png 1x"
      sizes="50px">
 
 <!-- Should not load regardless of srcset pref -->
 <img id="img-never"
      srcset="http://example.com/tests/image/test/mochitest/big.png 500w"
      sizes="50px">
+</div>
 
 <script type="application/javascript">
 
   const srcsetPref  = 'dom.image.srcset.enabled';
   const picturePref = 'dom.image.picture.enabled';
 
   SimpleTest.waitForExplicitFinish();
 
   var srcsetEnabled = SpecialPowers.getBoolPref(srcsetPref);
   var pictureEnabled = SpecialPowers.getBoolPref(picturePref);
 
-  is(pictureEnabled, false, "picture should be disabled pending bug 1017875");
+  is(pictureEnabled, true, "picture expected to be enabled by default");
 
-  function runTest() {
-    var img = document.querySelector("img");
-    var source = document.querySelector("source");
+  function setupTest() {
+    SpecialPowers.pushPrefEnv({'set': [[ "dom.image.picture.enabled", false ]] }, function() {
+      var container = document.querySelector("#testContainer");
+      // We want to re-create the elements with the pref disabled to ensure
+      // webIDL attributes are not attached
+      var iframe = document.createElement("iframe");
+      iframe.addEventListener("load", function() {
+        runTest(iframe);
+      });
+      document.body.appendChild(iframe);
+      iframe.src = "data:text/html;base64," + btoa(container.innerHTML);
+    });
+  }
+
+  function runTest(iframe) {
+    var doc = iframe.contentDocument;
+    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");
     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 = document.getElementById(id);
+      var testImg = doc.getElementById(id);
       is(testImg.naturalWidth, 1, "Image should have loaded small source");
     }
 
-    var srcsetOnlyImg = document.getElementById("img-srcset-only");
+    var srcsetOnlyImg = doc.getElementById("img-srcset-only");
     is(srcsetOnlyImg.naturalWidth, srcsetEnabled ? 1 : 0,
        "srcset image should only load if srcset is enabled, and never the computed width candidate");
 
-    var neverImg = document.getElementById("img-never");
+    var neverImg = doc.getElementById("img-never");
     is(neverImg.naturalWidth, 0, "Image should not have loaded");
 
     SimpleTest.finish();
   }
 
 </script>
 
 </body>
--- a/modules/libpref/init/all.js
+++ b/modules/libpref/init/all.js
@@ -4087,17 +4087,17 @@ pref("dom.vibrator.max_vibrate_list_len"
 
 // Battery API
 pref("dom.battery.enabled", true);
 
 // Image srcset
 pref("dom.image.srcset.enabled", true);
 
 // <picture> element and sizes
-pref("dom.image.picture.enabled", false);
+pref("dom.image.picture.enabled", true);
 
 // WebSMS
 pref("dom.sms.enabled", false);
 // Enable Latin characters replacement with corresponding ones in GSM SMS
 // 7-bit default alphabet.
 pref("dom.sms.strict7BitEncoding", false);
 pref("dom.sms.requestStatusReport", true);
 // Numeric default service id for SMS API calls with |serviceId| parameter