summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/fenced-frame/get-nested-configs.https.html
blob: ed9f953e74a304f4b99e3a8e688866cb3a0365c3 (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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
<!DOCTYPE html>
<title>window.fence.getNestedConfigs() test</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="resources/utils.js"></script>
<script src="/common/utils.js"></script>
<script src="/common/get-host-info.sub.js"></script>

<body>
<script>
promise_test(async (t) => {
  const key = token();
  const urn = await generateURNFromFledge(
      "resources/get-nested-configs-inner.html", [key]);
  attachFencedFrame(urn);

  const response = await nextValueFromServer(key);
  const [length, first_url] = response.split(",");

  assert_equals(length, '20', 'There should be 20 nested configurations.');
  assert_equals(first_url, 'opaque', 'The first config should be opaque.');
}, 'getNestedConfigs() created by FLEDGE should return configurations');

for (const resolve_to_config of [true, false]) {
  promise_test(async (t) => {
    const key = token();
    const select_url_result = await runSelectURL(
        generateURL("resources/get-nested-configs-inner.html", [key]),
        [], resolve_to_config);
    attachFencedFrame(select_url_result);

    const response = await nextValueFromServer(key);
    const [length, first_url] = response.split(",");

    assert_equals(length, '0', 'There should be 0 nested configurations.');
  }, 'getNestedConfigs() from a fenced frame with the ' +
     (resolve_to_config ? 'config' : 'urn:uuid') +
     ' from sharedStroage.selectURL() should be empty');
}

promise_test(async (t) => {
  const key = token();
  const url = generateURL("resources/get-nested-configs-inner.html", [key]);
  attachFencedFrame(url, mode='default');

  const response = await nextValueFromServer(key);
  const [length, first_url] = response.split(",");

  assert_equals(length, '0', 'There should be 0 nested configurations.');
}, 'getNestedConfigs() from a default mode frame should be empty');

promise_test(async (t) => {
  const key = token();
  const urn = await generateURNFromFledge(
      "resources/get-nested-configs-nested-iframe.html", [key]);
  attachFencedFrame(urn);

  const response = await nextValueFromServer(key);
  const [length, first_url] = response.split(",");

  assert_equals(length, '20', 'There should be 20 nested configurations.');
}, 'getNestedConfigs() should work in a same-origin nested iframe');

promise_test(async (t) => {
  const key = token();

  const nested_url = generateURL("resources/embeddee.html", [key]);

  // Navigate a fenced frame to `navigate-nested-config.html`. That page will
  // in turn create a nested fenced frame which will be navigated to the URN of
  // the first item in the nested configs list, `nested_url`.
  const urn = await generateURNFromFledge(
      "resources/navigate-nested-config.html", [key],
      [nested_url]);
  attachFencedFrame(urn);

  const response = await nextValueFromServer(key);
  assert_equals(response, 'PASS', 'The nested URL should load.');
}, 'Nested configs created by FLEDGE should be navigable by fenced frame');

promise_test(async (t) => {
  const key = token();

  const nested_url = generateURL("resources/embeddee.html", [key]);

  // Navigate a fenced frame to `navigate-nested-config.html`. That page will
  // in turn create a nested fenced frame which will be navigated to the URN of
  // the first item in the nested configs list, `nested_url`.
  const urn = await generateURNFromFledge(
      "resources/navigate-nested-config.html", [key],
      [nested_url]);
  attachIFrame(urn);

  const response = await nextValueFromServer(key);
  assert_equals(response, 'PASS', 'The nested URL should load.');
}, 'Nested configs created by FLEDGE should be navigable by URN iframe');

promise_test(async (t) => {
  const key = token();

  const nested_url = generateURL("resources/embeddee.html", [key]);

  // Navigate a fenced frame to `navigate-nested-config.html`. That page will
  // in turn create a nested fenced frame which will be navigated to the URN of
  // the first item in the nested configs list, `nested_url`. Since this URN
  // is invalid, the navigation should gracefully fail.
  const urn = await generateURNFromFledge(
      "resources/navigate-nested-config.html", [key],
      []);
  attachFencedFrame(urn);

  // There is no API to observe whether the document in the FencedFrame loaded
  // or not. Instead, set up a timeout. If the document loads, "PASS" will be
  // sent to the server. Otherwise "BLOCKED" will be sent after 1 second.
  step_timeout(() => {
    writeValueToServer(key, "BLOCKED");
  }, 1000);

  const response = await nextValueFromServer(key);
  assert_equals(response, 'BLOCKED', 'The nested URL should not load.');
}, 'Navigating an invalid config should be handled gracefully');

</script>
</body>
</html>