summaryrefslogtreecommitdiffstats
path: root/browser/components/newtab/test/xpcshell/test_ASRouter_getTargetingParameters.js
blob: fb3b037660764f34dfb3db574d87b9bf8b2ffa6d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
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"
  );
});