Bug 1264529 - Add wpt for img adoption; r=jdm
authorEdgar Chen <echen@mozilla.com>
Wed, 18 Jan 2017 18:59:13 +0800
changeset 409591 e676a13582cb320644c0467996a4aa804dab0255
parent 409590 0f515e0bae0e90cb3fe772a5edf501fa0e6dfa7d
child 409592 7b8937970f9ca85db88cb2496f2112175fd847c8
child 409627 cda03201b522c7fd3e7b10827b04bf5483e32816
push id7391
push usermtabara@mozilla.com
push dateMon, 12 Jun 2017 13:08:53 +0000
treeherdermozilla-beta@2191d7f87e2e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjdm
bugs1264529
milestone55.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 1264529 - Add wpt for img adoption; r=jdm MozReview-Commit-ID: 35ulxlUdwgj
testing/web-platform/meta/MANIFEST.json
testing/web-platform/tests/html/semantics/embedded-content/the-img-element/adoption.html
--- a/testing/web-platform/meta/MANIFEST.json
+++ b/testing/web-platform/meta/MANIFEST.json
@@ -100542,16 +100542,22 @@
     ]
    ],
    "html/semantics/embedded-content/the-img-element/Image-constructor.html": [
     [
      "/html/semantics/embedded-content/the-img-element/Image-constructor.html",
      {}
     ]
    ],
+   "html/semantics/embedded-content/the-img-element/adoption.html": [
+    [
+     "/html/semantics/embedded-content/the-img-element/adoption.html",
+     {}
+    ]
+   ],
    "html/semantics/embedded-content/the-img-element/current-pixel-density/basic.html": [
     [
      "/html/semantics/embedded-content/the-img-element/current-pixel-density/basic.html",
      {}
     ]
    ],
    "html/semantics/embedded-content/the-img-element/current-pixel-density/error.html": [
     [
@@ -188237,16 +188243,20 @@
   "html/semantics/embedded-content/the-img-element/3.jpg": [
    "842453aa8de65e562f5925c3fac90431c186a7fa",
    "support"
   ],
   "html/semantics/embedded-content/the-img-element/Image-constructor.html": [
    "2047645c2bdecc90189878cc68e861087d7bd84b",
    "testharness"
   ],
+  "html/semantics/embedded-content/the-img-element/adoption.html": [
+   "6786386a825f42b04733a2e91c5e95ea907c00fc",
+   "testharness"
+  ],
   "html/semantics/embedded-content/the-img-element/brokenimg.jpg": [
    "200b8085f98203ccf455504727ba9d92203f1080",
    "support"
   ],
   "html/semantics/embedded-content/the-img-element/contains.json": [
    "74de4312124b394cb2d6442810af6938cb7360c3",
    "support"
   ],
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/html/semantics/embedded-content/the-img-element/adoption.html
@@ -0,0 +1,91 @@
+<!doctype html>
+<meta charset=utf-8>
+<title>Adopting an image updates the image data</title>
+<script src=/resources/testharness.js></script>
+<script src=/resources/testharnessreport.js></script>
+<div id=log></div>
+
+<!-- tests -->
+
+<div id="adoptTest1"></div>
+<picture id="adoptTest2">
+<source srcset="/images/green-2x2.png">
+</picture>
+
+<script>
+function resolve(url) {
+  if (url === "") {
+    return url;
+  }
+  var a = document.createElement('a');
+  a.href = url;
+  return a.href;
+}
+
+function t(desc, data, expect) {
+  async_test(function(t) {
+    var d = (new DOMParser()).parseFromString(data, 'text/html');
+    var i = d.querySelector('img');
+    i.onerror = this.unreached_func('got unexpected error event');
+    i.onload = this.step_func_done(function() {
+      assert_equals(i.currentSrc, resolve(expect));
+    });
+    var n = d.querySelector('[adopt-node]');
+    document.adoptNode(n);
+  }, desc);
+}
+
+onload = function() {
+
+  t('img (src only)',
+    '<img src="/images/green-1x1.png" adopt-node>',
+    '/images/green-1x1.png');
+
+  t('img (src only), parent is picture',
+    '<picture adopt-node><img src="/images/green-1x1.png"></picture>',
+    '/images/green-1x1.png');
+
+  t('img (src only), previous sibling is source',
+    '<picture adopt-node><source srcset="/images/green-1x1.png"><img src="/images/green-2x2.png"></picture>',
+    '/images/green-1x1.png');
+
+  t('img (srcset 1 cand)',
+    '<img srcset="/images/green-1x1.png" adopt-node>',
+    '/images/green-1x1.png');
+
+  t('img (srcset 1 cand), parent is picture',
+    '<picture adopt-node><img srcset="/images/green-1x1.png"></picture>',
+    '/images/green-1x1.png');
+
+  t('img (srcset 1 cand), previous sibling is source',
+    '<picture adopt-node><source srcset="/images/green-1x1.png"><img srcset="/images/green-2x2.png"></picture>',
+    '/images/green-1x1.png');
+
+  async_test(function(t) {
+    var d = (new DOMParser()).parseFromString('<template><img src="/images/green-1x1.png"></template>', 'text/html');
+    var i = d.querySelector('template').content.querySelector('img').cloneNode(1);
+    i.onerror = this.unreached_func('got unexpected error event');
+    i.onload = this.step_func_done(function() {
+      assert_equals(i.currentSrc, resolve('/images/green-1x1.png'));
+    });
+
+    document.getElementById('adoptTest1').appendChild(i);
+  }, 'adopt a cloned img in template');
+
+  async_test(function(t) {
+    var preload = new Image();
+    preload.src = '/images/green-1x1.png?' + Math.random();
+    preload.onload = t.step_func(function() {
+      var d = (new DOMParser()).parseFromString('<img src="' + preload.src + '">', 'text/html');
+      var i = d.querySelector('img');
+      i.onerror = this.unreached_func('got unexpected error event');
+      i.onload = this.step_func_done(function() {
+        assert_equals(i.currentSrc, resolve("/images/green-2x2.png"));
+      });
+
+      var p = document.getElementById('adoptTest2');
+      p.appendChild(i);
+    });
+  }, 'adoption is from appendChild');
+};
+</script>