Skip to main content
aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorRoland Grunberg2017-11-08 13:43:21 -0500
committerLeo Ufimtsev2017-11-20 17:00:52 -0500
commit04e1259bd25fb90406f30ad787e0ab94f0107ff4 (patch)
treeab8c2786e33cd1c31be90d4d30d4f6a8dd769fb7 /tests
parentc4dbd5147969b56fcdab866aeb8a9539a7bdf1d1 (diff)
downloadeclipse.platform.swt-04e1259bd25fb90406f30ad787e0ab94f0107ff4.tar.gz
eclipse.platform.swt-04e1259bd25fb90406f30ad787e0ab94f0107ff4.tar.xz
eclipse.platform.swt-04e1259bd25fb90406f30ad787e0ab94f0107ff4.zip
Bug 522181: [Webkit2] Implement clearSessions() on WebKit2.
The WebKit2 implementation of clearSessions() will remove session and non-session (those with an expiry) cookies. The API specifies only the former shall be removed but there is no way to be more selective for now. Tested on WEBKIT1 and WEBKIT2 using the JUnit test provided. The general test approach involves manipulating cookies through javascript. Some additional tests have also been added. test_evaluate_Cookie acts as a sanity check for the correct functioning of 'document.cookie' and the browser.evaluate() functionality. test_get_set_Cookies will eventually help with further implementation of the Cookie API on WEBKIT2. Change-Id: Icc17fe90bf4de38c8d5f0fbb7b5937552ce33d54 Signed-off-by: Roland Grunberg <rgrunber@redhat.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_browser_Browser.java107
1 files changed, 107 insertions, 0 deletions
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 86def025c6..1c3deb9241 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
@@ -150,6 +150,113 @@ public void test_ConstructorLorg_eclipse_swt_widgets_CompositeI() {
browser = new Browser(null, SWT.NONE); // Should throw.
}
+
+@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());
+}
+
+@Test
+public void test_ClearAllSessionCookies () {
+ 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());
+}
+
+/**
+ * TODO: Remove this once Webkit2 Cookie port complete
+ */
+private String toCookieEvalString (String key) {
+ return "var name = \"" + key + "=\";\n" +
+ " var decodedCookie = decodeURIComponent(document.cookie);\n" +
+ " var ca = decodedCookie.split(';');\n" +
+ " for(var i = 0; i < ca.length; i++) {\n" +
+ " var c = ca[i];\n" +
+ " while (c.charAt(0) == ' ') {\n" +
+ " c = c.substring(1);\n" +
+ " }\n" +
+ " if (c.indexOf(name) == 0) {\n" +
+ " return c.substring(name.length, c.length);\n" +
+ " }\n" +
+ " }\n" +
+ " return \"\";";
+}
+
+@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);
+}
+
@Override
@Test
public void test_getChildren() {

Back to the top