Search in sources :

Example 21 with Browser

use of org.eclipse.swt.browser.Browser in project eclipse.platform.swt by eclipse.

the class Test_org_eclipse_swt_browser_Browser method test_VisibilityWindowListener_multiple_shells.

/**
 * Verify that if multiple child shells are open, no duplicate visibility events are sent.
 */
@Test
public void test_VisibilityWindowListener_multiple_shells() {
    AtomicBoolean secondChildCompleted = new AtomicBoolean(false);
    AtomicInteger childCount = new AtomicInteger(0);
    browser.addOpenWindowListener(event -> {
        Shell childShell = new Shell(shell);
        childShell.setText("Child shell " + childCount.get());
        childShell.setLayout(new FillLayout());
        Browser browserChild = new Browser(childShell, SWT.NONE);
        event.browser = browserChild;
        browserChild.setText("Child window");
        browserChild.addVisibilityWindowListener(new VisibilityWindowAdapter() {

            AtomicInteger invocationCount = new AtomicInteger(1);

            AtomicInteger childID = new AtomicInteger(childCount.get());

            @Override
            public void show(WindowEvent event) {
                if (childID.get() == 0 && invocationCount.get() >= 2) {
                    // are considered 'legal' as long as they don't contain size and location information.
                    if (event.location != null || event.size != null) {
                        fail("Child browser's visibility show listener should only be fired once");
                    }
                }
                invocationCount.incrementAndGet();
            }
        });
        if (childCount.get() == 1) {
            browserChild.addProgressListener(new ProgressAdapter() {

                @Override
                public void completed(ProgressEvent event) {
                    secondChildCompleted.set(true);
                }
            });
        }
        childShell.open();
        childCount.incrementAndGet();
    });
    shell.open();
    browser.setText("<html>" + "<script type='text/javascript'>" + // opens child window.
    "window.open();" + "window.open();" + "</script>\n" + "<body>This test uses javascript to open a new window.</body></html>");
    boolean passed = waitForPassCondition(() -> secondChildCompleted.get());
    String errMsg = "\nTest timed out.";
    assertTrue(errMsg, passed);
}
Also used : VisibilityWindowAdapter(org.eclipse.swt.browser.VisibilityWindowAdapter) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Shell(org.eclipse.swt.widgets.Shell) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) WindowEvent(org.eclipse.swt.browser.WindowEvent) FillLayout(org.eclipse.swt.layout.FillLayout) ProgressAdapter(org.eclipse.swt.browser.ProgressAdapter) ProgressEvent(org.eclipse.swt.browser.ProgressEvent) Browser(org.eclipse.swt.browser.Browser) Test(org.junit.Test)

Example 22 with Browser

use of org.eclipse.swt.browser.Browser in project eclipse.platform.swt by eclipse.

the class Test_org_eclipse_swt_browser_Browser method test_ConstructorLorg_eclipse_swt_widgets_CompositeI.

/**
 * Test that if Browser is constructed with the parent being "null", Browser throws an exception.
 */
@Override
@Test(expected = IllegalArgumentException.class)
public void test_ConstructorLorg_eclipse_swt_widgets_CompositeI() {
    Browser browser = new Browser(shell, SWT.NONE);
    browser.dispose();
    browser = new Browser(shell, SWT.BORDER);
    // System.out.println("Test_org_eclipse_swt_browser_Browser#test_Constructor*#getBrowserType(): " + browser.getBrowserType());
    browser.dispose();
    // Should throw.
    browser = new Browser(null, SWT.NONE);
}
Also used : Browser(org.eclipse.swt.browser.Browser) Test(org.junit.Test)

Example 23 with Browser

use of org.eclipse.swt.browser.Browser in project eclipse.platform.swt by eclipse.

the class Test_org_eclipse_swt_browser_Browser method test_CloseWindowListener_closeShell.

@Test
public void test_CloseWindowListener_closeShell() {
    Display display = Display.getCurrent();
    Shell shell = new Shell(display);
    Browser browser = new Browser(shell, SWT.NONE);
    // shouldn't throw
    browser.addCloseWindowListener(event -> {
    });
    shell.close();
}
Also used : Shell(org.eclipse.swt.widgets.Shell) Display(org.eclipse.swt.widgets.Display) Browser(org.eclipse.swt.browser.Browser) Test(org.junit.Test)

