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 | /* -*- Mode: javascript; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2; js-indent-level: 2; -*- */ |
michael@0 | 2 | /* Any copyright is dedicated to the Public Domain. |
michael@0 | 3 | http://creativecommons.org/publicdomain/zero/1.0/ */ |
michael@0 | 4 | |
michael@0 | 5 | function run_test() |
michael@0 | 6 | { |
michael@0 | 7 | Cu.import("resource://gre/modules/jsdebugger.jsm"); |
michael@0 | 8 | addDebuggerToGlobal(this); |
michael@0 | 9 | let loader = Cc["@mozilla.org/moz/jssubscript-loader;1"] |
michael@0 | 10 | .getService(Components.interfaces.mozIJSSubScriptLoader); |
michael@0 | 11 | loader.loadSubScript("resource://gre/modules/devtools/server/actors/script.js"); |
michael@0 | 12 | |
michael@0 | 13 | test_LSA_disconnect(); |
michael@0 | 14 | test_LSA_grip(); |
michael@0 | 15 | test_LSA_onSubstring(); |
michael@0 | 16 | } |
michael@0 | 17 | |
michael@0 | 18 | const TEST_STRING = "This is a very long string!"; |
michael@0 | 19 | |
michael@0 | 20 | function makeMockLongStringActor() |
michael@0 | 21 | { |
michael@0 | 22 | let string = TEST_STRING; |
michael@0 | 23 | let actor = new LongStringActor(string); |
michael@0 | 24 | actor.actorID = "longString1"; |
michael@0 | 25 | actor.registeredPool = { |
michael@0 | 26 | longStringActors: { |
michael@0 | 27 | longString1: actor |
michael@0 | 28 | } |
michael@0 | 29 | }; |
michael@0 | 30 | return actor; |
michael@0 | 31 | } |
michael@0 | 32 | |
michael@0 | 33 | function test_LSA_disconnect() |
michael@0 | 34 | { |
michael@0 | 35 | let actor = makeMockLongStringActor(); |
michael@0 | 36 | do_check_eq(actor.registeredPool.longStringActors[actor.actorID], actor); |
michael@0 | 37 | |
michael@0 | 38 | actor.disconnect(); |
michael@0 | 39 | do_check_eq(actor.registeredPool.longStringActors[actor.actorID], void 0); |
michael@0 | 40 | } |
michael@0 | 41 | |
michael@0 | 42 | function test_LSA_substring() |
michael@0 | 43 | { |
michael@0 | 44 | let actor = makeMockLongStringActor(); |
michael@0 | 45 | do_check_eq(actor._substring(0, 4), TEST_STRING.substring(0, 4)); |
michael@0 | 46 | do_check_eq(actor._substring(6, 9), TEST_STRING.substring(6, 9)); |
michael@0 | 47 | do_check_eq(actor._substring(0, TEST_STRING.length), TEST_STRING); |
michael@0 | 48 | } |
michael@0 | 49 | |
michael@0 | 50 | function test_LSA_grip() |
michael@0 | 51 | { |
michael@0 | 52 | let actor = makeMockLongStringActor(); |
michael@0 | 53 | |
michael@0 | 54 | let grip = actor.grip(); |
michael@0 | 55 | do_check_eq(grip.type, "longString"); |
michael@0 | 56 | do_check_eq(grip.initial, TEST_STRING.substring(0, DebuggerServer.LONG_STRING_INITIAL_LENGTH)); |
michael@0 | 57 | do_check_eq(grip.length, TEST_STRING.length); |
michael@0 | 58 | do_check_eq(grip.actor, actor.actorID); |
michael@0 | 59 | } |
michael@0 | 60 | |
michael@0 | 61 | function test_LSA_onSubstring() |
michael@0 | 62 | { |
michael@0 | 63 | let actor = makeMockLongStringActor(); |
michael@0 | 64 | let response; |
michael@0 | 65 | |
michael@0 | 66 | // From the start |
michael@0 | 67 | response = actor.onSubstring({ |
michael@0 | 68 | start: 0, |
michael@0 | 69 | end: 4 |
michael@0 | 70 | }); |
michael@0 | 71 | do_check_eq(response.from, actor.actorID); |
michael@0 | 72 | do_check_eq(response.substring, TEST_STRING.substring(0, 4)); |
michael@0 | 73 | |
michael@0 | 74 | // In the middle |
michael@0 | 75 | response = actor.onSubstring({ |
michael@0 | 76 | start: 5, |
michael@0 | 77 | end: 8 |
michael@0 | 78 | }); |
michael@0 | 79 | do_check_eq(response.from, actor.actorID); |
michael@0 | 80 | do_check_eq(response.substring, TEST_STRING.substring(5, 8)); |
michael@0 | 81 | |
michael@0 | 82 | // Whole string |
michael@0 | 83 | response = actor.onSubstring({ |
michael@0 | 84 | start: 0, |
michael@0 | 85 | end: TEST_STRING.length |
michael@0 | 86 | }); |
michael@0 | 87 | do_check_eq(response.from, actor.actorID); |
michael@0 | 88 | do_check_eq(response.substring, TEST_STRING); |
michael@0 | 89 | |
michael@0 | 90 | // Negative index |
michael@0 | 91 | response = actor.onSubstring({ |
michael@0 | 92 | start: -5, |
michael@0 | 93 | end: TEST_STRING.length |
michael@0 | 94 | }); |
michael@0 | 95 | do_check_eq(response.from, actor.actorID); |
michael@0 | 96 | do_check_eq(response.substring, |
michael@0 | 97 | TEST_STRING.substring(-5, TEST_STRING.length)); |
michael@0 | 98 | |
michael@0 | 99 | // Past the end |
michael@0 | 100 | response = actor.onSubstring({ |
michael@0 | 101 | start: TEST_STRING.length - 5, |
michael@0 | 102 | end: 100 |
michael@0 | 103 | }); |
michael@0 | 104 | do_check_eq(response.from, actor.actorID); |
michael@0 | 105 | do_check_eq(response.substring, |
michael@0 | 106 | TEST_STRING.substring(TEST_STRING.length - 5, 100)); |
michael@0 | 107 | } |