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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith <style type="text/css" id="styleblock" class="highlight-ignore">
3cc649c1be9045cc550d30e800634e2979c030f4Luke Smith color: #000 !important;
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith font: normal 125%/1.4 Arial, sans-serif;
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith .yui-skin-sam .yui-console .yui-console-content {
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith font-size: 10px;
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith width: 32em;
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith .yui-skin-sam .yui-console .yui-console-bd {
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith height: 50em;
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith .yui-skin-sam .yui-console-entry-pass .yui-console-entry-cat {
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith background: #070;
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith color: #fff;
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith .yui-skin-sam .yui-console-entry-fail .yui-console-entry-cat {
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith background: #700;
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith color: #fff;
c28f85fdfe5f4318a887f384ac1e58d40414fdbaLuke Smith .yui3-skin-sam .yui-console-entry-time {
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith display: none;
3cc649c1be9045cc550d30e800634e2979c030f4Luke Smith<div id="testbed" style="color: #000 !important"></div>
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith<script src="http://yui.yahooapis.com/3.0.0/build/yui/yui.js"></script>
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith filter : 'raw',
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith logInclude : { TestRunner: true }
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith}).use('test','console', function (Y) {
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smithvar d = document,
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith suite = new Y.Test.Suite("!important related Tests"),
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smithfunction getCssText( allRules ) {
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith var content = [], rule, i, len;
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith for ( i = 0, len = allRules.length; i < len; ++i ) {
3cc649c1be9045cc550d30e800634e2979c030f4Luke Smith "test !important reported in cssText for <style> block": function () {
3cc649c1be9045cc550d30e800634e2979c030f4Luke Smith found = false,
3cc649c1be9045cc550d30e800634e2979c030f4Luke Smith found = true;
3cc649c1be9045cc550d30e800634e2979c030f4Luke Smith "test !important reported in cssText for <h1 style=>": function () {
d1d2cd31e46648eecbaab4ac0e707de282bfabf7Luke Smith var x = d.getElementById('testbed').style;
d1d2cd31e46648eecbaab4ac0e707de282bfabf7Luke Smith // Opera refreshes cssTest after a style property is changed
3cc649c1be9045cc550d30e800634e2979c030f4Luke Smith "test new sheet with important": function () {
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith var s = d.createElement('style'),
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith css = "#foo { color: red !important; } #bar { height: 100px; }";
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith d.getElementsByTagName('head')[0].appendChild( s );
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith Assert.areEqual( 2, rules.length, "Missing the !important rule?" );
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith css = getCssText( rules );
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith Assert.isTrue( /important/i.test( css.join('') ),
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith "No parsed rule reports !important in its cssText");
3cc649c1be9045cc550d30e800634e2979c030f4Luke Smith "test new rule with important": function () {
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith sheet.insertRule( ".foo { background-color: #000 !important; }", 2 );
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith sheet.addRule( ".foo", "background-color: #000 !important;", 2 );
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith var css = getCssText( rules ),
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith Assert.areEqual( 3, rules.length, "Missing the inserted !important rule?" );
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith Assert.areEqual( 2, m.length, "Not reporting !important in the cssText" );
3cc649c1be9045cc550d30e800634e2979c030f4Luke Smith "test new property with important": function () {
3cc649c1be9045cc550d30e800634e2979c030f4Luke Smith var rule = rules[1] || Assert.fail("Unable to find a rule");
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith rule.style.paddingBottom = '10px !important';
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith Y.log( getCssText( rules ).join("\n"), "info", "TestRunner" );
3cc649c1be9045cc550d30e800634e2979c030f4Luke Smith // !important shouldn't show up in value
3cc649c1be9045cc550d30e800634e2979c030f4Luke Smith Assert.areEqual( '10px', rule.style.paddingBottom );
3cc649c1be9045cc550d30e800634e2979c030f4Luke Smith // but should be in the cssText
3cc649c1be9045cc550d30e800634e2979c030f4Luke Smith /padding.*?:\s*10px\s*!\s*important/i.test( rule.style.cssText ) );
3cc649c1be9045cc550d30e800634e2979c030f4Luke Smith "test existing property with important": function () {
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith for ( var i = rules.length - 1, rule; i >= 0; --i ) {
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith rule = rules[i];
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith rule.style.height = '5em !important';
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith Y.log( getCssText( rules ).join("\n"), "info", "TestRunner" );
3cc649c1be9045cc550d30e800634e2979c030f4Luke Smith // !important shouldn't show up in value
3cc649c1be9045cc550d30e800634e2979c030f4Luke Smith // but should be in the cssText
3cc649c1be9045cc550d30e800634e2979c030f4Luke Smith "test set property with important via cssText": function () {
3cc649c1be9045cc550d30e800634e2979c030f4Luke Smith p.style.cssText = 'text-align: right !important';
3cc649c1be9045cc550d30e800634e2979c030f4Luke Smith Y.log( getCssText( [p] ).join("\n"), "info", "TestRunner" );
3cc649c1be9045cc550d30e800634e2979c030f4Luke Smith // !important should not show up in property value
3cc649c1be9045cc550d30e800634e2979c030f4Luke Smith // but it should in cssText
3cc649c1be9045cc550d30e800634e2979c030f4Luke Smith /text-align\s*:\s*right !\s*important/i.test(p.style.cssText) );
d1d2cd31e46648eecbaab4ac0e707de282bfabf7Luke Smith // Opera refreshes cssTest after a style property is changed
d1d2cd31e46648eecbaab4ac0e707de282bfabf7Luke Smith /text-align\s*:\s*right !\s*important/i.test(p.style.cssText) );
3cc649c1be9045cc550d30e800634e2979c030f4Luke Smith "test off dom style property with important": function () {
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith p.style.textAlign = 'right !important';
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith Y.log( getCssText( [p] ).join("\n"), "info", "TestRunner" );
3cc649c1be9045cc550d30e800634e2979c030f4Luke Smith // !important should not show up in property value
3cc649c1be9045cc550d30e800634e2979c030f4Luke Smith // but it should in cssText
3cc649c1be9045cc550d30e800634e2979c030f4Luke Smith /text-align\s*:\s*right !\s*important/i.test(p.style.cssText),
3cc649c1be9045cc550d30e800634e2979c030f4Luke Smith "value containing !important did not update cssText with !important");
3cc649c1be9045cc550d30e800634e2979c030f4Luke Smith "test on dom style property with important": function () {
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith d.body.style.textAlign = 'right !important';
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith Y.log( getCssText( [d.body] ).join("\n"), "info", "TestRunner" );
3cc649c1be9045cc550d30e800634e2979c030f4Luke Smith // !important should not show up in property value
3cc649c1be9045cc550d30e800634e2979c030f4Luke Smith Assert.areEqual( 'right', d.body.style.textAlign );
3cc649c1be9045cc550d30e800634e2979c030f4Luke Smith // but it should in cssText
3cc649c1be9045cc550d30e800634e2979c030f4Luke Smith /text-align\s*:\s*right !\s*important/i.test(d.body.style.cssText),
3cc649c1be9045cc550d30e800634e2979c030f4Luke Smith "value containing !important did not update cssText with !important");
94128ee2c806f4d0c5a2a0f427353dd84e0ed646Luke Smith "test setProperty + getPropertyPriority": function () {
94128ee2c806f4d0c5a2a0f427353dd84e0ed646Luke Smith d.body.style.setProperty("color", "#555", "important");
94128ee2c806f4d0c5a2a0f427353dd84e0ed646Luke Smith Assert.areEqual("important", d.body.style.getPropertyPriority("color"));
94128ee2c806f4d0c5a2a0f427353dd84e0ed646Luke Smith "test style.prop = x + getPropertyPriority": function () {
94128ee2c806f4d0c5a2a0f427353dd84e0ed646Luke Smith d.body.style.paddingLeft = "3px !important";
94128ee2c806f4d0c5a2a0f427353dd84e0ed646Luke Smith Assert.areEqual("important", d.body.style.getPropertyPriority("padding-left"));
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smithvar yconsole = new Y.Console({
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith contentBox:"log",
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith newestOnTop: false,
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith height: '600px'