Bug 853709 - Tests. r=mrbkap
authorBobby Holley <bobbyholley@gmail.com>
Wed, 01 Oct 2014 13:52:43 +0200
changeset 208192 9956ea441d9174d35dc3ddf3a40c767f96658bb0
parent 208191 1c6f050126d7200a72802ebec3c51dc7e9f904f9
child 208193 df8c49b33b2219add48ed17521fc35fc77757f87
push id27580
push userkwierso@gmail.com
push dateWed, 01 Oct 2014 23:26:55 +0000
treeherderautoland@af6c928893c0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmrbkap
bugs853709
milestone35.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 853709 - Tests. r=mrbkap
js/xpconnect/tests/unit/test_bug853709.js
js/xpconnect/tests/unit/xpcshell.ini
new file mode 100644
--- /dev/null
+++ b/js/xpconnect/tests/unit/test_bug853709.js
@@ -0,0 +1,35 @@
+const Cu = Components.utils;
+
+function setupChromeSandbox() {
+  this.chromeObj = {a: 2, __exposedProps__: {a: "rw", b: "rw"} };
+  this._b = 3;
+  Object.defineProperty(chromeObj, 'b', { configurable: true,
+                                          get: function() { return _b; },
+                                          set: function(val) { _b = val; } });
+  this.chromeArr = [4, 2, 1];
+}
+
+function checkDefineThrows(sb, obj, prop, desc) {
+  var result = Cu.evalInSandbox('(function() { try { Object.defineProperty(' + obj + ', "' + prop + '", ' + desc.toSource() + '); return "nothrow"; } catch (e) { return e.toString(); }})();', sb);
+  do_check_neq(result, 'nothrow');
+  do_check_true(!!/denied/.exec(result));
+  do_check_true(result.indexOf(prop) != -1); // Make sure the prop name is in the error message.
+}
+
+function run_test() {
+  var chromeSB = new Cu.Sandbox(this);
+  var contentSB = new Cu.Sandbox('http://www.example.org');
+  Cu.evalInSandbox('(' + setupChromeSandbox.toSource() + ')()', chromeSB);
+  contentSB.chromeObj = chromeSB.chromeObj;
+  contentSB.chromeArr = chromeSB.chromeArr;
+
+  do_check_eq(Cu.evalInSandbox('chromeObj.a', contentSB), 2);
+  do_check_eq(Cu.evalInSandbox('chromeObj.b', contentSB), 3);
+  do_check_eq(Cu.evalInSandbox('chromeObj.b = 4; chromeObj.b', contentSB), 4);
+  do_check_eq(Cu.evalInSandbox('chromeArr[1]', contentSB), 2);
+
+  checkDefineThrows(contentSB, 'chromeObj', 'a', {get: function() { return 2; }});
+  checkDefineThrows(contentSB, 'chromeObj', 'a', {configurable: true, get: function() { return 2; }});
+  checkDefineThrows(contentSB, 'chromeObj', 'b', {configurable: true, get: function() { return 2; }, set: function() {}});
+  checkDefineThrows(contentSB, 'chromeArr', '1', {configurable: true, get: function() { return 2; }});
+}
--- a/js/xpconnect/tests/unit/xpcshell.ini
+++ b/js/xpconnect/tests/unit/xpcshell.ini
@@ -30,16 +30,17 @@ support-files =
 [test_bug805807.js]
 [test_bug809652.js]
 [test_bug809674.js]
 [test_bug813901.js]
 [test_bug845201.js]
 [test_bug845862.js]
 [test_bug849730.js]
 [test_bug851895.js]
+[test_bug853709.js]
 [test_bug854558.js]
 [test_bug856067.js]
 [test_bug868675.js]
 [test_bug867486.js]
 [test_bug872772.js]
 [test_bug885800.js]
 [test_bug930091.js]
 [test_bug961054.js]