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 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | let provider; |
michael@0 | 6 | |
michael@0 | 7 | function test() { |
michael@0 | 8 | waitForExplicitFinish(); |
michael@0 | 9 | |
michael@0 | 10 | replaceAlertsService(); |
michael@0 | 11 | registerCleanupFunction(restoreAlertsService); |
michael@0 | 12 | |
michael@0 | 13 | let manifest = { |
michael@0 | 14 | origin: 'http://example.com', |
michael@0 | 15 | name: "Example Provider", |
michael@0 | 16 | workerURL: "http://example.com/browser/toolkit/components/social/test/browser/worker_social.js" |
michael@0 | 17 | }; |
michael@0 | 18 | |
michael@0 | 19 | SocialService.addProvider(manifest, function (p) { |
michael@0 | 20 | // toolkit does not enable providers by default, that is handled in the |
michael@0 | 21 | // browser, we need to enable it in our tests. |
michael@0 | 22 | p.enabled = true; |
michael@0 | 23 | provider = p; |
michael@0 | 24 | runTests(tests, undefined, undefined, function () { |
michael@0 | 25 | SocialService.removeProvider(provider.origin, finish); |
michael@0 | 26 | }); |
michael@0 | 27 | }); |
michael@0 | 28 | } |
michael@0 | 29 | |
michael@0 | 30 | let tests = { |
michael@0 | 31 | testProfile: function(next) { |
michael@0 | 32 | let expect = { |
michael@0 | 33 | portrait: "https://example.com/portrait.jpg", |
michael@0 | 34 | userName: "trickster", |
michael@0 | 35 | displayName: "Kuma Lisa", |
michael@0 | 36 | profileURL: "http://en.wikipedia.org/wiki/Kuma_Lisa" |
michael@0 | 37 | } |
michael@0 | 38 | function ob(aSubject, aTopic, aData) { |
michael@0 | 39 | Services.obs.removeObserver(ob, "social:profile-changed"); |
michael@0 | 40 | is(aData, provider.origin, "update of profile from our provider"); |
michael@0 | 41 | let profile = provider.profile; |
michael@0 | 42 | is(profile.portrait, expect.portrait, "portrait is set"); |
michael@0 | 43 | is(profile.userName, expect.userName, "userName is set"); |
michael@0 | 44 | is(profile.displayName, expect.displayName, "displayName is set"); |
michael@0 | 45 | is(profile.profileURL, expect.profileURL, "profileURL is set"); |
michael@0 | 46 | next(); |
michael@0 | 47 | } |
michael@0 | 48 | Services.obs.addObserver(ob, "social:profile-changed", false); |
michael@0 | 49 | let port = provider.getWorkerPort(); |
michael@0 | 50 | port.postMessage({topic: "test-profile", data: expect}); |
michael@0 | 51 | port.close(); |
michael@0 | 52 | }, |
michael@0 | 53 | |
michael@0 | 54 | testAmbientNotification: function(next) { |
michael@0 | 55 | let expect = { |
michael@0 | 56 | name: "test-ambient" |
michael@0 | 57 | } |
michael@0 | 58 | function ob(aSubject, aTopic, aData) { |
michael@0 | 59 | Services.obs.removeObserver(ob, "social:ambient-notification-changed"); |
michael@0 | 60 | is(aData, provider.origin, "update is from our provider"); |
michael@0 | 61 | let notif = provider.ambientNotificationIcons[expect.name]; |
michael@0 | 62 | is(notif.name, expect.name, "ambientNotification reflected"); |
michael@0 | 63 | |
michael@0 | 64 | next(); |
michael@0 | 65 | } |
michael@0 | 66 | Services.obs.addObserver(ob, "social:ambient-notification-changed", false); |
michael@0 | 67 | let port = provider.getWorkerPort(); |
michael@0 | 68 | port.postMessage({topic: "test-ambient", data: expect}); |
michael@0 | 69 | port.close(); |
michael@0 | 70 | }, |
michael@0 | 71 | |
michael@0 | 72 | testProfileCleared: function(next) { |
michael@0 | 73 | let sent = { |
michael@0 | 74 | userName: "" |
michael@0 | 75 | }; |
michael@0 | 76 | function ob(aSubject, aTopic, aData) { |
michael@0 | 77 | Services.obs.removeObserver(ob, "social:profile-changed"); |
michael@0 | 78 | is(aData, provider.origin, "update of profile from our provider"); |
michael@0 | 79 | is(Object.keys(provider.profile).length, 0, "profile was cleared by empty username"); |
michael@0 | 80 | is(Object.keys(provider.ambientNotificationIcons).length, 0, "icons were cleared by empty username"); |
michael@0 | 81 | |
michael@0 | 82 | next(); |
michael@0 | 83 | } |
michael@0 | 84 | Services.obs.addObserver(ob, "social:profile-changed", false); |
michael@0 | 85 | provider.workerAPI._port.postMessage({topic: "test-profile", data: sent}); |
michael@0 | 86 | }, |
michael@0 | 87 | |
michael@0 | 88 | testNoCookies: function(next) { |
michael@0 | 89 | // use a big, blunt stick to remove cookies. |
michael@0 | 90 | Services.cookies.removeAll(); |
michael@0 | 91 | let port = provider.getWorkerPort(); |
michael@0 | 92 | port.onmessage = function onMessage(event) { |
michael@0 | 93 | let {topic, data} = event.data; |
michael@0 | 94 | if (topic == "test.cookies-get-response") { |
michael@0 | 95 | is(data.length, 0, "got no cookies"); |
michael@0 | 96 | port.close(); |
michael@0 | 97 | next(); |
michael@0 | 98 | } |
michael@0 | 99 | } |
michael@0 | 100 | port.postMessage({topic: "test-initialization"}); |
michael@0 | 101 | port.postMessage({topic: "test.cookies-get"}); |
michael@0 | 102 | }, |
michael@0 | 103 | |
michael@0 | 104 | testCookies: function(next) { |
michael@0 | 105 | let port = provider.getWorkerPort(); |
michael@0 | 106 | port.onmessage = function onMessage(event) { |
michael@0 | 107 | let {topic, data} = event.data; |
michael@0 | 108 | if (topic == "test.cookies-get-response") { |
michael@0 | 109 | is(data.length, 2, "got 2 cookies"); |
michael@0 | 110 | is(data[0].name, "cheez", "cookie has the correct name"); |
michael@0 | 111 | is(data[0].value, "burger", "cookie has the correct value"); |
michael@0 | 112 | is(data[1].name, "moar", "cookie has the correct name"); |
michael@0 | 113 | is(data[1].value, "bacon", "cookie has the correct value"); |
michael@0 | 114 | Services.cookies.remove('.example.com', '/', 'cheez', false); |
michael@0 | 115 | Services.cookies.remove('.example.com', '/', 'moar', false); |
michael@0 | 116 | port.close(); |
michael@0 | 117 | next(); |
michael@0 | 118 | } |
michael@0 | 119 | } |
michael@0 | 120 | var MAX_EXPIRY = Math.pow(2, 62); |
michael@0 | 121 | Services.cookies.add('.example.com', '/', 'cheez', 'burger', false, false, true, MAX_EXPIRY); |
michael@0 | 122 | Services.cookies.add('.example.com', '/', 'moar', 'bacon', false, false, true, MAX_EXPIRY); |
michael@0 | 123 | port.postMessage({topic: "test-initialization"}); |
michael@0 | 124 | port.postMessage({topic: "test.cookies-get"}); |
michael@0 | 125 | }, |
michael@0 | 126 | |
michael@0 | 127 | testWorkerReload: function(next) { |
michael@0 | 128 | let fw = {}; |
michael@0 | 129 | Cu.import("resource://gre/modules/FrameWorker.jsm", fw); |
michael@0 | 130 | |
michael@0 | 131 | let worker = fw.getFrameWorkerHandle(provider.workerURL, undefined, "testWorkerReload"); |
michael@0 | 132 | let port = provider.getWorkerPort(); |
michael@0 | 133 | // this observer will be fired when the worker reloads - it ensures the |
michael@0 | 134 | // old port was closed and the new worker is functioning. |
michael@0 | 135 | Services.obs.addObserver(function reloadObserver() { |
michael@0 | 136 | Services.obs.removeObserver(reloadObserver, "social:provider-reload"); |
michael@0 | 137 | ok(port._closed, "old port was closed by the reload"); |
michael@0 | 138 | let newWorker = fw.getFrameWorkerHandle(provider.workerURL, undefined, "testWorkerReload - worker2"); |
michael@0 | 139 | let newPort = provider.getWorkerPort(); |
michael@0 | 140 | newPort.onmessage = function (e) { |
michael@0 | 141 | let topic = e.data.topic; |
michael@0 | 142 | switch (topic) { |
michael@0 | 143 | case "test-initialization-complete": |
michael@0 | 144 | // and we are done. |
michael@0 | 145 | newPort.close(); |
michael@0 | 146 | next(); |
michael@0 | 147 | break; |
michael@0 | 148 | } |
michael@0 | 149 | } |
michael@0 | 150 | newPort.postMessage({topic: "test-initialization"}); |
michael@0 | 151 | }, "social:provider-reload", false); |
michael@0 | 152 | |
michael@0 | 153 | port.onmessage = function (e) { |
michael@0 | 154 | let topic = e.data.topic; |
michael@0 | 155 | switch (topic) { |
michael@0 | 156 | case "test-initialization-complete": |
michael@0 | 157 | // tell the worker to send the reload msg - that will trigger the |
michael@0 | 158 | // frameworker to unload and for our content script's unload |
michael@0 | 159 | // handler to post a "test-result" message. |
michael@0 | 160 | port.postMessage({topic: "test-reload-init"}); |
michael@0 | 161 | // and the "social:provider-reload" observer should fire... |
michael@0 | 162 | break; |
michael@0 | 163 | } |
michael@0 | 164 | } |
michael@0 | 165 | port.postMessage({topic: "test-initialization"}); |
michael@0 | 166 | }, |
michael@0 | 167 | |
michael@0 | 168 | testNotificationLinks: function(next) { |
michael@0 | 169 | let port = provider.getWorkerPort(); |
michael@0 | 170 | let data = { |
michael@0 | 171 | id: 'an id', |
michael@0 | 172 | body: 'the text', |
michael@0 | 173 | action: 'link', |
michael@0 | 174 | actionArgs: {} // will get a toURL elt during the tests... |
michael@0 | 175 | } |
michael@0 | 176 | let testArgs = [ |
michael@0 | 177 | // toURL, expectedLocation, expectedWhere] |
michael@0 | 178 | ["http://example.com", "http://example.com/", "tab"], |
michael@0 | 179 | // bug 815970 - test that a mis-matched scheme gets patched up. |
michael@0 | 180 | ["https://example.com", "http://example.com/", "tab"], |
michael@0 | 181 | // check an off-origin link is not opened. |
michael@0 | 182 | ["https://mochitest:8888/", null, null] |
michael@0 | 183 | ]; |
michael@0 | 184 | |
michael@0 | 185 | // we monkey-patch openUILinkIn |
michael@0 | 186 | let oldopenUILinkIn = window.openUILinkIn; |
michael@0 | 187 | registerCleanupFunction(function () { |
michael@0 | 188 | // restore the monkey-patch |
michael@0 | 189 | window.openUILinkIn = oldopenUILinkIn; |
michael@0 | 190 | }); |
michael@0 | 191 | let openLocation; |
michael@0 | 192 | let openWhere; |
michael@0 | 193 | window.openUILinkIn = function(location, where) { |
michael@0 | 194 | openLocation = location; |
michael@0 | 195 | openWhere = where; |
michael@0 | 196 | } |
michael@0 | 197 | |
michael@0 | 198 | // the testing framework. |
michael@0 | 199 | let toURL, expectedLocation, expectedWhere; |
michael@0 | 200 | function nextTest() { |
michael@0 | 201 | if (testArgs.length == 0) { |
michael@0 | 202 | port.close(); |
michael@0 | 203 | next(); // all out of tests! |
michael@0 | 204 | return; |
michael@0 | 205 | } |
michael@0 | 206 | openLocation = openWhere = null; |
michael@0 | 207 | [toURL, expectedLocation, expectedWhere] = testArgs.shift(); |
michael@0 | 208 | data.actionArgs.toURL = toURL; |
michael@0 | 209 | port.postMessage({topic: 'test-notification-create', data: data}); |
michael@0 | 210 | }; |
michael@0 | 211 | |
michael@0 | 212 | port.onmessage = function(evt) { |
michael@0 | 213 | if (evt.data.topic == "did-notification-create") { |
michael@0 | 214 | is(openLocation, expectedLocation, "url actually opened was " + openLocation); |
michael@0 | 215 | is(openWhere, expectedWhere, "the url was opened in a " + expectedWhere); |
michael@0 | 216 | nextTest(); |
michael@0 | 217 | } |
michael@0 | 218 | } |
michael@0 | 219 | // and kick off the tests. |
michael@0 | 220 | port.postMessage({topic: "test-initialization"}); |
michael@0 | 221 | nextTest(); |
michael@0 | 222 | }, |
michael@0 | 223 | |
michael@0 | 224 | }; |