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: js; js-indent-level: 2; -*- */
2 /* Any copyright is dedicated to the Public Domain.
3 http://creativecommons.org/publicdomain/zero/1.0/ */
5 // Test the functionality of the BreakpointStore object.
7 function run_test()
8 {
9 Cu.import("resource://gre/modules/jsdebugger.jsm");
10 addDebuggerToGlobal(this);
11 let loader = Cc["@mozilla.org/moz/jssubscript-loader;1"]
12 .getService(Components.interfaces.mozIJSSubScriptLoader);
13 loader.loadSubScript("resource://gre/modules/devtools/server/actors/script.js");
15 test_has_breakpoint();
16 test_bug_754251();
17 test_add_breakpoint();
18 test_remove_breakpoint();
19 test_find_breakpoints();
20 }
22 function test_has_breakpoint() {
23 let bpStore = new BreakpointStore();
24 let location = {
25 url: "http://example.com/foo.js",
26 line: 3
27 };
28 let columnLocation = {
29 url: "http://example.com/bar.js",
30 line: 5,
31 column: 15
32 };
34 // Shouldn't have breakpoint
35 do_check_eq(null, bpStore.hasBreakpoint(location),
36 "Breakpoint not added and shouldn't exist.");
38 bpStore.addBreakpoint(location);
39 do_check_true(!!bpStore.hasBreakpoint(location),
40 "Breakpoint added but not found in Breakpoint Store.");
42 bpStore.removeBreakpoint(location);
43 do_check_eq(null, bpStore.hasBreakpoint(location),
44 "Breakpoint removed but still exists.");
46 // Same checks for breakpoint with a column
47 do_check_eq(null, bpStore.hasBreakpoint(columnLocation),
48 "Breakpoint with column not added and shouldn't exist.");
50 bpStore.addBreakpoint(columnLocation);
51 do_check_true(!!bpStore.hasBreakpoint(columnLocation),
52 "Breakpoint with column added but not found in Breakpoint Store.");
54 bpStore.removeBreakpoint(columnLocation);
55 do_check_eq(null, bpStore.hasBreakpoint(columnLocation),
56 "Breakpoint with column removed but still exists in Breakpoint Store.");
57 }
59 // Note: Removing this test will regress bug 754251. See comment above
60 // ThreadActor.breakpointStore.
61 function test_bug_754251() {
62 let instance1 = new ThreadActor();
63 let instance2 = new ThreadActor();
64 do_check_true(instance1.breakpointStore instanceof BreakpointStore);
65 do_check_eq(instance1.breakpointStore, ThreadActor.breakpointStore);
66 do_check_eq(instance2.breakpointStore, ThreadActor.breakpointStore);
67 }
69 function test_add_breakpoint() {
70 // Breakpoint with column
71 let bpStore = new BreakpointStore();
72 let location = {
73 url: "http://example.com/foo.js",
74 line: 10,
75 column: 9
76 };
77 bpStore.addBreakpoint(location);
78 do_check_true(!!bpStore.hasBreakpoint(location),
79 "We should have the column breakpoint we just added");
81 // Breakpoint without column (whole line breakpoint)
82 location = {
83 url: "http://example.com/bar.js",
84 line: 103
85 };
86 bpStore.addBreakpoint(location);
87 do_check_true(!!bpStore.hasBreakpoint(location),
88 "We should have the whole line breakpoint we just added");
89 }
91 function test_remove_breakpoint() {
92 // Breakpoint with column
93 let bpStore = new BreakpointStore();
94 let location = {
95 url: "http://example.com/foo.js",
96 line: 10,
97 column: 9
98 };
99 bpStore.addBreakpoint(location);
100 bpStore.removeBreakpoint(location);
101 do_check_eq(bpStore.hasBreakpoint(location), null,
102 "We should not have the column breakpoint anymore");
104 // Breakpoint without column (whole line breakpoint)
105 location = {
106 url: "http://example.com/bar.js",
107 line: 103
108 };
109 bpStore.addBreakpoint(location);
110 bpStore.removeBreakpoint(location);
111 do_check_eq(bpStore.hasBreakpoint(location), null,
112 "We should not have the whole line breakpoint anymore");
113 }
115 function test_find_breakpoints() {
116 let bps = [
117 { url: "foo.js", line: 10 },
118 { url: "foo.js", line: 10, column: 3 },
119 { url: "foo.js", line: 10, column: 10 },
120 { url: "foo.js", line: 23, column: 89 },
121 { url: "bar.js", line: 10, column: 1 },
122 { url: "bar.js", line: 20, column: 5 },
123 { url: "bar.js", line: 30, column: 34 },
124 { url: "bar.js", line: 40, column: 56 }
125 ];
127 let bpStore = new BreakpointStore();
129 for (let bp of bps) {
130 bpStore.addBreakpoint(bp);
131 }
133 // All breakpoints
135 let bpSet = Set(bps);
136 for (let bp of bpStore.findBreakpoints()) {
137 bpSet.delete(bp);
138 }
139 do_check_eq(bpSet.size, 0,
140 "Should be able to iterate over all breakpoints");
142 // Breakpoints by URL
144 bpSet = Set(bps.filter(bp => { return bp.url === "foo.js" }));
145 for (let bp of bpStore.findBreakpoints({ url: "foo.js" })) {
146 bpSet.delete(bp);
147 }
148 do_check_eq(bpSet.size, 0,
149 "Should be able to filter the iteration by url");
151 // Breakpoints by URL and line
153 bpSet = Set(bps.filter(bp => { return bp.url === "foo.js" && bp.line === 10; }));
154 let first = true;
155 for (let bp of bpStore.findBreakpoints({ url: "foo.js", line: 10 })) {
156 if (first) {
157 do_check_eq(bp.column, undefined,
158 "Should always get the whole line breakpoint first");
159 first = false;
160 } else {
161 do_check_neq(bp.column, undefined,
162 "Should not get the whole line breakpoint any time other than first.");
163 }
164 bpSet.delete(bp);
165 }
166 do_check_eq(bpSet.size, 0,
167 "Should be able to filter the iteration by url and line");
168 }