diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
commit | 2aa4a82499d4becd2284cdb482213d541b8804dd (patch) | |
tree | b80bf8bf13c3766139fbacc530efd0dd9d54394c /toolkit/components/normandy/test/browser/browser_ActionsManager.js | |
parent | Initial commit. (diff) | |
download | firefox-2aa4a82499d4becd2284cdb482213d541b8804dd.tar.xz firefox-2aa4a82499d4becd2284cdb482213d541b8804dd.zip |
Adding upstream version 86.0.1.upstream/86.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'toolkit/components/normandy/test/browser/browser_ActionsManager.js')
-rw-r--r-- | toolkit/components/normandy/test/browser/browser_ActionsManager.js | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/toolkit/components/normandy/test/browser/browser_ActionsManager.js b/toolkit/components/normandy/test/browser/browser_ActionsManager.js new file mode 100644 index 0000000000..2b8afbb632 --- /dev/null +++ b/toolkit/components/normandy/test/browser/browser_ActionsManager.js @@ -0,0 +1,63 @@ +"use strict"; + +ChromeUtils.import("resource://normandy/actions/BaseAction.jsm", this); +ChromeUtils.import("resource://normandy/lib/ActionsManager.jsm", this); +ChromeUtils.import("resource://normandy/lib/NormandyApi.jsm", this); +ChromeUtils.import("resource://normandy/lib/Uptake.jsm", this); +const { ActionSchemas } = ChromeUtils.import( + "resource://normandy/actions/schemas/index.js" +); + +// Test life cycle methods for actions +decorate_task(async function(reportActionStub, Stub) { + let manager = new ActionsManager(); + const recipe = { id: 1, action: "test-local-action-used" }; + + let actionUsed = { + processRecipe: sinon.stub(), + finalize: sinon.stub(), + }; + let actionUnused = { + processRecipe: sinon.stub(), + finalize: sinon.stub(), + }; + manager.localActions = { + "test-local-action-used": actionUsed, + "test-local-action-unused": actionUnused, + }; + + await manager.processRecipe(recipe, BaseAction.suitability.FILTER_MATCH); + await manager.finalize(); + + Assert.deepEqual( + actionUsed.processRecipe.args, + [[recipe, BaseAction.suitability.FILTER_MATCH]], + "used action should be called with the recipe" + ); + ok( + actionUsed.finalize.calledOnce, + "finalize should be called on used action" + ); + Assert.deepEqual( + actionUnused.processRecipe.args, + [], + "unused action should not be called with the recipe" + ); + ok( + actionUnused.finalize.calledOnce, + "finalize should be called on the unused action" + ); +}); + +decorate_task(async function() { + for (const [name, Constructor] of Object.entries( + ActionsManager.actionConstructors + )) { + const action = new Constructor(); + Assert.deepEqual( + ActionSchemas[name], + action.schema, + "action name should map to a schema" + ); + } +}); |