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.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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.LegacyWindow;
  5. import com.vaadin.ui.Panel;
  6. import com.vaadin.ui.VerticalLayout;
  7. public class ExecuteJavaScript extends AbstractTestCase {
  8. @Override
  9. public void init() {
  10. final LegacyWindow mainWindow = new LegacyWindow("Test");
  11. setMainWindow(mainWindow);
  12. for (final String script : new String[] { "alert('foo');",
  13. "window.print()", "document.write('foo')" }) {
  14. VerticalLayout pl = new VerticalLayout();
  15. pl.setMargin(true);
  16. Panel p = new Panel("Example: " + script, pl);
  17. pl.addComponent(createScriptButton(script));
  18. mainWindow.addComponent(p);
  19. }
  20. }
  21. private Button createScriptButton(final String script) {
  22. Button b = new Button(script);
  23. b.addClickListener(event -> getMainWindow().executeJavaScript(script));
  24. return b;
  25. }
  26. @Override
  27. protected String getDescription() {
  28. return "Test for the Window.executeJavaScript method. Click a button to execute the javascript";
  29. }
  30. @Override
  31. protected Integer getTicketNumber() {
  32. return 3589;
  33. }
  34. }