summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/speculation-rules/prerender/resources/message-boxes.html
blob: 8e0a6e874fdf27feb4b01d8e4cbcc297250c9cd2 (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
<!DOCTYPE html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/speculation-rules/prerender/resources/utils.js"></script>
<script>
function runAlertTest() {
  window.alert('Hello! Preprendering!');
  return 'no block';
}

function runConfirmTest() {
  const result = window.confirm('Are you preprendering page?');
  return 'the return value is ' + (result === true ? 'yes' : 'no');
}

function runPromptTest() {
  const result = window.prompt('Are you preprendering page?',
    'the default value');
  return 'the return value is ' + (result === null ? 'null' : result);
}

const params = new URLSearchParams(location.search);

const uid = params.get('uid');

// The main test page (restriction-message-boxes.html) loads the
// initiator page, then the initiator page will prerender itself with the
// `prerendering` parameter.
const isPrerendering = params.has('prerendering');

if (isPrerendering) {
  // Test web APIs on the pages.
  const bc = new PrerenderChannel('prerender-channel', uid);
  assert_true(document.prerendering);
  if (params.has('alert')) {
    bc.postMessage(runAlertTest());
  } else if (params.has('confirm')) {
    bc.postMessage(runConfirmTest());
  } else if (params.has('prompt')) {
    bc.postMessage(runPromptTest());
  }
  bc.close();
  window.close();
} else {
  // Initiator pages should prerender the prerendering page.
  const url = new URL(document.URL);
  url.searchParams.append('prerendering', '');
  startPrerendering(url);
}
</script>