Search in sources :

Example 1 with ProgressListener.completedAdapter

use of org.eclipse.swt.browser.ProgressListener.completedAdapter in project eclipse.platform.swt by eclipse.

the class Test_org_eclipse_swt_browser_Browser method test_evalute_Cookies.

@Test
public void test_evalute_Cookies() {
    final AtomicBoolean loaded = new AtomicBoolean(false);
    browser.addProgressListener(ProgressListener.completedAdapter(event -> loaded.set(true)));
    // Using JavaScript Cookie API on local (file) URL gives DOM Exception 18
    browser.setUrl("http://www.eclipse.org/swt");
    waitForPassCondition(() -> loaded.get());
    // Set the cookies
    // document.cookie behaves different from other global vars
    browser.evaluate("document.cookie = \"cookie1=value1\";");
    browser.evaluate("document.cookie = \"cookie2=value2\";");
    // Retrieve entire cookie store
    String res = (String) browser.evaluate("return document.cookie;");
    assertTrue(!res.isEmpty());
}
Also used : HttpURLConnection(java.net.HttpURLConnection) StatusTextListener(org.eclipse.swt.browser.StatusTextListener) URL(java.net.URL) Assume.assumeFalse(org.junit.Assume.assumeFalse) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) LocationAdapter(org.eclipse.swt.browser.LocationAdapter) CloseWindowListener(org.eclipse.swt.browser.CloseWindowListener) ProgressListener(org.eclipse.swt.browser.ProgressListener) TitleListener(org.eclipse.swt.browser.TitleListener) VisibilityWindowAdapter(org.eclipse.swt.browser.VisibilityWindowAdapter) AtomicReference(java.util.concurrent.atomic.AtomicReference) Supplier(java.util.function.Supplier) Point(org.eclipse.swt.graphics.Point) AtomicReferenceArray(java.util.concurrent.atomic.AtomicReferenceArray) BrowserFunction(org.eclipse.swt.browser.BrowserFunction) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ProgressEvent(org.eclipse.swt.browser.ProgressEvent) TestName(org.junit.rules.TestName) LocationListener.changedAdapter(org.eclipse.swt.browser.LocationListener.changedAdapter) VisibilityWindowListener.showAdapter(org.eclipse.swt.browser.VisibilityWindowListener.showAdapter) WindowEvent(org.eclipse.swt.browser.WindowEvent) LocationListener(org.eclipse.swt.browser.LocationListener) ProgressListener.completedAdapter(org.eclipse.swt.browser.ProgressListener.completedAdapter) Assert.fail(org.junit.Assert.fail) SWTException(org.eclipse.swt.SWTException) VisibilityWindowListener(org.eclipse.swt.browser.VisibilityWindowListener) FillLayout(org.eclipse.swt.layout.FillLayout) AtomicIntegerArray(java.util.concurrent.atomic.AtomicIntegerArray) Before(org.junit.Before) OpenWindowListener(org.eclipse.swt.browser.OpenWindowListener) ProgressAdapter(org.eclipse.swt.browser.ProgressAdapter) Browser(org.eclipse.swt.browser.Browser) Shell(org.eclipse.swt.widgets.Shell) MalformedURLException(java.net.MalformedURLException) Assert.assertNotNull(org.junit.Assert.assertNotNull) Assert.assertTrue(org.junit.Assert.assertTrue) IOException(java.io.IOException) Test(org.junit.Test) Display(org.eclipse.swt.widgets.Display) Instant(java.time.Instant) LocationListener.changingAdapter(org.eclipse.swt.browser.LocationListener.changingAdapter) Assert.assertNull(org.junit.Assert.assertNull) Rule(org.junit.Rule) Assert.assertFalse(org.junit.Assert.assertFalse) SWT(org.eclipse.swt.SWT) LocationEvent(org.eclipse.swt.browser.LocationEvent) Assume.assumeTrue(org.junit.Assume.assumeTrue) Assert.assertEquals(org.junit.Assert.assertEquals) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Test(org.junit.Test)

Example 2 with ProgressListener.completedAdapter

use of org.eclipse.swt.browser.ProgressListener.completedAdapter in project eclipse.platform.swt by eclipse.

the class Test_org_eclipse_swt_browser_Browser method test_ClearAllSessionCookies.

