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.

JavascriptManagerTest.java 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /*
  2. * Copyright 2000-2014 Vaadin Ltd.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy of
  6. * the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations under
  14. * the License.
  15. */
  16. package com.vaadin.tests.extensions;
  17. import com.vaadin.server.VaadinRequest;
  18. import com.vaadin.tests.components.AbstractTestUI;
  19. import com.vaadin.tests.util.Log;
  20. import com.vaadin.ui.JavaScript;
  21. import com.vaadin.ui.JavaScriptFunction;
  22. import elemental.json.JsonArray;
  23. import elemental.json.JsonNull;
  24. public class JavascriptManagerTest extends AbstractTestUI {
  25. private Log log = new Log(5);
  26. @Override
  27. protected void setup(VaadinRequest request) {
  28. addComponent(log);
  29. final JavaScript js = JavaScript.getCurrent();
  30. js.addFunction("testing.doTest", new JavaScriptFunction() {
  31. @Override
  32. public void call(JsonArray arguments) {
  33. log.log("Got " + arguments.length() + " arguments");
  34. log.log("Argument 1 as a number: " + (int) arguments.getNumber(0));
  35. log.log("Argument 2 as a string: " + arguments.getString(1));
  36. log.log("Argument 3.p as a boolean: "
  37. + arguments.getObject(2).getBoolean("p"));
  38. log.log("Argument 4 is JSONObject.NULL: "
  39. + (arguments.get(3) instanceof JsonNull));
  40. js.removeFunction("testing.doTest");
  41. }
  42. });
  43. js.execute("window.testing.doTest(42, 'text', {p: true}, null)");
  44. }
  45. @Override
  46. protected String getTestDescription() {
  47. return "Test javascript callback handling by adding a callback and invoking the javascript.";
  48. }
  49. @Override
  50. protected Integer getTicketNumber() {
  51. // TODO Auto-generated method stub
  52. return null;
  53. }
  54. }