private void assertUrlRewritten(String tagName, String attr, String orig, String rewritten) throws Exception { String markUp = "<" + tagName + " " + attr + "=\"" + orig + "\">"; String expected = attr + "=\"" + rewritten + "\""; testMarkup(markUp, expected); }
private void assertUrlRewritten(String tagName, String attr, String orig, String rewritten) throws Exception { String markUp = "<" + tagName + " " + attr + "=\"" + orig + "\">"; String expected = attr + "=\"" + rewritten + "\""; testMarkup(markUp, expected); }
private void testMarkup(String markup, String expected) throws GadgetException{ testMarkup(markup, expected, null); }
private void testMarkup(String markup, String expected) throws GadgetException{ testMarkup(markup, expected, null); }
@Test public void testErrorDuringRewrite() throws Exception { String markup = "<script>window['x']={}; with(x) {};</script>"; String expected = "<html><head></head><body><ul class=\"gadgets-messages\">"; List<String> messages = ImmutableList.of( ""with" blocks are not allowed"); testMarkup(markup, expected, messages); }
@Test public void testCssExpression() throws Exception { String markup = "<div style='top:expression(alert(0), 0)'>test</div>"; String expected = "<div>test</div>"; List<String> messages = ImmutableList.of( "css property top has bad value: ==>expression(alert(0), 0)"); testMarkup(markup, expected, messages); }
@Test public void testCssExpression() throws Exception { String markup = "<div style='top:expression(alert(0), 0)'>test</div>"; String expected = "<div>test</div>"; List<String> messages = ImmutableList.of( "css property top has bad value: ==>expression(alert(0), 0)"); testMarkup(markup, expected, messages); }
@Test public void testErrorDuringRewrite() throws Exception { String markup = "<script>window['x']={}; with(x) {};</script>"; String expected = "<html><head></head><body><ul class=\"gadgets-messages\">"; List<String> messages = ImmutableList.of( ""with" blocks are not allowed"); testMarkup(markup, expected, messages); }
@Test public void testRewrite() throws Exception { String markup = "<script>window['a']=0;</script>"; String expected = "caja___.start"; List<String> messages = ImmutableList.of(); testMarkup(markup, expected, messages); }
@Test public void testRewrite() throws Exception { String markup = "<script>window['a']=0;</script>"; String expected = "caja___.start"; List<String> messages = ImmutableList.of(); testMarkup(markup, expected, messages); }
public void testIncludedURLRequestMarkedInternal() throws Exception { CacheProvider lru = new LruCacheProvider(3); DefaultHtmlSerializer defaultSerializer = new DefaultHtmlSerializer(); CapturingPipeline pipeline = new CapturingPipeline(); rewriter = new CajaContentRewriter(lru, pipeline, defaultSerializer, proxyUriManager) { @Override protected PluginCompiler makePluginCompiler(PluginMeta m, MessageQueue q) { BuildInfo bi = EasyMock.createNiceMock(BuildInfo.class); expect(bi.getBuildInfo()).andReturn("bi").anyTimes(); expect(bi.getBuildTimestamp()).andReturn("0").anyTimes(); expect(bi.getBuildVersion()).andReturn("0").anyTimes(); expect(bi.getCurrentTime()).andReturn(0L).anyTimes(); replay(bi); return new PluginCompiler(bi, m, q); } }; // we don't really care what the result looks like, we just want to check the issued request String markup = "<script type=\"text/javascript\" src=\"http://www.example.com/scripts/scriptFile.js\"></script>"; String expected = ""; testMarkup( markup, expected ); assertNotNull( pipeline.request ); assertTrue( pipeline.request.isInternalRequest() ); }
public void testIncludedURLRequestMarkedInternal() throws Exception { CacheProvider lru = new LruCacheProvider(3); DefaultHtmlSerializer defaultSerializer = new DefaultHtmlSerializer(); CapturingPipeline pipeline = new CapturingPipeline(); rewriter = new CajaContentRewriter(lru, pipeline, defaultSerializer, proxyUriManager) { @Override protected PluginCompiler makePluginCompiler(PluginMeta m, MessageQueue q) { BuildInfo bi = EasyMock.createNiceMock(BuildInfo.class); expect(bi.getBuildInfo()).andReturn("bi").anyTimes(); expect(bi.getBuildTimestamp()).andReturn("0").anyTimes(); expect(bi.getBuildVersion()).andReturn("0").anyTimes(); expect(bi.getCurrentTime()).andReturn(0L).anyTimes(); replay(bi); return new PluginCompiler(bi, m, q); } }; // we don't really care what the result looks like, we just want to check the issued request String markup = "<script type=\"text/javascript\" src=\"http://www.example.com/scripts/scriptFile.js\"></script>"; String expected = ""; testMarkup( markup, expected ); assertNotNull( pipeline.request ); assertTrue( pipeline.request.isInternalRequest() ); }