Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: chrome/content/tests/tests/suffixTreeManipulation.js

Issue 8382011: Applied changes from emailed code review (Closed)
Patch Set: Created Sept. 28, 2012, 1:40 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/content/tests/tests/hooks.js ('k') | chrome/locale/en-US/locale.properties » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 = "{0fa2149e-bb2c-4ac2-a8d3-479599819475}";
+ 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");
+ });
+})();
« no previous file with comments | « chrome/content/tests/tests/hooks.js ('k') | chrome/locale/en-US/locale.properties » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld