<!DOCTYPE html>
<html>
<head>
<script>
var firstFrame;
var secondFrame;
var callbackCount = 0;

function start() {
  if (window.testRunner) {
    testRunner.dumpAsText();
    testRunner.waitUntilDone();
  }

  firstFrame = document.createElement('iframe');
  document.body.appendChild(firstFrame);
  var div = document.createElement('div');
  firstFrame.appendChild(div);
  secondFrame = document.createElement('iframe');
  secondFrame.src = 'javascript:window.top.reallyStart();';
  div.appendChild(secondFrame);
  var firstFrameRoot = firstFrame.contentDocument.documentElement;
  document.documentElement.appendChild(div);
  firstFrameRoot.appendChild(secondFrame);
}

function reallyStart(frame) {
  secondFrame.contentWindow.onpagehide = function () {
    firstFrame.src = 'javascript:window.top.navigateThere();';
  };
  firstFrame.src = 'javascript:window.top.navigateHere();';

  if (window.location.hash == '#done') {
    if (window.testRunner)
      testRunner.notifyDone();
    return;
  }

  window.setTimeout(function () {
    window.location.hash = '#done';
    window.location.reload();
  }, 0);
}

function navigateHere() {
  return 'a';
}

function navigateThere() {
  firstFrame.src='javascript:window.top.navigateThereNested();';
  return 'b';
}

function navigateThereNested() {
  return 'c';
}
</script>
</head>
<body onload="start()">
<p>This is a simple test that triggering a navigation from a pagehide handler in
a frame being navigated doesn't crash.</p>
</body>
</html>
