private Node addNodesToHtml(List<Node> nodes) throws Exception { Node html = elem("html"); Node head = elem("head"); Node body = elem("body"); html.appendChild(head); html.appendChild(body); for (Node node : nodes) { body.appendChild(node); } html.getOwnerDocument().appendChild(html); return head; } }
private Node addNodesToHtml(List<Node> nodes) throws Exception { Node html = elem("html"); Node head = elem("head"); Node body = elem("body"); html.appendChild(head); html.appendChild(body); for (Node node : nodes) { body.appendChild(node); } html.getOwnerDocument().appendChild(html); return head; } }
private Node addNodesToHtml(List<Node> nodes) throws Exception { Node html = elem("html"); Node head = elem("head"); Node body = elem("body"); html.appendChild(head); html.appendChild(body); for (Node node : nodes) { body.appendChild(node); } html.getOwnerDocument().appendChild(html); return head; } }
@Test public void visitBypassesNonStyle() throws Exception { Node node = elem("div"); assertEquals(VisitStatus.BYPASS, getVisitStatus(node)); }
@Test public void visitReservesStyleNode() throws Exception { assertEquals(VisitStatus.RESERVE_NODE, getVisitStatus(elem("style"))); }
@Test public void visitBypassesNonStyle() throws Exception { Node node = elem("div"); assertEquals(VisitStatus.BYPASS, getVisitStatus(node)); }
@Test public void visitBypassesNonStyle() throws Exception { Node node = elem("div"); assertEquals(VisitStatus.BYPASS, getVisitStatus(node)); }
@Test public void visitReservesStyleNode() throws Exception { assertEquals(VisitStatus.RESERVE_NODE, getVisitStatus(elem("style"))); }
@Test public void visitReservesCasedStyleNode() throws Exception { assertEquals(VisitStatus.RESERVE_NODE, getVisitStatus(elem("sTyLE"))); }
@Test public void visitReservesStyleNode() throws Exception { assertEquals(VisitStatus.RESERVE_NODE, getVisitStatus(elem("style"))); }
@Test public void visitReservesCasedStyleNode() throws Exception { assertEquals(VisitStatus.RESERVE_NODE, getVisitStatus(elem("sTyLE"))); }
@Test public void visitReservesCasedStyleNode() throws Exception { assertEquals(VisitStatus.RESERVE_NODE, getVisitStatus(elem("sTyLE"))); }
@Test public void visitBypassesStyleWhenRewriterOff() throws Exception { assertEquals(VisitStatus.BYPASS, getVisitStatus(config(false, true, true), elem("style"))); }
@Test public void visitBypassesStyleWhenStyleTagNotIncluded() throws Exception { assertEquals(VisitStatus.BYPASS, getVisitStatus(config(true, false, true), elem("style"))); }
@Test public void visitBypassesStyleWhenStyleTagNotIncluded() throws Exception { assertEquals(VisitStatus.BYPASS, getVisitStatus(config(true, false, true), elem("style"))); }
@Test public void visitBypassesStyleWhenRewriterOff() throws Exception { assertEquals(VisitStatus.BYPASS, getVisitStatus(config(false, true, true), elem("style"))); }
@Test public void visitBypassesStyleWhenRewriterOff() throws Exception { assertEquals(VisitStatus.BYPASS, getVisitStatus(config(false, true, true), elem("style"))); }
@Test public void visitBypassesStyleWhenStyleTagNotIncluded() throws Exception { assertEquals(VisitStatus.BYPASS, getVisitStatus(config(true, false, true), elem("style"))); }
@Test public void revisitExtractSpecRelativeDisabled() throws Exception { Uri base = GADGET_URI; Gadget gadget = gadget(); CssResponseRewriter cssRewriter = createMock(CssResponseRewriter.class); Element elem1 = elem("elem1"); Element elem2 = elem("elem2"); List<String> extractedUrls1 = ImmutableList.of(); List<String> extractedUrls2 = ImmutableList.of(); expect(cssRewriter.rewrite(eq(elem1), eq(base), isA(UriMaker.class), eq(true), eq(gadget.getContext()))) .andReturn(extractedUrls1).once(); expect(cssRewriter.rewrite(eq(elem2), eq(base), isA(UriMaker.class), eq(true), eq(gadget.getContext()))) .andReturn(extractedUrls2).once(); replay(cssRewriter); // Tag name isn't inspected since visit() filters this. List<Node> nodes = ImmutableList.<Node>of(elem1, elem2); Node head = addNodesToHtml(nodes); assertFalse(getRevisitStatus(gadget, false, cssRewriter, nodes)); verify(cssRewriter); assertEquals(0, head.getChildNodes().getLength()); }
@Test public void revisitExtractSpecRelativeDisabled() throws Exception { Uri base = GADGET_URI; Gadget gadget = gadget(); CssResponseRewriter cssRewriter = createMock(CssResponseRewriter.class); Element elem1 = elem("elem1"); Element elem2 = elem("elem2"); List<String> extractedUrls1 = ImmutableList.of(); List<String> extractedUrls2 = ImmutableList.of(); expect(cssRewriter.rewrite(eq(elem1), eq(base), isA(UriMaker.class), eq(true), eq(gadget.getContext()))) .andReturn(extractedUrls1).once(); expect(cssRewriter.rewrite(eq(elem2), eq(base), isA(UriMaker.class), eq(true), eq(gadget.getContext()))) .andReturn(extractedUrls2).once(); replay(cssRewriter); // Tag name isn't inspected since visit() filters this. List<Node> nodes = ImmutableList.<Node>of(elem1, elem2); Node head = addNodesToHtml(nodes); assertFalse(getRevisitStatus(gadget, false, cssRewriter, nodes)); verify(cssRewriter); assertEquals(0, head.getChildNodes().getLength()); }