summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/fenced-frame/resources/default-enabled-features-helper.js
blob: 5b4c292622f0ae1f073ea7e4ab257407ca6a7e77 (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
// This is a helper file used for the attribution-reporting-*.https.html tests.
// To use this, make sure you import these scripts:
// <script src="/resources/testharness.js"></script>
// <script src="/resources/testharnessreport.js"></script>
// <script src="/common/utils.js"></script>
// <script src="/common/dispatcher/dispatcher.js"></script>
// <script src="resources/utils.js"></script>
// <script src="/common/get-host-info.sub.js"></script>

async function runDefaultEnabledFeaturesTest(t, should_load, fenced_origin,
    generator_api="fledge", allow="") {
  const fencedframe = await attachFencedFrameContext({
      generator_api: generator_api,
      attributes: [["allow", allow]],
      origin: fenced_origin});

  if (!should_load) {
    const fencedframe_blocked = new Promise(r => t.step_timeout(r, 1000));
    const fencedframe_loaded = fencedframe.execute(() => {});
    assert_equals(await Promise.any([
      fencedframe_blocked.then(() => "blocked"),
      fencedframe_loaded.then(() => "loaded"),
    ]), "blocked", "The fenced frame should not be loaded.");
    return;
  }

  await fencedframe.execute((generator_api) => {
    assert_true(
        document.featurePolicy.allowsFeature('attribution-reporting'),
        "Attribution reporting should be allowed if the fenced " +
        "frame loaded using FLEDGE or shared storage.");

    if (generator_api == "fledge") {
      assert_true(
            document.featurePolicy.allowsFeature('shared-storage'),
            "Shared Storage should be allowed if the fenced " +
            "frame loaded using FLEDGE.");
      assert_true(
            document.featurePolicy.allowsFeature('private-aggregation'),
            "Private Aggregation should be allowed if the fenced " +
            "frame loaded using FLEDGE.");
    } else {
      assert_true(
            document.featurePolicy.allowsFeature('shared-storage'),
            "Shared Storage should be allowed if the fenced " +
            "frame loaded using Shared Storage.");
      assert_false(
            document.featurePolicy.allowsFeature('private-aggregation'),
            "Private Aggregation should be disabled if the fenced " +
            "frame loaded using Shared Storage.");
    }
  }, [generator_api]);
}