com.google.caja.util
Class RhinoTestBed
java.lang.Object
com.google.caja.util.RhinoTestBed
public class RhinoTestBed
- extends java.lang.Object
A testbed that allows running javascript via the Rhino interpreter.
TODO(mikesamuel): maybe replace this with the JSR 223 stuff.
- Author:
- mikesamuel@gmail.com
Field Summary |
private static java.lang.String |
HTML_NS
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
HTML_NS
private static final java.lang.String HTML_NS
- See Also:
- Constant Field Values
RhinoTestBed
private RhinoTestBed()
runJs
public static java.lang.Object runJs(Executor.Input... inputs)
- Runs the javascript from the given inputs in order, and returns the
result.
runJsUnittestFromHtml
public static void runJsUnittestFromHtml(org.w3c.dom.Element html)
throws java.io.IOException,
ParseException
- Given an HTML file that references javascript sources, load all
the scripts, set up the DOM using env.js, and start JSUnit.
This lets us write test html files that can be run both
in a browser, and automatically via ANT.
NOTE: This method interprets the input HTML in an idiosyncratic way to
facilitate conveniently bundling test code into one file. It handles each
<script>
block in the input as follows:
- If the directive prologue of the block contains the
'use cajita'
directive, its contents are cajoled as Cajita.
- If the directive prologue of the block contains the
'use valija'
directive, its contents are cajoled as Valija. At
the time of writing, this method is the only component in Caja
that recognizes the 'use valija'
directive. Consequently, and
because we do not wish to commit to supporting this directive for Caja
clients, it is notably absent from
Directive.RecognizedValue
.
- Otherwise, the block is run as plain JavaScript.
- Parameters:
html
- an HTML DOM tree to run in Rhino.
- Throws:
java.io.IOException
ParseException
cajole
private static ParseTreeNode cajole(Block program,
MessageQueue mq)
render
private static java.lang.String render(ParseTreeNode n)
shouldCajoleBlock
private static boolean shouldCajoleBlock(Block block)
parseJavascript
private static Block parseJavascript(CharProducer cp,
MessageQueue mq)
throws ParseException
- Throws:
ParseException
loadResource
private static CharProducer loadResource(InputSource resource)
throws java.io.IOException
- Throws:
java.io.IOException
prefixWithBlankLines
private static java.lang.String prefixWithBlankLines(java.lang.String s,
int n)
textContentOf
private static CharProducer textContentOf(org.w3c.dom.Element script)
Copyright (C) 2008 Google Inc.
Licensed under the Apache License, Version 2.0