~ubuntu-branches/ubuntu/raring/maas/raring-updates

« back to all changes in this revision

Viewing changes to src/maasserver/static/jslibs/yui/3.4.1/tests/stylesheet/tests/stylesheet-tests.js

  • Committer: Package Import Robot
  • Author(s): Andres Rodriguez
  • Date: 2012-07-03 17:42:37 UTC
  • mfrom: (1.1.13)
  • Revision ID: package-import@ubuntu.com-20120703174237-p8l0keuuznfg721k
Tags: 0.1+bzr709+dfsg-0ubuntu1
* New Upstream release
* debian/control:
  - Depends on python-celery, python-tempita, libjs-yui3-{full,min},
    libjs-raphael
* debian/maas.install:
  - Install apiclient, celeryconfig.py, maas-import-pxe-files, preseeds_v2.
  - Update to install various files from chroot, rather tha manually copy
    them from the source.
* debian/maas.links: symlink celeryconfig.py
* debian/maas.maas-celery.upstart: Add job.
* debian/rules:
  - Install celery upstart job.
  - Do not install jslibs as packages are now used.
  - Drop copying of maas_local_settings_sample.py as source now ships
    a maas_local_settings.py
* debian/patches:
  - 04-maas-http-fix.patch: Drop. Merged upstream.
  - 01-fix-database-settings.patch: Refreshed.
  - 99_enums_js.patch: Added until creation of enum.js / build process
    is fixed.
