11import { describe , it , expect , beforeEach , ddescribe , iit , xit , el } from 'angular2/test_lib' ;
2- import { CssProcessor } from 'angular2/src/core/compiler/css_processor' ;
2+ import { CssProcessor , CssTransformer } from 'angular2/src/core/compiler/css_processor' ;
33
44import { ShadowDomStrategy } from 'angular2/src/core/compiler/shadow_dom_strategy' ;
55
@@ -8,6 +8,8 @@ import {CompileElement} from 'angular2/src/core/compiler/pipeline/compile_elemen
88import { CompileStep } from 'angular2/src/core/compiler/pipeline/compile_step' ;
99import { CompileControl } from 'angular2/src/core/compiler/pipeline/compile_control' ;
1010
11+ import { DOM } from 'angular2/src/dom/dom_adapter' ;
12+
1113import { Component } from 'angular2/src/core/annotations/annotations' ;
1214
1315import { DirectiveMetadata } from 'angular2/src/core/compiler/directive_metadata' ;
@@ -28,7 +30,7 @@ export function main() {
2830
2931 it ( 'it should set ignoreBindings to true for style elements' , ( ) => {
3032 var strategy = new FakeShadowDomStrategy ( null ) ;
31- var cssProcessor = new CssProcessor ( ) ;
33+ var cssProcessor = new CssProcessor ( null ) ;
3234
3335 var pipeline = createPipeline ( cssProcessor , strategy , 'http://base' ) ;
3436 var results = pipeline . process ( el ( '<div><style></style></div>' ) ) ;
@@ -44,13 +46,26 @@ export function main() {
4446 } ) ;
4547 var strategy = new FakeShadowDomStrategy ( compileStep ) ;
4648
47- var cssProcessor = new CssProcessor ( ) ;
49+ var cssProcessor = new CssProcessor ( null ) ;
4850 var pipeline = createPipeline ( cssProcessor , strategy , 'http://base' ) ;
4951 var results = pipeline . process ( el ( '<div><style></style></div>' ) ) ;
5052
5153 expect ( processedEls . length ) . toEqual ( 1 ) ;
5254 expect ( processedEls [ 0 ] ) . toBe ( results [ 1 ] . element ) ;
5355 } ) ;
56+
57+ it ( 'should apply the given transformers' , ( ) => {
58+ var strategy = new FakeShadowDomStrategy ( null ) ;
59+ var cssProcessor = new CssProcessor ( [
60+ new FakeCssTransformer ( '/*transformer1 */' ) ,
61+ new FakeCssTransformer ( '/*transformer2 */' ) ,
62+ ] ) ;
63+
64+ var pipeline = createPipeline ( cssProcessor , strategy , 'http://base' ) ;
65+ var results = pipeline . process ( el ( '<div><style></style></div>' ) ) ;
66+
67+ expect ( results [ 1 ] . element ) . toHaveText ( '/*transformer1 *//*transformer2 */' ) ;
68+ } ) ;
5469 } ) ;
5570 } ) ;
5671}
@@ -79,4 +94,19 @@ class MockStep extends CompileStep {
7994 }
8095}
8196
97+ class FakeCssTransformer extends CssTransformer {
98+ _css : string ;
99+
100+ constructor ( css : string ) {
101+ super ( ) ;
102+ this . _css = css ;
103+ }
104+
105+ transform ( styleEl ) {
106+ var cssText = DOM . getText ( styleEl ) ;
107+ cssText += this . _css ;
108+ DOM . setText ( styleEl , cssText ) ;
109+ }
110+ }
111+
82112class SomeComponent { }
0 commit comments