Bug 1348099 part 2 - Add tests for DOM Xrays that properties are exposed to only proper object types. r?bz draft
authorTing-Yu Chou <janus926@gmail.com>
Thu, 22 Jun 2017 14:43:11 +0800
changeset 601715 d5eba2ff18d646f6d47eea916cff8294ccb07f65
parent 601714 1f50ef621abee0b705e35f113abe810ec8890cb5
child 601997 fb345dfd7da5bd81a8ca7db1b26470e20030d4aa
child 601998 84614cfa6a6616452d0a0a1de47c527da90f10b1
push id66199
push userbmo:janus926@gmail.com
push dateThu, 29 Jun 2017 03:01:06 +0000
reviewersbz
bugs1348099
milestone56.0a1
Bug 1348099 part 2 - Add tests for DOM Xrays that properties are exposed to only proper object types. r?bz MozReview-Commit-ID: Iu86lAviFJK
dom/bindings/test/test_dom_xrays.html
--- a/dom/bindings/test/test_dom_xrays.html
+++ b/dom/bindings/test/test_dom_xrays.html
@@ -214,16 +214,73 @@ function test()
   is(storage.foo, "bar", "Should have a 'foo' property");
   ok('foo' in storage, "Really should have a 'foo' property");
   is(storage.getItem("foo"), "bar", "Should have an item named 'foo'");
   delete storage.foo
   is(storage.foo, undefined, "Should not have a 'foo' property again");
   ok(!('foo' in storage), "Really should not have a 'foo' property again");
   is(storage.getItem("foo"), null, "Should not have an item named 'foo' again");
 
+  // Non-static properties are not exposed on interface objects or instances.
+  is(win.HTMLInputElement.checkValidity, undefined,
+     "Shouldn't see non-static property on interface objects");
+  is(Object.getOwnPropertyDescriptor(win.HTMLInputElement, "checkValidity"), undefined,
+     "Shouldn't see non-static property on interface objects");
+  is(Object.getOwnPropertyNames(win.HTMLInputElement).indexOf("checkValidity"), -1,
+     "Shouldn't see non-static property on interface objects");
+  isnot(typeof doc.createElement("input").checkValidity, "undefined",
+        "Should see non-static property on prototype objects");
+  is(Object.getOwnPropertyDescriptor(doc.createElement("input"), "checkValidity"), undefined,
+     "Shouldn't see non-static property on instances");
+  isnot(typeof Object.getOwnPropertyDescriptor(win.HTMLInputElement.prototype, "checkValidity"), "undefined",
+        "Should see non-static property on prototype objects");
+
+  // Static properties are not exposed on prototype objects or instances.
+  isnot(typeof win.URL.createObjectURL, "undefined",
+        "Should see static property on interface objects");
+  isnot(typeof Object.getOwnPropertyDescriptor(win.URL, "createObjectURL"), "undefined",
+        "Should see static property on interface objects");
+  isnot(Object.getOwnPropertyNames(win.URL).indexOf("createObjectURL"), -1,
+        "Should see static property on interface objects");
+  is(new URL('http://example.org').createObjectURL, undefined,
+     "Shouldn't see static property on instances and prototype ojbects");
+  is(Object.getOwnPropertyDescriptor(new URL('http://example.org'), "createObjectURL"), undefined,
+     "Shouldn't see static property on instances");
+  is(Object.getOwnPropertyDescriptor(win.URL.prototype, "createObjectURL"), undefined,
+     "Shouldn't see static property on prototype objects");
+
+  // Unforgeable properties are not exposed on prototype objects or interface
+  // objects.
+  is(Window.document, undefined,
+     "Shouldn't see unforgeable property on interface objects");
+  is(Object.getOwnPropertyDescriptor(Window, "document"), undefined,
+     "Shouldn't see unforgeable property on interface objects");
+  is(Object.getOwnPropertyNames(Window).indexOf("document"), -1,
+     "Shouldn't see unforgeable property on interface objects");
+  isnot(typeof win.document, "undefined",
+        "Should see unforgeable property on instances");
+  isnot(typeof Object.getOwnPropertyDescriptor(win, "document"), "undefined",
+        "Should see unforgeable property on instances");
+  is(Object.getOwnPropertyDescriptor(Window.prototype, "document"), undefined,
+     "Shouldn't see unforgeable property on prototype objects");
+
+  // Constant properties are not exposted on instances.
+  isnot(typeof win.Node.ELEMENT_NODE, "undefined",
+        "Should see constant property on interface objects");
+  isnot(typeof Object.getOwnPropertyDescriptor(win.Node, "ELEMENT_NODE"), "undefined",
+        "Should see constant property on interface objects");
+  isnot(Object.getOwnPropertyNames(win.Node).indexOf("ELEMENT_NODE"), -1,
+        "Should see constant property on interface objects");
+  isnot(typeof elem.ELEMENT_NODE, "undefined",
+        "Should see constant property on prototype objects");
+  is(Object.getOwnPropertyDescriptor(elem, "ELEMENT_NODE"), undefined,
+     "Shouldn't see constant property on instances");
+  isnot(typeof Object.getOwnPropertyDescriptor(win.Node.prototype, "ELEMENT_NODE"), "undefined",
+        "Should see constant property on prototype objects");
+
   SimpleTest.finish();
 }
 
 SimpleTest.waitForExplicitFinish();
 addLoadEvent(test);
 
 </script>
 </pre>