OLD | NEW |
(Empty) | |
| 1 (function() |
| 2 { |
| 3 function getModuleGlobal(module) |
| 4 { |
| 5 let result = Cu.getGlobalForObject(require(module)); |
| 6 if (result == window) |
| 7 { |
| 8 // Work-around for bug 736316 - getGlobalForObject gave us our own window |
| 9 let {XPIProvider} = Cu.import("resource://gre/modules/XPIProvider.jsm", nu
ll); |
| 10 let addonID = "{0fa2149e-bb2c-4ac2-a8d3-479599819475}"; |
| 11 if (addonID in XPIProvider.bootstrapScopes) |
| 12 result = XPIProvider.bootstrapScopes[addonID]; |
| 13 } |
| 14 |
| 15 if ("require" in result) |
| 16 result = result.require.scopes[module]; |
| 17 return result; |
| 18 } |
| 19 |
| 20 let {onWhitelistEntryAdded, onWhitelistEntryRemoved} = require("rules"); |
| 21 let rulesGlobal = getModuleGlobal("rules"); |
| 22 |
| 23 function saveRules() |
| 24 { |
| 25 this._rulesBackup = rulesGlobal.rules; |
| 26 rulesGlobal.rules = {domain: {}}; |
| 27 } |
| 28 |
| 29 function restoreRules() |
| 30 { |
| 31 rulesGlobal.rules = this._rulesBackup; |
| 32 } |
| 33 |
| 34 module("Suffix tree manipulation", { |
| 35 setup: saveRules, |
| 36 teardown: restoreRules |
| 37 }); |
| 38 |
| 39 test("Adding entries", function() |
| 40 { |
| 41 let priority = " " + rulesGlobal.CUSTOM_RULE_PRIORITY; |
| 42 let domains = rulesGlobal.rules.domain; |
| 43 |
| 44 deepEqual(domains, {}, "Initial state"); |
| 45 |
| 46 onWhitelistEntryAdded("foo"); |
| 47 deepEqual(domains, { |
| 48 "o": "of" + priority |
| 49 }, "Added foo"); |
| 50 |
| 51 onWhitelistEntryAdded("goo"); |
| 52 deepEqual(domains, { |
| 53 "o": { |
| 54 "o": { |
| 55 "f": priority, |
| 56 "g": priority |
| 57 } |
| 58 } |
| 59 }, "Added goo"); |
| 60 |
| 61 onWhitelistEntryAdded("xyzfoo"); |
| 62 deepEqual(domains, { |
| 63 "o": { |
| 64 "o": { |
| 65 "f": { |
| 66 "": priority, |
| 67 "z": "yx" + priority |
| 68 }, |
| 69 "g": priority |
| 70 } |
| 71 } |
| 72 }, "Added xyzfoo"); |
| 73 |
| 74 onWhitelistEntryAdded("o"); |
| 75 deepEqual(domains, { |
| 76 "o": { |
| 77 "": priority, |
| 78 "o": { |
| 79 "f": { |
| 80 "": priority, |
| 81 "z": "yx" + priority |
| 82 }, |
| 83 "g": priority |
| 84 } |
| 85 } |
| 86 }, "Added o"); |
| 87 |
| 88 domains.o[""] = " 1234"; |
| 89 onWhitelistEntryAdded("o"); |
| 90 deepEqual(domains, { |
| 91 "o": { |
| 92 "": priority, |
| 93 "o": { |
| 94 "f": { |
| 95 "": priority, |
| 96 "z": "yx" + priority |
| 97 }, |
| 98 "g": priority |
| 99 } |
| 100 } |
| 101 }, "Re-added o"); |
| 102 }); |
| 103 |
| 104 test("Removing entries", function() |
| 105 { |
| 106 let priority = " " + rulesGlobal.CUSTOM_RULE_PRIORITY; |
| 107 let domains = rulesGlobal.rules.domain = { |
| 108 "o": { |
| 109 "": priority, |
| 110 "o": { |
| 111 "f": { |
| 112 "": priority, |
| 113 "z": "yx" + priority |
| 114 }, |
| 115 "g": priority |
| 116 } |
| 117 } |
| 118 }; |
| 119 |
| 120 deepEqual(domains, { |
| 121 "o": { |
| 122 "": priority, |
| 123 "o": { |
| 124 "f": { |
| 125 "": priority, |
| 126 "z": "yx" + priority |
| 127 }, |
| 128 "g": priority |
| 129 } |
| 130 } |
| 131 }, "Initial state"); |
| 132 |
| 133 onWhitelistEntryRemoved("o"); |
| 134 deepEqual(domains, { |
| 135 "o": { |
| 136 "o": { |
| 137 "f": { |
| 138 "": priority, |
| 139 "z": "yx" + priority |
| 140 }, |
| 141 "g": priority |
| 142 } |
| 143 } |
| 144 }, "Removed o"); |
| 145 |
| 146 onWhitelistEntryRemoved("go"); |
| 147 deepEqual(domains, { |
| 148 "o": { |
| 149 "o": { |
| 150 "f": { |
| 151 "": priority, |
| 152 "z": "yx" + priority |
| 153 }, |
| 154 "g": priority |
| 155 } |
| 156 } |
| 157 }, "Removed go"); |
| 158 |
| 159 onWhitelistEntryRemoved("foo"); |
| 160 deepEqual(domains, { |
| 161 "o": { |
| 162 "o": { |
| 163 "f": { |
| 164 "z": "yx" + priority |
| 165 }, |
| 166 "g": priority |
| 167 } |
| 168 } |
| 169 }, "Removed foo"); |
| 170 |
| 171 onWhitelistEntryRemoved("xxyzfoo"); |
| 172 deepEqual(domains, { |
| 173 "o": { |
| 174 "o": { |
| 175 "f": { |
| 176 "z": "yx" + priority |
| 177 }, |
| 178 "g": priority |
| 179 } |
| 180 } |
| 181 }, "Removed xxyzfoo"); |
| 182 |
| 183 onWhitelistEntryRemoved("xyzfoo"); |
| 184 deepEqual(domains, { |
| 185 "o": { |
| 186 "o": { |
| 187 "f": { |
| 188 }, |
| 189 "g": priority |
| 190 } |
| 191 } |
| 192 }, "Removed xyzfoo"); |
| 193 |
| 194 domains.o.o.g = " 1234"; |
| 195 deepEqual(domains, { |
| 196 "o": { |
| 197 "o": { |
| 198 "f": { |
| 199 }, |
| 200 "g": " 1234" |
| 201 } |
| 202 } |
| 203 }, "Attempted to remove goo"); |
| 204 }); |
| 205 })(); |
OLD | NEW |