summaryrefslogtreecommitdiffstats
path: root/dom/html/test/test_bug557087-1.html
blob: d6040ace169439a08aeb741a3e24092ac748096e (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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=557087
-->
<head>
  <title>Test for Bug 557087</title>
  <script src="/tests/SimpleTest/SimpleTest.js"></script>
  <script src="/tests/SimpleTest/EventUtils.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=557087">Mozilla Bug 557087</a>
<p id="display"></p>
<div id="content">
</div>
<pre id="test">
<script type="application/javascript">

/** Test for Bug 557087 **/

function checkDisabledAttribute(aFieldset)
{
  ok('disabled' in aFieldset,
     "fieldset elements should have the disabled attribute");

  ok(!aFieldset.disabled,
     "fieldset elements disabled attribute should be disabled");
  is(aFieldset.getAttribute('disabled'), null,
    "fieldset elements disabled attribute should be disabled");

  aFieldset.disabled = true;
  ok(aFieldset.disabled,
     "fieldset elements disabled attribute should be enabled");
  isnot(aFieldset.getAttribute('disabled'), null,
    "fieldset elements disabled attribute should be enabled");

  aFieldset.removeAttribute('disabled');
  aFieldset.setAttribute('disabled', '');
  ok(aFieldset.disabled,
     "fieldset elements disabled attribute should be enabled");
  isnot(aFieldset.getAttribute('disabled'), null,
    "fieldset elements disabled attribute should be enabled");

  aFieldset.removeAttribute('disabled');
  ok(!aFieldset.disabled,
     "fieldset elements disabled attribute should be disabled");
  is(aFieldset.getAttribute('disabled'), null,
    "fieldset elements disabled attribute should be disabled");
}

function checkDisabledPseudoClass(aFieldset)
{
  is(document.querySelector(":disabled"), null,
     "no elements should have :disabled applied to them");

  aFieldset.disabled = true;
  is(document.querySelector(":disabled"), aFieldset,
     ":disabled should apply to fieldset elements");

  aFieldset.disabled = false;
  is(document.querySelector(":disabled"), null,
     "no elements should have :disabled applied to them");
}

function checkEnabledPseudoClass(aFieldset)
{
  is(document.querySelector(":enabled"), aFieldset,
     ":enabled should apply to fieldset elements");

  aFieldset.disabled = true;
  is(document.querySelector(":enabled"), null,
     "no elements should have :enabled applied to them");

  aFieldset.disabled = false;
  is(document.querySelector(":enabled"), aFieldset,
     ":enabled should apply to fieldset elements");
}

function checkFocus(aFieldset)
{
  aFieldset.disabled = true;
  aFieldset.setAttribute('tabindex', 1);

  aFieldset.focus();

  isnot(document.activeElement, aFieldset,
        "fieldset can't be focused when disabled");
  aFieldset.removeAttribute('tabindex');
  aFieldset.disabled = false;
}

function checkClickEvent(aFieldset)
{
  var clickHandled = false;

  aFieldset.disabled = true;

  aFieldset.addEventListener("click", function(aEvent) {
    clickHandled = true;
  }, {once: true});

  sendMouseEvent({type:'click'}, aFieldset);
  SimpleTest.executeSoon(function() {
    ok(!clickHandled, "When disabled, fieldset should prevent click events");
    SimpleTest.finish();
  });
}

SimpleTest.waitForExplicitFinish();

var fieldset = document.createElement("fieldset");
var content  = document.getElementById('content');
content.appendChild(fieldset);

checkDisabledAttribute(fieldset);
checkDisabledPseudoClass(fieldset);
checkEnabledPseudoClass(fieldset);
checkFocus(fieldset);
checkClickEvent(fieldset);

</script>
</pre>
</body>
</html>