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 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4 "use strict";
6 module.metadata = {
7 "engines": {
8 "Firefox": "*"
9 }
10 };
12 const { Toolbar } = require("sdk/ui/toolbar");
13 const { Loader } = require("sdk/test/loader");
14 const { identify } = require("sdk/ui/id");
15 const { getMostRecentBrowserWindow, open, getOuterId } = require("sdk/window/utils");
16 const { ready, close } = require("sdk/window/helpers");
17 const { defer } = require("sdk/core/promise");
18 const { send, stop, Reactor } = require("sdk/event/utils");
19 const { object } = require("sdk/util/sequence");
20 const { CustomizationInput } = require("sdk/input/customizable-ui");
21 const { OutputPort } = require("sdk/output/system");
22 const output = new OutputPort({ id: "toolbar-change" });
24 const wait = (toolbar, event) => {
25 let { promise, resolve } = defer();
26 toolbar.once(event, resolve);
27 return promise;
28 };
30 const show = ({id}) => send(output, object([id, {collapsed: false}]));
31 const hide = ({id}) => send(output, object([id, {collapsed: true}]));
32 const retitle = ({id}, title) => send(output, object([id, {title: title}]));
34 const isAttached = ({id}, window=getMostRecentBrowserWindow()) =>
35 !!window.document.getElementById(id);
37 const isCollapsed = ({id}, window=getMostRecentBrowserWindow()) =>
38 window.document.getElementById(id).getAttribute("collapsed") === "true";
40 const closeViaButton = ({id}, window=getMostRecentBrowserWindow()) =>
41 window.document.getElementById("close-" + id).click();
43 const readTitle = ({id}, window=getMostRecentBrowserWindow()) =>
44 window.document.getElementById(id).getAttribute("toolbarname");
46 exports["test toolbar API"] = function*(assert) {
47 assert.throws(() => new Toolbar(),
48 /The `option.title`/,
49 "toolbar requires title");
51 assert.throws(() => new Toolbar({ hidden: false }),
52 /The `option.title`/,
53 "toolbar requires title");
55 const t1 = new Toolbar({ title: "foo" });
57 assert.throws(() => new Toolbar({ title: "foo" }),
58 /already exists/,
59 "can't create identical toolbars");
61 assert.ok(t1.id, "toolbar has an id");
62 assert.equal(t1.id, identify(t1), "identify returns toolbar id");
63 assert.deepEqual(t1.items, [], "toolbar items are empty");
64 assert.equal(t1.title, void(0), "title is void until attached");
65 assert.equal(t1.hidden, void(0), "hidden is void until attached");
67 yield wait(t1, "attach");
69 assert.equal(t1.title, "foo", "title is set after attach");
70 assert.equal(t1.hidden, false, "by default toolbar isn't hidden");
72 assert.throws(() => new Toolbar({ title: "foo" }),
73 /already exists/,
74 "still can't create identical toolbar");
77 const t2 = new Toolbar({ title: "bar", hidden: true });
78 assert.pass("can create different toolbar though");
80 assert.ok(t2.id, "toolbar has an id");
81 assert.equal(t2.id, identify(t2), "identify returns toolbar id");
82 assert.notEqual(t2.id, t1.id, "each toolbar has unique id");
84 yield wait(t2, "attach");
86 assert.equal(t2.title, "bar", "title is set after attach");
87 assert.equal(t2.hidden, true, "toolbar is hidden as specified");
89 t2.destroy();
90 t1.destroy();
92 yield wait(t1, "detach");
94 assert.equal(t1.title, void(0), "title is voided after detach");
95 assert.equal(t1.hidden, void(0), "hidden is void fater detach");
98 const t3 = new Toolbar({ title: "foo" });
99 assert.pass("Can create toolbar after identical was detached");
101 assert.equal(t3.id, t1.id, "toolbar has a same id");
102 assert.equal(t3.id, identify(t3), "identify returns toolbar.id");
103 assert.equal(t3.title, void(0), "title is void before attach");
104 assert.equal(t3.hidden, void(0), "hidden is void before attach");
106 yield wait(t3, "attach");
108 assert.equal(t3.title, "foo", "title is set");
109 assert.equal(t3.hidden, false, "toolbar is hidden");
111 t3.destroy();
113 yield wait(t3, "detach");
114 };
116 exports["test show / hide toolbar"] = function*(assert) {
117 const t1 = new Toolbar({ title: "foo" });
119 yield wait(t1, "attach");
121 assert.equal(t1.title, "foo", "title is set after attach");
122 assert.equal(t1.hidden, false, "by default toolbar isn't hidden");
123 assert.ok(isAttached(t1), "toolbar was actually attarched");
124 assert.ok(!isCollapsed(t1), "toolbar isn't collapsed");
126 hide(t1);
127 assert.equal(t1.hidden, false, "not hidden yet");
129 yield wait(t1, "hide");
130 assert.equal(t1.hidden, true, "toolbar got hidden");
131 assert.ok(isCollapsed(t1), "toolbar is collapsed");
133 show(t1);
135 yield wait(t1, "show");
136 assert.equal(t1.hidden, false, "toolbar got shown");
137 assert.ok(!isCollapsed(t1), "toolbar isn't collapsed");
139 t1.destroy();
140 yield wait(t1, "detach");
141 assert.ok(!isAttached(t1), "toolbar is no longer attached");
142 };
144 exports["test multiple windows & toolbars"] = function*(assert) {
145 const w1 = getMostRecentBrowserWindow();
146 const t1 = new Toolbar({ title: "multi window" });
148 yield wait(t1, "attach");
150 assert.equal(t1.title, "multi window", "title is set after attach");
151 assert.equal(t1.hidden, false, "by default toolbar isn't hidden");
152 assert.ok(isAttached(t1, w1), "toolbar was actually attarched");
153 assert.ok(!isCollapsed(t1, w1), "toolbar isn't collapsed");
155 const w2 = open();
156 yield ready(w2);
158 assert.ok(isAttached(t1, w2), "toolbar was attached to second window");
159 assert.ok(!isCollapsed(t1, w2), "toolbar isn't collabsed");
161 hide(t1);
162 yield wait(t1, "hide");
164 assert.ok(isCollapsed(t1, w1) && isCollapsed(t1, w2),
165 "toolbar is collabsed");
168 const w3 = open();
169 yield ready(w3);
171 assert.ok(isAttached(t1, w1) && isAttached(t1, w2) && isAttached(t1, w3),
172 "toolbar is attached to all windows");
173 assert.ok(isCollapsed(t1, w3) && isCollapsed(t1, w3) && isCollapsed(t1, w3),
174 "toolbar still collapsed in all windows");
177 const t2 = new Toolbar({ title: "multi hidden", hidden: true });
179 yield wait(t2, "attach");
181 assert.equal(t2.title, "multi hidden", "title is set after attach");
182 assert.equal(t2.hidden, true, "isn't hidden as specified");
184 assert.ok(isAttached(t1, w1) && isAttached(t1, w2) && isAttached(t1, w3),
185 "toolbar#1 is still attached");
186 assert.ok(isAttached(t2, w1) && isAttached(t2, w2) && isAttached(t2, w3),
187 "toolbar#2 was attached to all windows");
189 assert.ok(isCollapsed(t1, w1) && isCollapsed(t1, w2) && isCollapsed(t1, w3),
190 "toolbar#1 is still collapsed");
192 assert.ok(isCollapsed(t2, w1) && isCollapsed(t2, w2) && isCollapsed(t2, w3),
193 "toolbar#2 is collapsed");
195 t1.destroy();
196 yield wait(t1, "detach");
198 assert.ok(!isAttached(t1, w1) && !isAttached(t1, w2) && !isAttached(t1, w3),
199 "toolbar#1 was detached from all windows");
200 assert.ok(isAttached(t2, w1) && isAttached(t2, w2) && isAttached(t2, w3),
201 "toolbar#2 is still attached to all windows");
203 yield close(w2);
205 assert.ok(isAttached(t2, w1) && isAttached(t2, w3),
206 "toolbar#2 is still attached to remaining windows");
207 assert.ok(isCollapsed(t2, w1) && isCollapsed(t2, w3),
208 "toolbar#2 is still collapsed");
210 show(t2);
211 yield wait(t2, "show");
213 assert.ok(!isCollapsed(t2, w1) && !isCollapsed(t2, w3),
214 "toolbar#2 is not collapsed");
216 yield close(w3);
218 assert.ok(isAttached(t2, w1), "still attached to last window");
219 assert.ok(!isCollapsed(t2, w1), "still isn't collapsed");
221 t2.destroy();
222 yield wait(t2, "detach");
224 assert.ok(!isAttached(t2, w1), "toolbar was removed");
225 };
227 exports["test toolbar persistence"] = function*(assert) {
228 const t1 = new Toolbar({ title: "per sist ence" });
230 yield wait(t1, "attach");
232 assert.equal(t1.hidden, false, "toolbar is visible");
234 hide(t1);
235 yield wait(t1, "hide");
237 assert.equal(t1.hidden, true, "toolbar is hidden");
238 assert.ok(isCollapsed(t1), "toolbar is collapsed");
240 t1.destroy();
242 yield wait(t1, "detach");
244 const t2 = new Toolbar({ title: "per sist ence" });
246 yield wait(t2, "attach");
248 assert.equal(t2.hidden, true, "toolbar persisted state");
249 assert.ok(isCollapsed(t2), "toolbar is collapsed");
251 show(t2);
252 t2.destroy();
254 yield wait(t2, "detach");
256 const t3 = new Toolbar({ title: "per sist ence", hidden: true });
258 yield wait(t3, "attach");
260 assert.equal(t3.hidden, false, "toolbar persisted state & ignored option");
261 assert.ok(!isCollapsed(t3), "toolbar isn1t collapsed");
263 t3.destroy();
265 yield wait(t3, "detach");
266 };
269 exports["test toolbar unload"] = function*(assert) {
270 // We override add-on id, otherwise two instances of Toolbar host (view.js)
271 // handling same updates, cause message port is bound to add-on id.
272 const loader = Loader(module, null, null, {id: "toolbar-unload-addon"});
273 const { Toolbar } = loader.require("sdk/ui/toolbar");
275 const w1 = getMostRecentBrowserWindow();
276 const w2 = open();
278 yield ready(w2);
280 const t1 = new Toolbar({ title: "unload" });
282 yield wait(t1, "attach");
284 assert.ok(isAttached(t1, w1) && isAttached(t1, w2),
285 "attached to both windows");
288 loader.unload();
291 assert.ok(!isAttached(t1, w1) && !isAttached(t1, w2),
292 "detached from both windows on unload");
294 yield close(w2);
295 };
297 exports["test toolbar close button"] = function*(assert) {
298 const t1 = new Toolbar({ title: "close with button" });
300 yield wait(t1, "attach");
301 const w1 = getMostRecentBrowserWindow();
302 const w2 = open();
304 yield ready(w2);
306 assert.ok(!isCollapsed(t1, w1) && !isCollapsed(t1, w2),
307 "toolbar isn't collapsed");
309 closeViaButton(t1);
311 yield wait(t1, "hide");
313 assert.ok(isCollapsed(t1, w1) && isCollapsed(t1, w2),
314 "toolbar was collapsed");
316 t1.destroy();
317 yield wait(t1, "detach");
318 yield close(w2);
319 };
321 exports["test title change"] = function*(assert) {
322 const w1 = getMostRecentBrowserWindow();
323 const w2 = open();
325 yield ready(w2);
327 const t1 = new Toolbar({ title: "first title" });
328 const id = t1.id;
330 yield wait(t1, "attach");
333 assert.equal(t1.title, "first title",
334 "correct title is set");
335 assert.equal(readTitle(t1, w1), "first title",
336 "title set in the view of first window");
337 assert.equal(readTitle(t1, w2), "first title",
338 "title set in the view of second window");
340 retitle(t1, "second title");
342 // Hide & show so to make sure changes go through a round
343 // loop.
344 hide(t1);
345 yield wait(t1, "hide");
346 show(t1);
347 yield wait(t1, "show");
349 assert.equal(t1.id, id, "id remains same");
350 assert.equal(t1.title, "second title", "instance title was updated");
351 assert.equal(readTitle(t1, w1), "second title",
352 "title updated in first window");
353 assert.equal(readTitle(t1, w2), "second title",
354 "title updated in second window");
356 t1.destroy();
357 yield wait(t1, "detach");
358 yield close(w2);
359 };
361 exports["test toolbar is not customizable"] = function*(assert, done) {
362 const { window, document, gCustomizeMode } = getMostRecentBrowserWindow();
363 const outerId = getOuterId(window);
364 const input = new CustomizationInput();
365 const customized = defer();
366 const customizedEnd = defer();
368 new Reactor({ onStep: value => {
369 if (value[outerId] === true)
370 customized.resolve();
371 if (value[outerId] === null)
372 customizedEnd.resolve();
373 }}).run(input);
375 const toolbar = new Toolbar({ title: "foo" });
377 yield wait(toolbar, "attach");
379 let view = document.getElementById(toolbar.id);
380 let label = view.querySelector("label");
381 let inner = view.querySelector("toolbar");
383 assert.equal(view.getAttribute("customizable"), "false",
384 "The outer toolbar is not customizable.");
386 assert.ok(label.collapsed,
387 "The label is not displayed.")
389 assert.equal(inner.getAttribute("customizable"), "true",
390 "The inner toolbar is customizable.");
392 assert.equal(window.getComputedStyle(inner).visibility, "visible",
393 "The inner toolbar is visible.");
395 // Enter in customization mode
396 gCustomizeMode.toggle();
398 yield customized.promise;
400 assert.equal(view.getAttribute("customizable"), "false",
401 "The outer toolbar is not customizable.");
403 assert.equal(label.collapsed, false,
404 "The label is displayed.")
406 assert.equal(inner.getAttribute("customizable"), "true",
407 "The inner toolbar is customizable.");
409 assert.equal(window.getComputedStyle(inner).visibility, "hidden",
410 "The inner toolbar is hidden.");
412 // Exit from customization mode
413 gCustomizeMode.toggle();
415 yield customizedEnd.promise;
417 assert.equal(view.getAttribute("customizable"), "false",
418 "The outer toolbar is not customizable.");
420 assert.ok(label.collapsed,
421 "The label is not displayed.")
423 assert.equal(inner.getAttribute("customizable"), "true",
424 "The inner toolbar is customizable.");
426 assert.equal(window.getComputedStyle(inner).visibility, "visible",
427 "The inner toolbar is visible.");
429 toolbar.destroy();
430 };
432 exports["test button are attached to toolbar"] = function*(assert) {
433 const { document } = getMostRecentBrowserWindow();
434 const { ActionButton, ToggleButton } = require("sdk/ui");
435 const { identify } = require("sdk/ui/id");
437 let action = ActionButton({
438 id: "btn-1",
439 label: "action",
440 icon: "./placeholder.png"
441 });
443 let toggle = ToggleButton({
444 id: "btn-2",
445 label: "toggle",
446 icon: "./placeholder.png"
447 });
449 const toolbar = new Toolbar({
450 title: "foo",
451 items: [action, toggle]
452 });
454 yield wait(toolbar, "attach");
456 let actionNode = document.getElementById(identify(action));
457 let toggleNode = document.getElementById(identify(toggle));
459 assert.notEqual(actionNode, null,
460 "action button exists in the document");
462 assert.notEqual(actionNode, null,
463 "action button exists in the document");
465 assert.notEqual(toggleNode, null,
466 "toggle button exists in the document");
468 assert.equal(actionNode.nextElementSibling, toggleNode,
469 "action button is placed before toggle button");
471 assert.equal(actionNode.parentNode.parentNode.id, toolbar.id,
472 "buttons are placed in the correct toolbar");
474 toolbar.destroy();
475 };
477 require("sdk/test").run(exports);