Index: tests/com/google/caja/plugin/templates/TemplateSanitizerTest.java
===================================================================
--- tests/com/google/caja/plugin/templates/TemplateSanitizerTest.java (revision 0)
+++ tests/com/google/caja/plugin/templates/TemplateSanitizerTest.java (working copy)
@@ -1,4 +1,4 @@
-// Copyright (C) 2008 Google Inc.
+// Copyright (C) 2009 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@@ -12,201 +12,179 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-package com.google.caja.plugin;
+package com.google.caja.plugin.templates;
import com.google.caja.lang.html.HtmlSchema;
-import com.google.caja.lexer.HtmlTokenType;
-import com.google.caja.lexer.InputSource;
-import com.google.caja.lexer.ParseException;
-import com.google.caja.lexer.TokenConsumer;
-import com.google.caja.lexer.TokenQueue;
-import com.google.caja.parser.html.DomParser;
import com.google.caja.parser.html.Nodes;
-import com.google.caja.render.Concatenator;
-import com.google.caja.reporting.EchoingMessageQueue;
import com.google.caja.reporting.Message;
-import com.google.caja.reporting.MessageContext;
import com.google.caja.reporting.MessageLevel;
-import com.google.caja.reporting.MessageQueue;
-import com.google.caja.reporting.RenderContext;
+import com.google.caja.util.CajaTestCase;
import com.google.caja.util.MoreAsserts;
-import java.io.IOException;
-import java.io.OutputStreamWriter;
-import java.io.PrintWriter;
-import java.io.StringReader;
-import java.net.URI;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
-import org.w3c.dom.DocumentFragment;
import org.w3c.dom.Node;
-import junit.framework.TestCase;
-
-/**
- * @author mikesamuel@gmail.com (Mike Samuel)
- */
-public class HtmlSanitizerTest extends TestCase {
- private static final PrintWriter err
- = new PrintWriter(new OutputStreamWriter(System.err));
- private InputSource is;
- private MessageContext mc;
- private MessageQueue mq;
-
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- is = new InputSource(new URI("test:///" + getName()));
- mc = new MessageContext();
- mc.addInputSource(is);
- mq = new EchoingMessageQueue(err, mc);
- }
-
- @Override
- protected void tearDown() throws Exception {
- super.tearDown();
- is = null;
- mc = null;
- mq = null;
- err.flush();
- }
-
+public class TemplateSanitizerTest extends CajaTestCase {
public void testSingleElement() throws Exception {
- assertValid(html("
"), "
");
+ assertValid(htmlFragment(fromString("
")), "
");
}
public void testText() throws Exception {
- assertValid(html("Hello World"), "Hello World");
+ assertValid(htmlFragment(fromString("Hello World")), "Hello World");
}
public void testFormattingElement() throws Exception {
- assertValid(html("Hello"), "Hello");
+ assertValid(htmlFragment(fromString("Hello")), "Hello");
}
public void testUnknownAttribute() throws Exception {
- assertValid(html("Hello"),
- "Hello",
- "WARNING: removing unknown attribute unknown on b");
+ assertValid(
+ htmlFragment(fromString("Hello")),
+ "Hello",
+ "WARNING: removing unknown attribute unknown on b");
}
public void testKnownAttribute() throws Exception {
- assertValid(html("Hello"), "Hello");
+ assertValid(htmlFragment(fromString("Hello")),
+ "Hello");
}
public void testUnknownElement() throws Exception {
assertValid(
- html("Hello"),
+ htmlFragment(fromString("Hello")),
"Hello",
"WARNING: removing unknown tag bogus",
"WARNING: removing attribute id when folding bogus into parent");
}
public void testUnknownEverything() throws Exception {
- assertValid(html("Hello"),
- "Hello",
- "WARNING: removing unknown tag bogus",
- "WARNING: removing unknown attribute unknown on bogus");
+ assertValid(
+ htmlFragment(fromString("Hello")),
+ "Hello",
+ "WARNING: removing unknown tag bogus",
+ "WARNING: removing unknown attribute unknown on bogus");
}
public void testDisallowedElement() throws Exception {
- assertValid(html(""),
- "disallowed",
- "WARNING: removing disallowed tag script");
+ assertValid(
+ htmlFragment(fromString("")),
+ "disallowed",
+ "WARNING: removing disallowed tag script");
}
public void testAttributeValidity() throws Exception {
- assertValid(html("
"),
- "");
+ assertValid(
+ htmlFragment(fromString("")),
+ "");
}
public void testAttributePatternsTagSpecific() throws Exception {
- assertValid(html(""), "");
- assertValid(html("