<!DOCTYPE HTML>
<body/>
<script src="../../../../../resources/testharness.js"></script>
<script src="../../../../../resources/testharnessreport.js"></script>

<script>

function passiveHandlerAddNonPassive() {
  var handler = function handler(e) {
    e.preventDefault();
    assert_false(e.defaultPrevented);
  }
  document.addEventListener('test', handler, {"passive": true});
  document.addEventListener('test', handler, {"passive": false});
  document.body.dispatchEvent(new Event('test', {'bubbles': true, 'cancelable': true}));
}

function nonPassiveHandlerAddPassive() {
  var handler = function handler(e) {
    e.preventDefault();
    assert_true(e.defaultPrevented);
  }
  document.addEventListener('test', handler, {"passive": false});
  document.addEventListener('test', handler, {"passive": true});
  document.body.dispatchEvent(new Event('test', {'bubbles': true, 'cancelable': true}));
}

function passiveHandlerAddNonPassiveCapturing() {
  var handlersCalled = 0;
  var handler = function handler(e) {
    handlersCalled++;
  }
  document.addEventListener('test', handler, {"passive": true});
  document.addEventListener('test', handler, {"passive": false, "capture": true});
  document.body.dispatchEvent(new Event('test', {'bubbles': true, 'cancelable': true}));
  assert_equals(handlersCalled, 2, "Handlers called correct number of times");
}

test(passiveHandlerAddNonPassive, "Passive Handler");
test(nonPassiveHandlerAddPassive, "Non Passive Handler");
test(passiveHandlerAddNonPassiveCapturing, "Passive Handler And Non Passive Capturing");

</script>
