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 const { Cc, Ci } = require('chrome');
7 const { Symbiont } = require('sdk/deprecated/symbiont');
8 const self = require('sdk/self');
9 const fixtures = require("./fixtures");
10 const { close } = require('sdk/window/helpers');
11 const app = require("sdk/system/xul-app");
13 function makeWindow() {
14 let content =
15 '<?xml version="1.0"?>' +
16 '<window ' +
17 'xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">' +
18 '<iframe id="content" type="content"/>' +
19 '</window>';
20 var url = "data:application/vnd.mozilla.xul+xml;charset=utf-8," +
21 encodeURIComponent(content);
22 var features = ["chrome", "width=10", "height=10"];
24 return Cc["@mozilla.org/embedcomp/window-watcher;1"].
25 getService(Ci.nsIWindowWatcher).
26 openWindow(null, url, null, features.join(","), null);
27 }
29 exports['test:constructing symbiont && validating API'] = function(assert) {
30 let contentScript = ["1;", "2;"];
31 let contentScriptFile = fixtures.url("test-content-symbiont.js");
33 // We can avoid passing a `frame` argument. Symbiont will create one
34 // by using HiddenFrame module
35 let contentSymbiont = Symbiont({
36 contentScriptFile: contentScriptFile,
37 contentScript: contentScript,
38 contentScriptWhen: "start"
39 });
41 assert.equal(
42 contentScriptFile,
43 contentSymbiont.contentScriptFile,
44 "There is one contentScriptFile, as specified in options."
45 );
46 assert.equal(
47 contentScript.length,
48 contentSymbiont.contentScript.length,
49 "There are two contentScripts, as specified in options."
50 );
51 assert.equal(
52 contentScript[0],
53 contentSymbiont.contentScript[0],
54 "There are two contentScripts, as specified in options."
55 );
56 assert.equal(
57 contentScript[1],
58 contentSymbiont.contentScript[1],
59 "There are two contentScripts, as specified in options."
60 )
61 assert.equal(
62 contentSymbiont.contentScriptWhen,
63 "start",
64 "contentScriptWhen is as specified in options."
65 );
67 contentSymbiont.destroy();
68 };
70 exports["test:communication with worker global scope"] = function(assert, done) {
71 if (app.is('Fennec')) {
72 assert.pass('Test skipped on Fennec');
73 done();
74 }
76 let window = makeWindow();
77 let contentSymbiont;
79 assert.ok(!!window, 'there is a window');
81 function onMessage1(message) {
82 assert.equal(message, 1, "Program gets message via onMessage.");
83 contentSymbiont.removeListener('message', onMessage1);
84 contentSymbiont.on('message', onMessage2);
85 contentSymbiont.postMessage(2);
86 };
88 function onMessage2(message) {
89 if (5 == message) {
90 close(window).then(done);
91 }
92 else {
93 assert.equal(message, 3, "Program gets message via onMessage2.");
94 contentSymbiont.postMessage(4)
95 }
96 }
98 window.addEventListener("load", function onLoad() {
99 window.removeEventListener("load", onLoad, false);
100 let frame = window.document.getElementById("content");
101 contentSymbiont = Symbiont({
102 frame: frame,
103 contentScript: 'new ' + function() {
104 self.postMessage(1);
105 self.on("message", function onMessage(message) {
106 if (message === 2)
107 self.postMessage(3);
108 if (message === 4)
109 self.postMessage(5);
110 });
111 } + '()',
112 contentScriptWhen: 'ready',
113 onMessage: onMessage1
114 });
116 frame.setAttribute("src", "data:text/html;charset=utf-8,<html><body></body></html>");
117 }, false);
118 };
120 exports['test:pageWorker'] = function(assert, done) {
121 let worker = Symbiont({
122 contentURL: 'about:buildconfig',
123 contentScript: 'new ' + function WorkerScope() {
124 self.on('message', function(data) {
125 if (data.valid)
126 self.postMessage('bye!');
127 })
128 self.postMessage(window.location.toString());
129 },
130 onMessage: function(msg) {
131 if (msg == 'bye!') {
132 done()
133 } else {
134 assert.equal(
135 worker.contentURL + '',
136 msg
137 );
138 worker.postMessage({ valid: true });
139 }
140 }
141 });
142 };
144 exports["test:document element present on 'start'"] = function(assert, done) {
145 let xulApp = require("sdk/system/xul-app");
146 let worker = Symbiont({
147 contentURL: "about:buildconfig",
148 contentScript: "self.postMessage(!!document.documentElement)",
149 contentScriptWhen: "start",
150 onMessage: function(message) {
151 if (xulApp.versionInRange(xulApp.platformVersion, "2.0b6", "*"))
152 assert.ok(message, "document element present on 'start'");
153 else
154 assert.pass("document element not necessarily present on 'start'");
155 done();
156 }
157 });
158 };
160 require("test").run(exports);