@Test
public void test_ClearAllSessionCookies() {
    if (isWebkit2) {
        // clearSessions will only work for Webkit2 when >= 2.16
        assumeTrue(webkitGtkVersionInts[1] >= 16);
    }
    final AtomicBoolean loaded = new AtomicBoolean(false);
    browser.addProgressListener(ProgressListener.completedAdapter(event -> loaded.set(true)));
    // Using JavaScript Cookie API on local (file) URL gives DOM Exception 18
    browser.setUrl("http://www.eclipse.org/swt");
    waitForPassCondition(() -> loaded.get());
    // Set the cookies
    if (isWebkit2) {
        // TODO: Remove this once Webkit2 Cookie port complete
        browser.evaluate("document.cookie = \"cookie1=value1\";");
        browser.evaluate("document.cookie = \"cookie2=value2\";");
    } else {
        Browser.setCookie("cookie1=value1", "http://www.eclipse.org/swt");
        Browser.setCookie("cookie2=value2", "http://www.eclipse.org/swt");
    }
    // Get the cookies
    String v1, v2;
    if (isWebkit2) {
        // TODO: Remove this once Webkit2 Cookie port complete
        v1 = (String) browser.evaluate(toCookieEvalString("cookie1"));
        v2 = (String) browser.evaluate(toCookieEvalString("cookie2"));
    } else {
        v1 = Browser.getCookie("cookie1", "http://www.eclipse.org/swt");
        v2 = Browser.getCookie("cookie2", "http://www.eclipse.org/swt");
    }
    assertEquals("value1", v1);
    assertEquals("value2", v2);
    Browser.clearSessions();
    // Should be empty
    String e1, e2;
    if (isWebkit2) {
        // TODO: Remove this once Webkit2 Cookie port complete
        e1 = (String) browser.evaluate(toCookieEvalString("cookie1"));
        e2 = (String) browser.evaluate(toCookieEvalString("cookie2"));
    } else {
        e1 = Browser.getCookie("cookie1", "http://www.eclipse.org/swt");
        e2 = Browser.getCookie("cookie2", "http://www.eclipse.org/swt");
    }
    assertTrue(e1 == null || e1.isEmpty());
    assertTrue(e2 == null || e2.isEmpty());
}
Also used : HttpURLConnection(java.net.HttpURLConnection) StatusTextListener(org.eclipse.swt.browser.StatusTextListener) URL(java.net.URL) Assume.assumeFalse(org.junit.Assume.assumeFalse) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) LocationAdapter(org.eclipse.swt.browser.LocationAdapter) CloseWindowListener(org.eclipse.swt.browser.CloseWindowListener) ProgressListener(org.eclipse.swt.browser.ProgressListener) TitleListener(org.eclipse.swt.browser.TitleListener) VisibilityWindowAdapter(org.eclipse.swt.browser.VisibilityWindowAdapter) AtomicReference(java.util.concurrent.atomic.AtomicReference) Supplier(java.util.function.Supplier) Point(org.eclipse.swt.graphics.Point) AtomicReferenceArray(java.util.concurrent.atomic.AtomicReferenceArray) BrowserFunction(org.eclipse.swt.browser.BrowserFunction) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ProgressEvent(org.eclipse.swt.browser.ProgressEvent) TestName(org.junit.rules.TestName) LocationListener.changedAdapter(org.eclipse.swt.browser.LocationListener.changedAdapter) VisibilityWindowListener.showAdapter(org.eclipse.swt.browser.VisibilityWindowListener.showAdapter) WindowEvent(org.eclipse.swt.browser.WindowEvent) LocationListener(org.eclipse.swt.browser.LocationListener) ProgressListener.completedAdapter(org.eclipse.swt.browser.ProgressListener.completedAdapter) Assert.fail(org.junit.Assert.fail) SWTException(org.eclipse.swt.SWTException) VisibilityWindowListener(org.eclipse.swt.browser.VisibilityWindowListener) FillLayout(org.eclipse.swt.layout.FillLayout) AtomicIntegerArray(java.util.concurrent.atomic.AtomicIntegerArray) Before(org.junit.Before) OpenWindowListener(org.eclipse.swt.browser.OpenWindowListener) ProgressAdapter(org.eclipse.swt.browser.ProgressAdapter) Browser(org.eclipse.swt.browser.Browser) Shell(org.eclipse.swt.widgets.Shell) MalformedURLException(java.net.MalformedURLException) Assert.assertNotNull(org.junit.Assert.assertNotNull) Assert.assertTrue(org.junit.Assert.assertTrue) IOException(java.io.IOException) Test(org.junit.Test) Display(org.eclipse.swt.widgets.Display) Instant(java.time.Instant) LocationListener.changingAdapter(org.eclipse.swt.browser.LocationListener.changingAdapter) Assert.assertNull(org.junit.Assert.assertNull) Rule(org.junit.Rule) Assert.assertFalse(org.junit.Assert.assertFalse) SWT(org.eclipse.swt.SWT) LocationEvent(org.eclipse.swt.browser.LocationEvent) Assume.assumeTrue(org.junit.Assume.assumeTrue) Assert.assertEquals(org.junit.Assert.assertEquals) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Test(org.junit.Test)

Example 3 with ProgressListener.completedAdapter

use of org.eclipse.swt.browser.ProgressListener.completedAdapter in project eclipse.platform.swt by eclipse.

the class Test_org_eclipse_swt_browser_Browser method test_get_set_Cookies.

