4
<title>Test Page</title>
5
<style type="text/css" id="styleblock" class="highlight-ignore">
7
color: #000 !important;
8
font: normal 125%/1.4 Arial, sans-serif;
10
.yui-skin-sam .yui-console .yui-console-content {
14
.yui-skin-sam .yui-console .yui-console-bd {
17
.yui-skin-sam .yui-console-entry-pass .yui-console-entry-cat {
21
.yui-skin-sam .yui-console-entry-fail .yui-console-entry-cat {
25
.yui3-skin-sam .yui-console-entry-time {
30
<body class="yui3-skin-sam">
32
<div id="testbed" style="color: #000 !important"></div>
34
<script src="http://yui.yahooapis.com/3.0.0/build/yui/yui.js"></script>
38
logInclude : { TestRunner: true }
39
}).use('test','console', function (Y) {
43
suite = new Y.Test.Suite("!important related Tests"),
47
function getCssText( allRules ) {
48
var content = [], rule, i, len;
50
for ( i = 0, len = allRules.length; i < len; ++i ) {
53
(rule.selectorText || rule.tagName) +
54
' { ' + rule.style.cssText + ' } ');
60
suite.add(new Y.Test.Case({
63
"test !important reported in cssText for <style> block": function () {
64
var style = d.getElementById('styleblock'),
65
sheet = style.sheet || style.styleSheet,
66
rules = sheet.cssRules || sheet.rules,
70
for (i = rules.length - 1; i >= 0; --i) {
71
if (/important/.test(rules[i].style.cssText)) {
80
"test !important reported in cssText for <h1 style=>": function () {
81
var x = d.getElementById('testbed').style;
83
Assert.isTrue(!!/important/.test(x.cssText));
85
// Opera refreshes cssTest after a style property is changed
87
Assert.isTrue(!!/important/.test(x.cssText));
90
"test new sheet with important": function () {
91
var s = d.createElement('style'),
94
css = "#foo { color: red !important; } #bar { height: 100px; }";
98
s.styleSheet.cssText = css;
100
s.appendChild( d.createTextNode(css) );
103
d.getElementsByTagName('head')[0].appendChild( s );
105
sheet = s.sheet || s.styleSheet,
106
rules = sheet.cssRules || sheet.rules;
108
Assert.areEqual( 2, rules.length, "Missing the !important rule?" );
110
css = getCssText( rules );
112
Y.log( css.join("\n"), "info", "TestRunner" );
114
Assert.isTrue( /important/i.test( css.join('') ),
115
"No parsed rule reports !important in its cssText");
118
"test new rule with important": function () {
119
if ( sheet.insertRule ) {
120
sheet.insertRule( ".foo { background-color: #000 !important; }", 2 );
122
sheet.addRule( ".foo", "background-color: #000 !important;", 2 );
125
var css = getCssText( rules ),
126
m = css.join('').match( /important/gi ) || [];
128
Y.log( css.join("\n"), "info", "TestRunner" );
130
Assert.areEqual( 3, rules.length, "Missing the inserted !important rule?" );
131
Assert.areEqual( 2, m.length, "Not reporting !important in the cssText" );
135
"test new property with important": function () {
136
var rule = rules[1] || Assert.fail("Unable to find a rule");
138
rule.style.paddingBottom = '10px !important';
140
Y.log( getCssText( rules ).join("\n"), "info", "TestRunner" );
142
// !important shouldn't show up in value
143
Assert.areEqual( '10px', rule.style.paddingBottom );
145
// but should be in the cssText
147
/padding.*?:\s*10px\s*!\s*important/i.test( rule.style.cssText ) );
150
"test existing property with important": function () {
151
for ( var i = rules.length - 1, rule; i >= 0; --i ) {
154
if ( /bar/.test( rule.selectorText ) ) {
155
rule.style.height = '5em !important';
157
Y.log( getCssText( rules ).join("\n"), "info", "TestRunner" );
159
// !important shouldn't show up in value
160
Assert.areEqual( '5em', rule.style.height );
162
// but should be in the cssText
164
/height.*?:\s*5em\s*!\s*important/i.test(
165
rule.style.cssText ) );
172
"test set property with important via cssText": function () {
173
var p = d.createElement('p');
175
p.style.cssText = 'text-align: right !important';
177
Y.log( getCssText( [p] ).join("\n"), "info", "TestRunner" );
179
// !important should not show up in property value
180
Assert.areEqual( 'right', p.style.textAlign );
182
// but it should in cssText
184
/text-align\s*:\s*right !\s*important/i.test(p.style.cssText) );
186
// Opera refreshes cssTest after a style property is changed
187
p.style.color = '#111';
189
/text-align\s*:\s*right !\s*important/i.test(p.style.cssText) );
192
"test off dom style property with important": function () {
193
var p = d.createElement('p');
195
p.style.color = '#000';
196
p.style.textAlign = 'right !important';
198
Y.log( getCssText( [p] ).join("\n"), "info", "TestRunner" );
200
// !important should not show up in property value
201
Assert.areEqual( 'right', p.style.textAlign );
203
// but it should in cssText
205
/text-align\s*:\s*right !\s*important/i.test(p.style.cssText),
206
"value containing !important did not update cssText with !important");
209
"test on dom style property with important": function () {
210
d.body.style.color = '#000';
211
d.body.style.textAlign = 'right !important';
213
Y.log( getCssText( [d.body] ).join("\n"), "info", "TestRunner" );
215
// !important should not show up in property value
216
Assert.areEqual( 'right', d.body.style.textAlign );
218
// but it should in cssText
220
/text-align\s*:\s*right !\s*important/i.test(d.body.style.cssText),
221
"value containing !important did not update cssText with !important");
224
"test setProperty + getPropertyPriority": function () {
225
d.body.style.setProperty("color", "#555", "important");
227
Assert.areEqual("important", d.body.style.getPropertyPriority("color"));
230
"test style.prop = x + getPropertyPriority": function () {
231
d.body.style.paddingLeft = "3px !important";
233
Assert.areEqual("important", d.body.style.getPropertyPriority("padding-left"));
237
var yconsole = new Y.Console({
243
Y.Test.Runner.add(suite);