stylesheet-tests.js revision 998276643802ff9fb197fe220cbd9552da00a624
// Set up the document for testing
// May need setAttribute?
//Y.one("link:not([href^=http]),link[href=^http://localhost/]").set('id', 'locallink');
if (!Y.one("#testbed")) {
}
var d = document,
Dom = {},
StyleSheet = Y.StyleSheet,
StyleAssert = {},
cssText = 'h1 { font: normal 125%/1.4 Arial, sans-serif; }';
if (!Y.one("#styleblock")) {
} else {
}
}
StyleAssert.normalizeColor = function (c) {
return c && (c+'').
function (m,r,g,b) {
});
};
throw new Assert.ComparisonFailure(
}
};
if (conf) {
}
};
};
i;
}
}
};
name : "Test <style> node creation",
setUp : function () {
},
tearDown : function () {
},
test_createNew : function () {
Y.StyleSheet('test');
},
test_createFromExistingStyle : function () {
Y.StyleSheet('styleblock');
},
test_createFromExistingLink : function () {
Y.StyleSheet('locallink');
},
test_createEntireSheet : function () {
Y.StyleSheet("#target { font-weight: bold; }");
},
test_gettingFromCache : function () {
// By name
var a = new StyleSheet('test'),
b = new StyleSheet('test');
// By generated id
b = new StyleSheet(a.getId());
// By node
b = new StyleSheet('styleblock');
}
}));
name : "Test xdomain stylesheet access",
setUp : function () {
rel : 'stylesheet',
});
},
tearDown : function () {
},
_should : {
error : {
"StyleSheet seeded with remote link should fail" : true,
"getCssText on a remote StyleSheet should throw an error" : true,
"set(..) on a remote StyleSheet should throw an error" : true,
"disabling a remote StyleSheet should throw an error" : true
}
},
"StyleSheet seeded with remote link should fail" : function () {
// Each line should throw an exception
Y.StyleSheet(this.remoteLink);
throw Error("This is an informative test only");
},
"getCssText on a remote StyleSheet should throw an error" : function () {
// Each line should throw an exception
sheet.getCssText();
throw Error("This is an informative test only");
},
"set(..) on a remote StyleSheet should throw an error" : function () {
// Each line should throw an exception
throw Error("This is an informative test only");
},
"disabling a remote StyleSheet should throw an error" : function () {
// Each line should throw an exception
throw Error("This is an informative test only");
}
}));
name : "Test set",
_should: {
fail: {
}
},
setUp : function () {
id:'target',
innerHTML:'<p>1</p><p>2</p><pre>pre</pre>'
});
},
tearDown : function () {
// This should be unnecessary, but for the sake of cleanliness...
},
test_addSimpleSelector : function () {
color : '#123456',
backgroundColor : '#eef',
border : '1px solid #ccc'
});
"color");
"backgroundColor");
"border");
},
test_addRuleWithInvalidValue : function () {
// This would throw an exception in IE if anywhere
},
test_descendantSelector : function () {
"#target p { text-align: right; }");
},
test_setCommaSelector : function () {
if (!sheet) {
}
paddingLeft: '16px'
});
"#target p");
"#target pre");
},
test_important: function () {
if (!sheet) {
}
paddingBottom: '10px !important'
});
Assert.areEqual(1,(sheet.cssRules || sheet.rules).length, "!important rule not added to the sheet");
}
}));
setUp : function () {
this.stylesheet.enable();
this.before = {
};
},
tearDown : function () {
this.stylesheet.enable();
},
test_disableSheet : function () {
color : '#123456',
backgroundColor : '#eef',
border : '1px solid #ccc'
});
"color (enabled)");
"backgroundColor (enabled)");
"border (enabled)");
this.stylesheet.disable();
"color (disabled)");
"backgroundColor (disabled)");
"border (disabled)");
},
test_enableSheet : function () {
this.stylesheet.disable();
color : '#123456',
backgroundColor : '#eef',
border : '1px solid #ccc'
});
"color (disabled)");
"backgroundColor (disabled)");
"border (disabled)");
this.stylesheet.enable();
"color (enabled)");
"backgroundColor (enabled)");
"border (enabled)");
}
}));
name : "Test unset",
setUp : function () {
id:'target',
innerHTML:'<p>1</p><p>2</p><pre>pre</pre>'
});
this.before = {
};
},
tearDown : function () {
// This should be unnecessary, but for the sake of cleanliness...
},
test_unset : function () {
color : '#f00',
backgroundColor : '#eef',
border : '1px solid #ccc'
});
"color (before unset)");
"backgroundColor (before unset)");
"border (before unset)");
"color (after unset)");
"backgroundColor (after unset)");
"border (after unset)");
},
test_removeRule : function () {
"#target { text-align: right; }");
"#target text-align still in place");
},
test_unsetCommaSelector : function () {
before = {
],
]
},
if (!sheet) {
}
marginRight: '30px',
paddingLeft: '16px'
});
"Comma selector split failure");
after = [
];
"Should still be 3 rules");
after = [
];
},
test_removeCommaSelector : function () {
var /*p = this.testNode.getElementsByTagName('p')[0],
pre = this.testNode.getElementsByTagName('pre')[0],
before = {
paddingLeft: [
Y.DOM.getStyle(this.testNode,'paddingLeft'),
Y.DOM.getStyle(p,'paddingLeft'),
Y.DOM.getStyle(pre,'paddingLeft')
]
},
*/
if (!sheet) {
}
paddingLeft: '16px'
});
"Comma selector split failure");
}
}));
name : "Test getCssText",
_should: {
fail: {
test_important: true
}
},
setUp : function () {
id:'target',
innerHTML:'<p>1</p><p>2</p><pre>pre</pre>'
});
padding: '3px'
});
},
tearDown : function () {
},
test_getRuleCSS : function () {
},
test_getSheetCSS : function () {
},
test_important: function () {
paddingBottom: '10px !important'
});
}
}
}));
setUp : function () {
if (!d.getElementById('target')) {
id:'target',
innerHTML:'<p id="p1">1</p><p id="p2">2</p><p id="p3">3</p>'
});
}
},
test_float : function () {
overflow: 'hidden',
background: '#000',
zoom: 1
})
.set('#target p',{
height:'100px',
width:'100px',
border: '5px solid #ccc',
background: '#fff',
margin: '1em'
})
},
test_opacity : function () {
}
}));
name: "Testbed Cleanup",
testbedCleanup: function () {
}
}));