com.google.caja.util
Class RhinoTestBed

java.lang.Object
  extended by 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

Nested Class Summary
static class RhinoTestBed.JunitSandBoxSafe
           
 
Field Summary
private static java.lang.String HTML_NS
           
 
Constructor Summary
private RhinoTestBed()
           
 
Method Summary
private static ParseTreeNode cajole(Block program, MessageQueue mq)
           
private static CharProducer loadResource(InputSource resource)
           
private static Block parseJavascript(CharProducer cp, MessageQueue mq)
           
private static java.lang.String prefixWithBlankLines(java.lang.String s, int n)
           
private static java.lang.String render(ParseTreeNode n)
           
static java.lang.Object runJs(Executor.Input... inputs)
          Runs the javascript from the given inputs in order, and returns the result.
static void runJsUnittestFromHtml(org.w3c.dom.Element html)
          Given an HTML file that references javascript sources, load all the scripts, set up the DOM using env.js, and start JSUnit.
private static boolean shouldCajoleBlock(Block block)
           
private static CharProducer textContentOf(org.w3c.dom.Element script)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

HTML_NS

private static final java.lang.String HTML_NS
See Also:
Constant Field Values
Constructor Detail

RhinoTestBed

private RhinoTestBed()
Method Detail

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:

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