raw.html revision 13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8f
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith<!doctype html>
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith<html>
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith<head>
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith <title>Test Page</title>
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith <style type="text/css" id="styleblock" class="highlight-ignore">
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith h1 {
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith font: normal 125%/1.4 Arial, sans-serif;
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith }
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith .yui-skin-sam .yui-console .yui-console-content {
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith font-size: 10px;
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith width: 32em;
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith }
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith .yui-skin-sam .yui-console .yui-console-bd {
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith height: 50em;
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith }
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith .yui-skin-sam .yui-console-entry-pass .yui-console-entry-cat {
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith background: #070;
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith color: #fff;
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith }
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith .yui-skin-sam .yui-console-entry-fail .yui-console-entry-cat {
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith background: #700;
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith color: #fff;
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith }
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith .yui-skin-sam .yui-console-entry-time {
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith display: none;
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith }
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith </style>
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith</head>
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith<body class="yui-skin-sam">
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith<h1>Tests</h1>
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith<div id="testbed"></div>
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith<script src="http://yui.yahooapis.com/3.0.0/build/yui/yui.js"></script>
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith<script>
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke SmithYUI({
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith filter : 'raw',
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith logInclude : { TestRunner: true }
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith}).use('test','console', function (Y) {
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smithvar d = document,
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith Assert = Y.Assert,
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith suite = new Y.Test.Suite("!important related Tests"),
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith sheet,
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith rules;
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smithfunction getCssText( allRules ) {
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith var content = [], rule, i, len;
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith for ( i = 0, len = allRules.length; i < len; ++i ) {
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith rule = allRules[i];
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith content.push(
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith (rule.selectorText || rule.tagName) +
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith ' { ' + rule.style.cssText + ' } ');
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith }
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith return content;
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith}
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smithsuite.add(new Y.Test.Case({
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith name: "!important",
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith test_new_sheet_with_important: function () {
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith var s = d.createElement('style'),
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith css;
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith css = "#foo { color: red !important; } #bar { height: 100px; }";
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith s.type = 'text/css';
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith if (s.styleSheet) {
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith s.styleSheet.cssText = css;
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith } else {
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith s.appendChild( d.createTextNode(css) );
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith }
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith d.getElementsByTagName('head')[0].appendChild( s );
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith sheet = s.sheet || s.styleSheet,
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith rules = sheet.cssRules || sheet.rules;
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith Assert.areEqual( 2, rules.length, "Missing the !important rule?" );
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith css = getCssText( rules );
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith Y.log( css.join("\n"), "info", "TestRunner" );
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith Assert.isTrue( /important/i.test( css.join('') ),
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith "No parsed rule reports !important in its cssText");
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith },
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith test_new_rule_with_important: function () {
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith if ( sheet.insertRule ) {
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith sheet.insertRule( ".foo { background-color: #000 !important; }", 2 );
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith } else {
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith sheet.addRule( ".foo", "background-color: #000 !important;", 2 );
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith }
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith var css = getCssText( rules ),
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith m = css.join('').match( /important/gi ) || [];
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith Y.log( css.join("\n"), "info", "TestRunner" );
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith
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" );
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith },
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith test_new_property_with_important: function () {
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith var rule = rules[0] || Assert.fail("Unable to find a rule");
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith rule.style.paddingBottom = '10px !important';
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith Y.log( getCssText( rules ).join("\n"), "info", "TestRunner" );
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith Assert.areEqual( '10px !important', rule.style.paddingBottom );
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith },
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke 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
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith if ( /bar/.test( rule.selectorText ) ) {
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith rule.style.height = '5em !important';
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith Y.log( getCssText( rules ).join("\n"), "info", "TestRunner" );
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith Assert.areEqual( '5em !important', rule.style.height );
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith break;
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith }
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith }
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith },
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith test_off_dom_style_property_with_important: function () {
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith var p = d.createElement('p');
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith p.style.color = '#000';
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith p.style.textAlign = 'right !important';
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith Y.log( getCssText( [p] ).join("\n"), "info", "TestRunner" );
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith try {
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith Assert.areEqual( 'right !important', p.style.textAlign );
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith }
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith catch (e) {
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith Assert.areEqual( 'right', p.style.textAlign );
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith }
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith },
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith test_on_dom_style_property_with_important: function () {
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith d.body.style.color = '#000';
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith d.body.style.textAlign = 'right !important';
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith Y.log( getCssText( [d.body] ).join("\n"), "info", "TestRunner" );
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith try {
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith Assert.areEqual( 'right !important', d.body.style.textAlign );
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith }
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith catch (e) {
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith Assert.areEqual( 'right', d.body.style.textAlign );
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith }
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith }
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith}));
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smithvar yconsole = new Y.Console({
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith contentBox:"log",
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith newestOnTop: false,
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith height: '600px'
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith}).render();
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke SmithY.Test.Runner.add(suite);
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke SmithY.Test.Runner.run();
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith});
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith</script>
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith</body>
13a5ee3728c8d0a8ac7b95cf29627b0b8c05da8fLuke Smith</html>