@Test
public void test_get_set_Cookies() {
    assumeFalse("Not implemented on webkit2 yet. Bug 522181.", isWebkit2);
    final AtomicBoolean loaded = new AtomicBoolean(false);
    browser.addProgressListener(ProgressListener.completedAdapter(event -> loaded.set(true)));
    // Using JavaScript Cookie API on local (file) URL gives DOM Exception 18
    browser.setUrl("http://www.eclipse.org/swt");
    waitForPassCondition(() -> loaded.get());
    // Set the cookies
    Browser.setCookie("cookie1=value1", "http://www.eclipse.org/swt");
    Browser.setCookie("cookie2=value2", "http://www.eclipse.org/swt");
    // Get the cookies
    String v1 = Browser.getCookie("cookie1", "http://www.eclipse.org/swt");
    assertEquals("value1", v1);
    String v2 = Browser.getCookie("cookie2", "http://www.eclipse.org/swt");
    assertEquals("value2", v2);
}
Also used : HttpURLConnection(java.net.HttpURLConnection) StatusTextListener(org.eclipse.swt.browser.StatusTextListener) URL(java.net.URL) Assume.assumeFalse(org.junit.Assume.assumeFalse) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) LocationAdapter(org.eclipse.swt.browser.LocationAdapter) CloseWindowListener(org.eclipse.swt.browser.CloseWindowListener) ProgressListener(org.eclipse.swt.browser.ProgressListener) TitleListener(org.eclipse.swt.browser.TitleListener) VisibilityWindowAdapter(org.eclipse.swt.browser.VisibilityWindowAdapter) AtomicReference(java.util.concurrent.atomic.AtomicReference) Supplier(java.util.function.Supplier) Point(org.eclipse.swt.graphics.Point) AtomicReferenceArray(java.util.concurrent.atomic.AtomicReferenceArray) BrowserFunction(org.eclipse.swt.browser.BrowserFunction) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ProgressEvent(org.eclipse.swt.browser.ProgressEvent) TestName(org.junit.rules.TestName) LocationListener.changedAdapter(org.eclipse.swt.browser.LocationListener.changedAdapter) VisibilityWindowListener.showAdapter(org.eclipse.swt.browser.VisibilityWindowListener.showAdapter) WindowEvent(org.eclipse.swt.browser.WindowEvent) LocationListener(org.eclipse.swt.browser.LocationListener) ProgressListener.completedAdapter(org.eclipse.swt.browser.ProgressListener.completedAdapter) Assert.fail(org.junit.Assert.fail) SWTException(org.eclipse.swt.SWTException) VisibilityWindowListener(org.eclipse.swt.browser.VisibilityWindowListener) FillLayout(org.eclipse.swt.layout.FillLayout) AtomicIntegerArray(java.util.concurrent.atomic.AtomicIntegerArray) Before(org.junit.Before) OpenWindowListener(org.eclipse.swt.browser.OpenWindowListener) ProgressAdapter(org.eclipse.swt.browser.ProgressAdapter) Browser(org.eclipse.swt.browser.Browser) Shell(org.eclipse.swt.widgets.Shell) MalformedURLException(java.net.MalformedURLException) Assert.assertNotNull(org.junit.Assert.assertNotNull) Assert.assertTrue(org.junit.Assert.assertTrue) IOException(java.io.IOException) Test(org.junit.Test) Display(org.eclipse.swt.widgets.Display) Instant(java.time.Instant) LocationListener.changingAdapter(org.eclipse.swt.browser.LocationListener.changingAdapter) Assert.assertNull(org.junit.Assert.assertNull) Rule(org.junit.Rule) Assert.assertFalse(org.junit.Assert.assertFalse) SWT(org.eclipse.swt.SWT) LocationEvent(org.eclipse.swt.browser.LocationEvent) Assume.assumeTrue(org.junit.Assume.assumeTrue) Assert.assertEquals(org.junit.Assert.assertEquals) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Test(org.junit.Test)

Aggregations

IOException (java.io.IOException)3 HttpURLConnection (java.net.HttpURLConnection)3 MalformedURLException (java.net.MalformedURLException)3 URL (java.net.URL)3 Instant (java.time.Instant)3 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 AtomicIntegerArray (java.util.concurrent.atomic.AtomicIntegerArray)3 AtomicReference (java.util.concurrent.atomic.AtomicReference)3 AtomicReferenceArray (java.util.concurrent.atomic.AtomicReferenceArray)3 Supplier (java.util.function.Supplier)3 SWT (org.eclipse.swt.SWT)3 SWTException (org.eclipse.swt.SWTException)3 Browser (org.eclipse.swt.browser.Browser)3 BrowserFunction (org.eclipse.swt.browser.BrowserFunction)3 CloseWindowListener (org.eclipse.swt.browser.CloseWindowListener)3 LocationAdapter (org.eclipse.swt.browser.LocationAdapter)3 LocationEvent (org.eclipse.swt.browser.LocationEvent)3 LocationListener (org.eclipse.swt.browser.LocationListener)3 LocationListener.changedAdapter (org.eclipse.swt.browser.LocationListener.changedAdapter)3