| OLD | NEW |
| 1 (function() | 1 (function() |
| 2 { | 2 { |
| 3 let testRunner = null; | 3 let testRunner = null; |
| 4 let randomResult = 0.5; | 4 let randomResult = 0.5; |
| 5 | 5 |
| 6 let originalInfo; | 6 let originalInfo; |
| 7 let info = require("info"); | 7 let info = require("info"); |
| 8 | 8 |
| 9 function showNotifications(url) | 9 function showNotifications(url) |
| 10 { | 10 { |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 216 }); | 216 }); |
| 217 | 217 |
| 218 Prefs.notificationdata = {}; | 218 Prefs.notificationdata = {}; |
| 219 registerHandler([information]); | 219 registerHandler([information]); |
| 220 testRunner.runScheduledTasks(1); | 220 testRunner.runScheduledTasks(1); |
| 221 | 221 |
| 222 let expected = (result ? [information] : []); | 222 let expected = (result ? [information] : []); |
| 223 deepEqual(showNotifications(), expected, "Selected notification for " + JS
ON.stringify(information.targets)); | 223 deepEqual(showNotifications(), expected, "Selected notification for " + JS
ON.stringify(information.targets)); |
| 224 deepEqual(showNotifications(), [], "No notification on second call"); | 224 deepEqual(showNotifications(), [], "No notification on second call"); |
| 225 } | 225 } |
| 226 }); |
| 227 |
| 228 test("Multiple targets", function() |
| 229 { |
| 230 let targets = [ |
| 231 ["extension", "adblockpluschrome", true], |
| 232 ["extension", "adblockplus", false], |
| 233 ["extensionMinVersion", "1.4", true], |
| 234 ["extensionMinVersion", "1.5", false], |
| 235 ["application", "chrome", true], |
| 236 ["application", "firefox", false], |
| 237 ["applicationMinVersion", "27", true], |
| 238 ["applicationMinVersion", "28", false], |
| 239 ["platform", "chromium", true], |
| 240 ["platform", "gecko", false], |
| 241 ["platformMinVersion", "12", true], |
| 242 ["platformMinVersion", "13", false], |
| 243 ]; |
| 226 | 244 |
| 227 function pairs(array) | 245 function pairs(array) |
| 228 { | 246 { |
| 229 for (let element1 of array) | 247 for (let element1 of array) |
| 230 for (let element2 of array) | 248 for (let element2 of array) |
| 231 yield [element1, element2]; | 249 if (element1 != element2) |
| 250 yield [element1, element2]; |
| 232 } | 251 } |
| 252 |
| 233 for (let [[propName1, value1, result1], [propName2, value2, result2]] in pai
rs(targets)) | 253 for (let [[propName1, value1, result1], [propName2, value2, result2]] in pai
rs(targets)) |
| 234 { | 254 { |
| 235 let targetInfo1 = {}; | 255 let targetInfo1 = {}; |
| 236 targetInfo1[propName1] = value1; | 256 targetInfo1[propName1] = value1; |
| 237 let targetInfo2 = {}; | 257 let targetInfo2 = {}; |
| 238 targetInfo2[propName2] = value2; | 258 targetInfo2[propName2] = value2; |
| 239 | 259 |
| 240 let information = fixConstructors({ | 260 let information = fixConstructors({ |
| 241 id: 1, | 261 id: 1, |
| 242 type: "information", | 262 type: "information", |
| 243 message: {"en-US": "Information"}, | 263 message: {"en-US": "Information"}, |
| 244 targets: [targetInfo1, targetInfo2] | 264 targets: [targetInfo1, targetInfo2] |
| 245 }); | 265 }); |
| 246 | 266 |
| 247 Prefs.notificationdata = {}; | 267 Prefs.notificationdata = {}; |
| 248 registerHandler([information]); | 268 registerHandler([information]); |
| 249 testRunner.runScheduledTasks(1); | 269 testRunner.runScheduledTasks(1); |
| 250 | 270 |
| 251 let expected = (result1 || result2 ? [information] : []) | 271 let expected = (result1 || result2 ? [information] : []) |
| 252 deepEqual(showNotifications(), expected, "Selected notification for " + JS
ON.stringify(information.targets)); | 272 deepEqual(showNotifications(), expected, "Selected notification for " + JS
ON.stringify(information.targets)); |
| 253 deepEqual(showNotifications(), [], "No notification on second call"); | |
| 254 | |
| 255 information = fixConstructors({ | |
| 256 id: 1, | |
| 257 type: "information", | |
| 258 message: {"en-US": "Information"}, | |
| 259 targets: [targetInfo1] | |
| 260 }); | |
| 261 let critical = fixConstructors({ | |
| 262 id: 2, | |
| 263 type: "critical", | |
| 264 message: {"en-US": "Critical"}, | |
| 265 targets: [targetInfo2] | |
| 266 }); | |
| 267 | |
| 268 Prefs.notificationdata = {}; | |
| 269 registerHandler([information, critical]); | |
| 270 testRunner.runScheduledTasks(1); | |
| 271 | |
| 272 expected = (result2 ? [critical] : (result1 ? [information] : [])); | |
| 273 deepEqual(showNotifications(), expected, "Selected notification for inform
ation with " + JSON.stringify(information.targets) + " and critical with " + JSO
N.stringify(critical.targets)); | |
| 274 } | 273 } |
| 275 }); | 274 }); |
| 276 | 275 |
| 277 test("Parameters sent", function() | 276 test("Parameters sent", function() |
| 278 { | 277 { |
| 279 Prefs.notificationdata = { | 278 Prefs.notificationdata = { |
| 280 data: { | 279 data: { |
| 281 version: "3" | 280 version: "3" |
| 282 }, | 281 }, |
| 283 }; | 282 }; |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 478 equal(texts.message, "fr"); | 477 equal(texts.message, "fr"); |
| 479 }); | 478 }); |
| 480 | 479 |
| 481 test("Missing translation", function() | 480 test("Missing translation", function() |
| 482 { | 481 { |
| 483 let notification = {message: {"en-US": "en-US"}}; | 482 let notification = {message: {"en-US": "en-US"}}; |
| 484 let texts = Notification.getLocalizedTexts(notification, "fr"); | 483 let texts = Notification.getLocalizedTexts(notification, "fr"); |
| 485 equal(texts.message, "en-US"); | 484 equal(texts.message, "en-US"); |
| 486 }); | 485 }); |
| 487 })(); | 486 })(); |
| OLD | NEW |