Index: chrome/content/tests/tests/suffixTreeManipulation.js |
=================================================================== |
new file mode 100644 |
--- /dev/null |
+++ b/chrome/content/tests/tests/suffixTreeManipulation.js |
@@ -0,0 +1,205 @@ |
+(function() |
+{ |
+ function getModuleGlobal(module) |
+ { |
+ let result = Cu.getGlobalForObject(require(module)); |
+ if (result == window) |
+ { |
+ // Work-around for bug 736316 - getGlobalForObject gave us our own window |
+ let {XPIProvider} = Cu.import("resource://gre/modules/XPIProvider.jsm", null); |
+ let addonID = "{d10d0bf8-f5b5-c8b4-a8b2-2b9879e08c5d}" |
+ if (addonID in XPIProvider.bootstrapScopes) |
+ result = XPIProvider.bootstrapScopes[addonID]; |
+ } |
+ |
+ if ("require" in result) |
+ result = result.require.scopes[module]; |
+ return result; |
+ } |
+ |
+ let {onWhitelistEntryAdded, onWhitelistEntryRemoved} = require("rules"); |
+ let rulesGlobal = getModuleGlobal("rules"); |
+ |
+ function saveRules() |
+ { |
+ this._rulesBackup = rulesGlobal.rules; |
+ rulesGlobal.rules = {domain: {}}; |
+ } |
+ |
+ function restoreRules() |
+ { |
+ rulesGlobal.rules = this._rulesBackup; |
+ } |
+ |
+ module("Suffix tree manipulation", { |
+ setup: saveRules, |
+ teardown: restoreRules |
+ }); |
+ |
+ test("Adding entries", function() |
+ { |
+ let priority = " " + rulesGlobal.CUSTOM_RULE_PRIORITY; |
+ let domains = rulesGlobal.rules.domain; |
+ |
+ deepEqual(domains, {}, "Initial state"); |
+ |
+ onWhitelistEntryAdded("foo"); |
+ deepEqual(domains, { |
+ "o": "of" + priority |
+ }, "Added foo"); |
+ |
+ onWhitelistEntryAdded("goo"); |
+ deepEqual(domains, { |
+ "o": { |
+ "o": { |
+ "f": priority, |
+ "g": priority |
+ } |
+ } |
+ }, "Added goo"); |
+ |
+ onWhitelistEntryAdded("xyzfoo"); |
+ deepEqual(domains, { |
+ "o": { |
+ "o": { |
+ "f": { |
+ "": priority, |
+ "z": "yx" + priority |
+ }, |
+ "g": priority |
+ } |
+ } |
+ }, "Added xyzfoo"); |
+ |
+ onWhitelistEntryAdded("o"); |
+ deepEqual(domains, { |
+ "o": { |
+ "": priority, |
+ "o": { |
+ "f": { |
+ "": priority, |
+ "z": "yx" + priority |
+ }, |
+ "g": priority |
+ } |
+ } |
+ }, "Added o"); |
+ |
+ domains.o[""] = " 1234"; |
+ onWhitelistEntryAdded("o"); |
+ deepEqual(domains, { |
+ "o": { |
+ "": priority, |
+ "o": { |
+ "f": { |
+ "": priority, |
+ "z": "yx" + priority |
+ }, |
+ "g": priority |
+ } |
+ } |
+ }, "Re-added o"); |
+ }); |
+ |
+ test("Removing entries", function() |
+ { |
+ let priority = " " + rulesGlobal.CUSTOM_RULE_PRIORITY; |
+ let domains = rulesGlobal.rules.domain = { |
+ "o": { |
+ "": priority, |
+ "o": { |
+ "f": { |
+ "": priority, |
+ "z": "yx" + priority |
+ }, |
+ "g": priority |
+ } |
+ } |
+ }; |
+ |
+ deepEqual(domains, { |
+ "o": { |
+ "": priority, |
+ "o": { |
+ "f": { |
+ "": priority, |
+ "z": "yx" + priority |
+ }, |
+ "g": priority |
+ } |
+ } |
+ }, "Initial state"); |
+ |
+ onWhitelistEntryRemoved("o"); |
+ deepEqual(domains, { |
+ "o": { |
+ "o": { |
+ "f": { |
+ "": priority, |
+ "z": "yx" + priority |
+ }, |
+ "g": priority |
+ } |
+ } |
+ }, "Removed o"); |
+ |
+ onWhitelistEntryRemoved("go"); |
+ deepEqual(domains, { |
+ "o": { |
+ "o": { |
+ "f": { |
+ "": priority, |
+ "z": "yx" + priority |
+ }, |
+ "g": priority |
+ } |
+ } |
+ }, "Removed go"); |
+ |
+ onWhitelistEntryRemoved("foo"); |
+ deepEqual(domains, { |
+ "o": { |
+ "o": { |
+ "f": { |
+ "z": "yx" + priority |
+ }, |
+ "g": priority |
+ } |
+ } |
+ }, "Removed foo"); |
+ |
+ onWhitelistEntryRemoved("xxyzfoo"); |
+ deepEqual(domains, { |
+ "o": { |
+ "o": { |
+ "f": { |
+ "z": "yx" + priority |
+ }, |
+ "g": priority |
+ } |
+ } |
+ }, "Removed xxyzfoo"); |
+ |
+ onWhitelistEntryRemoved("xyzfoo"); |
+ deepEqual(domains, { |
+ "o": { |
+ "o": { |
+ "f": { |
+ }, |
+ "g": priority |
+ } |
+ } |
+ }, "Removed xyzfoo"); |
+ |
+ domains.o.o.g = " 1234"; |
+ deepEqual(domains, { |
+ "o": { |
+ "o": { |
+ "f": { |
+ }, |
+ "g": " 1234" |
+ } |
+ } |
+ }, "Attempted to remove goo"); |
+ }); |
+})(); |