Bug 1082450 - Tests. r=gabor
authorBobby Holley <bobbyholley@gmail.com>
Wed, 15 Oct 2014 15:05:10 +0200
changeset 210545 204a676d3c8efcecd13af0251317db33b1614024
parent 210544 76dca963dd49a294791c37c4e544b6317b8ff829
child 210546 db0912d0106deb90f48d82c46b73ef84e356351e
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewersgabor
bugs1082450
milestone36.0a1
Bug 1082450 - Tests. r=gabor
js/xpconnect/tests/unit/test_bug1082450.js
js/xpconnect/tests/unit/xpcshell.ini
new file mode 100644
--- /dev/null
+++ b/js/xpconnect/tests/unit/test_bug1082450.js
@@ -0,0 +1,40 @@
+const Cu = Components.utils;
+function run_test() {
+
+  var sb = new Cu.Sandbox('http://www.example.com');
+  function checkThrows(str, rgxp) {
+    try {
+      sb.eval(str);
+      do_check_true(false);
+    } catch (e) {
+      do_check_true(rgxp.test(e));
+    }
+  }
+
+  sb.exposed = {
+    get getterProp() { return 42; },
+    set setterProp(x) { },
+    get getterSetterProp() { return 42; },
+    set getterSetterProp(x) { },
+    simpleValueProp: 42,
+    objectValueProp: { val: 42, __exposedProps__: { val: 'r' } },
+    contentCallableValueProp: new sb.Function('return 42'),
+    chromeCallableValueProp: function() {},
+    __exposedProps__: { getterProp : 'r',
+                        setterProp : 'w',
+                        getterSetterProp: 'rw',
+                        simpleValueProp: 'r',
+                        objectValueProp: 'r',
+                        contentCallableValueProp: 'r',
+                        chromeCallableValueProp: 'r' }
+  };
+
+  do_check_eq(sb.eval('exposed.simpleValueProp'), 42);
+  do_check_eq(sb.eval('exposed.objectValueProp.val'), 42);
+  checkThrows('exposed.getterProp;', /privileged accessor/i);
+  checkThrows('exposed.setterProp = 42;', /privileged accessor/i);
+  checkThrows('exposed.getterSetterProp;', /privileged accessor/i);
+  checkThrows('exposed.getterSetterProp = 42;', /privileged accessor/i);
+  do_check_eq(sb.eval('exposed.contentCallableValueProp()'), 42);
+  checkThrows('exposed.chromeCallableValueProp();', /privileged or cross-origin callable/i);
+}
--- a/js/xpconnect/tests/unit/xpcshell.ini
+++ b/js/xpconnect/tests/unit/xpcshell.ini
@@ -46,16 +46,17 @@ support-files =
 [test_bug961054.js]
 [test_bug976151.js]
 [test_bug1001094.js]
 [test_bug1021312.js]
 [test_bug1033253.js]
 [test_bug1033920.js]
 [test_bug1033927.js]
 [test_bug1034262.js]
+[test_bug1082450.js]
 [test_bug_442086.js]
 [test_file.js]
 [test_blob.js]
 [test_blob2.js]
 [test_file2.js]
 [test_import.js]
 [test_import_fail.js]
 [test_interposition.js]