@Test public void revisitNothingExtracted() throws Exception { Gadget gadget = gadget(); CssResponseRewriter cssRewriter = createMock(CssResponseRewriter.class); replay(cssRewriter); // Tag name isn't inspected since visit() filters this. List<Node> nodes = ImmutableList.<Node>of(); Node head = addNodesToHtml(nodes); assertFalse(getRevisitStatus(gadget, true, cssRewriter, nodes)); verify(cssRewriter); assertEquals(0, head.getChildNodes().getLength()); }
@Test public void visitBypassesStyleWhenStyleTagNotIncluded() throws Exception { assertEquals(VisitStatus.BYPASS, getVisitStatus(config(true, false, true), elem("style"))); }
private VisitStatus getVisitStatus(Node node) throws Exception { return getVisitStatus(config(true, true, true), node); }
@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 visitBypassesNonStyle() throws Exception { Node node = elem("div"); assertEquals(VisitStatus.BYPASS, getVisitStatus(node)); }
@Test public void visitBypassesComment() throws Exception { Comment comment = doc.createComment("comment"); assertEquals(VisitStatus.BYPASS, getVisitStatus(comment)); }
private boolean getRevisitStatus( Gadget gadget, boolean shouldRewriteUrl, CssResponseRewriter cssRewriter, List<Node> nodes) throws Exception { return new StyleTagExtractorVisitor( config(true, true, shouldRewriteUrl), cssRewriter, proxyUriManager) .revisit(gadget, nodes); }
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 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 visitBypassesNonStyle() throws Exception { Node node = elem("div"); assertEquals(VisitStatus.BYPASS, getVisitStatus(node)); }
private VisitStatus getVisitStatus(Node node) throws Exception { return getVisitStatus(config(true, true, true), node); }
@Test public void visitBypassesText() throws Exception { Text text = doc.createTextNode("text"); assertEquals(VisitStatus.BYPASS, getVisitStatus(text)); }
private boolean getRevisitStatus( Gadget gadget, boolean shouldRewriteUrl, CssResponseRewriter cssRewriter, List<Node> nodes) throws Exception { return new StyleTagExtractorVisitor( config(true, true, shouldRewriteUrl), cssRewriter, proxyUriManager) .revisit(gadget, nodes); }
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 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 visitBypassesStyleWhenStyleTagNotIncluded() throws Exception { assertEquals(VisitStatus.BYPASS, getVisitStatus(config(true, false, true), elem("style"))); }
@Test public void visitBypassesNonStyle() throws Exception { Node node = elem("div"); assertEquals(VisitStatus.BYPASS, getVisitStatus(node)); }
@Test public void revisitNothingExtracted() throws Exception { Gadget gadget = gadget(); CssResponseRewriter cssRewriter = createMock(CssResponseRewriter.class); replay(cssRewriter); // Tag name isn't inspected since visit() filters this. List<Node> nodes = ImmutableList.of(); Node head = addNodesToHtml(nodes); assertFalse(getRevisitStatus(gadget, true, cssRewriter, nodes)); verify(cssRewriter); assertEquals(0, head.getChildNodes().getLength()); }
private VisitStatus getVisitStatus(Node node) throws Exception { return getVisitStatus(config(true, true, true), node); }
@Test public void visitBypassesComment() throws Exception { Comment comment = doc.createComment("comment"); assertEquals(VisitStatus.BYPASS, getVisitStatus(comment)); }