* debian/maas.postinst: Update bzr version to correctly handle upgrades.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
YUI.add('stylesheet-tests', function(Y) {
2
 
 
3
 
// Set up the document for testing
4
 
 
5
 
// May need setAttribute?
6
 
//Y.one("link:not([href^=http]),link[href=^http://localhost/]").set('id', 'locallink');
7
 
Y.one("link").set('id', 'locallink');
8
 
if (!Y.one("#testbed")) {
9
 
    Y.one("body").append('<div id="testbed"></div>');
10
 
}
11
 
 
12
 
var d = document,
13
 
    Assert      = Y.Assert,
14
 
    Dom         = {},
15
 
    StyleSheet  = Y.StyleSheet,
16
 
    suite       = new Y.Test.Suite("Y.StyleSheet"),
17
 
    StyleAssert = {},
18
 
    testbed     = d.getElementById('testbed'),
19
 
    style   = Y.Node.create('<style type="text/css" id="styleblock"></style>'),
20
 
    cssText = 'h1 { font: normal 125%/1.4 Arial, sans-serif; }';
21
 
 
22
 
if (!Y.one("#styleblock")) {
23
 
    Y.one("head").append(style);
24
 
 
25
 
    if (style._node.styleSheet) {
26
 
        style._node.styleSheet.cssText = cssText;
27
 
    } else {
28
 
        style.append(cssText);
29
 
    }
30
 
}
31
 
 
32
 
StyleAssert.normalizeColor = function (c) {
33
 
    return c && (c+'').
34
 
        replace(/#([0-9a-f])([0-9a-f])([0-9a-f])(?![0-9a-f])/i,'#$1$1$2$2$3$3').
35
 
        replace(/#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})(?![0-9a-f])/i,
36
 
            function (m,r,g,b) {
37
 
                return "rgb("+parseInt(r,16)+", "+
38
 
                              parseInt(g,16)+", "+
39
 
                              parseInt(b,16)+")";
40
 
            });
41
 
};
42
 
StyleAssert.areEqual = function (a,b,msg) {
43
 
    var aa = StyleAssert.normalizeColor(a),
44
 
        bb = StyleAssert.normalizeColor(b);
45
 
 
46
 
    if (aa === 'bold') { aa = '700'; }
47
 
    if (bb === 'bold') { bb = '700'; }
48
 
 
49
 
    if (aa !== bb) {
50
 
        throw new Assert.ComparisonFailure(
51
 
            Assert._formatMessage(msg, "Values should be equal."), a, b);
52
 
    }
53
 
};
54
 
 
55
 
Dom.add = function (el,tag,conf) {
56
 
    var child = d.createElement(tag);
57
 
    if (conf) {
58
 
        Y.mix(child,conf,true);
59
 
    }
60
 
    return el.appendChild(child);
61
 
};
62
 
Dom.getNodeCount = function (tag,root) {
63
 
    return (root||d).getElementsByTagName(tag||'*').length;
64
 
};
65
 
Dom.getSheet = function (yuid) {
66
 
    var nodes = d.getElementsByTagName('style'),
67
 
        i;
68
 
 
69
 
    for (i = nodes.length - 1; i >= 0; --i) {
70
 
        if (Y.stamp(nodes[i]) === yuid) {
71
 
            return (nodes[i].sheet || nodes[i].styleSheet);
72
 
        }
73
 
    }
74
 
};
75
 
 
76
 
suite.add(new Y.Test.Case({
77
 
    name : "Test &lt;style&gt; node creation",
78
 
 
79
 
    setUp : function () {
80
 
        this.styleNodeCount = Dom.getNodeCount('style');
81
 
        this.linkNodeCount  = Dom.getNodeCount('link');
82
 
 
83
 
        this.testNode = Dom.add(testbed,'div',{id:'target'});
84
 
    },
85
 
 
86
 
    tearDown : function () {
87
 
        testbed.innerHTML = '';
88
 
    },
89
 
 
90
 
    test_createNew : function () {
91
 
        Y.StyleSheet('test');
92
 
 
93
 
        Assert.areSame(this.styleNodeCount + 1, Dom.getNodeCount('style'));
94
 
    },
95
 
 
96
 
    test_createFromExistingStyle : function () {
97
 
        Y.StyleSheet('styleblock');
98
 
 
99
 
        Assert.areSame(this.styleNodeCount, Dom.getNodeCount('style'));
100
 
    },
101
 
 
102
 
    test_createFromExistingLink : function () {
103
 
        Y.StyleSheet('locallink');
104
 
 
105
 
        Assert.areSame(this.styleNodeCount, Dom.getNodeCount('style'),"style");
106
 
        Assert.areSame(this.linkNodeCount, Dom.getNodeCount('link'),"link");
107
 
    },
108
 
 
109
 
    test_createEntireSheet : function () {
110
 
        Y.StyleSheet("#target { font-weight: bold; }");
111
 
 
112
 
        Assert.areSame(this.styleNodeCount + 1, Dom.getNodeCount('style'));
113
 
 
114
 
        StyleAssert.areEqual('bold',Y.DOM.getStyle(this.testNode,'fontWeight'));
115
 
    },
116
 
 
117
 
    test_gettingFromCache : function () {
118
 
        // By name
119
 
        var a = new StyleSheet('test'),
120
 
            b = new StyleSheet('test');
121
 
 
122
 
        Assert.areSame(this.styleNodeCount, Dom.getNodeCount('style'));
123
 
        Assert.areSame(a,b,"From cache by name");
124
 
 
125
 
        // By generated id
126
 
        b = new StyleSheet(a.getId());
127
 
 
128
 
        Assert.areSame(this.styleNodeCount, Dom.getNodeCount('style'));
129
 
        Assert.areSame(a,b,"From cache by yuiSSID");
130
 
 
131
 
        // By node
132
 
        a = new StyleSheet(d.getElementById('styleblock'));
133
 
        b = new StyleSheet('styleblock');
134
 
 
135
 
        Assert.areSame(this.styleNodeCount, Dom.getNodeCount('style'));
136
 
        Assert.areSame(a,b,"From cache by node vs id");
137
 
    }
138
 
}));
139
 
 
140
 
suite.add(new Y.Test.Case({
141
 
    name : "Test xdomain stylesheet access",
142
 
 
143
 
    setUp : function () {
144
 
        this.remoteLink = Dom.add(
145
 
            d.getElementsByTagName('head')[0],'link',{
146
 
                type : 'text/css',
147
 
                rel  : 'stylesheet',
148
 
                href : 'http://yui.yahooapis.com/2.6.0/build/base/base-min.css'
149
 
            });
150
 
    },
151
 
 
152
 
    tearDown : function () {
153
 
        this.remoteLink.parentNode.removeChild(this.remoteLink);
154
 
    },
155
 
 
156
 
    _should : {
157
 
        error : {
158
 
            "StyleSheet seeded with remote link should fail"          : true,
159
 
            "getCssText on a remote StyleSheet should throw an error" : true,
160
 
            "set(..) on a remote StyleSheet should throw an error"    : true,
161
 
            "disabling a remote StyleSheet should throw an error"     : true
162
 
        }
163
 
    },
164
 
 
165
 
    "StyleSheet seeded with remote link should fail" : function () {
166
 
        // Each line should throw an exception
167
 
        Y.StyleSheet(this.remoteLink);
168
 
 
169
 
        Y.log("StyleSheet creation allowed from remote file", "warn", "TestRunner");
170
 
        throw Error("This is an informative test only");
171
 
    },
172
 
 
173
 
    "getCssText on a remote StyleSheet should throw an error" : function () {
174
 
        // Each line should throw an exception
175
 
        var sheet = Y.StyleSheet(this.remoteLink);
176
 
 
177
 
        sheet.getCssText();
178
 
 
179
 
        Y.log("Getting cssText of a remote StyleSheet allowed", "warn", "TestRunner");
180
 
        throw Error("This is an informative test only");
181
 
    },
182
 
 
183
 
    "set(..) on a remote StyleSheet should throw an error" : function () {
184
 
        // Each line should throw an exception
185
 
        var sheet = Y.StyleSheet(this.remoteLink);
186
 
 
187
 
        sheet.set('#target', { color: '#f00' });
188
 
 
189
 
        Y.log("Creating rules in a remote StyleSheet allowed", "warn", "TestRunner");
190
 
        throw Error("This is an informative test only");
191
 
    },
192
 
 
193
 
    "disabling a remote StyleSheet should throw an error" : function () {
194
 
        // Each line should throw an exception
195
 
        var sheet = Y.StyleSheet(this.remoteLink);
196
 
 
197
 
        sheet.disable();
198
 
 
199
 
        Y.log("Disabling a remote StyleSheet allowed", "warn", "TestRunner");
200
 
        throw Error("This is an informative test only");
201
 
    }
202
 
}));
203
 
 
204
 
suite.add(new Y.Test.Case({
205
 
    name : "Test set",
206
 
 
207
 
    _should: {
208
 
        fail: {
209
 
            test_important: 2528707  // bug
210
 
        }
211
 
    },
212
 
 
213
 
    setUp : function () {
214
 
        this.stylesheet = new StyleSheet('test');
215
 
 
216
 
        this.testNode = Dom.add(testbed,'div',{
217
 
            id:'target',
218
 
            innerHTML:'<p>1</p><p>2</p><pre>pre</pre>'
219
 
        });
220
 
    },
221
 
    tearDown : function () {
222
 
        testbed.innerHTML = '';
223
 
        this.stylesheet.unset('#target');
224
 
        this.stylesheet.unset('#target p');
225
 
        this.stylesheet.unset('#target pre');
226
 
        // This should be unnecessary, but for the sake of cleanliness...
227
 
        this.stylesheet.unset('#target, #target p, #target pre');
228
 
    },
229
 
 
230
 
    test_addSimpleSelector : function () {
231
 
        this.stylesheet.set('#target',{
232
 
            color           : '#123456',
233
 
            backgroundColor : '#eef',
234
 
            border          : '1px solid #ccc'
235
 
        });
236
 
 
237
 
        StyleAssert.areEqual('#123456',
238
 
                        Y.DOM.getStyle(this.testNode,'color'),
239
 
                        "color");
240
 
        StyleAssert.areEqual('#eef',
241
 
                        Y.DOM.getStyle(this.testNode,'backgroundColor'),
242
 
                        "backgroundColor");
243
 
        StyleAssert.areEqual('#ccc',
244
 
                        Y.DOM.getStyle(this.testNode,'borderLeftColor'),
245
 
                        "border");
246
 
    },
247
 
 
248
 
    test_addRuleWithInvalidValue : function () {
249
 
        // This would throw an exception in IE if anywhere
250
 
        this.stylesheet.set('#target .foo .bar', { color : 'invalid-value' });
251
 
    },
252
 
 
253
 
    test_descendantSelector : function () {
254
 
        var before = Y.DOM.getStyle(
255
 
                        testbed.getElementsByTagName('pre')[0],'textAlign');
256
 
 
257
 
        this.stylesheet.set('#target p', { textAlign: 'right' });
258
 
 
259
 
        StyleAssert.areEqual('right',
260
 
                        Y.DOM.getStyle(
261
 
                            testbed.getElementsByTagName('p')[0],'textAlign'),
262
 
                        "#target p { text-align: right; }");
263
 
 
264
 
        StyleAssert.areEqual(before,
265
 
                        Y.DOM.getStyle(
266
 
                            testbed.getElementsByTagName('pre')[0],'textAlign'),
267
 
                        "#target pre should not be set (maybe auto/inherit?)");
268
 
    },
269
 
 
270
 
    test_setCommaSelector : function () {
271
 
        var sheet = Dom.getSheet(this.stylesheet.getId());
272
 
 
273
 
        if (!sheet) {
274
 
            Assert.fail("Could not find this StyleSheet's node or sheet");
275
 
        }
276
 
 
277
 
        this.stylesheet.set('#target, #target p, #target pre', {
278
 
            paddingLeft: '16px'
279
 
        });
280
 
 
281
 
        Assert.areEqual(3,(sheet.cssRules || sheet.rules).length, "Comma selector split failure");
282
 
 
283
 
        StyleAssert.areEqual('16px', Y.DOM.getStyle(this.testNode,'paddingLeft'));
284
 
        StyleAssert.areEqual('16px',
285
 
                        Y.DOM.getStyle(
286
 
                            testbed.getElementsByTagName('p')[0],'paddingLeft'),
287
 
                        "#target p");
288
 
        StyleAssert.areEqual('16px',
289
 
                        Y.DOM.getStyle(
290
 
                            testbed.getElementsByTagName('pre')[0],'paddingLeft'),
291
 
                        "#target pre");
292
 
    },
293
 
 
294
 
    test_important: function () {
295
 
        var target   = Y.one('#target'),
296
 
            sheet    = Dom.getSheet(this.stylesheet.getId()),
297
 
            original = target.get('offsetHeight');
298
 
 
299
 
        if (!sheet) {
300
 
            Assert.fail("Could not find this StyleSheet's node or sheet");
301
 
        }
302
 
 
303
 
        this.stylesheet.set('#target p', {
304
 
            paddingBottom: '10px !important'
305
 
        });
306
 
 
307
 
        Assert.areEqual(1,(sheet.cssRules || sheet.rules).length, "!important rule not added to the sheet");
308
 
 
309
 
        Assert.areNotEqual(original, target.get('offsetHeight'));
310
 
 
311
 
        Assert.fail(); // remove when the bug is fixed
312
 
    }
313
 
}));
314
 
 
315
 
suite.add(new Y.Test.Case({
316
 
    name : "Test Enable/Disable sheet",
317
 
 
318
 
    setUp : function () {
319
 
        this.stylesheet = new StyleSheet('test');
320
 
 
321
 
        this.stylesheet.enable();
322
 
 
323
 
        this.testNode = Dom.add(testbed,'div',{id:'target'});
324
 
 
325
 
        this.before = {
326
 
            color           : Y.DOM.getStyle(this.testNode,'color'),
327
 
            backgroundColor : Y.DOM.getStyle(this.testNode,'backgroundColor'),
328
 
            borderLeftColor : Y.DOM.getStyle(this.testNode,'borderLeftColor')
329
 
        };
330
 
 
331
 
    },
332
 
 
333
 
    tearDown : function () {
334
 
        testbed.innerHTML = '';
335
 
        this.stylesheet.enable();
336
 
        this.stylesheet.unset('#target');
337
 
        this.stylesheet.unset('#target p');
338
 
    },
339
 
 
340
 
    test_disableSheet : function () {
341
 
        this.stylesheet.set('#target',{
342
 
            color           : '#123456',
343
 
            backgroundColor : '#eef',
344
 
            border          : '1px solid #ccc'
345
 
        });
346
 
 
347
 
        StyleAssert.areEqual('#123456',
348
 
                        Y.DOM.getStyle(this.testNode,'color'),
349
 
                        "color (enabled)");
350
 
        StyleAssert.areEqual('#eef',
351
 
                        Y.DOM.getStyle(this.testNode,'backgroundColor'),
352
 
                        "backgroundColor (enabled)");
353
 
        StyleAssert.areEqual('#ccc',
354
 
                        Y.DOM.getStyle(this.testNode,'borderLeftColor'),
355
 
                        "border (enabled)");
356
 
 
357
 
        this.stylesheet.disable();
358
 
 
359
 
        StyleAssert.areEqual(this.before.color,
360
 
                        Y.DOM.getStyle(this.testNode,'color'),
361
 
                        "color (disabled)");
362
 
        StyleAssert.areEqual(this.before.backgroundColor,
363
 
                        Y.DOM.getStyle(this.testNode,'backgroundColor'),
364
 
                        "backgroundColor (disabled)");
365
 
        StyleAssert.areEqual(this.before.borderLeftColor,
366
 
                        Y.DOM.getStyle(this.testNode,'borderLeftColor'),
367
 
                        "border (disabled)");
368
 
    },
369
 
 
370
 
    test_enableSheet : function () {
371
 
        this.stylesheet.disable();
372
 
 
373
 
        this.stylesheet.set('#target',{
374
 
            color           : '#123456',
375
 
            backgroundColor : '#eef',
376
 
            border          : '1px solid #ccc'
377
 
        });
378
 
 
379
 
        StyleAssert.areEqual(this.before.color,
380
 
                        Y.DOM.getStyle(this.testNode,'color'),
381
 
                        "color (disabled)");
382
 
        StyleAssert.areEqual(this.before.backgroundColor,
383
 
                        Y.DOM.getStyle(this.testNode,'backgroundColor'),
384
 
                        "backgroundColor (disabled)");
385
 
        StyleAssert.areEqual(this.before.borderLeftColor,
386
 
                        Y.DOM.getStyle(this.testNode,'borderLeftColor'),
387
 
                        "border (disabled)");
388
 
 
389
 
        this.stylesheet.enable();
390
 
 
391
 
        StyleAssert.areEqual('#123456',
392
 
                        Y.DOM.getStyle(this.testNode,'color'),
393
 
                        "color (enabled)");
394
 
        StyleAssert.areEqual('#eef',
395
 
                        Y.DOM.getStyle(this.testNode,'backgroundColor'),
396
 
                        "backgroundColor (enabled)");
397
 
        StyleAssert.areEqual('#ccc',
398
 
                        Y.DOM.getStyle(this.testNode,'borderLeftColor'),
399
 
                        "border (enabled)");
400
 
    }
401
 
}));
402
 
 
403
 
suite.add(new Y.Test.Case({
404
 
    name : "Test unset",
405
 
 
406
 
    setUp : function () {
407
 
        this.stylesheet = new StyleSheet('test');
408
 
 
409
 
        this.testNode = Dom.add(testbed,'div',{
410
 
            id:'target',
411
 
            innerHTML:'<p>1</p><p>2</p><pre>pre</pre>'
412
 
        });
413
 
 
414
 
        this.before = {
415
 
            color           : Y.DOM.getStyle(this.testNode,'color'),
416
 
            backgroundColor : Y.DOM.getStyle(this.testNode,'backgroundColor'),
417
 
            borderLeftColor : Y.DOM.getStyle(this.testNode,'borderLeftColor'),
418
 
            textAlign       : Y.DOM.getStyle(this.testNode,'textAlign')
419
 
        };
420
 
 
421
 
    },
422
 
    tearDown : function () {
423
 
        testbed.innerHTML = '';
424
 
        this.stylesheet.unset('#target');
425
 
        this.stylesheet.unset('#target p');
426
 
        this.stylesheet.unset('#target pre');
427
 
        // This should be unnecessary, but for the sake of cleanliness...
428
 
        this.stylesheet.unset('#target, #target p, #target pre');
429
 
    },
430
 
 
431
 
    test_unset : function () {
432
 
        this.stylesheet.set('#target',{
433
 
            color           : '#f00',
434
 
            backgroundColor : '#eef',
435
 
            border          : '1px solid #ccc'
436
 
        });
437
 
 
438
 
        StyleAssert.areEqual('#f00',
439
 
                        Y.DOM.getStyle(this.testNode,'color'),
440
 
                        "color (before unset)");
441
 
        StyleAssert.areEqual('#eef',
442
 
                        Y.DOM.getStyle(this.testNode,'backgroundColor'),
443
 
                        "backgroundColor (before unset)");
444
 
        StyleAssert.areEqual('#ccc',
445
 
                        Y.DOM.getStyle(this.testNode,'borderLeftColor'),
446
 
                        "border (before unset)");
447
 
 
448
 
        this.stylesheet.unset('#target', 'color');
449
 
 
450
 
        StyleAssert.areEqual(this.before.color,
451
 
                        Y.DOM.getStyle(this.testNode,'color'),
452
 
                        "color (after unset)");
453
 
 
454
 
        this.stylesheet.unset('#target', ['backgroundColor','border']);
455
 
 
456
 
        StyleAssert.areEqual(this.before.backgroundColor,
457
 
                        Y.DOM.getStyle(this.testNode,'backgroundColor'),
458
 
                        "backgroundColor (after unset)");
459
 
        StyleAssert.areEqual(this.before.borderLeftColor,
460
 
                        Y.DOM.getStyle(this.testNode,'borderLeftColor'),
461
 
                        "border (after unset)");
462
 
    },
463
 
 
464
 
    test_removeRule : function () {
465
 
        this.stylesheet.set('#target', { textAlign: 'right' });
466
 
 
467
 
        StyleAssert.areEqual('right',
468
 
                        Y.DOM.getStyle(this.testNode,'textAlign'),
469
 
                        "#target { text-align: right; }");
470
 
 
471
 
        this.stylesheet.unset('#target');
472
 
        StyleAssert.areEqual(this.before.textAlign,
473
 
                        Y.DOM.getStyle(this.testNode,'textAlign'),
474
 
                        "#target text-align still in place");
475
 
    },
476
 
 
477
 
    test_unsetCommaSelector : function () {
478
 
        var p      = this.testNode.getElementsByTagName('p')[0],
479
 
            pre    = this.testNode.getElementsByTagName('pre')[0],
480
 
            before = {
481
 
                paddingLeft:[
482
 
                    Y.DOM.getStyle(this.testNode,'paddingLeft'),
483
 
                    Y.DOM.getStyle(p,'paddingLeft'),
484
 
                    Y.DOM.getStyle(pre,'paddingLeft')
485
 
                ],
486
 
                marginRight:[
487
 
                    Y.DOM.getStyle(this.testNode,'marginRight'),
488
 
                    Y.DOM.getStyle(p,'marginRight'),
489
 
                    Y.DOM.getStyle(pre,'marginRight')
490
 
                ]
491
 
            },
492
 
            after,
493
 
            sheet = Dom.getSheet(this.stylesheet.getId());
494
 
 
495
 
        if (!sheet) {
496
 
            Assert.fail("Could not find this StyleSheet's node or sheet");
497
 
        }
498
 
 
499
 
        this.stylesheet.set('#target, #target p, #target pre', {
500
 
            marginRight: '30px',
501
 
            paddingLeft: '16px'
502
 
        });
503
 
 
504
 
 
505
 
        Assert.areEqual(3,(sheet.cssRules || sheet.rules).length,
506
 
                        "Comma selector split failure");
507
 
 
508
 
 
509
 
        this.stylesheet.unset('#target, #target p, #target pre','paddingLeft');
510
 
 
511
 
        after = [
512
 
            Y.DOM.getStyle(this.testNode,'paddingLeft'),
513
 
            Y.DOM.getStyle(p,'paddingLeft'),
514
 
            Y.DOM.getStyle(pre,'paddingLeft')
515
 
        ];
516
 
 
517
 
        Assert.areEqual(3,(sheet.cssRules || sheet.rules).length,
518
 
                        "Should still be 3 rules");
519
 
 
520
 
        Y.ArrayAssert.itemsAreEqual(before.paddingLeft,after);
521
 
 
522
 
        after = [
523
 
            Y.DOM.getStyle(this.testNode,'marginRight'),
524
 
            Y.DOM.getStyle(p,'marginRight'),
525
 
            Y.DOM.getStyle(pre,'marginRight')
526
 
        ];
527
 
        Y.ArrayAssert.itemsAreEqual(['30px','30px','30px'],after);
528
 
    },
529
 
 
530
 
    test_removeCommaSelector : function () {
531
 
        var /*p      = this.testNode.getElementsByTagName('p')[0],
532
 
            pre    = this.testNode.getElementsByTagName('pre')[0],
533
 
            before = {
534
 
                paddingLeft: [
535
 
                    Y.DOM.getStyle(this.testNode,'paddingLeft'),
536
 
                    Y.DOM.getStyle(p,'paddingLeft'),
537
 
                    Y.DOM.getStyle(pre,'paddingLeft')
538
 
                ]
539
 
            },
540
 
            */
541
 
            sheet = Dom.getSheet(this.stylesheet.getId());
542
 
 
543
 
        if (!sheet) {
544
 
            Assert.fail("Could not capture this StyleSheet's node or sheet");
545
 
        }
546
 
 
547
 
        this.stylesheet.set('#target, #target p, #target pre', {
548
 
            paddingLeft: '16px'
549
 
        });
550
 
 
551
 
        Assert.areEqual(3,(sheet.cssRules || sheet.rules).length,
552
 
                        "Comma selector split failure");
553
 
 
554
 
        this.stylesheet.unset('#target, #target pre','paddingLeft');
555
 
 
556
 
        Assert.areEqual(1,(sheet.cssRules || sheet.rules).length);
557
 
    }
558
 
}));
559
 
 
560
 
suite.add(new Y.Test.Case({
561
 
    name : "Test getCssText",
562
 
 
563
 
    _should: {
564
 
        fail: {
565
 
            test_important: true
566
 
        }
567
 
    },
568
 
 
569
 
    setUp : function () {
570
 
        this.stylesheet = new StyleSheet('test');
571
 
 
572
 
        this.testNode = Dom.add(testbed,'div',{
573
 
            id:'target',
574
 
            innerHTML:'<p>1</p><p>2</p><pre>pre</pre>'
575
 
        });
576
 
 
577
 
        this.stylesheet.set('#target, #target p', {
578
 
            padding: '3px'
579
 
        });
580
 
    },
581
 
    tearDown : function () {
582
 
        testbed.innerHTML = '';
583
 
        this.stylesheet.unset('#target');
584
 
        this.stylesheet.unset('#target p');
585
 
    },
586
 
 
587
 
    test_getRuleCSS : function () {
588
 
        var css = this.stylesheet.getCssText('#target p');
589
 
        Y.log(css, 'info','TestLogger');
590
 
        Assert.isString(css);
591
 
        Assert.areSame(true, /padding/i.test(css));
592
 
    },
593
 
 
594
 
    test_getSheetCSS : function () {
595
 
        var css = this.stylesheet.getCssText();
596
 
 
597
 
        Y.log(css, 'info','TestLogger');
598
 
 
599
 
        Assert.isString(css);
600
 
        Assert.areSame(true, /padding/i.test(css));
601
 
        Assert.areSame(true, /#target/i.test(css));
602
 
        Assert.areSame(true, /#target\s+p\s+\{/i.test(css));
603
 
    },
604
 
 
605
 
    test_important: function () {
606
 
        this.stylesheet.set('#target p', {
607
 
            paddingBottom: '10px !important'
608
 
        });
609
 
 
610
 
        var css = this.stylesheet.getCssText();
611
 
 
612
 
        if (/important/i.test(css)) {
613
 
            Y.log("!important not found in cssText", "warn", "TestRunner");
614
 
        }
615
 
 
616
 
        Assert.fail(); // remove when the bug is fixed
617
 
    }
618
 
}));
619
 
 
620
 
suite.add(new Y.Test.Case({
621
 
    name : "Test float/opacity",
622
 
 
623
 
    setUp : function () {
624
 
        this.stylesheet = new StyleSheet('test');
625
 
 
626
 
        if (!d.getElementById('target')) {
627
 
            this.testNode = Dom.add(testbed,'div',{
628
 
                id:'target',
629
 
                innerHTML:'<p id="p1">1</p><p id="p2">2</p><p id="p3">3</p>'
630
 
            });
631
 
        }
632
 
    },
633
 
 
634
 
    test_float : function () {
635
 
        var p1 = Y.DOM.byId('p1'),
636
 
            p2 = Y.DOM.byId('p2'),
637
 
            p3 = Y.DOM.byId('p3');
638
 
 
639
 
        this.stylesheet.set('#target',{
640
 
                            overflow: 'hidden',
641
 
                            background: '#000',
642
 
                            zoom: 1
643
 
                        })
644
 
                        .set('#target p',{
645
 
                            height:'100px',
646
 
                            width:'100px',
647
 
                            border: '5px solid #ccc',
648
 
                            background: '#fff',
649
 
                            margin: '1em'
650
 
                        })
651
 
                        .set('#p1',{ 'float': 'left' })
652
 
                        .set('#p2',{ cssFloat: 'left' })
653
 
                        .set('#p3',{ styleFloat: 'left' });
654
 
 
655
 
        Assert.areEqual('left', Y.DOM.getStyle(p1,'float'));
656
 
        Assert.areEqual('left', Y.DOM.getStyle(p2,'float'));
657
 
        Assert.areEqual('left', Y.DOM.getStyle(p3,'float'));
658
 
    },
659
 
 
660
 
    test_opacity : function () {
661
 
        var p1 = Y.DOM.byId('p1'),
662
 
            p2 = Y.DOM.byId('p2'),
663
 
            p3 = Y.DOM.byId('p3');
664
 
 
665
 
        this.stylesheet.set('#p1',{ opacity: 0.5 }).
666
 
                        set('#p2',{ opacity: ".2" }).
667
 
                        set('#p3',{ opacity: 1 });
668
 
 
669
 
        Assert.areEqual(0.5,Y.DOM.getStyle(p1,'opacity'));
670
 
        Assert.areEqual(0.2,Y.DOM.getStyle(p2,'opacity'));
671
 
        Assert.areEqual(1,Y.DOM.getStyle(p3,'opacity'));
672
 
    }
673
 
}));
674
 
 
675
 
suite.add(new Y.Test.Case({
676
 
    name: "Testbed Cleanup",
677
 
 
678
 
    testbedCleanup: function () {
679
 
        Y.all('#testbed,style').remove(true);
680
 
    }
681
 
}));
682
 
 
683
 
Y.Test.Runner.add(suite);
684
 
 
685
 
 
686
 
}, '@VERSION@' ,{requires:['stylesheet', 'test']});