Debian Codegraph @

tests/reproducers/signed/SavingCookies/testcases/SavingCookiesTests.java

raw
1 /* SavingCookieTests.java
2 Copyright (C) 2011 Red Hat, Inc.
3
4 This file is part of IcedTea.
5
6 IcedTea is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, version 2.
9
10 IcedTea is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with IcedTea; see the file COPYING. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 02110-1301 USA.
19
20 Linking this library statically or dynamically with other modules is
21 making a combined work based on this library. Thus, the terms and
22 conditions of the GNU General Public License cover the whole
23 combination.
24
25 As a special exception, the copyright holders of this library give you
26 permission to link this library with independent modules to produce an
27 executable, regardless of the license terms of these independent
28 modules, and to copy and distribute the resulting executable under
29 terms of your choice, provided that you also meet, for each linked
30 independent module, the terms and conditions of the license of that
31 module. An independent module is a module which is not derived from
32 or based on this library. If you modify this library, you may extend
33 this exception to your version of the library, but you are not
34 obligated to do so. If you do not wish to do so, delete this
35 exception statement from your version.
36 */
37
38 import java.util.Arrays;
39 import java.util.Collections;
40 import java.util.List;
41
42 import net.sourceforge.jnlp.ContentReaderListener;
43 import net.sourceforge.jnlp.ProcessResult;
44 import net.sourceforge.jnlp.annotations.Bug;
45 import net.sourceforge.jnlp.annotations.TestInBrowsers;
46 import net.sourceforge.jnlp.browsertesting.BrowserTest;
47 import net.sourceforge.jnlp.browsertesting.Browsers;
48 import org.junit.Assert;
49
50 import org.junit.Test;
51
52 public class SavingCookiesTests extends BrowserTest {
53
54 static final String ENTERING_CHECK = "Entered CheckingCookies";
55 static final String CHECKING_COMPLETION = "Finished CheckingCookies";
56 static final String SAVING_COMPLETION = "Finished SavingCookies";
57 private final static List<String> TRUSTALL = Collections.unmodifiableList(Arrays.asList(new String[] { "-Xtrustall" }));
58
59 static class ParallelRun extends Thread {
60
61 ParallelRun(String url, String completionString) {
62 this.url = url;
63 this.completionString = completionString;
64 this.completed = false;
65 }
66
67 ProcessResult pr;
68 private String url;
69 private String completionString;
70 volatile boolean completed;
71
72 @Override
73 public void run() {
74 try {
75 final ContentReaderListener stdoutListener = new ContentReaderListener() {
76 @Override
77 public void charReaded(char ch) {
78 }
79
80 @Override
81 public synchronized void lineReaded(String s) {
82 if (completionString != null && s.contains(completionString)) {
83 completed = true;
84 }
85 }
86 };
87 if (url.endsWith(".html")) {
88 pr = server.executeBrowser(url, stdoutListener, null);
89 } else if (url.endsWith(".jnlp")) {
90 pr = server.executeJavawsHeadless(TRUSTALL, url, stdoutListener, null, null);
91 }
92 } catch (Exception ex) {
93 throw new RuntimeException(ex);
94 } finally {
95 completed = true;
96 }
97 }
98 }
99
100 final String COOKIE_SESSION_CHECK = "Found cookie: TEST=session";
101 final String COOKIE_PERSISTENT_CHECK = "Found cookie: TEST=persistent";
102
103 @Test
104 @TestInBrowsers(testIn = { Browsers.one })
105 public void AppletCheckCookieIsntSet() throws Exception {
106 final String COOKIE_SANITY_CHECK = "Found cookie: TEST=";
107 ProcessResult pr = server.executeBrowser("/CheckCookie.html");
108
109 Assert.assertFalse("stdout should NOT contain '" + COOKIE_SANITY_CHECK + "' but did.", pr.stdout.contains(COOKIE_SANITY_CHECK));
110 Assert.assertTrue("stdout should contain '" + CHECKING_COMPLETION + "' but did not.", pr.stdout.contains(CHECKING_COMPLETION));
111 }
112
113 @Test
114 @TestInBrowsers(testIn = { Browsers.one })
115 @Bug(id = "PR588")
116 public void AppletSessionCookieShowDoc() throws Exception {
117 ProcessResult pr = server.executeBrowser("/SaveSessionCookieAndGotoCheck.html");
118
119 Assert.assertTrue("stdout should contain '" + ENTERING_CHECK + "' but did not.", pr.stdout.contains(ENTERING_CHECK));
120 Assert.assertTrue("stdout should contain '" + COOKIE_SESSION_CHECK + "' but did not.", pr.stdout.contains(COOKIE_SESSION_CHECK));
121 }
122
123 @Test
124 @TestInBrowsers(testIn = { Browsers.one })
125 @Bug(id = "PR588")
126 public void AppletSessionCookieParallel() throws Exception {
127 ParallelRun save = new ParallelRun("/SaveSessionCookie.html", SAVING_COMPLETION);
128 save.start();
129 while (!save.completed) {
130 Thread.sleep(100);
131 }
132
133 ProcessResult check = server.executeBrowser("/CheckCookie.html");
134 save.join();
135
136 Assert.assertTrue("stdout should contain '" + ENTERING_CHECK + "' but did not.", save.pr.stdout.contains(ENTERING_CHECK));
137 //XXX: It is necessary to check save.pr's stdout, because it does not show up in 'check.stdout' for some reason
138 Assert.assertTrue("stdout should contain '" + COOKIE_SESSION_CHECK + "' but did not.", save.pr.stdout.contains(COOKIE_SESSION_CHECK));
139 }
140
141 @Test
142 @TestInBrowsers(testIn = { Browsers.one })
143 @Bug(id = "PR588")
144 public void AppletSessionCookieSequential() throws Exception {
145 ProcessResult save = server.executeBrowser("/SaveSessionCookie.html");
146 ProcessResult check = server.executeBrowser("/CheckCookie.html");
147 Assert.assertTrue("stdout should contain '" + ENTERING_CHECK + "' but did not.", check.stdout.contains(ENTERING_CHECK));
148 //Session cookies should NOT be intact upon browser close and re-open
149 Assert.assertFalse("stdout should NOT contain '" + COOKIE_SESSION_CHECK + "' but did.", check.stdout.contains(COOKIE_SESSION_CHECK));
150 }
151
152 @Test
153 @TestInBrowsers(testIn = { Browsers.one })
154 @Bug(id = "PR588")
155 public void AppletPersistentCookieShowDoc() throws Exception {
156 ProcessResult pr = server.executeBrowser("/SavePersistentCookieAndGotoCheck.html");
157
158 Assert.assertTrue("stdout should contain '" + ENTERING_CHECK + "' but did not.", pr.stdout.contains(ENTERING_CHECK));
159 Assert.assertTrue("stdout should contain '" + COOKIE_PERSISTENT_CHECK + "' but did not.", pr.stdout.contains(COOKIE_PERSISTENT_CHECK));
160 }
161
162 @Test
163 @TestInBrowsers(testIn = { Browsers.one })
164 @Bug(id = "PR588")
165 public void AppletPersistentCookieSequential() throws Exception {
166 ProcessResult save = server.executeBrowser("/SavePersistentCookie.html");
167 //Use show doc to clear cookie afterwards
168 ProcessResult check = server.executeBrowser("/CheckCookieAndGotoClear.html");
169 Assert.assertTrue("stdout should contain '" + ENTERING_CHECK + "' but did not.", check.stdout.contains(ENTERING_CHECK));
170 //Persistent cookies should be stored past this point
171 Assert.assertTrue("stdout should contain '" + COOKIE_PERSISTENT_CHECK + "' but did not.", check.stdout.contains(COOKIE_PERSISTENT_CHECK));
172 }
173
174 }