test_proxies_via_xray.html (3588B)
1 <!DOCTYPE HTML> 2 <html> 3 <!-- 4 https://bugzilla.mozilla.org/show_bug.cgi?id=1021066 5 --> 6 <head> 7 <meta charset="utf-8"> 8 <title>Test for Bug 1021066</title> 9 <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> 10 <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"/> 11 </head> 12 <body> 13 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1021066">Mozilla Bug 1021066</a> 14 <p id="display"></p> 15 <div id="content" style="display: none"> 16 <iframe id="t" src="http://example.org/tests/dom/bindings/test/file_proxies_via_xray.html"></iframe> 17 </div> 18 <pre id="test"> 19 <script type="application/javascript"> 20 21 /** Test for Bug 1021066 */ 22 23 function test() { 24 "use strict"; // So we'll get exceptions on sets 25 var doc = document.getElementById("t").contentWindow.document; 26 ok(!("x" in doc), "Should have an Xray here"); 27 is(doc.x, undefined, "Really should have an Xray here"); 28 is(doc.wrappedJSObject.x, 5, "And wrapping the right thing"); 29 30 // Test overridebuiltins binding without named setter 31 is(doc.y, doc.getElementById("y"), 32 "Named getter should work on Document"); 33 try { 34 doc.z = 5; 35 ok(false, "Should have thrown on set of readonly property on Document"); 36 } catch (e) { 37 ok(/read-only/.test(e.message), 38 "Threw the right exception on set of readonly property on Document"); 39 } 40 41 doc.w = 5; 42 is(doc.w, 5, "Should be able to set things that are not named props"); 43 44 // Test non-overridebuiltins binding without named setter 45 var l = doc.getElementsByTagName("img"); 46 is(l.y, doc.getElementById("y"), 47 "Named getter should work on HTMLCollection"); 48 try { 49 l.z = 5; 50 ok(false, "Should have thrown on set of readonly property on HTMLCollection"); 51 } catch (e) { 52 ok(/read-only/.test(e.message), 53 "Should throw the right exception on set of readonly property on HTMLCollection"); 54 } 55 try { 56 l[10] = 5; 57 ok(false, "Should have thrown on set of indexed property on HTMLCollection"); 58 } catch (e) { 59 ok(/doesn't have an indexed property setter/.test(e.message), 60 "Should throw the right exception on set of indexed property on HTMLCollection"); 61 } 62 63 // Test overridebuiltins binding with named setter 64 var d = doc.documentElement.dataset; 65 d.foo = "bar"; 66 // Check that this actually got passed on to the underlying object. 67 is(d.wrappedJSObject.foo, "bar", 68 "Set should get forwarded to the underlying object"); 69 is(doc.documentElement.getAttribute("data-foo"), "bar", 70 "Attribute setter should have been called"); 71 d.foo = "baz"; 72 // Check that this actually got passed on to the underlying object. 73 is(d.wrappedJSObject.foo, "baz", 74 "Set should get forwarded to the underlying object again"); 75 is(doc.documentElement.getAttribute("data-foo"), "baz", 76 "Attribute setter should have been called again"); 77 78 // Test non-overridebuiltins binding with named setter 79 var s = doc.defaultView.localStorage; 80 s.test_proxies_via_xray = "bar"; 81 // Check that this actually got passed on to the underlying object. 82 is(s.wrappedJSObject.test_proxies_via_xray, "bar", 83 "Set should get forwarded to the underlying object without overridebuiltins"); 84 s.test_proxies_via_xray = "baz"; 85 // Check that this actually got passed on to the underlying object. 86 is(s.wrappedJSObject.test_proxies_via_xray, "baz", 87 "Set should get forwarded to the underlying object again without overridebuiltins"); 88 89 SimpleTest.finish(); 90 } 91 92 SimpleTest.waitForExplicitFinish(); 93 addLoadEvent(test); 94 95 </script> 96 </pre> 97 </body> 98 </html>