Example 24 with Browser

use of org.eclipse.swt.browser.Browser in project eclipse.platform.swt by eclipse.

the class Test_org_eclipse_swt_browser_Browser method test_OpenWindowListener_closeShell.

@Test
public void test_OpenWindowListener_closeShell() {
    Display display = Display.getCurrent();
    Shell shell = new Shell(display);
    Browser browser = new Browser(shell, SWT.NONE);
    browser.addOpenWindowListener(event -> {
    });
    shell.close();
}
Also used : Shell(org.eclipse.swt.widgets.Shell) Display(org.eclipse.swt.widgets.Display) Browser(org.eclipse.swt.browser.Browser) Test(org.junit.Test)

Example 25 with Browser

use of org.eclipse.swt.browser.Browser in project eclipse.platform.swt by eclipse.

the class Test_org_eclipse_swt_browser_Browser method test_BrowserFunction_callback_with_boolean.

/**
 * Test that javascript can call java and pass a Boolean to java.
 * loosely based on Snippet307.
 */
@Test
public void test_BrowserFunction_callback_with_boolean() {
    // On webkit1, this test works if ran on it's own. But sometimes in test-suite with other tests it causes jvm crash.
    // culprit seems to be the main_context_iteration() call in shell.setVisible().
    // See Bug 509587.  Solution: Webkit2.
    assumeFalse(webkit1SkipMsg(), isWebkit1);
    AtomicBoolean javaCallbackExecuted = new AtomicBoolean(false);
    class JavascriptCallback extends // Note: Local class defined inside method.
    BrowserFunction {

        JavascriptCallback(Browser browser, String name) {
            super(browser, name);
        }

        @Override
        public Object function(Object[] arguments) {
            Boolean returnBool = (Boolean) arguments[0];
            javaCallbackExecuted.set(returnBool);
            return null;
        }
    }
    String htmlWithScript = "<html><head>\n" + "<script language=\"JavaScript\">\n" + // Define a javascript function.
    "function callCustomFunction() {\n" + "     document.body.style.backgroundColor = 'red'\n" + // This calls the javafunction that we registered.
    "		jsCallbackToJava(true)\n" + "}" + "</script>\n" + "</head>\n" + "<body> I'm going to make a callback to java </body>\n" + "</html>\n";
    browser.setText(htmlWithScript);
    new JavascriptCallback(browser, "jsCallbackToJava");
    browser.addProgressListener(callCustomFunctionUponLoad);
    shell.open();
    boolean passed = waitForPassCondition(() -> javaCallbackExecuted.get());
    String message = "Javascript did not pass a boolean back to java";
    assertTrue(message, passed);
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) BrowserFunction(org.eclipse.swt.browser.BrowserFunction) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Browser(org.eclipse.swt.browser.Browser) Test(org.junit.Test)

Aggregations

Browser (org.eclipse.swt.browser.Browser)62 Shell (org.eclipse.swt.widgets.Shell)26 Display (org.eclipse.swt.widgets.Display)25 Test (org.junit.Test)22 FillLayout (org.eclipse.swt.layout.FillLayout)19 GridData (org.eclipse.swt.layout.GridData)16 IOException (java.io.IOException)13 ProgressEvent (org.eclipse.swt.browser.ProgressEvent)13 Composite (org.eclipse.swt.widgets.Composite)13 BrowserFunction (org.eclipse.swt.browser.BrowserFunction)12 LocationEvent (org.eclipse.swt.browser.LocationEvent)12 URL (java.net.URL)11 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)11 ProgressListener (org.eclipse.swt.browser.ProgressListener)11 WindowEvent (org.eclipse.swt.browser.WindowEvent)11 GridLayout (org.eclipse.swt.layout.GridLayout)11 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)10 LocationAdapter (org.eclipse.swt.browser.LocationAdapter)10 LocationListener (org.eclipse.swt.browser.LocationListener)10 ProgressAdapter (org.eclipse.swt.browser.ProgressAdapter)10