EMMA Coverage Report (generated Mon Nov 01 16:48:29 PDT 2010)
[all classes][com.google.caja.plugin]

COVERAGE SUMMARY FOR SOURCE FILE [PipelineMakerTest.java]

nameclass, %method, %block, %line, %
PipelineMakerTest.java100% (1/1)100% (9/9)90%  (359/400)74%  (29/39)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class PipelineMakerTest100% (1/1)100% (9/9)90%  (359/400)74%  (29/39)
PipelineMakerTest (): void 100% (1/1)100% (3/3)100% (1/1)
assertPipeline (Planner$PlanState, Planner$PlanState, String []): void 100% (1/1)100% (70/70)100% (11/11)
testDebuggingModePipeline (): void 100% (1/1)100% (67/67)100% (2/2)
testDefaultPipeline (): void 100% (1/1)100% (55/55)100% (2/2)
testFailEarly (): void 100% (1/1)33%  (6/18)43%  (3/7)
testHtmlAlreadyNamespaced (): void 100% (1/1)100% (55/55)100% (2/2)
testJsOnly (): void 100% (1/1)100% (25/25)100% (2/2)
testJsOnlyOutput (): void 100% (1/1)100% (57/57)100% (2/2)
testNoPath (): void 100% (1/1)42%  (21/50)40%  (4/10)

1// Copyright (C) 2010 Google Inc.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//      http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14 
15package com.google.caja.plugin;
16 
17import com.google.caja.lang.css.CssSchema;
18import com.google.caja.lang.html.HtmlSchema;
19import com.google.caja.parser.quasiliteral.ModuleManager;
20import com.google.caja.reporting.TestBuildInfo;
21import com.google.caja.util.CajaTestCase;
22import com.google.caja.util.Lists;
23import com.google.caja.util.MoreAsserts;
24import com.google.caja.util.Pipeline;
25 
26import java.util.Arrays;
27import java.util.List;
28 
29public class PipelineMakerTest extends CajaTestCase {
30  public final void testDefaultPipeline() throws Exception {
31    assertPipeline(
32        PipelineMaker.DEFAULT_PRECONDS,
33        PipelineMaker.DEFAULT_GOALS,
34        "LegacyNamespaceFixupStage",
35        "ResolveUriStage",
36        "RewriteHtmlStage",
37        "InlineCssImportsStage",
38        "SanitizeHtmlStage",
39        "ValidateCssStage",
40        "RewriteCssStage",
41        "HtmlToBundleStage",
42        "OptimizeJavascriptStage",
43        "ValidateJavascriptStage",
44        "ConsolidateCodeStage",
45        "CheckForErrorsStage");
46  }
47 
48  public final void testJsOnlyOutput() throws Exception {
49    assertPipeline(
50        PipelineMaker.DEFAULT_PRECONDS,
51        PipelineMaker.DEFAULT_GOALS.without(PipelineMaker.HTML_SAFE_STATIC),
52        "LegacyNamespaceFixupStage",
53        "ResolveUriStage",
54        "RewriteHtmlStage",
55        "InlineCssImportsStage",
56        "SanitizeHtmlStage",
57        "ValidateCssStage",
58        "RewriteCssStage",
59        "HtmlToJsStage",
60        "OptimizeJavascriptStage",
61        "ValidateJavascriptStage",
62        "ConsolidateCodeStage",
63        "CheckForErrorsStage");
64  }
65 
66  public final void testDebuggingModePipeline() throws Exception {
67    assertPipeline(
68        PipelineMaker.DEFAULT_PRECONDS,
69        PipelineMaker.DEFAULT_GOALS
70            .without(PipelineMaker.ONE_CAJOLED_MODULE)
71            .with(PipelineMaker.ONE_CAJOLED_MODULE_DEBUG),
72        "LegacyNamespaceFixupStage",
73        "ResolveUriStage",
74        "RewriteHtmlStage",
75        "InlineCssImportsStage",
76        "SanitizeHtmlStage",
77        "ValidateCssStage",
78        "RewriteCssStage",
79        "HtmlToBundleStage",
80        "OptimizeJavascriptStage",
81        "ValidateJavascriptStage",
82        "ConsolidateCodeStage",
83        "InferFilePositionsStage",  // extra
84        "DebuggingSymbolsStage",  // extra
85        "CheckForErrorsStage");
86  }
87 
88  public final void testHtmlAlreadyNamespaced() throws Exception {
89    assertPipeline(
90        PipelineMaker.HTML_XMLNS.with(PipelineMaker.JS).with(PipelineMaker.CSS),
91        PipelineMaker.DEFAULT_GOALS,
92        "ResolveUriStage",
93        "RewriteHtmlStage",
94        "InlineCssImportsStage",
95        "SanitizeHtmlStage",
96        "ValidateCssStage",
97        "RewriteCssStage",
98        "HtmlToBundleStage",
99        "OptimizeJavascriptStage",
100        "ValidateJavascriptStage",
101        "ConsolidateCodeStage",
102        "CheckForErrorsStage");
103  }
104 
105  public final void testJsOnly() throws Exception {
106    assertPipeline(
107        PipelineMaker.JS,
108        PipelineMaker.ONE_CAJOLED_MODULE.with(PipelineMaker.SANITY_CHECK),
109        "OptimizeJavascriptStage",
110        "ValidateJavascriptStage",
111        "ConsolidateCodeStage",
112        "CheckForErrorsStage");
113  }
114 
115  public final void testFailEarly() {
116    try {
117      PipelineMaker.planState("bogus");
118    } catch (IllegalArgumentException ex) {
119      assertEquals("bogus", ex.getMessage());
120      return;
121    }
122    fail("completed");
123  }
124 
125  public final void testNoPath() {
126    PipelineMaker pm = new PipelineMaker(
127        CssSchema.getDefaultCss21Schema(mq), HtmlSchema.getDefault(mq),
128        new ModuleManager(
129            TestBuildInfo.getInstance(), UriFetcher.NULL_NETWORK, false, mq),
130        PipelineMaker.HTML, PipelineMaker.CSS);
131    long t0 = System.nanoTime();
132    try {
133      pm.populate(Lists.<Pipeline.Stage<Jobs>>newArrayList());
134    } catch (Planner.UnsatisfiableGoalException ex) {
135      long t1 = System.nanoTime();
136      System.err.println("Took " + ((t1 - t0) / 1e9) + "s");
137      return;
138    }
139    fail("completed");
140  }
141 
142  private void assertPipeline(
143      Planner.PlanState preconds, Planner.PlanState goals, String... expected)
144      throws Exception {
145 
146    List<Pipeline.Stage<Jobs>> stages = Lists.newArrayList();
147    PipelineMaker pm = new PipelineMaker(
148        CssSchema.getDefaultCss21Schema(mq), HtmlSchema.getDefault(mq),
149        new ModuleManager(
150            TestBuildInfo.getInstance(), UriFetcher.NULL_NETWORK, false, mq),
151        preconds, goals);
152    {
153      long t0 = System.nanoTime();
154      pm.populate(stages);
155      long t1 = System.nanoTime();
156      System.err.println("Took " + (t1 - t0) / 1e9 + "s");
157    }
158 
159    List<String> classes = Lists.newArrayList();
160    for (Pipeline.Stage<Jobs> stage : stages) {
161      classes.add(stage.getClass().getSimpleName());
162    }
163 
164    MoreAsserts.assertListsEqual(Arrays.asList(expected), classes);
165  }
166}

[all classes][com.google.caja.plugin]
EMMA 2.0.5312 (C) Vladimir Roubtsov