1 /* CodebasesAttsNoDialogsTest1.java
2  Copyright (C) 2013 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.io.File;
39 import java.io.FileNotFoundException;
40 import java.io.FileOutputStream;
41 import java.io.IOException;
42 import java.io.InputStream;
43 import java.io.OutputStream;
44 import java.net.URL;
45 import java.util.AbstractMap;
46 import java.util.ArrayList;
47 import java.util.Arrays;
48 import java.util.Enumeration;
49 import java.util.List;
50 import java.util.zip.ZipEntry;
51 import java.util.zip.ZipFile;
52 import java.util.zip.ZipOutputStream;
53 import net.sourceforge.jnlp.OptionsDefinitions;
54 import net.sourceforge.jnlp.ProcessResult;
55 import net.sourceforge.jnlp.ProcessWrapper;
56 import net.sourceforge.jnlp.ServerAccess;
57 import net.sourceforge.jnlp.ServerLauncher;
58 import net.sourceforge.jnlp.annotations.Bug;
59 import net.sourceforge.jnlp.annotations.NeedsDisplay;
60 import net.sourceforge.jnlp.annotations.TestInBrowsers;
61 import net.sourceforge.jnlp.browsertesting.BrowserTest;
62 import static net.sourceforge.jnlp.browsertesting.BrowserTest.server;
63 import net.sourceforge.jnlp.browsertesting.Browsers;
64 import net.sourceforge.jnlp.closinglisteners.AutoErrorClosingListener;
65 import net.sourceforge.jnlp.closinglisteners.AutoOkClosingListener;
66 import net.sourceforge.jnlp.config.DeploymentConfiguration;
67 import net.sourceforge.jnlp.runtime.ManifestAttributesChecker;
68 import net.sourceforge.jnlp.security.appletextendedsecurity.AppletSecurityLevel;
69 import net.sourceforge.jnlp.tools.DeploymentPropertiesModifier;
70 import net.sourceforge.jnlp.util.FileUtils;
71 import org.junit.AfterClass;
72 
73 import org.junit.Assert;
74 import org.junit.BeforeClass;
75 import org.junit.Test;
76 
77 /**
78  *
79  * null, empty, none, wrong, correct jnlp x html different codebases.
80  *
81  * no dialogs should be appeared. Second testsuite with ALL dialogs (head only)
82  *
83  *
84  */
85 public class CodebasesAttsDialogsTest1 extends BrowserTest {
86 
87     private static final String appletCloseString = CodebasesAttsNoDialogsTest1.appletCloseString;
88     private static final String[] JAVAWS_HTML_ARRAY = CodebasesAttsNoDialogsTest1.JAVAWS_HTML_ARRAY;
89     private static final List<String> JAVAWS_HTML_LIST = CodebasesAttsNoDialogsTest1.JAVAWS_HTML_LIST;
90     //disabled - 1.6 specific. We need dialogs to pop up.  Anyway, in 1.6 all such tests are disbaled for runtime anyway
91     private static final String[] JAVAWS_HEADLES_ARRAY = new String[]{};//{OptionsDefinitions.OPTIONS.HTML.HEADLESS.option};
92     private static final List<String> JAVAWS_HEADLES_LIST = Arrays.asList(JAVAWS_HEADLES_ARRAY);
93 
94     private static final String JNLPAPP = CodebasesAttsNoDialogsTest1.JNLPAPP;
95     private static final String JNLPAPPLET = CodebasesAttsNoDialogsTest1.JNLPAPPLET;
96     private static final String HTML = CodebasesAttsNoDialogsTest1.HTML;
97     private static final String HTMLHREF = CodebasesAttsNoDialogsTest1.HTMLHREF;
98     private static final String CodebasesAtts = CodebasesAttsNoDialogsTest1.CodebasesAtts;
99 
100     private static ServerLauncher secondValidServer;
101     private static DeploymentPropertiesModifier.MultipleDeploymentPropertiesModifier ensuredDP;
102 
103     public static final String[] files = new String[]{"CodebasesAttsApp.jnlp", "CodebasesAtts.html", "CodebasesAttsApplet.jnlp", "CodebasesAttsJnlpHref.html"};
104 
105     @BeforeClass
initSecondaryServers()106     public static void initSecondaryServers() throws IOException {
107         secondValidServer = ServerAccess.getIndependentInstanceOnTmpDir();
108     }
109 
110     @AfterClass
stopSecondaryServers()111     public static void stopSecondaryServers() throws IOException {
112         secondValidServer.stop();
113     }
114 
115     @BeforeClass
setProperties()116     public static void setProperties() throws IOException {
117         ensuredDP = new DeploymentPropertiesModifier.MultipleDeploymentPropertiesModifier(
118                 new AbstractMap.SimpleEntry(DeploymentConfiguration.KEY_ENABLE_MANIFEST_ATTRIBUTES_CHECK, ManifestAttributesChecker.MANIFEST_ATTRIBUTES_CHECK.ALL.name()),
119                 new AbstractMap.SimpleEntry(DeploymentConfiguration.KEY_SECURITY_LEVEL, AppletSecurityLevel.ASK_UNSIGNED.name())
120         );
121         ensuredDP.setProperties();
122     }
123 
124     @AfterClass
resetProperties()125     public static void resetProperties() throws IOException {
126         ensuredDP.restoreProperties();
127     }
128 
129     @Test
allTestsInThisFileAreDisabled()130     public void allTestsInThisFileAreDisabled(){
131         //because 1.6 do not support headless dialogues
132     }
133 
134     @NeedsDisplay
135     //@Test
136     @Bug(id = "PR2489")
codebasesAttsTestWorksJnlp1_null()137     public void codebasesAttsTestWorksJnlp1_null() throws Exception {
138         prepare(null);
139         ProcessWrapper pw = new ProcessWrapper(server.getJavawsLocation(), JAVAWS_HEADLES_LIST, server.getUrl(JNLPAPP));
140         pw.addStdOutListener(new AutoOkClosingListener());
141         pw.addStdErrListener(new AutoErrorClosingListener());
142         //pw.setWriter("YES\nYES\nYES\nYES\n");
143         ProcessResult pr = pw.execute();
144         Assert.assertTrue(pr.stdout.contains(appletCloseString));
145         Assert.assertTrue(pr.stdout.contains(CodebasesAtts));
146         Assert.assertTrue(pr.stdout.contains("id: 1"));
147         Assert.assertTrue(pr.stdout.contains("BID0"));
148     }
149 
150     @NeedsDisplay
151     //@Test
152     @Bug(id = "PR2489")
codebasesAttsTestWorksJnlp2_null()153     public void codebasesAttsTestWorksJnlp2_null() throws Exception {
154         prepare(null);
155         ProcessWrapper pw = new ProcessWrapper(server.getJavawsLocation(), JAVAWS_HEADLES_LIST, server.getUrl(JNLPAPPLET));
156         pw.addStdOutListener(new AutoOkClosingListener());
157         pw.addStdErrListener(new AutoErrorClosingListener());
158         //pw.setWriter("YES\nYES\nYES\nYES\n");
159         ProcessResult pr = pw.execute();
160         Assert.assertTrue(pr.stdout.contains(appletCloseString));
161         Assert.assertTrue(pr.stdout.contains(CodebasesAtts));
162         Assert.assertTrue(pr.stdout.contains("id: 1"));
163         Assert.assertTrue(pr.stdout.contains("BID0"));
164     }
165 
166     @NeedsDisplay
167     //@Test  //rowsers dont support headless dialogues
168     @TestInBrowsers(testIn = Browsers.one)
169     @Bug(id = "PR2489")
codebasesAttsTestWorksHtml1_null()170     public void codebasesAttsTestWorksHtml1_null() throws Exception {
171         prepare(null);
172         ProcessResult pr = server.executeBrowser(null, HTML, new AutoOkClosingListener(), new AutoErrorClosingListener());
173         Assert.assertTrue(pr.stdout.contains(appletCloseString));
174         Assert.assertTrue(pr.stdout.contains(CodebasesAtts));
175         Assert.assertTrue(pr.stdout.contains("id: 1"));
176         Assert.assertTrue(pr.stdout.contains("BID0"));
177     }
178 
179     @NeedsDisplay
180     //@Test //browsers do not support ehadless dialogues
181     @TestInBrowsers(testIn = Browsers.one)
182     @Bug(id = "PR2489")
codebasesAttsTestWorksHtml2_null()183     public void codebasesAttsTestWorksHtml2_null() throws Exception {
184         prepare(null);
185         ProcessResult pr = server.executeBrowser(null, HTMLHREF, new AutoOkClosingListener(), new AutoErrorClosingListener());
186         Assert.assertTrue(pr.stdout.contains(appletCloseString));
187         Assert.assertTrue(pr.stdout.contains(CodebasesAtts));
188         Assert.assertTrue(pr.stdout.contains("id: 1"));
189         Assert.assertTrue(pr.stdout.contains("BID0"));
190     }
191 
192     @NeedsDisplay
193     //@Test
194     @Bug(id = "PR2489")
codebasesAttsTestWorksJavawsHtml1_null()195     public void codebasesAttsTestWorksJavawsHtml1_null() throws Exception {
196         prepare(null);
197         ArrayList<String> HTML_HEADLESS = new ArrayList<>();
198         HTML_HEADLESS.addAll(JAVAWS_HEADLES_LIST);
199         HTML_HEADLESS.addAll(JAVAWS_HTML_LIST);
200         ProcessWrapper pw = new ProcessWrapper(server.getJavawsLocation(), HTML_HEADLESS, server.getUrl(HTML));
201         pw.addStdOutListener(new AutoOkClosingListener());
202         pw.addStdErrListener(new AutoErrorClosingListener());
203         //pw.setWriter("YES\nYES\nYES\nYES\n");
204         ProcessResult pr = pw.execute();
205         Assert.assertTrue(pr.stdout.contains(appletCloseString));
206         Assert.assertTrue(pr.stdout.contains(CodebasesAtts));
207         Assert.assertTrue(pr.stdout.contains("id: 1"));
208         Assert.assertTrue(pr.stdout.contains("BID0"));
209     }
210 
211     @NeedsDisplay
212     //@Test
213     @Bug(id = "PR2489")
codebasesAttsTestWorksJavawsHtml2_null()214     public void codebasesAttsTestWorksJavawsHtml2_null() throws Exception {
215         prepare(null);
216         ArrayList<String> HTML_HEADLESS = new ArrayList<>();
217         HTML_HEADLESS.addAll(JAVAWS_HEADLES_LIST);
218         HTML_HEADLESS.addAll(JAVAWS_HTML_LIST);
219         ProcessWrapper pw = new ProcessWrapper(server.getJavawsLocation(), HTML_HEADLESS, server.getUrl(HTMLHREF));
220         pw.addStdOutListener(new AutoOkClosingListener());
221         pw.addStdErrListener(new AutoErrorClosingListener());
222         //pw.setWriter("YES\nYES\nYES\nYES\n");
223         ProcessResult pr = pw.execute();
224         Assert.assertTrue(pr.stdout.contains(appletCloseString));
225         Assert.assertTrue(pr.stdout.contains(CodebasesAtts));
226         Assert.assertTrue(pr.stdout.contains("id: 1"));
227         Assert.assertTrue(pr.stdout.contains("BID0"));
228     }
229 
prepare(String codebase)230     public static void prepare(String codebase) throws IOException {
231         prepare(codebase, codebase);
232     }
233 
prepare(String codebase1, String codebase2)234     public static void prepare(String codebase1, String codebase2) throws IOException {
235         CodebasesAttsNoDialogsTest1.prepareSingle(codebase1, null, null, '1', ServerAccess.getInstance().getDir(), files);
236         CodebasesAttsNoDialogsTest1.prepareSingle(codebase2, null, null, '2', secondValidServer.getDir(), files);
237     }
238 
239 }
240