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

Unified Diff: test/stub-modules/common.js

Issue 29354864: Issue 4223 - Migrate some more of adblockplustests (Closed)
Patch Set: Created Sept. 25, 2016, 1:38 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
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];
+};

Powered by Google App Engine
This is Rietveld