public static Gadget makeGadget(GadgetContext context) { try { final GadgetSpec spec = new GadgetSpec(context.getUrl(), "<Module><ModulePrefs author=\"a\" title=\"t\"></ModulePrefs>" + "<Content></Content></Module>"); return new Gadget().setSpec(spec).setContext(context); } catch (Exception e) { throw new RuntimeException("Unexpected boilerplate parse failure"); } }
public static Gadget makeGadget(GadgetContext context) { try { final GadgetSpec spec = new GadgetSpec(context.getUrl(), "<Module><ModulePrefs author=\"a\" title=\"t\"></ModulePrefs>" + "<Content></Content></Module>"); return new Gadget().setSpec(spec).setContext(context); } catch (Exception e) { throw new RuntimeException("Unexpected boilerplate parse failure"); } }
public static Gadget makeGadget(GadgetContext context) { try { final GadgetSpec spec = new GadgetSpec(context.getUrl(), "<Module><ModulePrefs author=\"a\" title=\"t\"></ModulePrefs>" + "<Content></Content></Module>"); return new Gadget().setSpec(spec).setContext(context); } catch (Exception e) { throw new RuntimeException("Unexpected boilerplate parse failure"); } }
private Gadget mockGadget(boolean nocache, boolean debug, boolean isContainer) { GadgetContext context = createMock(GadgetContext.class); expect(context.getContainer()).andReturn(CONTAINER).anyTimes(); expect(context.getIgnoreCache()).andReturn(nocache).anyTimes(); expect(context.getDebug()).andReturn(debug).anyTimes(); expect(context.getUrl()).andReturn(GADGET_URI).anyTimes(); expect(context.getRenderingContext()).andReturn( isContainer ? RenderingContext.CONTAINER : RenderingContext.GADGET).anyTimes(); replay(context); return new Gadget().setContext(context); }
@Before @Override public void setUp() throws Exception { super.setUp(); gadget = new Gadget().setContext(unsanitaryGadgetContext); gadget.setSpec(new GadgetSpec(Uri.parse("http://www.example.org/gadget.xml"), "<Module><ModulePrefs title=''/><Content type='x-html-sanitized'/></Module>")); gadget.setCurrentView(gadget.getSpec().getViews().values().iterator().next()); gadgetNoCacheAndDebug = new Gadget().setContext(unsanitaryGadgetContextNoCacheAndDebug); gadgetNoCacheAndDebug.setSpec(new GadgetSpec(Uri.parse("http://www.example.org/gadget.xml"), "<Module><ModulePrefs title=''/><Content type='x-html-sanitized'/></Module>")); gadgetNoCacheAndDebug.setCurrentView(gadgetNoCacheAndDebug.getSpec().getViews().values().iterator().next()); }
private Gadget makeGadget(String content) throws GadgetException { GadgetSpec spec = new GadgetSpec(SPEC_URL, "<Module><ModulePrefs title=''/><Content><![CDATA[" + content + "]]></Content></Module>"); return new Gadget() .setSpec(spec) .setContext(CONTEXT) .setCurrentView(spec.getView("default")); }
private Gadget makeGadget(String content) throws GadgetException { GadgetSpec spec = new GadgetSpec(SPEC_URL, "<Module><ModulePrefs title=''/><Content><![CDATA[" + content + "]]></Content></Module>"); return new Gadget() .setSpec(spec) .setContext(CONTEXT) .setCurrentView(spec.getView("default")); }
private Gadget makeGadget(String content) throws GadgetException { GadgetSpec spec = new GadgetSpec(SPEC_URL, "<Module><ModulePrefs title=''/><Content><![CDATA[" + content + "]]></Content></Module>"); return new Gadget() .setSpec(spec) .setContext(CONTEXT) .setCurrentView(spec.getView("default")); }
private Gadget makeGadget(String content) throws GadgetException { GadgetSpec spec = new GadgetSpec(SPEC_URL, "<Module><ModulePrefs title=''/><Content><![CDATA[" + content + "]]></Content></Module>"); return new Gadget() .setSpec(spec) .setContext(CONTEXT) .setCurrentView(spec.getView("default")); }
private Gadget makeGadget(String content) throws GadgetException { GadgetSpec spec = new GadgetSpec(SPEC_URL, "<Module><ModulePrefs title=''/><Content><![CDATA[" + content + "]]></Content></Module>"); return new Gadget() .setSpec(spec) .setContext(CONTEXT) .setCurrentView(spec.getView("default")); }
private Gadget makeGadget(String content) throws GadgetException { GadgetSpec spec = new GadgetSpec(SPEC_URL, "<Module><ModulePrefs title=''/><Content><![CDATA[" + content + "]]></Content></Module>"); return new Gadget() .setSpec(spec) .setContext(CONTEXT) .setCurrentView(spec.getView("default")); }
@Test public void doesNothingWhenNotSanitized() throws Exception { String markup = "<script src=\"http://evil.org/evil\"></script> <b>hello</b>"; Gadget gadget = new Gadget().setContext(unsanitaryGadgetContext); gadget.setSpec(new GadgetSpec(Uri.parse("www.example.org/gadget.xml"), "<Module><ModulePrefs title=''/><Content type='html'/></Module>")); gadget.setCurrentView(gadget.getSpec().getViews().values().iterator().next()); assertEquals(markup, rewrite(gadget, markup, set("b"), set())); }
@Test public void doesNothingWhenNotSanitized() throws Exception { String markup = "<script src=\"http://evil.org/evil\"></script> <b>hello</b>"; Gadget gadget = new Gadget().setContext(unsanitaryGadgetContext); gadget.setSpec(new GadgetSpec(Uri.parse("www.example.org/gadget.xml"), "<Module><ModulePrefs title=''/><Content type='html'/></Module>")); gadget.setCurrentView(gadget.getSpec().getViews().values().iterator().next()); assertEquals(markup, rewrite(gadget, markup, set("b"), set())); }
@Test public void doesNothingWhenNotSanitized() throws Exception { String markup = "<script src=\"http://evil.org/evil\"></script> <b>hello</b>"; Gadget gadget = new Gadget().setContext(unsanitaryGadgetContext); gadget.setSpec(new GadgetSpec(Uri.parse("www.example.org/gadget.xml"), "<Module><ModulePrefs title=''/><Content type='html'/></Module>")); gadget.setCurrentView(gadget.getSpec().getViews().values().iterator().next()); assertEquals(markup, rewrite(gadget, markup, set("b"), set())); }
@Test public void getLocale() throws Exception { Gadget gadget = new Gadget() .setContext(context) .setSpec(new GadgetSpec(Uri.parse(SPEC_URL), SPEC_XML)); LocaleSpec localeSpec = gadget.getLocale(); assertEquals("VALUE", localeSpec.getMessageBundle().getMessages().get("name")); }
@Test public void getLocale() throws Exception { Gadget gadget = new Gadget() .setContext(context) .setSpec(new GadgetSpec(Uri.parse(SPEC_URL), SPEC_XML)); LocaleSpec localeSpec = gadget.getLocale(); assertEquals("VALUE", localeSpec.getMessageBundle().getMessages().get("name")); }
@Test public void getLocale() throws Exception { Gadget gadget = new Gadget() .setContext(context) .setSpec(new GadgetSpec(Uri.parse(SPEC_URL), SPEC_XML)); LocaleSpec localeSpec = gadget.getLocale(); assertEquals("VALUE", localeSpec.getMessageBundle().getMessages().get("name")); }
private void setupGadget(String gadgetXml) throws SpecParserException { gadgetSpec = new GadgetSpec(GADGET_URI, gadgetXml); gadget = new Gadget(); gadget.setSpec(gadgetSpec); gadget.setContext(new GadgetContext() {}); gadget.setCurrentView(gadgetSpec.getView("default")); content = new MutableContent(new NekoSimplifiedHtmlParser( new ParseModule.DOMImplementationProvider().get()), gadget.getCurrentView().getContent()); }
private void setupGadget(String gadgetXml) throws SpecParserException { gadgetSpec = new GadgetSpec(GADGET_URI, gadgetXml); gadget = new Gadget(); gadget.setSpec(gadgetSpec); gadget.setContext(new GadgetContext() {}); gadget.setCurrentView(gadgetSpec.getView("default")); content = new MutableContent(new NekoSimplifiedHtmlParser( new ParseModule.DOMImplementationProvider().get()), gadget.getCurrentView().getContent()); }
private void setupGadget(String gadgetXml) throws SpecParserException { gadgetSpec = new GadgetSpec(GADGET_URI, gadgetXml); gadget = new Gadget(); gadget.setSpec(gadgetSpec); gadget.setContext(new GadgetContext() {}); gadget.setCurrentView(gadgetSpec.getView("default")); content = new MutableContent(new NekoSimplifiedHtmlParser( new ParseModule.DOMImplementationProvider().get()), gadget.getCurrentView().getContent()); }