test_components.js (748B)
1 function run_test() { 2 var sb1 = Cu.Sandbox("http://www.blah.com"); 3 var sb2 = Cu.Sandbox(this); 4 var rv; 5 6 // non-chrome accessing chrome Components 7 sb1.C = Components; 8 checkThrows("C.interfaces", sb1); 9 checkThrows("C.utils", sb1); 10 checkThrows("C.classes", sb1); 11 12 // non-chrome accessing own Components: shouldn't exist. 13 Assert.equal(Cu.evalInSandbox("typeof Components", sb1), 'undefined'); 14 15 // chrome accessing chrome 16 sb2.C = Components; 17 rv = Cu.evalInSandbox("C.utils", sb2); 18 Assert.equal(rv, Cu); 19 } 20 21 function checkThrows(expression, sb) { 22 var result = Cu.evalInSandbox('(function() { try { ' + expression + '; return "allowed"; } catch (e) { return e.toString(); }})();', sb); 23 Assert.ok(!!/denied/.exec(result)); 24 }