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