Skip to main content
aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorLeo Ufimtsev2017-11-06 11:52:38 -0500
committerLeo Ufimtsev2017-12-01 13:45:15 -0500
commit8009c3b86dee4f50191b785f9c121ef5cdd24746 (patch)
tree5f6294dc2ffef1f164dda77b88c91b00de2fe096 /tests
parent382c1d03f132e44887b0dcb83fdb7f7578ef9db2 (diff)
downloadeclipse.platform.swt-8009c3b86dee4f50191b785f9c121ef5cdd24746.tar.gz
eclipse.platform.swt-8009c3b86dee4f50191b785f9c121ef5cdd24746.tar.xz
eclipse.platform.swt-8009c3b86dee4f50191b785f9c121ef5cdd24746.zip
Bug 510905 [Webkit2] BrowserFunction with return value back to
Javascript (PRIOR TO MERGING, SWT BINARY REPO NEEDS TO BE PATCHED) Webkit2 moved it's webprocess into a separate process. For javascript to call a function, it needs to do so via the separate process. To interact with the separate process, we need to implement a webextension, which is a separate '.so' file loaded at run time. The extension needs to reside in it's own folder otherwise webkit will try to load the other .so files as extensions. (See Library.java changes). Communication between the extension and the main process is done via a gdbus channel. Javascript/Java types are packaged into GVariants and transmitted via gdbus. Compilation of the webextension requires webkit2gtk package to be present on build servers. Tests: - All jUnits pass - SWT Snippet (307) that use BrowserFunction work. - Attached local snippet can be used to test sending various paramaters over gdbus and receiving them back prints to main webview. - Child eclipse works fine with the patch. - Afaik, no known error/warnings are produced. (If there are, let me know). This might break 32bit build of SWT though, not tested on 32 bit. Patch set log: -------------- Patchset 6: - Passing webview as string in javascript function. Patchset 8: - Implemented dynamic gdbus bindigs on SWT/Java side. Works. (fairly large patch) Patchset 9: - Implemented gdbus bindings on client side, such that it can reach server. (working) Patchset 10: - Added GVariant conversion functions on SWT side. Works. - Moved code out of OS.java to reside only in WebKitGTK Patchset 11: - Figured out how to provide return value as an object array. Added snippet to show how to provide a string return value. (working) Patchset 12: - Passed webview pointer, index and token to Java. - Fixed typo in type definition. > (Working) Patchset 13: - Now passing javascript arguments along through gdbus to java. > (Working) Patchset 14: (Week 46) - Implemented support for 'null'. (use byte as magic number). - Found that there is a bug in how I deal with return value in gdbus, gdbus returns an array (always). Need to return first item in array. Patchset 15: (Week 46) - Implemented proper return value of java to javascript. - Found that js calls with no paramaters call() fail, need to fix. Patchset 16: (Week 46) - Implemented support for empty arrays (including calls without args). - Code tidy. - Found that I need to implement input argument verification from JS call and from java code ran by user, otherwise gdbus can crash. Patchset 17: (Week 46) - Implement checking of user-input arguments, to ensure it won't break gdbus connection. Patchset 18: (Week 46) - Implemented checking of return value from userfunction, so bad return value doesn't break gdbus. - Code tidy/polish. - Need to implement lazy loading of gdbus, only init gdbus for the first function that we instantiate. - Also still getting warning when loading webkit library. Patchset 19: [Week 47] - Implemented lazy loading of gdbus, to only load when needed. - wrapped getPID() into lock, otherwise had strange debug/execution behaviour. Patchset 20: [Week 47] - Two BrowserInstances with Two BrowserFunctions seem to hang (snippet), (need to investigate) Patchset 21: [W47] - Removed redundant print statements. Cleaned up code. Patchset 22: [W47] - Moved Webkit extension initialization logic into a callback, so that it's guaranteed to be loaded at the most optimal time. (All jUnits pass). Patchset 23: [W47] - Removed redundant println. Patchset 24: [W47] - Implemented mechanism by which webextension is compiled and loaded from a folder. (This needs a patch to binary project's build.properties) Patchset 25: [W47] - Code tidy. Patch complete (ish). Patchset 26: [W47] - forgot to add files to patchset 25. Patchset 27: [W47] - Verified that Browser widget will continue to work if webextension fails to load. - Added relevant warnings. Patchset 28: - Minor update on SWT_LIB_VERSIONS. Change-Id: Iccfc48bc78774ac4120aafd976186381f247c562 Signed-off-by: Leo Ufimtsev <lufimtse@redhat.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/org.eclipse.swt.tests.gtk/Bug Snippets/org/eclipse/swt/tests/gtk/snippets/Bug510905_Browser_JsConsole.java111
-rw-r--r--tests/org.eclipse.swt.tests.gtk/Bug Snippets/org/eclipse/swt/tests/gtk/snippets/Bug510905_Browser_TwoJsConsoles.java115
-rw-r--r--tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_browser_Browser.java4
3 files changed, 226 insertions, 4 deletions
diff --git a/tests/org.eclipse.swt.tests.gtk/Bug Snippets/org/eclipse/swt/tests/gtk/snippets/Bug510905_Browser_JsConsole.java b/tests/org.eclipse.swt.tests.gtk/Bug Snippets/org/eclipse/swt/tests/gtk/snippets/Bug510905_Browser_JsConsole.java
new file mode 100644
index 0000000000..638591f827
--- /dev/null
+++ b/tests/org.eclipse.swt.tests.gtk/Bug Snippets/org/eclipse/swt/tests/gtk/snippets/Bug510905_Browser_JsConsole.java
@@ -0,0 +1,111 @@
+package org.eclipse.swt.tests.gtk.snippets;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.browser.Browser;
+import org.eclipse.swt.browser.BrowserFunction;
+import org.eclipse.swt.events.KeyAdapter;
+import org.eclipse.swt.events.KeyEvent;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Text;
+
+/*
+ * Title: [GTK3][Webkit2] Implement webkit2 support for browser function (Part 2: Java return a value from callback.)
+ * How to run: Snippet to execute javascript via input prompt, to test Browser Func return value ability.
+ * Bug description:
+ * Expected results:
+ * GTK Version(s):
+ */
+public class Bug510905_Browser_JsConsole {
+
+ static int count = 0;
+
+ public static void main(String[] args) {
+ Display display = new Display();
+ Shell shell = new Shell(display);
+ shell.setSize(500, 600);
+
+ GridLayout gridLayout = new GridLayout();
+ shell.setLayout(gridLayout);
+
+ final Text jsConsole = new Text(shell, SWT.BORDER);
+// jsConsole.setText("document.body.innerHTML = theJavaFunction(123, 'hello', null, true)");
+ jsConsole.setText("document.body.innerHTML = theJavaFunction()"); // Case where there are no paramaters.
+ jsConsole.setSelection(jsConsole.getText().length());
+ GridData data = new GridData(SWT.FILL, SWT.BEGINNING, true, false);
+ jsConsole.setLayoutData(data);
+
+ final Browser browser = new Browser(shell, SWT.NONE);
+ browser.setText("hello <b>world!</b>");
+ data = new GridData(SWT.FILL, SWT.FILL, true, true);
+ browser.setLayoutData(data);
+
+ jsConsole.addKeyListener(new KeyAdapter() {
+ @Override
+ public void keyPressed(KeyEvent e) {
+ if (e.keyCode == 13) { // 13 = Enter
+ browser.execute(jsConsole.getText());
+ }
+ }
+ });
+
+ Button loadNewPage = new Button(shell, SWT.PUSH);
+ loadNewPage.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
+ loadNewPage.setText("Load new Page");
+ loadNewPage.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ browser.setText("New page!" + count++);
+ }
+ });
+
+
+ // BrowserFunction Code
+ @SuppressWarnings("unused")
+ final BrowserFunction function = new CustomFunction (browser, "theJavaFunction");
+
+ shell.open();
+ while (!shell.isDisposed()) {
+ if (!display.readAndDispatch())
+ display.sleep();
+ }
+ display.dispose();
+ }
+
+ static class CustomFunction extends BrowserFunction { // copied from snippet 307
+ CustomFunction (Browser browser, String name) {
+ super (browser, name);
+ }
+ @Override
+ public Object function (Object[] arguments) {
+ System.out.println ("theJavaFunction() called from javascript with args:");
+ for (int i = 0; i < arguments.length; i++) {
+ Object arg = arguments[i];
+ if (arg == null) {
+ System.out.println ("\t-->null");
+ } else {
+ System.out.println ("\t-->" + arg.getClass ().getName () + ": " + arg.toString ());
+ }
+ }
+ return arguments;
+// return new Point(1, 2);
+
+// Object returnValue = new Object[] {
+// new Short ((short)3),
+// new Boolean (true),
+// null,
+// new Object[] {"a string", new Boolean (false)},
+// "hi",
+// new Float (2.0f / 3.0f),
+// };
+// return returnValue;
+
+// return new Double(42.0);
+ }
+ }
+}
diff --git a/tests/org.eclipse.swt.tests.gtk/Bug Snippets/org/eclipse/swt/tests/gtk/snippets/Bug510905_Browser_TwoJsConsoles.java b/tests/org.eclipse.swt.tests.gtk/Bug Snippets/org/eclipse/swt/tests/gtk/snippets/Bug510905_Browser_TwoJsConsoles.java
new file mode 100644
index 0000000000..f3dcacc4d7
--- /dev/null
+++ b/tests/org.eclipse.swt.tests.gtk/Bug Snippets/org/eclipse/swt/tests/gtk/snippets/Bug510905_Browser_TwoJsConsoles.java
@@ -0,0 +1,115 @@
+package org.eclipse.swt.tests.gtk.snippets;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.browser.Browser;
+import org.eclipse.swt.browser.BrowserFunction;
+import org.eclipse.swt.events.KeyAdapter;
+import org.eclipse.swt.events.KeyEvent;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.layout.RowLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Text;
+
+/*
+ * Title: [GTK3][Webkit2] Implement webkit2 support for browser function (Part 2: Java return a value from callback.)
+ * How to run: Snippet to execute javascript via input prompt, to test Browser Func return value ability.
+ * Bug description:
+ * Expected results:
+ * GTK Version(s):
+ */
+public class Bug510905_Browser_TwoJsConsoles {
+
+ static int count = 0;
+
+ public static void main(String[] args) {
+ Display display = new Display();
+ Shell shell = new Shell(display);
+ shell.setSize(500, 600);
+
+ shell.setLayout(new RowLayout());
+
+ Composite leftBrowser = new Composite(shell, SWT.NONE);
+ Composite rightBrowser = new Composite(shell, SWT.None);
+ Button button = new Button (rightBrowser, SWT.PUSH);
+ button.setText("my button");
+
+
+ final Browser browser = makeBrowserWithConsole(leftBrowser, "theJavaFunction");
+ new CustomFunction (browser, "theJavaFunction");
+
+ final Browser browser2 = makeBrowserWithConsole(rightBrowser, "theJavaFunction");
+ new CustomFunction (browser2, "theJavaFunction");
+
+ shell.open();
+ while (!shell.isDisposed()) {
+ if (!display.readAndDispatch())
+ display.sleep();
+ }
+ display.dispose();
+ }
+
+ /**
+ * @param leftBrowser
+ * @return
+ */
+ private static Browser makeBrowserWithConsole(Composite leftBrowser, String funcName) {
+ GridLayout gridLayout = new GridLayout();
+ leftBrowser.setLayout(gridLayout);
+
+ final Text jsConsole = new Text(leftBrowser, SWT.BORDER);
+ jsConsole.setText("document.body.innerHTML = " + funcName + "(123)"); // Case where there are no paramaters.
+ jsConsole.setSelection(jsConsole.getText().length());
+ GridData data = new GridData(SWT.FILL, SWT.BEGINNING, true, false);
+ jsConsole.setLayoutData(data);
+
+ final Browser browser = new Browser(leftBrowser, SWT.NONE);
+ browser.setText("hello <b>world!</b>");
+ data = new GridData(SWT.FILL, SWT.FILL, true, true);
+ browser.setLayoutData(data);
+
+ jsConsole.addKeyListener(new KeyAdapter() {
+ @Override
+ public void keyPressed(KeyEvent e) {
+ if (e.keyCode == 13) { // 13 = Enter
+ browser.execute(jsConsole.getText());
+ }
+ }
+ });
+
+ Button loadNewPage = new Button(leftBrowser, SWT.PUSH);
+ loadNewPage.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
+ loadNewPage.setText("Load new Page");
+ loadNewPage.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ browser.setText("New page!" + count++);
+ }
+ });
+ return browser;
+ }
+
+ static class CustomFunction extends BrowserFunction { // copied from snippet 307
+ CustomFunction (Browser browser, String name) {
+ super (browser, name);
+ }
+ @Override
+ public Object function (Object[] arguments) {
+ System.out.println ("theJavaFunction() called from javascript with args:");
+ for (int i = 0; i < arguments.length; i++) {
+ Object arg = arguments[i];
+ if (arg == null) {
+ System.out.println ("\t-->null");
+ } else {
+ System.out.println ("\t-->" + arg.getClass ().getName () + ": " + arg.toString ());
+ }
+ }
+ return arguments;
+ }
+ }
+}
diff --git a/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_browser_Browser.java b/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_browser_Browser.java
index 1c3deb9241..5aa58f2aa7 100644
--- a/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_browser_Browser.java
+++ b/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_browser_Browser.java
@@ -2082,10 +2082,6 @@ public void test_BrowserFunction_callback_with_javaReturningInt () {
// culprit seems to be the main_context_iteration() call in shell.setVisible().
// See Bug 509587. Solution: Webkit2.
assumeFalse(webkit1SkipMsg(), isWebkit1);
-
- // Skip till Bug 510905 is implemented.
- assumeFalse("Skipping test_BrowserFunction_callback_with_javaReturningInt. Java's callback to Javascript doesn't support return yet", isWebkit2);
-
AtomicInteger returnInt = new AtomicInteger(0);
class JavascriptCallback extends BrowserFunction { // Note: Local class defined inside method.

Back to the top