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 | <?xml version="1.0"?> |
michael@0 | 2 | <?xml-stylesheet type="text/css" href="chrome://global/skin"?> |
michael@0 | 3 | <?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?> |
michael@0 | 4 | <window title="Mozilla Bug 503926" |
michael@0 | 5 | xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> |
michael@0 | 6 | <script type="application/javascript" |
michael@0 | 7 | src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> |
michael@0 | 8 | |
michael@0 | 9 | <!-- test results are displayed in the html:body --> |
michael@0 | 10 | <body xmlns="http://www.w3.org/1999/xhtml"> |
michael@0 | 11 | <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=964293" |
michael@0 | 12 | target="_blank">Cu.cloneInto()</a> |
michael@0 | 13 | </body> |
michael@0 | 14 | |
michael@0 | 15 | <!-- test code goes here --> |
michael@0 | 16 | <script type="application/javascript"> |
michael@0 | 17 | <![CDATA[ |
michael@0 | 18 | |
michael@0 | 19 | const Cu = Components.utils; |
michael@0 | 20 | const Ci = Components.interfaces; |
michael@0 | 21 | |
michael@0 | 22 | const TypedArrayThings = [ |
michael@0 | 23 | 'Int8Array', |
michael@0 | 24 | 'Uint8Array', |
michael@0 | 25 | 'Uint8ClampedArray', |
michael@0 | 26 | 'Int16Array', |
michael@0 | 27 | 'Uint16Array', |
michael@0 | 28 | 'Int32Array', |
michael@0 | 29 | 'Uint32Array', |
michael@0 | 30 | 'Float32Array', |
michael@0 | 31 | 'Float64Array', |
michael@0 | 32 | ]; |
michael@0 | 33 | |
michael@0 | 34 | function getType(a) { |
michael@0 | 35 | if (a === null || a === undefined) |
michael@0 | 36 | return 'null'; |
michael@0 | 37 | |
michael@0 | 38 | if (Array.isArray(a)) |
michael@0 | 39 | return 'array'; |
michael@0 | 40 | |
michael@0 | 41 | if (a instanceof Ci.nsIDOMFile) |
michael@0 | 42 | return 'file'; |
michael@0 | 43 | |
michael@0 | 44 | if (a instanceof Ci.nsIDOMBlob) |
michael@0 | 45 | return 'blob'; |
michael@0 | 46 | |
michael@0 | 47 | if (TypedArrayThings.indexOf(a.constructor.name) !== -1) |
michael@0 | 48 | return a.constructor.name; |
michael@0 | 49 | |
michael@0 | 50 | if (typeof a == 'object') |
michael@0 | 51 | return 'object'; |
michael@0 | 52 | |
michael@0 | 53 | if (typeof a == 'function') |
michael@0 | 54 | return 'function'; |
michael@0 | 55 | |
michael@0 | 56 | return 'primitive'; |
michael@0 | 57 | } |
michael@0 | 58 | |
michael@0 | 59 | function compare(a, b) { |
michael@0 | 60 | is (getType(a), getType(b), 'Type matches'); |
michael@0 | 61 | |
michael@0 | 62 | var type = getType(a); |
michael@0 | 63 | if (type == 'array') { |
michael@0 | 64 | is (a.length, b.length, 'Array.length matches'); |
michael@0 | 65 | for (var i = 0; i < a.length; ++i) { |
michael@0 | 66 | compare(a[i], b[i]); |
michael@0 | 67 | } |
michael@0 | 68 | |
michael@0 | 69 | return; |
michael@0 | 70 | } |
michael@0 | 71 | |
michael@0 | 72 | if (type == 'file' || type == 'blob') { |
michael@0 | 73 | ok ( a === b, 'They should match'); |
michael@0 | 74 | return; |
michael@0 | 75 | } |
michael@0 | 76 | |
michael@0 | 77 | if (type == 'object') { |
michael@0 | 78 | ok ( a !== b, 'They should not match'); |
michael@0 | 79 | |
michael@0 | 80 | var aProps = []; |
michael@0 | 81 | for (var p in a) aProps.push(p); |
michael@0 | 82 | |
michael@0 | 83 | var bProps = []; |
michael@0 | 84 | for (var p in b) bProps.push(p); |
michael@0 | 85 | |
michael@0 | 86 | is (aProps.length, bProps.length, 'Props match'); |
michael@0 | 87 | is (aProps.sort().toSource(), bProps.sort().toSource(), 'Props match - using toSource()'); |
michael@0 | 88 | |
michael@0 | 89 | for (var p in a) { |
michael@0 | 90 | compare(a[p], b[p]); |
michael@0 | 91 | } |
michael@0 | 92 | |
michael@0 | 93 | return; |
michael@0 | 94 | } |
michael@0 | 95 | |
michael@0 | 96 | if (type == 'function') { |
michael@0 | 97 | ok ( a !== b, 'They should not match'); |
michael@0 | 98 | return; |
michael@0 | 99 | } |
michael@0 | 100 | |
michael@0 | 101 | if (type != 'null') { |
michael@0 | 102 | is (a.toSource(), b.toSource(), 'Matching using toSource()'); |
michael@0 | 103 | } |
michael@0 | 104 | } |
michael@0 | 105 | |
michael@0 | 106 | var sandboxOptions = { |
michael@0 | 107 | wantXrays: true, |
michael@0 | 108 | wantExportHelpers: true, |
michael@0 | 109 | }; |
michael@0 | 110 | var sandbox = new Cu.Sandbox(window, sandboxOptions); |
michael@0 | 111 | // The second sandbox is for testing the exportHelper version of the cloneInto |
michael@0 | 112 | var sandbox2 = new Cu.Sandbox("http://example.com", sandboxOptions); |
michael@0 | 113 | sandbox.sandbox2 = sandbox2; |
michael@0 | 114 | |
michael@0 | 115 | function cloneAndTest(test, cloneOptions) { |
michael@0 | 116 | var output = sandbox.test = Cu.cloneInto(test, sandbox, cloneOptions); |
michael@0 | 117 | compare(test, output); |
michael@0 | 118 | |
michael@0 | 119 | sandbox.cloneOptions = cloneOptions; |
michael@0 | 120 | output = Cu.evalInSandbox('cloneInto(test, sandbox2, cloneOptions)', sandbox); |
michael@0 | 121 | compare(test, output); |
michael@0 | 122 | } |
michael@0 | 123 | |
michael@0 | 124 | var tests = [ |
michael@0 | 125 | 1, |
michael@0 | 126 | null, |
michael@0 | 127 | true, |
michael@0 | 128 | 'hello world', |
michael@0 | 129 | [1, 2, 3], |
michael@0 | 130 | { a: 1, b: 2 }, |
michael@0 | 131 | { blob: new Blob([]), file: new File(new Blob([])) }, |
michael@0 | 132 | new Date(), |
michael@0 | 133 | { a: 1, b: {}, c: [1, 2, 3, { d: new Blob([]) } ], e: 'hello world' }, |
michael@0 | 134 | ]; |
michael@0 | 135 | |
michael@0 | 136 | for (var i = 0; i < tests.length; ++i) { |
michael@0 | 137 | cloneAndTest(tests[i]); |
michael@0 | 138 | } |
michael@0 | 139 | |
michael@0 | 140 | try { |
michael@0 | 141 | var output = Cu.cloneInto({ a: function() {} }, sandbox); |
michael@0 | 142 | ok(false, 'Function should not be cloned by default'); |
michael@0 | 143 | } catch(e) { |
michael@0 | 144 | ok(true, 'Function should not be cloned by default'); |
michael@0 | 145 | } |
michael@0 | 146 | |
michael@0 | 147 | try { |
michael@0 | 148 | sandbox2.sandbox = sandbox; |
michael@0 | 149 | Cu.evalInSandbox('cloneInto({}, sandbox)', sandbox2); |
michael@0 | 150 | ok(false, 'CloneInto should only work on less privileged target scopes.'); |
michael@0 | 151 | } catch(e) { |
michael@0 | 152 | ok(/denied|insecure/.test(e), |
michael@0 | 153 | 'CloneInto should only work on less privileged target scopes.'); |
michael@0 | 154 | } |
michael@0 | 155 | |
michael@0 | 156 | var test = { a: function() { return 42; } } |
michael@0 | 157 | cloneAndTest(test, { cloneFunctions: true }); |
michael@0 | 158 | ]]> |
michael@0 | 159 | </script> |
michael@0 | 160 | </window> |