| OLD | NEW |
| 1 (function() | 1 (function() |
| 2 { | 2 { |
| 3 let testRunner = null; | 3 let testRunner = null; |
| 4 let server = null; | |
| 5 let randomResult = 0.5; | 4 let randomResult = 0.5; |
| 6 | 5 |
| 7 let originalInfo; | 6 let originalInfo; |
| 8 let info = require("info"); | 7 let info = require("info"); |
| 9 | 8 |
| 10 module("Notification handling", | 9 module("Notification handling", |
| 11 { | 10 { |
| 12 setup: function() | 11 setup: function() |
| 13 { | 12 { |
| 14 testRunner = this; | 13 testRunner = this; |
| 15 | 14 |
| 16 preparePrefs.call(this); | 15 preparePrefs.call(this); |
| 17 setupVirtualTime.call(this, function(wrapTimer) | 16 setupVirtualTime.call(this, function(wrapTimer) |
| 18 { | 17 { |
| 19 let NotificationModule = getModuleGlobal("notification"); | 18 let NotificationModule = getModuleGlobal("notification"); |
| 20 NotificationModule.downloader._timer = wrapTimer(NotificationModule.down
loader._timer); | 19 NotificationModule.downloader._timer = wrapTimer(NotificationModule.down
loader._timer); |
| 21 }, "notification", "downloader"); | 20 }, "notification", "downloader"); |
| 22 | 21 setupVirtualXMLHttp.call(this, "notification", "downloader"); |
| 23 server = new nsHttpServer(); | |
| 24 server.start(1234); | |
| 25 | 22 |
| 26 originalInfo = {}; | 23 originalInfo = {}; |
| 27 for (let key in info) | 24 for (let key in info) |
| 28 originalInfo[key] = info[key]; | 25 originalInfo[key] = info[key]; |
| 29 | 26 |
| 30 info.addonName = "adblockpluschrome"; | 27 info.addonName = "adblockpluschrome"; |
| 31 info.addonVersion = "1.4.1"; | 28 info.addonVersion = "1.4.1"; |
| 32 info.application = "chrome"; | 29 info.application = "chrome"; |
| 33 info.applicationVersion = "27.0"; | 30 info.applicationVersion = "27.0"; |
| 34 info.platform = "chromium"; | 31 info.platform = "chromium"; |
| 35 info.platformVersion = "12.0"; | 32 info.platformVersion = "12.0"; |
| 36 | 33 |
| 37 Prefs.notificationurl = "http://127.0.0.1:1234/notification.json"; | 34 Prefs.notificationurl = "http://example.com/notification.json"; |
| 38 Prefs.notificationdata = {}; | 35 Prefs.notificationdata = {}; |
| 39 | 36 |
| 40 // Replace Math.random() function | 37 // Replace Math.random() function |
| 41 let DownloaderGlobal = Cu.getGlobalForObject(getModuleGlobal("downloader")
); | 38 let DownloaderGlobal = Cu.getGlobalForObject(getModuleGlobal("downloader")
); |
| 42 this._origRandom = DownloaderGlobal.Math.random; | 39 this._origRandom = DownloaderGlobal.Math.random; |
| 43 DownloaderGlobal.Math.random = function() randomResult; | 40 DownloaderGlobal.Math.random = function() randomResult; |
| 44 randomResult = 0.5; | 41 randomResult = 0.5; |
| 45 }, | 42 }, |
| 46 | 43 |
| 47 teardown: function() | 44 teardown: function() |
| 48 { | 45 { |
| 49 restorePrefs.call(this); | 46 restorePrefs.call(this); |
| 50 restoreVirtualTime.call(this); | 47 restoreVirtualTime.call(this); |
| 51 | 48 restoreVirtualXMLHttp.call(this); |
| 52 stop(); | |
| 53 server.stop(function() | |
| 54 { | |
| 55 server = null; | |
| 56 start(); | |
| 57 }); | |
| 58 | 49 |
| 59 for (let key in originalInfo) | 50 for (let key in originalInfo) |
| 60 info[key] = originalInfo[key]; | 51 info[key] = originalInfo[key]; |
| 61 | 52 |
| 62 if (this._origRandom) | 53 if (this._origRandom) |
| 63 { | 54 { |
| 64 let DownloaderGlobal = Cu.getGlobalForObject(getModuleGlobal("downloader
")); | 55 let DownloaderGlobal = Cu.getGlobalForObject(getModuleGlobal("downloader
")); |
| 65 DownloaderGlobal.Math.random = this._origRandom; | 56 DownloaderGlobal.Math.random = this._origRandom; |
| 66 delete this._origRandom; | 57 delete this._origRandom; |
| 67 } | 58 } |
| 68 | 59 |
| 69 Notification.init(); | 60 Notification.init(); |
| 70 } | 61 } |
| 71 }); | 62 }); |
| 72 | 63 |
| 73 function registerHandler(notifications) | 64 function registerHandler(notifications) |
| 74 { | 65 { |
| 75 server.registerPathHandler("/notification.json", function(metadata, response
) | 66 testRunner.registerHandler("/notification.json", function(metadata) |
| 76 { | 67 { |
| 77 response.setStatusLine("1.1", "200", "OK"); | |
| 78 response.setHeader("Content-Type", "application/json"); | |
| 79 | |
| 80 let notification = { | 68 let notification = { |
| 81 version: 55, | 69 version: 55, |
| 82 notifications: notifications | 70 notifications: notifications |
| 83 }; | 71 }; |
| 84 | 72 |
| 85 let result = JSON.stringify(notification); | 73 return [Cr.NS_OK, 200, JSON.stringify(notification)]; |
| 86 response.bodyOutputStream.write(result, result.length); | |
| 87 }); | 74 }); |
| 88 } | 75 } |
| 89 | 76 |
| 90 function fixConstructors(object) | 77 function fixConstructors(object) |
| 91 { | 78 { |
| 92 // deepEqual() expects that the constructors used in expected objects and | 79 // deepEqual() expects that the constructors used in expected objects and |
| 93 // the ones in the actual results are the same. That means that we actually | 80 // the ones in the actual results are the same. That means that we actually |
| 94 // have to construct our objects in the context of the notification module. | 81 // have to construct our objects in the context of the notification module. |
| 95 let JSON = Cu.getGlobalForObject(Notification).JSON; | 82 let JSON = Cu.getGlobalForObject(Notification).JSON; |
| 96 return JSON.parse(JSON.stringify(object)); | 83 return JSON.parse(JSON.stringify(object)); |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 278 equal(texts.message, "fr"); | 265 equal(texts.message, "fr"); |
| 279 }); | 266 }); |
| 280 | 267 |
| 281 test("Missing translation", function() | 268 test("Missing translation", function() |
| 282 { | 269 { |
| 283 let notification = {message: {"en-US": "en-US"}}; | 270 let notification = {message: {"en-US": "en-US"}}; |
| 284 let texts = Notification.getLocalizedTexts(notification, "fr"); | 271 let texts = Notification.getLocalizedTexts(notification, "fr"); |
| 285 equal(texts.message, "en-US"); | 272 equal(texts.message, "en-US"); |
| 286 }); | 273 }); |
| 287 })(); | 274 })(); |
| OLD | NEW |