Bug 1529462 [wpt PR 15482] - Add some tests for the realms involved in creating new platform objects., a=testonly
☠☠ backed out by 66b1aba3fb43 ☠ ☠
authorMs2ger <Ms2ger@gmail.com>
Wed, 06 Mar 2019 16:52:21 +0000
changeset 522298 5eca1c95182a68ff4b0506bc6e501d3cc625a26a
parent 522297 467ad65e9ecfdc85cd7deca4aab57fd4502ee612
child 522299 899598b6d7ffc8a05855f901c6b4dc2c5db38f6a
push id10871
push usercbrindusan@mozilla.com
push dateMon, 18 Mar 2019 15:49:32 +0000
treeherdermozilla-beta@018abdd16060 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstestonly
bugs1529462, 15482
milestone67.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 1529462 [wpt PR 15482] - Add some tests for the realms involved in creating new platform objects., a=testonly Automatic update from web-platform-tests Add some tests for the realms involved in creating new platform objects. (#15482) -- wpt-commits: 1b2fbac6ae44eb3b88c1b01da2d2358eb2f7ef45 wpt-pr: 15482
testing/web-platform/tests/WebIDL/ecmascript-binding/constructors-support.html
testing/web-platform/tests/WebIDL/ecmascript-binding/constructors.html
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/WebIDL/ecmascript-binding/constructors-support.html
@@ -0,0 +1,8 @@
+<!DOCTYPE html>
+<script>
+window.badNewTarget = function() {};
+badNewTarget.prototype = 8;
+
+window.DOMParserSubclass = class extends DOMParser {}
+window.ForeignDOMParserSubclass = class extends parent.DOMParser {}
+</script>
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/WebIDL/ecmascript-binding/constructors.html
@@ -0,0 +1,96 @@
+<!DOCTYPE html>
+<meta charset=utf-8>
+<title>Realm for constructed objects</title>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<div id=log></div>
+<script>
+function object_realm(dp) {
+  // Note that browsers use the URL of the relevant global object's associated
+  // Document.
+  // https://github.com/w3c/DOM-Parsing/issues/46
+  var url = DOMParser.prototype.parseFromString.call(dp, "x", "text/html").documentURI;
+  var file = url.slice(url.lastIndexOf("/") + 1);
+  switch (file) {
+  case "constructors.html":
+    return "parent window";
+  case "constructors-support.html":
+    return "child window";
+  default:
+    return "???";
+  }
+}
+
+async_test(function() {
+  var iframe = document.createElement("iframe");
+  iframe.onload = this.step_func_done(function() {
+    var child = iframe.contentWindow;
+    test(function() {
+      var dp = new DOMParser();
+      assert_equals(Object.getPrototypeOf(dp), DOMParser.prototype);
+      assert_equals(object_realm(dp), "parent window");
+    }, "Normal constructor in parent window");
+
+    test(function() {
+      var dp = new child.DOMParser();
+      assert_equals(Object.getPrototypeOf(dp), child.DOMParser.prototype);
+      assert_equals(object_realm(dp), "child window");
+    }, "Normal constructor in child window");
+
+    test(function() {
+      var dp = Reflect.construct(child.DOMParser, [], DOMParser);
+      assert_equals(Object.getPrototypeOf(dp), DOMParser.prototype);
+      assert_equals(object_realm(dp), "child window");
+    }, "Constructor in child window with normal NewTarget from parent window");
+
+    test(function() {
+      var dp = Reflect.construct(DOMParser, [], child.DOMParser);
+      assert_equals(Object.getPrototypeOf(dp), child.DOMParser.prototype);
+      assert_equals(object_realm(dp), "parent window");
+    }, "Constructor in parent window with normal NewTarget from child window");
+
+    test(function() {
+      class DOMParserSubclass extends DOMParser {}
+      var dp = new DOMParserSubclass();
+      assert_equals(Object.getPrototypeOf(dp), DOMParserSubclass.prototype);
+      assert_equals(object_realm(dp), "parent window");
+    }, "Subclass constructor in parent window");
+
+    test(function() {
+      var dp = new child.DOMParserSubclass();
+      assert_equals(Object.getPrototypeOf(dp), child.DOMParserSubclass.prototype);
+      assert_equals(object_realm(dp), "child window");
+    }, "Subclass constructor in child window");
+
+    test(function() {
+      class ForeignDOMParserSubclass extends child.DOMParser {}
+      var dp = new ForeignDOMParserSubclass();
+      assert_equals(Object.getPrototypeOf(dp), ForeignDOMParserSubclass.prototype);
+      assert_equals(object_realm(dp), "child window");
+    }, "Subclass constructor in parent window with parent class in child window");
+
+    test(function() {
+      var dp = new child.ForeignDOMParserSubclass();
+      assert_equals(Object.getPrototypeOf(dp), child.ForeignDOMParserSubclass.prototype);
+      assert_equals(object_realm(dp), "parent window");
+    }, "Subclass constructor in child window with parent class in parent window");
+
+    test(function() {
+      var badNewTarget = function() {};
+      badNewTarget.prototype = 7;
+
+      var dp = Reflect.construct(child.DOMParser, [], badNewTarget);
+      assert_equals(Object.getPrototypeOf(dp), DOMParser.prototype);
+      assert_equals(object_realm(dp), "child window");
+    }, "Constructor in child window with bad NewTarget from parent window");
+
+    test(function() {
+      var dp = Reflect.construct(DOMParser, [], child.badNewTarget);
+      assert_equals(Object.getPrototypeOf(dp), child.DOMParser.prototype);
+      assert_equals(object_realm(dp), "parent window");
+    }, "Constructor in parent window with bad NewTarget from child window");
+  });
+  iframe.src = "constructors-support.html";
+  document.body.appendChild(iframe);
+});
+</script>