Sat, 03 Jan 2015 20:18:00 +0100
Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.
michael@0 | 1 | // Any copyright is dedicated to the Public Domain. |
michael@0 | 2 | // http://creativecommons.org/publicdomain/zero/1.0/ |
michael@0 | 3 | |
michael@0 | 4 | // Test Debugger.Object.prototype.unsafeDereference in the presence of |
michael@0 | 5 | // interesting cross-compartment wrappers. |
michael@0 | 6 | // |
michael@0 | 7 | // This is not really a debugger server test; it's more of a Debugger test. |
michael@0 | 8 | // But we need xpcshell and Components.utils.Sandbox to get |
michael@0 | 9 | // cross-compartment wrappers with interesting properties, and this is the |
michael@0 | 10 | // xpcshell test directory most closely related to the JS Debugger API. |
michael@0 | 11 | |
michael@0 | 12 | Components.utils.import("resource://gre/modules/jsdebugger.jsm"); |
michael@0 | 13 | addDebuggerToGlobal(this); |
michael@0 | 14 | |
michael@0 | 15 | // Add a method to Debugger.Object for fetching value properties |
michael@0 | 16 | // conveniently. |
michael@0 | 17 | Debugger.Object.prototype.getProperty = function (aName) { |
michael@0 | 18 | let desc = this.getOwnPropertyDescriptor(aName); |
michael@0 | 19 | if (!desc) |
michael@0 | 20 | return undefined; |
michael@0 | 21 | if (!desc.value) { |
michael@0 | 22 | throw Error("Debugger.Object.prototype.getProperty: " + |
michael@0 | 23 | "not a value property: " + aName); |
michael@0 | 24 | } |
michael@0 | 25 | return desc.value; |
michael@0 | 26 | }; |
michael@0 | 27 | |
michael@0 | 28 | function run_test() { |
michael@0 | 29 | // Create a low-privilege sandbox, and a chrome-privilege sandbox. |
michael@0 | 30 | let contentBox = Components.utils.Sandbox('http://www.example.com'); |
michael@0 | 31 | let chromeBox = Components.utils.Sandbox(this); |
michael@0 | 32 | |
michael@0 | 33 | // Create an objects in this compartment, and one in each sandbox. We'll |
michael@0 | 34 | // refer to the objects as "mainObj", "contentObj", and "chromeObj", in |
michael@0 | 35 | // variable and property names. |
michael@0 | 36 | var mainObj = { name: "mainObj" }; |
michael@0 | 37 | Components.utils.evalInSandbox('var contentObj = { name: "contentObj" };', |
michael@0 | 38 | contentBox); |
michael@0 | 39 | Components.utils.evalInSandbox('var chromeObj = { name: "chromeObj" };', |
michael@0 | 40 | chromeBox); |
michael@0 | 41 | |
michael@0 | 42 | // Give each global a pointer to all the other globals' objects. |
michael@0 | 43 | contentBox.mainObj = chromeBox.mainObj = mainObj; |
michael@0 | 44 | var contentObj = chromeBox.contentObj = contentBox.contentObj; |
michael@0 | 45 | var chromeObj = contentBox.chromeObj = chromeBox.chromeObj; |
michael@0 | 46 | |
michael@0 | 47 | // First, a whole bunch of basic sanity checks, to ensure that JavaScript |
michael@0 | 48 | // evaluated in various scopes really does see the world the way this |
michael@0 | 49 | // test expects it to. |
michael@0 | 50 | |
michael@0 | 51 | // The objects appear as global variables in the sandbox, and as |
michael@0 | 52 | // the sandbox object's properties in chrome. |
michael@0 | 53 | do_check_true(Components.utils.evalInSandbox('mainObj', contentBox) |
michael@0 | 54 | === contentBox.mainObj); |
michael@0 | 55 | do_check_true(Components.utils.evalInSandbox('contentObj', contentBox) |
michael@0 | 56 | === contentBox.contentObj); |
michael@0 | 57 | do_check_true(Components.utils.evalInSandbox('chromeObj', contentBox) |
michael@0 | 58 | === contentBox.chromeObj); |
michael@0 | 59 | do_check_true(Components.utils.evalInSandbox('mainObj', chromeBox) |
michael@0 | 60 | === chromeBox.mainObj); |
michael@0 | 61 | do_check_true(Components.utils.evalInSandbox('contentObj', chromeBox) |
michael@0 | 62 | === chromeBox.contentObj); |
michael@0 | 63 | do_check_true(Components.utils.evalInSandbox('chromeObj', chromeBox) |
michael@0 | 64 | === chromeBox.chromeObj); |
michael@0 | 65 | |
michael@0 | 66 | // We (the main global) can see properties of all objects in all globals. |
michael@0 | 67 | do_check_true(contentBox.mainObj.name === "mainObj"); |
michael@0 | 68 | do_check_true(contentBox.contentObj.name === "contentObj"); |
michael@0 | 69 | do_check_true(contentBox.chromeObj.name === "chromeObj"); |
michael@0 | 70 | |
michael@0 | 71 | // chromeBox can see properties of all objects in all globals. |
michael@0 | 72 | do_check_eq(Components.utils.evalInSandbox('mainObj.name', chromeBox), |
michael@0 | 73 | 'mainObj'); |
michael@0 | 74 | do_check_eq(Components.utils.evalInSandbox('contentObj.name', chromeBox), |
michael@0 | 75 | 'contentObj'); |
michael@0 | 76 | do_check_eq(Components.utils.evalInSandbox('chromeObj.name', chromeBox), |
michael@0 | 77 | 'chromeObj'); |
michael@0 | 78 | |
michael@0 | 79 | // contentBox can see properties of the content object, but not of either |
michael@0 | 80 | // chrome object, because by default, content -> chrome wrappers hide all |
michael@0 | 81 | // object properties. |
michael@0 | 82 | do_check_eq(Components.utils.evalInSandbox('mainObj.name', contentBox), |
michael@0 | 83 | undefined); |
michael@0 | 84 | do_check_eq(Components.utils.evalInSandbox('contentObj.name', contentBox), |
michael@0 | 85 | 'contentObj'); |
michael@0 | 86 | do_check_eq(Components.utils.evalInSandbox('chromeObj.name', contentBox), |
michael@0 | 87 | undefined); |
michael@0 | 88 | |
michael@0 | 89 | // When viewing an object in compartment A from the vantage point of |
michael@0 | 90 | // compartment B, Debugger should give the same results as debuggee code |
michael@0 | 91 | // would. |
michael@0 | 92 | |
michael@0 | 93 | // Create a debugger, debugging our two sandboxes. |
michael@0 | 94 | let dbg = new Debugger; |
michael@0 | 95 | |
michael@0 | 96 | // Create Debugger.Object instances referring to the two sandboxes, as |
michael@0 | 97 | // seen from their own compartments. |
michael@0 | 98 | let contentBoxDO = dbg.addDebuggee(contentBox); |
michael@0 | 99 | let chromeBoxDO = dbg.addDebuggee(chromeBox); |
michael@0 | 100 | |
michael@0 | 101 | // Use Debugger to view the objects from contentBox. We should get the |
michael@0 | 102 | // same D.O instance from both getProperty and makeDebuggeeValue, and the |
michael@0 | 103 | // same property visibility we checked for above. |
michael@0 | 104 | let mainFromContentDO = contentBoxDO.getProperty('mainObj'); |
michael@0 | 105 | do_check_eq(mainFromContentDO, contentBoxDO.makeDebuggeeValue(mainObj)); |
michael@0 | 106 | do_check_eq(mainFromContentDO.getProperty('name'), undefined); |
michael@0 | 107 | do_check_eq(mainFromContentDO.unsafeDereference(), mainObj); |
michael@0 | 108 | |
michael@0 | 109 | let contentFromContentDO = contentBoxDO.getProperty('contentObj'); |
michael@0 | 110 | do_check_eq(contentFromContentDO, contentBoxDO.makeDebuggeeValue(contentObj)); |
michael@0 | 111 | do_check_eq(contentFromContentDO.getProperty('name'), 'contentObj'); |
michael@0 | 112 | do_check_eq(contentFromContentDO.unsafeDereference(), contentObj); |
michael@0 | 113 | |
michael@0 | 114 | let chromeFromContentDO = contentBoxDO.getProperty('chromeObj'); |
michael@0 | 115 | do_check_eq(chromeFromContentDO, contentBoxDO.makeDebuggeeValue(chromeObj)); |
michael@0 | 116 | do_check_eq(chromeFromContentDO.getProperty('name'), undefined); |
michael@0 | 117 | do_check_eq(chromeFromContentDO.unsafeDereference(), chromeObj); |
michael@0 | 118 | |
michael@0 | 119 | // Similarly, viewing from chromeBox. |
michael@0 | 120 | let mainFromChromeDO = chromeBoxDO.getProperty('mainObj'); |
michael@0 | 121 | do_check_eq(mainFromChromeDO, chromeBoxDO.makeDebuggeeValue(mainObj)); |
michael@0 | 122 | do_check_eq(mainFromChromeDO.getProperty('name'), 'mainObj'); |
michael@0 | 123 | do_check_eq(mainFromChromeDO.unsafeDereference(), mainObj); |
michael@0 | 124 | |
michael@0 | 125 | let contentFromChromeDO = chromeBoxDO.getProperty('contentObj'); |
michael@0 | 126 | do_check_eq(contentFromChromeDO, chromeBoxDO.makeDebuggeeValue(contentObj)); |
michael@0 | 127 | do_check_eq(contentFromChromeDO.getProperty('name'), 'contentObj'); |
michael@0 | 128 | do_check_eq(contentFromChromeDO.unsafeDereference(), contentObj); |
michael@0 | 129 | |
michael@0 | 130 | let chromeFromChromeDO = chromeBoxDO.getProperty('chromeObj'); |
michael@0 | 131 | do_check_eq(chromeFromChromeDO, chromeBoxDO.makeDebuggeeValue(chromeObj)); |
michael@0 | 132 | do_check_eq(chromeFromChromeDO.getProperty('name'), 'chromeObj'); |
michael@0 | 133 | do_check_eq(chromeFromChromeDO.unsafeDereference(), chromeObj); |
michael@0 | 134 | } |