Package com.google.caja.parser.css

Examples of com.google.caja.parser.css.CssTree$Page


    // we then ensure it fails with URI-valued attribute CITE
    fails("blockquote[cite] { font-weight: bold }");
  }

  private void fails(String css) throws Exception {
    CssTree t = css(fromString(css), true);
    mq.getMessages().clear();
    CssValidator v = makeCssValidator(mq);
    assertTrue(css, !v.validateCss(ac(t)));
    MessageLevel maxLevel = MessageLevel.values()[0];
    for (Message msg : mq.getMessages()) {
View Full Code Here


    assertTrue(maxLevel.name(), MessageLevel.ERROR.compareTo(maxLevel) <= 0);
  }

  private void warns(String css) throws Exception {
    MessageQueue smq = new SimpleMessageQueue();
    CssTree t = css(fromString(css), true);
    CssValidator v = makeCssValidator(smq);
    boolean valid = v.validateCss(ac(t));
    mq.getMessages().addAll(smq.getMessages());
    assertTrue(css, valid);
    assertTrue(css, !mq.getMessages().isEmpty());
View Full Code Here

  private void runTest(String css, String golden, String... warnings)
    throws Exception {
    MessageContext mc = new MessageContext();
    mq.getMessages().clear();
    CssTree cssTree = css(fromString(css), true);
    MessageQueue smq = new SimpleMessageQueue();
    CssValidator v = makeCssValidator(smq);
    boolean valid = v.validateCss(ac(cssTree));
    mq.getMessages().addAll(smq.getMessages());

    // If no warnings are expected, the result should be valid
    if (warnings.length == 0) {
      if (!valid) {
        System.err.println(cssTree.toStringDeep());
      }
      assertTrue(css, valid);
    } else {
      removeInvalidNodes(AncestorChain.instance(cssTree));
    }

    mc.relevantKeys = new LinkedHashSet<SyntheticAttributeKey<?>>(
        Arrays.<SyntheticAttributeKey<?>>asList(
            CssValidator.CSS_PROPERTY_PART_TYPE,
            CssValidator.CSS_PROPERTY_PART));
    StringBuilder sb = new StringBuilder();
    cssTree.format(mc, sb);
    if (golden != null) {
      assertEquals(css, golden.trim(), sb.toString().trim());
    }

    List<String> actualWarnings = Lists.newArrayList();
View Full Code Here

                                        final List<String> unsafeUris) {
    css.acceptPreOrder(new Visitor() {
      public boolean visit(AncestorChain<?> ancestors) {
        ParseTreeNode node = ancestors.node;
        if (node instanceof CssTree.UriLiteral) {
          CssTree parent = (CssTree) ancestors.parent.node;
          assert(null != parent);
          String value = ((CssTree.CssLiteral) node).getValue();
          CssTree.UriLiteral repl = null;
          if (safeUris.contains(value)) {
            repl = new SafeUriLiteral(
                node.getFilePosition(), URI.create(value));
          } else if (unsafeUris.contains(value)) {
            repl = new UnsafeUriLiteral(
                node.getFilePosition(), URI.create(value));
          }
          if (repl != null) {
            parent.replaceChild(repl, node);
          } else {
            fail("URI literal " + value + " unaccounted for by test");
          }
        }
        return true;
View Full Code Here

TOP

Related Classes of com.google.caja.parser.css.CssTree$Page

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.