Index: test/stub-modules/common.js |
diff --git a/test/stub-modules/common.js b/test/stub-modules/common.js |
new file mode 100644 |
index 0000000000000000000000000000000000000000..971edb9b98e22a99adedf5c096cb28435f49e081 |
--- /dev/null |
+++ b/test/stub-modules/common.js |
@@ -0,0 +1,61 @@ |
+let {FilterStorage} = require("filterStorage"); |
+let {Subscription} = require("subscriptionClasses"); |
+let {Filter} = require("filterClasses"); |
+let {ElemHide} = require("elemHide"); |
+let {defaultMatcher} = require("matcher"); |
+let {CSSRules} = require("cssRules"); |
+let {FilterNotifier} = require("filterNotifier"); |
+let {Prefs} = require("prefs"); |
+ |
+exports.prepareFilterComponents = function(keepListeners) |
+{ |
+ this._backup = { |
+ subscriptions: FilterStorage.subscriptions, |
+ storageKnown: FilterStorage.knownSubscriptions, |
+ subscriptionsKnown: Subscription.knownSubscriptions, |
+ filtersKnown: Filter.knownFilters, |
+ listeners: FilterNotifier._listeners, |
+ sourceFile: FilterStorage.sourceFile |
+ }; |
+ |
+ FilterStorage.subscriptions = []; |
+ FilterStorage.knownSubscriptions = Object.create(null); |
+ Subscription.knownSubscriptions = Object.create(null); |
+ Filter.knownFilters = Object.create(null); |
+ if (!keepListeners) |
+ FilterNotifier._listeners = {}; |
+ |
+ defaultMatcher.clear(); |
+ ElemHide.clear(); |
+ CSSRules.clear(); |
+}; |
+ |
+exports.restoreFilterComponents = function() |
+{ |
+ FilterStorage.subscriptions = this._backup.subscriptions; |
+ FilterStorage.knownSubscriptions = this._backup.storageKnown; |
+ Subscription.knownSubscriptions = this._backup.subscriptionsKnown; |
+ Filter.knownFilters = this._backup.filtersKnown; |
+ FilterNotifier._listeners = this._backup.listeners; |
+ Object.defineProperty(FilterStorage, "sourceFile", |
+ {value: this._backup.sourceFile, configurable: true}); |
+ |
+ FilterNotifier.triggerListeners("load"); |
+}; |
+ |
+exports.preparePrefs = function() |
+{ |
+ this._pbackup = Object.create(null); |
+ for (let pref in Prefs) |
+ { |
+ if (Prefs.__lookupSetter__(pref)) |
+ this._pbackup[pref] = Prefs[pref]; |
+ } |
+ Prefs.enabled = true; |
+}; |
+ |
+exports.restorePrefs = function() |
+{ |
+ for (let pref in this._pbackup) |
+ Prefs[pref] = this._pbackup[pref]; |
+}; |