test_sandbox_metadata.js (1531B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 5 /* See https://bugzilla.mozilla.org/show_bug.cgi?id=898559 */ 6 7 function run_test() 8 { 9 let sandbox = Cu.Sandbox("http://www.blah.com", { 10 metadata: "test metadata", 11 }); 12 13 Cu.importGlobalProperties(["XMLHttpRequest"]); 14 15 Assert.equal(Cu.getSandboxMetadata(sandbox), "test metadata"); 16 17 sandbox = Cu.Sandbox("http://www.blah.com", { 18 metadata: { foopy: { bar: 2 }, baz: "hi" } 19 }); 20 21 let metadata = Cu.getSandboxMetadata(sandbox); 22 Assert.equal(metadata.baz, "hi"); 23 Assert.equal(metadata.foopy.bar, 2); 24 metadata.baz = "foo"; 25 26 metadata = Cu.getSandboxMetadata(sandbox); 27 Assert.equal(metadata.baz, "foo"); 28 29 metadata = { foo: "bar" }; 30 Cu.setSandboxMetadata(sandbox, metadata); 31 metadata.foo = "baz"; 32 metadata = Cu.getSandboxMetadata(sandbox); 33 Assert.equal(metadata.foo, "bar"); 34 35 let thrown = false; 36 let reflector = new XMLHttpRequest(); 37 38 try { 39 Cu.setSandboxMetadata(sandbox, { foo: reflector }); 40 } catch(e) { 41 thrown = true; 42 } 43 44 Assert.equal(thrown, true); 45 46 sandbox = Cu.Sandbox(this, { 47 metadata: { foopy: { bar: 2 }, baz: "hi" } 48 }); 49 50 let inner = Cu.evalInSandbox("Components.utils.Sandbox('http://www.blah.com')", sandbox); 51 52 metadata = Cu.getSandboxMetadata(inner); 53 Assert.equal(metadata.baz, "hi"); 54 Assert.equal(metadata.foopy.bar, 2); 55 metadata.baz = "foo"; 56 }