diff options
Diffstat (limited to 'browser/components/newtab/test/xpcshell/test_ASRouter_getTargetingParameters.js')
-rw-r--r-- | browser/components/newtab/test/xpcshell/test_ASRouter_getTargetingParameters.js | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/browser/components/newtab/test/xpcshell/test_ASRouter_getTargetingParameters.js b/browser/components/newtab/test/xpcshell/test_ASRouter_getTargetingParameters.js new file mode 100644 index 0000000000..fb3b037660 --- /dev/null +++ b/browser/components/newtab/test/xpcshell/test_ASRouter_getTargetingParameters.js @@ -0,0 +1,73 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ + */ + +"use strict"; + +const { ASRouter } = ChromeUtils.import( + "resource://activity-stream/lib/ASRouter.jsm" +); + +add_task(async function nested_objects() { + const target = { + get foo() { + return Promise.resolve("foo"); + }, + baz: { + get qux() { + return Promise.resolve("qux"); + }, + get corge() { + return { + get grault() { + return Promise.resolve("grault"); + }, + }; + }, + }, + }; + + const params = await ASRouter.getTargetingParameters(target); + Assert.deepEqual( + params, + { + foo: "foo", + baz: { + qux: "qux", + corge: { + grault: "grault", + }, + }, + }, + "getTargetingParameters should resolve nested promises" + ); +}); + +add_task(async function arrays() { + const target = { + foo: [1, 2, 3], + bar: [Promise.resolve(1), Promise.resolve(2), Promise.resolve(3)], + baz: Promise.resolve([1, 2, 3]), + qux: Promise.resolve([ + Promise.resolve(1), + Promise.resolve(2), + Promise.resolve(3), + ]), + quux: Promise.resolve({ + corge: [Promise.resolve(1), 2, 3], + }), + }; + + const params = await ASRouter.getTargetingParameters(target); + Assert.deepEqual( + params, + { + foo: [1, 2, 3], + bar: [1, 2, 3], + baz: [1, 2, 3], + qux: [1, 2, 3], + quux: { corge: [1, 2, 3] }, + }, + "getEnvironmentSnapshot should resolve arrays correctly" + ); +}); |