[icedtea-web][rfc] Reproducer for PR588, java cookie jar cookies being stored properly

Jiri Vanek jvanek at redhat.com
Fri Aug 10 05:52:25 PDT 2012


On 08/09/2012 10:38 PM, Adam Domurad wrote:
> [Sorry for the independent post - some of my emails from distro-pkg-dev
> seem to have fallen off the face of the earth and I'm not sure how I
> could reply using the archive. ]
>
> As Jiri suggested, I have expanded the reproducer to not only use
> showDocument with session cookies. The tests now also test multiple tabs
> being open, and access after the browser has been closed (does not work
> for session cookies). Permanent cookies are tested for all of these
> tests.
>
> Javaws tests were not included because it was difficult for me to
> produce behaviour where a webstart-like application created cookies and
> was able to read them ... more work to do here later. But for now, these
> should be sufficient for testing the aspects of PR588
>

Fair  enough :) Test looks all in all good, the only (but blocker) issue is that most of the tests 
are constantly FAILING  for me. (f16,jdk6 and f17 jdk7) - only AppletCheckCookieIsntSet and 
AppletSessionCookieSequential looks working :(

The issue is all over the same -  all applets are correctly launched but the cookie previously saved 
is not found.  (iterating cookie map => [])

> ChangeLog:
> 2012-08-09  Adam Domurad<adomurad at redhat.com>
>
> 	Reproducers for PR588, sets persistent and session cookies in the
> 	cookie jar and tries to read them with various means.
> 	* tests/reproducers/signed/SavingCookies/resources/CheckCookie.html:
> 	Print the cookie store contents
> 	*
> tests/reproducers/signed/SavingCookies/resources/CheckCookieAndGotoClear.html:
> 	Print the cookie store contents, and then go to
> 	ClearPersistentCookie.html with showDocument
> 	*
> tests/reproducers/signed/SavingCookies/resources/ClearPersistentCookie.html:
> 	Clear the test cookie so it does not interfere with further tests
> 	*
> tests/reproducers/signed/SavingCookies/resources/SavePersistentCookie.html:
> 	Create a persistent cookie
> 	*
> tests/reproducers/signed/SavingCookies/resources/SavePersistentCookieAndGotoCheck.html:
> 	Create a persistent cookie and check it with showDocument
> 	*
> tests/reproducers/signed/SavingCookies/resources/SaveSessionCookie.html:
> 	Create a session cookie
> 	*
> tests/reproducers/signed/SavingCookies/resources/SaveSessionCookieAndGotoCheck.html:
> 	Create a session cookie and check it with showDocument
> 	* tests/reproducers/signed/SavingCookies/srcs/CheckingCookies.java:
> 	Checks the contents of the cookie store.
> 	Depending on the test, this may go to another page upon completion.
> 	* tests/reproducers/signed/SavingCookies/srcs/SavingCookies.java:
> 	Store cookies in the java cookie store. Depending on the test, this may
> 	go to another page upon completion.
> 	*
> tests/reproducers/signed/SavingCookies/testcases/SavingCookiesTests.java
> 	Test driver for testing persistent and session cookies in different
> 	ways

> +import java.util.HashMap;
> +import java.util.List;
> +import java.util.Map;
> +
> +public class CheckingCookies extends Applet {
> +    static class Killer extends Thread {
> +
> +        public int n = 2000;
> +
> +        @Override
> +        public void run() {
> +            try {
> +                Thread.sleep(n);
> +                System.out.println("Applet killing itself after " + n + " ms of life");
> +                System.exit(0);
> +            } catch (Exception ex) {
> +            }
> +        }
> +    }
> +


You do not need killer in browser. And I see you are not using it. feel free to keep it inside for 
case that javaws reproducers will enter the game.

There are also some unused imports.


> +    static private void printCookieInfo(URI uri) throws IOException {
> +        CookieHandler handler = CookieHandler.getDefault();
> +        Map<String, List<String>> cookieMap = null;
> +
> +        if (handler == null) {
> +            System.out.println("Failing due to lack of CookieHandler class!");
> +            return;
> +        }
> +        System.out.println("Using CookieHandler class: " + handler.getClass().getCanonicalName());
> +
> +        cookieMap = handler.get(uri, new HashMap<String, List<String>>());
> +        for (Map.Entry<String, List<String>> entry : cookieMap.entrySet()) {
> +            System.out.println("Iterating cookiemap with " + entry.getKey() + " => " + entry.getValue());
> +            if (entry.getKey().contains("Cookie")) {
> +                for (String cookie : entry.getValue()) {
> +                    System.out.println("Found cookie: " + cookie);
> +                }
> +            }
> +        }
> +    }
> +
> +    /* If a show-document param was set, go there */
> +    private void gotoNextDocument() {
> +        URL baseURL = getCodeBase();
> +        String nextDocument = getParameter("show-document");
> +        if (nextDocument != null) {
> +            try {
> +                System.out.println("Calling showDocument(" + nextDocument + ")");
> +                getAppletContext().showDocument(new URL(baseURL.toString() + nextDocument));
> +            } catch (Exception e) {
> +                e.printStackTrace();
> +            }
> +        }
> +    }
> +
> +    @Override
> +    public void start() {
> +        System.out.println("Entered CheckingCookies.java");
> +        try {
> +            printCookieInfo(getCodeBase().toURI());
> +        } catch (Exception e) {
> +            e.printStackTrace();
> +        }
> +        System.out.println("Finished CheckingCookies.java");
> +
> +        gotoNextDocument();
> +    }
> +}
> diff --git a/tests/reproducers/signed/SavingCookies/srcs/SavingCookies.java b/tests/reproducers/signed/SavingCookies/srcs/SavingCookies.java
> new file mode 100644
...

This is no magic -  you launch process, you are getting its stdout/err. Then you launch second 
process - and it does nothing more then forward handling of of its job to first process. So Second 
process die, and first one is (correctly)

> +        //XXX: It is necessary to check save.pr's stdout, because it does not show up in 'check.stdout' for some reason
> +        Assert.assertTrue("stdout should contain '" + COOKIE_SESSION_CHECK + "' but did not.", save.pr.stdout.contains(COOKIE_SESSION_CHECK));
> +    }
> +
> +    @Test
> +    @TestInBrowsers(testIn = { Browsers.one })
> +    @Bug(id = "PR588")
> +    public void AppletSessionCookieSequential() throws Exception {
> +        ProcessResult save = server.executeBrowser("/SaveSessionCookie.html");
> +        ProcessResult check = server.executeBrowser("/CheckCookie.html");
> +        Assert.assertTrue("stdout should contain '" + ENTERING_CHECK + "' but did not.", check.stdout.contains(ENTERING_CHECK));
> +        //Session cookies should NOT be intact upon browser close and re-open
> +        Assert.assertFalse("stdout should NOT contain '" + COOKIE_SESSION_CHECK + "' but did.", check.stdout.contains(COOKIE_SESSION_CHECK));
> +    }
> +
> +    @Test
> +    @TestInBrowsers(testIn = { Browsers.one })
> +    @Bug(id = "PR588")
> +    public void AppletPersistentCookieShowDoc() throws Exception {
> +        ProcessResult pr = server.executeBrowser("/SavePersistentCookieAndGotoCheck.html");
> +
> +        Assert.assertTrue("stdout should contain '" + ENTERING_CHECK + "' but did not.", pr.stdout.contains(ENTERING_CHECK));
> +        Assert.assertTrue("stdout should contain '" + COOKIE_PERSISTENT_CHECK + "' but did not.", pr.stdout.contains(COOKIE_PERSISTENT_CHECK));
> +    }
> +
> +    @Test
> +    @TestInBrowsers(testIn = { Browsers.one })
> +    @Bug(id = "PR588")
> +    public void AppletPersistentCookieSequential() throws Exception {
> +        ProcessResult save = server.executeBrowser("/SavePersistentCookie.html");
> +        //Use show doc to clear cookie afterwards
> +        ProcessResult check = server.executeBrowser("/CheckCookieAndGotoClear.html");
> +        Assert.assertTrue("stdout should contain '" + ENTERING_CHECK + "' but did not.", check.stdout.contains(ENTERING_CHECK));
> +        //Persistent cookies should be stored past this point
> +        Assert.assertTrue("stdout should contain '" + COOKIE_PERSISTENT_CHECK + "' but did not.", check.stdout.contains(COOKIE_PERSISTENT_CHECK));
> +    }
> +
> +}
> \ No newline at end of file
>




More information about the distro-pkg-dev mailing list