You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ExecuteJavaScript.java 1.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. package com.vaadin.tests.components.window;
  2. import com.vaadin.tests.components.AbstractTestCase;
  3. import com.vaadin.ui.Button;
  4. import com.vaadin.ui.Button.ClickEvent;
  5. import com.vaadin.ui.LegacyWindow;
  6. import com.vaadin.ui.Panel;
  7. import com.vaadin.ui.VerticalLayout;
  8. public class ExecuteJavaScript extends AbstractTestCase {
  9. @Override
  10. public void init() {
  11. final LegacyWindow mainWindow = new LegacyWindow("Test");
  12. setMainWindow(mainWindow);
  13. for (final String script : new String[] { "alert('foo');",
  14. "window.print()", "document.write('foo')" }) {
  15. VerticalLayout pl = new VerticalLayout();
  16. pl.setMargin(true);
  17. Panel p = new Panel("Example: " + script, pl);
  18. pl.addComponent(createScriptButton(script));
  19. mainWindow.addComponent(p);
  20. }
  21. }
  22. private Button createScriptButton(final String script) {
  23. Button b = new Button(script);
  24. b.addListener(new Button.ClickListener() {
  25. @Override
  26. public void buttonClick(ClickEvent event) {
  27. getMainWindow().executeJavaScript(script);
  28. }
  29. });
  30. return b;
  31. }
  32. @Override
  33. protected String getDescription() {
  34. return "Test for the Window.executeJavaScript method. Click a button to execute the javascript";
  35. }
  36. @Override
  37. protected Integer getTicketNumber() {
  38. return 3589;
  39. }
  40. }