summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/dom/events/Event-returnValue.html
blob: 08df2d41416ffccf65c9fe606469181a9f95f6a8 (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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>Event.returnValue</title>
  <link rel="author" title="Chris Rebert" href="http://chrisrebert.com">
  <link rel="help" href="https://dom.spec.whatwg.org/#dom-event-returnvalue">
  <meta name="flags" content="dom">
  <script src="/resources/testharness.js"></script>
  <script src="/resources/testharnessreport.js"></script>
</head>
<body>
  <div id="log"></div>
  <script>
test(function() {
  var ev = new Event("foo");
  assert_true(ev.returnValue, "returnValue");
}, "When an event is created, returnValue should be initialized to true.");
test(function() {
  var ev = new Event("foo", {"cancelable": false});
  assert_false(ev.cancelable, "cancelable (before)");
  ev.preventDefault();
  assert_false(ev.cancelable, "cancelable (after)");
  assert_true(ev.returnValue, "returnValue");
}, "preventDefault() should not change returnValue if cancelable is false.");
test(function() {
  var ev = new Event("foo", {"cancelable": false});
  assert_false(ev.cancelable, "cancelable (before)");
  ev.returnValue = false;
  assert_false(ev.cancelable, "cancelable (after)");
  assert_true(ev.returnValue, "returnValue");
}, "returnValue=false should have no effect if cancelable is false.");
test(function() {
  var ev = new Event("foo", {"cancelable": true});
  assert_true(ev.cancelable, "cancelable (before)");
  ev.preventDefault();
  assert_true(ev.cancelable, "cancelable (after)");
  assert_false(ev.returnValue, "returnValue");
}, "preventDefault() should change returnValue if cancelable is true.");
test(function() {
  var ev = new Event("foo", {"cancelable": true});
  assert_true(ev.cancelable, "cancelable (before)");
  ev.returnValue = false;
  assert_true(ev.cancelable, "cancelable (after)");
  assert_false(ev.returnValue, "returnValue");
}, "returnValue should change returnValue if cancelable is true.");
test(function() {
  var ev = document.createEvent("Event");
  ev.returnValue = false;
  ev.initEvent("foo", true, true);
  assert_true(ev.bubbles, "bubbles");
  assert_true(ev.cancelable, "cancelable");
  assert_true(ev.returnValue, "returnValue");
}, "initEvent should unset returnValue.");
test(function() {
  var ev = new Event("foo", {"cancelable": true});
  ev.preventDefault();
  ev.returnValue = true;// no-op
  assert_true(ev.defaultPrevented);
  assert_false(ev.returnValue);
}, "returnValue=true should have no effect once the canceled flag was set.");
  </script>
</body>
</html>