private boolean getVisitReserved(String tag, boolean resUrl, boolean resTag, String ... attrs) throws Exception { // Reserved when lower-case and both URL and Tag reserved. String attrName = ALL_RESOURCES.get(tag.toLowerCase()); attrName = attrName != null ? attrName : "src"; ArrayList <String> attrsList = Lists.newArrayList(attrs); attrsList.add(0, attrName); attrsList.add(1, URL_STRING); attrs = attrsList.toArray(attrs); Node node = elem(tag, attrs); ContentRewriterFeature.Config config = createMock(ContentRewriterFeature.Config.class); expect(config.shouldRewriteURL(URL_STRING)).andReturn(resUrl).anyTimes(); expect(config.shouldRewriteTag(tag.toLowerCase())).andReturn(resTag).anyTimes(); replay(config); ProxyingVisitor rewriter = new ProxyingVisitor(config, null, ProxyingVisitor.Tags.SCRIPT, ProxyingVisitor.Tags.STYLESHEET, ProxyingVisitor.Tags.EMBEDDED_IMAGES); VisitStatus status = rewriter.visit(null, node); verify(config); return status != VisitStatus.BYPASS; }
Gadget gadget = gadget(); ProxyingVisitor rewriter = new ProxyingVisitor(config, uriManager, ProxyingVisitor.Tags.SCRIPT, ProxyingVisitor.Tags.STYLESHEET, ProxyingVisitor.Tags.EMBEDDED_IMAGES); assertTrue(rewriter.revisit(gadget, nodes)); verify(config, uriManager);
@Override protected List<Visitor> makeVisitors(Gadget context, Uri gadgetUri) { ContentRewriterFeature.Config config = featureConfigFactory.get(gadgetUri); // Note that concat is including with proxy in order to prevent // proxying the rewritten concat url // Basically Url rewritters should all be in one dom walker. return Arrays.<Visitor>asList( new ConcatVisitor.Js(config, concatUriManager), new ConcatVisitor.Css(config, concatUriManager), new ProxyingVisitor(config, proxyUriManager, ProxyingVisitor.Tags.SCRIPT, ProxyingVisitor.Tags.STYLESHEET, ProxyingVisitor.Tags.EMBEDDED_IMAGES)); } }
Gadget gadget = gadget(); ProxyingVisitor rewriter = new ProxyingVisitor(config, uriManager, ProxyingVisitor.Tags.SCRIPT, ProxyingVisitor.Tags.STYLESHEET, ProxyingVisitor.Tags.EMBEDDED_IMAGES); assertTrue(rewriter.revisit(gadget, nodes)); verify(config, uriManager);
@Override protected List<Visitor> makeVisitors(Gadget context, Uri gadgetUri) { ContentRewriterFeature.Config config = featureConfigFactory.get(gadgetUri); // Note that concat is including with proxy in order to prevent // proxying the rewritten concat url // Basically Url rewritters should all be in one dom walker. return Arrays.<Visitor>asList( new ConcatVisitor.Js(config, concatUriManager), new ConcatVisitor.Css(config, concatUriManager), new ProxyingVisitor(config, proxyUriManager, ProxyingVisitor.Tags.SCRIPT, ProxyingVisitor.Tags.STYLESHEET, ProxyingVisitor.Tags.EMBEDDED_IMAGES)); } }
@Test public void imgWithEmptySrc() throws Exception { Node node = elem("img", "src", ""); ContentRewriterFeature.Config config = createMock(ContentRewriterFeature.Config.class); expect(config.shouldRewriteURL("")).andReturn(true).anyTimes(); expect(config.shouldRewriteTag("img")).andReturn(true).anyTimes(); replay(config); ProxyingVisitor rewriter = new ProxyingVisitor(config, null, ProxyingVisitor.Tags.SCRIPT, ProxyingVisitor.Tags.STYLESHEET, ProxyingVisitor.Tags.EMBEDDED_IMAGES); VisitStatus status = rewriter.visit(null, node); verify(config); assertEquals("Empty attribute should not be rewritten", VisitStatus.BYPASS, status); }
Gadget gadget = gadget(); ProxyingVisitor rewriter = new ProxyingVisitor(config, uriManager, ProxyingVisitor.Tags.SCRIPT, ProxyingVisitor.Tags.STYLESHEET, ProxyingVisitor.Tags.EMBEDDED_IMAGES); assertTrue(rewriter.revisit(gadget, nodes)); verify(config, uriManager);
@Override protected List<Visitor> makeVisitors(Gadget context, Uri gadgetUri) { ContentRewriterFeature.Config config = featureConfigFactory.get(context.getSpec()); // Note that concat is including with proxy in order to prevent // proxying the rewritten concat url // Basically Url rewritters should all be in one dom walker. return ImmutableList.of( new ConcatVisitor.Js(config, concatUriManager), new ConcatVisitor.Css(config, concatUriManager), new ProxyingVisitor(config, proxyUriManager, ProxyingVisitor.Tags.SCRIPT, ProxyingVisitor.Tags.STYLESHEET, ProxyingVisitor.Tags.EMBEDDED_IMAGES)); } }
private boolean getVisitReserved(String tag, boolean resUrl, boolean resTag, String ... attrs) throws Exception { // Reserved when lower-case and both URL and Tag reserved. String attrName = ALL_RESOURCES.get(tag.toLowerCase()); attrName = attrName != null ? attrName : "src"; ArrayList <String> attrsList = Lists.newArrayList(attrs); attrsList.add(0, attrName); attrsList.add(1, URL_STRING); attrs = attrsList.toArray(attrs); Node node = elem(tag, attrs); ContentRewriterFeature.Config config = createMock(ContentRewriterFeature.Config.class); expect(config.shouldRewriteURL(URL_STRING)).andReturn(resUrl).anyTimes(); expect(config.shouldRewriteTag(tag.toLowerCase())).andReturn(resTag).anyTimes(); replay(config); ProxyingVisitor rewriter = new ProxyingVisitor(config, null, ProxyingVisitor.Tags.SCRIPT, ProxyingVisitor.Tags.STYLESHEET, ProxyingVisitor.Tags.EMBEDDED_IMAGES); VisitStatus status = rewriter.visit(null, node); verify(config); return status != VisitStatus.BYPASS; }
private boolean getVisitReserved(String tag, boolean resUrl, boolean resTag, String ... attrs) throws Exception { // Reserved when lower-case and both URL and Tag reserved. String attrName = ALL_RESOURCES.get(tag.toLowerCase()); attrName = attrName != null ? attrName : "src"; ArrayList <String> attrsList = Lists.newArrayList(attrs); attrsList.add(0, attrName); attrsList.add(1, URL_STRING); attrs = attrsList.toArray(attrs); Node node = elem(tag, attrs); ContentRewriterFeature.Config config = createMock(ContentRewriterFeature.Config.class); expect(config.shouldRewriteURL(URL_STRING)).andReturn(resUrl).anyTimes(); expect(config.shouldRewriteTag(tag.toLowerCase())).andReturn(resTag).anyTimes(); replay(config); ProxyingVisitor rewriter = new ProxyingVisitor(config, null, ProxyingVisitor.Tags.SCRIPT, ProxyingVisitor.Tags.STYLESHEET, ProxyingVisitor.Tags.EMBEDDED_IMAGES); VisitStatus status = rewriter.visit(null, node); verify(config); return status != VisitStatus.BYPASS; }
@Test public void imgWithEmptySrc() throws Exception { Node node = elem("img", "src", ""); ContentRewriterFeature.Config config = createMock(ContentRewriterFeature.Config.class); expect(config.shouldRewriteURL("")).andReturn(true).anyTimes(); expect(config.shouldRewriteTag("img")).andReturn(true).anyTimes(); replay(config); ProxyingVisitor rewriter = new ProxyingVisitor(config, null, ProxyingVisitor.Tags.SCRIPT, ProxyingVisitor.Tags.STYLESHEET, ProxyingVisitor.Tags.EMBEDDED_IMAGES); VisitStatus status = rewriter.visit(null, node); verify(config); assertEquals("Empty attribute should not be rewritten", VisitStatus.BYPASS, status); }
@Test public void imgWithEmptySrc() throws Exception { Node node = elem("img", "src", ""); ContentRewriterFeature.Config config = createMock(ContentRewriterFeature.Config.class); expect(config.shouldRewriteURL("")).andReturn(true).anyTimes(); expect(config.shouldRewriteTag("img")).andReturn(true).anyTimes(); replay(config); ProxyingVisitor rewriter = new ProxyingVisitor(config, null, ProxyingVisitor.Tags.SCRIPT, ProxyingVisitor.Tags.STYLESHEET, ProxyingVisitor.Tags.EMBEDDED_IMAGES); VisitStatus status = rewriter.visit(null, node); verify(config); assertEquals("Empty attribute should not be rewritten", VisitStatus.BYPASS, status); }