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 | |
michael@0 | 2 | var cu = Components.utils; |
michael@0 | 3 | cu.import("resource://testing-common/httpd.js"); |
michael@0 | 4 | |
michael@0 | 5 | var httpserver = new HttpServer(); |
michael@0 | 6 | var httpserver2 = new HttpServer(); |
michael@0 | 7 | var testpath = "/simple"; |
michael@0 | 8 | var negativetestpath = "/negative"; |
michael@0 | 9 | var httpbody = "<?xml version='1.0' ?><root>0123456789</root>"; |
michael@0 | 10 | |
michael@0 | 11 | var sb = cu.Sandbox(["http://www.example.com", |
michael@0 | 12 | "http://localhost:4444/simple"], |
michael@0 | 13 | { wantGlobalProperties: ["XMLHttpRequest"] }); |
michael@0 | 14 | |
michael@0 | 15 | function createXHR(loc, async) |
michael@0 | 16 | { |
michael@0 | 17 | var xhr = new XMLHttpRequest(); |
michael@0 | 18 | xhr.open("GET", "http://localhost:" + loc, async); |
michael@0 | 19 | return xhr; |
michael@0 | 20 | } |
michael@0 | 21 | |
michael@0 | 22 | function checkResults(xhr) |
michael@0 | 23 | { |
michael@0 | 24 | if (xhr.readyState != 4) |
michael@0 | 25 | return false; |
michael@0 | 26 | |
michael@0 | 27 | do_check_eq(xhr.status, 200); |
michael@0 | 28 | do_check_eq(xhr.responseText, httpbody); |
michael@0 | 29 | |
michael@0 | 30 | var root_node = xhr.responseXML.getElementsByTagName('root').item(0); |
michael@0 | 31 | do_check_eq(root_node.firstChild.data, "0123456789"); |
michael@0 | 32 | return true; |
michael@0 | 33 | } |
michael@0 | 34 | |
michael@0 | 35 | var httpServersClosed = 0; |
michael@0 | 36 | function finishIfDone() |
michael@0 | 37 | { |
michael@0 | 38 | if (++httpServersClosed == 2) |
michael@0 | 39 | do_test_finished(); |
michael@0 | 40 | } |
michael@0 | 41 | |
michael@0 | 42 | function run_test() |
michael@0 | 43 | { |
michael@0 | 44 | do_test_pending(); |
michael@0 | 45 | |
michael@0 | 46 | httpserver.registerPathHandler(testpath, serverHandler); |
michael@0 | 47 | httpserver.start(4444); |
michael@0 | 48 | |
michael@0 | 49 | httpserver2.registerPathHandler(negativetestpath, serverHandler); |
michael@0 | 50 | httpserver2.start(4445); |
michael@0 | 51 | |
michael@0 | 52 | // Test sync XHR sending |
michael@0 | 53 | cu.evalInSandbox('var createXHR = ' + createXHR.toString(), sb); |
michael@0 | 54 | var res = cu.evalInSandbox('var sync = createXHR("4444/simple"); sync.send(null); sync', sb); |
michael@0 | 55 | do_check_true(checkResults(res)); |
michael@0 | 56 | |
michael@0 | 57 | // negative test sync XHR sending (to ensure that the xhr do not have chrome caps, see bug 779821) |
michael@0 | 58 | try { |
michael@0 | 59 | cu.evalInSandbox('var createXHR = ' + createXHR.toString(), sb); |
michael@0 | 60 | var res = cu.evalInSandbox('var sync = createXHR("4445/negative"); sync.send(null); sync', sb); |
michael@0 | 61 | do_check_false(true, "XHR created from sandbox should not have chrome caps"); |
michael@0 | 62 | } catch (e) { |
michael@0 | 63 | do_check_true(true); |
michael@0 | 64 | } |
michael@0 | 65 | |
michael@0 | 66 | httpserver2.stop(finishIfDone); |
michael@0 | 67 | |
michael@0 | 68 | // Test async XHR sending |
michael@0 | 69 | sb.finish = function(){ |
michael@0 | 70 | httpserver.stop(finishIfDone); |
michael@0 | 71 | } |
michael@0 | 72 | |
michael@0 | 73 | // We want to execute checkResults from the scope of the sandbox as well to |
michael@0 | 74 | // make sure that there are no permission errors related to nsEP. For that |
michael@0 | 75 | // we need to clone the function into the sandbox and make a few things |
michael@0 | 76 | // available for it. |
michael@0 | 77 | cu.evalInSandbox('var checkResults = ' + checkResults.toSource(), sb); |
michael@0 | 78 | sb.do_check_eq = do_check_eq; |
michael@0 | 79 | sb.httpbody = httpbody; |
michael@0 | 80 | |
michael@0 | 81 | function changeListener(event) { |
michael@0 | 82 | if (checkResults(async)) |
michael@0 | 83 | finish(); |
michael@0 | 84 | } |
michael@0 | 85 | |
michael@0 | 86 | var async = cu.evalInSandbox('var async = createXHR("4444/simple", true);' + |
michael@0 | 87 | 'async.addEventListener("readystatechange", ' + |
michael@0 | 88 | changeListener.toString() + ', false);' + |
michael@0 | 89 | 'async', sb); |
michael@0 | 90 | async.send(null); |
michael@0 | 91 | } |
michael@0 | 92 | |
michael@0 | 93 | function serverHandler(metadata, response) |
michael@0 | 94 | { |
michael@0 | 95 | response.setHeader("Content-Type", "text/xml", false); |
michael@0 | 96 | response.bodyOutputStream.write(httpbody, httpbody.length); |
michael@0 | 97 | } |