summaryrefslogtreecommitdiffstats
path: root/docshell/test/iframesandbox/file_top_navigation_by_user_activation_iframe.html
blob: b775579f28accaca49d5f8a5e60d970cbcad3b0d (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
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<script src="/tests/SimpleTest/EventUtils.js"></script>
<title>Test window for top navigation with user activation</title>
<script>
function navigate(aURL) {
  try {
    top.location.href = aURL;
  } catch (e) {
    top.postMessage("BLOCKED", "*");
  }
}

window.onmessage = (e) => {
  SpecialPowers.wrap(document).clearUserGestureActivation();
  let [command, url] = e.data;
  if (command == "CLICK") {
    let button = document.querySelector("button");
    button.addEventListener("click", () => {
      navigate(url);
    }, { once: true });
    synthesizeMouseAtCenter(button, {});
  } else if (command == "SCRIPT") {
    navigate(url);
  }
};
</script>
</head>
<body><button>Click</button></body>
</html>