<!DOCTYPE html>
<script src="portal-harness.js"></script>
<body>
<script>
  function testHistoryPushStateInPortal() {
    assert(history.length == 1, 'Initial history length');
    assert(!history.state, 'Initial history state');

    history.pushState('teststate', null, null);

    assert(history.length == 1, 'History length unchanged');
    assert(history.state == 'teststate', 'Update state');
  }

  function testHistoryReplaceStateInPortal() {
    assert(history.length == 1, 'Initial history length');
    assert(!history.state, 'Initial history state');

    history.replaceState('teststate', null, null);

    assert(history.length == 1, 'History length unchanged');
    assert(history.state == 'teststate', 'Update state');
  }

  function testLocationAssignInPortal() {
    assert(history.length == 1, 'Initial history length');
    let initialLocation = location.href;
    location.assign('#test');

    assert(history.length == 1, 'History length unchanged');
    assert(location.href != initialLocation, 'Update location');
  }

  function testLocationReplaceInPortal() {
    assert(history.length == 1, 'Initial history length');
    let initialLocation = location.href;
    location.replace('#test');

    assert(history.length == 1, 'History length unchanged');
    assert(location.href != initialLocation, 'Update location');
  }

  function testSetLocationHrefInPortal() {
    assert(history.length == 1, 'Initial history length');
    let initialLocation = location.href;
    location.href = '#test';

    assert(history.length == 1, 'History length unchanged');
    assert(location.href != initialLocation, 'Update location');
  }

  function testSyntheticAnchorClickInPortal() {
    assert(history.length == 1, 'Initial history length');
    let initialLocation = location.href;

    var anchor = document.createElement('a');
    anchor.href = '#test';
    document.body.appendChild(anchor);

    anchor.click();

    assert(history.length == 1, 'History length unchanged');
    assert(location.href != initialLocation, 'Update location');
  }
</script>
</body>
