diff options
Diffstat (limited to 'tests')
10 files changed, 395 insertions, 43 deletions
diff --git a/tests/jnlp_tests/signed/AppletTestSigned/testcases/AppletTestSignedTests.java b/tests/jnlp_tests/signed/AppletTestSigned/testcases/AppletTestSignedTests.java index 3fe1886..d3d87ba 100644 --- a/tests/jnlp_tests/signed/AppletTestSigned/testcases/AppletTestSignedTests.java +++ b/tests/jnlp_tests/signed/AppletTestSigned/testcases/AppletTestSignedTests.java @@ -40,13 +40,15 @@ import java.util.Collections; import java.util.List; import net.sourceforge.jnlp.ServerAccess; import net.sourceforge.jnlp.ServerAccess.ProcessResult; +import net.sourceforge.jnlp.browsertesting.BrowserTest; +import net.sourceforge.jnlp.browsertesting.Browsers; +import net.sourceforge.jnlp.annotations.TestInBrowsers; import org.junit.Assert; import org.junit.Test; -public class AppletTestSignedTests { +public class AppletTestSignedTests extends BrowserTest { - private static ServerAccess server = new ServerAccess(); private final List<String> l = Collections.unmodifiableList(Arrays.asList(new String[]{"-Xtrustall"})); @Test @@ -77,6 +79,7 @@ public class AppletTestSignedTests { } @Test + @TestInBrowsers(testIn = {Browsers.all}) public void AppletTestSignedFirefoxTest() throws Exception { ServerAccess.PROCESS_TIMEOUT = 30 * 1000; try { diff --git a/tests/jnlp_tests/signed/Spaces can be everywhere signed/testcases/SpacesCanBeEverywhereTestsSigned.java b/tests/jnlp_tests/signed/Spaces can be everywhere signed/testcases/SpacesCanBeEverywhereTestsSigned.java index 658876d..f33b203 100644 --- a/tests/jnlp_tests/signed/Spaces can be everywhere signed/testcases/SpacesCanBeEverywhereTestsSigned.java +++ b/tests/jnlp_tests/signed/Spaces can be everywhere signed/testcases/SpacesCanBeEverywhereTestsSigned.java @@ -40,14 +40,16 @@ import java.util.List; import net.sourceforge.jnlp.ServerAccess; import net.sourceforge.jnlp.annotations.Bug; import net.sourceforge.jnlp.annotations.NeedsDisplay; +import net.sourceforge.jnlp.browsertesting.BrowserTest; +import net.sourceforge.jnlp.browsertesting.Browsers; +import net.sourceforge.jnlp.annotations.TestInBrowsers; import org.junit.Assert; import org.junit.Test; @Bug(id={"http://mail.openjdk.java.net/pipermail/distro-pkg-dev/2011-October/016127.html","PR804","PR811"}) -public class SpacesCanBeEverywhereTestsSigned { +public class SpacesCanBeEverywhereTestsSigned extends BrowserTest { - private static ServerAccess server = new ServerAccess(); @Bug(id="PR811") @Test @@ -104,6 +106,7 @@ public class SpacesCanBeEverywhereTestsSigned { @Bug(id="PR811") @Test @NeedsDisplay + @TestInBrowsers(testIn = {Browsers.one}) public void SpacesCanBeEverywhereRemoteAppletTestsHtml2Signed() throws Exception { ServerAccess.ProcessResult pr = server.executeBrowser("/spaces+applet+Tests+signed.html"); String s="Signed spaces can be everywhere.jsr was launched correctly"; diff --git a/tests/jnlp_tests/simple/AppletBaseURLTest/testcases/AppletBaseURLTest.java b/tests/jnlp_tests/simple/AppletBaseURLTest/testcases/AppletBaseURLTest.java index 8b1d893..ec14cfa 100644 --- a/tests/jnlp_tests/simple/AppletBaseURLTest/testcases/AppletBaseURLTest.java +++ b/tests/jnlp_tests/simple/AppletBaseURLTest/testcases/AppletBaseURLTest.java @@ -35,17 +35,17 @@ obligated to do so. If you do not wish to do so, delete this exception statement from your version. */ -import net.sourceforge.jnlp.ServerAccess; import net.sourceforge.jnlp.ServerAccess.ProcessResult; import net.sourceforge.jnlp.annotations.Bug; import net.sourceforge.jnlp.annotations.NeedsDisplay; +import net.sourceforge.jnlp.annotations.TestInBrowsers; +import net.sourceforge.jnlp.browsertesting.BrowserTest; +import net.sourceforge.jnlp.browsertesting.Browsers; import org.junit.Assert; import org.junit.Test; -public class AppletBaseURLTest { - - private static ServerAccess server = new ServerAccess(); +public class AppletBaseURLTest extends BrowserTest{ private void evaluateApplet(ProcessResult pr, String baseName) { String s8 = "(?s).*Codebase is http://localhost:[0-9]{5}/ for this applet(?s).*"; @@ -68,6 +68,7 @@ public class AppletBaseURLTest { @Bug(id="PR855") @NeedsDisplay @Test + @TestInBrowsers(testIn={Browsers.one}) public void AppletInFirefoxTest() throws Exception { ProcessResult pr = server.executeBrowser("/AppletBaseURLTest.html"); pr.process.destroy(); @@ -78,6 +79,7 @@ public class AppletBaseURLTest { @Bug(id="PR855") @NeedsDisplay @Test + @TestInBrowsers(testIn={Browsers.one}) public void AppletWithJNLPHrefTest() throws Exception { ProcessResult pr = server.executeBrowser("/AppletJNLPHrefBaseURLTest.html"); pr.process.destroy(); diff --git a/tests/jnlp_tests/simple/AppletReadsInvalidJar/testcases/AppletReadsInvalidJarTests.java b/tests/jnlp_tests/simple/AppletReadsInvalidJar/testcases/AppletReadsInvalidJarTests.java index fef0e4a..11b0bb0 100644 --- a/tests/jnlp_tests/simple/AppletReadsInvalidJar/testcases/AppletReadsInvalidJarTests.java +++ b/tests/jnlp_tests/simple/AppletReadsInvalidJar/testcases/AppletReadsInvalidJarTests.java @@ -36,16 +36,16 @@ exception statement from your version. */ import net.sourceforge.jnlp.ServerAccess; -import net.sourceforge.jnlp.ServerAccess.ProcessResult; -import net.sourceforge.jnlp.LaunchException; +import net.sourceforge.jnlp.annotations.TestInBrowsers; +import net.sourceforge.jnlp.browsertesting.BrowserTest; +import net.sourceforge.jnlp.browsertesting.Browsers; import org.junit.Assert; import org.junit.Test; -public class AppletReadsInvalidJarTests { - - private static ServerAccess server = new ServerAccess(); +public class AppletReadsInvalidJarTests extends BrowserTest{ + static final String CORRECT_EXECUTION = "Program Executed Correctly."; static final String JNLP_EXPECTED_EXCEPTION = "ZipException"; @@ -60,6 +60,7 @@ public class AppletReadsInvalidJarTests { /*This SHOULD execute the applet!*/ @Test + @TestInBrowsers(testIn={Browsers.one}) public void AppletInFirefoxTest() throws Exception { ServerAccess.ProcessResult pr = server.executeBrowser("/AppletReadsInvalidJar.html"); diff --git a/tests/jnlp_tests/simple/AppletTakesLastParam/testcases/AppletTakesLastParamTests.java b/tests/jnlp_tests/simple/AppletTakesLastParam/testcases/AppletTakesLastParamTests.java index 05b1661..206f6de 100644 --- a/tests/jnlp_tests/simple/AppletTakesLastParam/testcases/AppletTakesLastParamTests.java +++ b/tests/jnlp_tests/simple/AppletTakesLastParam/testcases/AppletTakesLastParamTests.java @@ -37,13 +37,14 @@ exception statement from your version. import net.sourceforge.jnlp.ServerAccess; import net.sourceforge.jnlp.ServerAccess.ProcessResult; +import net.sourceforge.jnlp.browsertesting.BrowserTest; +import net.sourceforge.jnlp.browsertesting.Browsers; +import net.sourceforge.jnlp.annotations.TestInBrowsers; import org.junit.Assert; import org.junit.Test; -public class AppletTakesLastParamTests { - - private static ServerAccess server = new ServerAccess(); +public class AppletTakesLastParamTests extends BrowserTest { @Test public void AppletTest() throws Exception { @@ -59,6 +60,7 @@ public class AppletTakesLastParamTests { } @Test + @TestInBrowsers(testIn = {Browsers.one}) public void AppletInFirefoxTest() throws Exception { ServerAccess.ProcessResult pr = server.executeBrowser("/appletTakesLastParam.html"); evaluateApplet(pr); diff --git a/tests/jnlp_tests/simple/AppletTest/resources/appletAutoTests2.html b/tests/jnlp_tests/simple/AppletTest/resources/appletAutoTests2.html new file mode 100644 index 0000000..a5c370c --- /dev/null +++ b/tests/jnlp_tests/simple/AppletTest/resources/appletAutoTests2.html @@ -0,0 +1,44 @@ +<!-- + +This file is part of IcedTea. + +IcedTea is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +IcedTea is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with IcedTea; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. + + --> +<html><head></head><body bgcolor="blue"> +<p><applet code="AppletTest.class" archive="AppletTest.jar" codebase="." width="800" height="600"> + <param name="key1" value="value1"> + <param name="key2" value="#value2"> +</applet></p> +</body> +</html> diff --git a/tests/jnlp_tests/simple/AppletTest/testcases/AppletTestTests.java b/tests/jnlp_tests/simple/AppletTest/testcases/AppletTestTests.java index d93d6f4..9fd662d 100644 --- a/tests/jnlp_tests/simple/AppletTest/testcases/AppletTestTests.java +++ b/tests/jnlp_tests/simple/AppletTest/testcases/AppletTestTests.java @@ -37,15 +37,48 @@ exception statement from your version. import net.sourceforge.jnlp.ServerAccess; import net.sourceforge.jnlp.ServerAccess.ProcessResult; +import net.sourceforge.jnlp.browsertesting.BrowserTest; +import net.sourceforge.jnlp.browsertesting.Browsers; +import net.sourceforge.jnlp.annotations.Bug; +import net.sourceforge.jnlp.annotations.NeedsDisplay; +import net.sourceforge.jnlp.annotations.TestInBrowsers; import org.junit.Assert; import org.junit.Test; -public class AppletTestTests { +public class AppletTestTests extends BrowserTest { - private static ServerAccess server = new ServerAccess(); + @Test + @TestInBrowsers(testIn = {Browsers.googleChrome}) + @NeedsDisplay + public void doubleChrome() throws Exception { + server.PROCESS_TIMEOUT = 30 * 1000; + try { + //System.out.println("connecting AppletInFirefoxTest request in " + getBrowser().toString()); + //just verify loging is recording browser + ServerAccess.ProcessResult pr1 = server.executeBrowser("/appletAutoTests.html"); + if (pr1.process == null) { + Assert.assertTrue("If proces was null here, then google-chrome had to not exist, and so " + + ServerAccess.UNSET_BROWSER + + " should be in exception, but exception was " + + pr1.deadlyException.getMessage(), + pr1.deadlyException.getMessage().contains(ServerAccess.UNSET_BROWSER)); + return; + } + evaluateApplet(pr1); + Assert.assertTrue(pr1.wasTerminated); + //System.out.println("connecting AppletInFirefoxTest request in " + getBrowser().toString()); + // just verify loging is recording browser + ServerAccess.ProcessResult pr = server.executeBrowser("/appletAutoTests.html"); + evaluateApplet(pr); + Assert.assertTrue(pr.wasTerminated); + } finally { + server.PROCESS_TIMEOUT = 20 * 1000; //back to normal + } + } @Test + @NeedsDisplay public void AppletTest() throws Exception { ServerAccess.ProcessResult pr = server.executeJavawsHeadless(null, "/AppletTest.jnlp"); evaluateApplet(pr); @@ -73,8 +106,28 @@ public class AppletTestTests { } @Test - public void AppletInFirefoxTest() throws Exception { - server.PROCESS_TIMEOUT = 30 * 1000; + @TestInBrowsers(testIn = {Browsers.all}) + @NeedsDisplay + public void AppletInBrowserTest() throws Exception { + //System.out.println("connecting AppletInFirefoxTest request in " + getBrowser().toString()); + //just verify loging is recordingb rowser + ServerAccess.PROCESS_TIMEOUT = 30 * 1000; + try { + ServerAccess.ProcessResult pr = server.executeBrowser("/appletAutoTests2.html"); + evaluateApplet(pr); + Assert.assertTrue(pr.wasTerminated); + //Assert.assertEquals((Integer) 0, pr.returnValue); due to destroy is null + } finally { + ServerAccess.PROCESS_TIMEOUT = 20 * 1000; //back to normal + } + } + + @TestInBrowsers(testIn = {Browsers.all}) + @NeedsDisplay + public void AppletInBrowserTestXslowX() throws Exception { + //System.out.println("connecting AppletInFirefoxTest request in " + getBrowser().toString()); + //just verify loging is recording browser + ServerAccess.PROCESS_TIMEOUT = 30 * 1000; try { ServerAccess.ProcessResult pr = server.executeBrowser("/appletAutoTests.html"); pr.process.destroy(); @@ -82,7 +135,7 @@ public class AppletTestTests { Assert.assertTrue(pr.wasTerminated); //Assert.assertEquals((Integer) 0, pr.returnValue); due to destroy is null } finally { - server.PROCESS_TIMEOUT = 20 * 1000; //back to normal + ServerAccess.PROCESS_TIMEOUT = 20 * 1000; //back to normal } } } diff --git a/tests/jnlp_tests/simple/CheckServices/testcases/CheckServicesTests.java b/tests/jnlp_tests/simple/CheckServices/testcases/CheckServicesTests.java index 7257984..a36e394 100644 --- a/tests/jnlp_tests/simple/CheckServices/testcases/CheckServicesTests.java +++ b/tests/jnlp_tests/simple/CheckServices/testcases/CheckServicesTests.java @@ -35,18 +35,18 @@ obligated to do so. If you do not wish to do so, delete this exception statement from your version. */ -import net.sourceforge.jnlp.ServerAccess; import net.sourceforge.jnlp.ServerAccess.ProcessResult; import net.sourceforge.jnlp.annotations.Bug; import net.sourceforge.jnlp.annotations.NeedsDisplay; +import net.sourceforge.jnlp.annotations.TestInBrowsers; +import net.sourceforge.jnlp.browsertesting.BrowserTest; +import net.sourceforge.jnlp.browsertesting.Browsers; import org.junit.Assert; import org.junit.Test; @Bug(id="http://mail.openjdk.java.net/pipermail/distro-pkg-dev/2012-February/017153.html") -public class CheckServicesTests { - - private static ServerAccess server = new ServerAccess(); +public class CheckServicesTests extends BrowserTest{ public void evaluateApplet(ProcessResult pr) { String s0 = "Codebase for applet was found in constructor"; @@ -79,6 +79,7 @@ public class CheckServicesTests { @Test @NeedsDisplay + @TestInBrowsers(testIn={Browsers.one}) public void CheckPluginJNLPHServices() throws Exception { ProcessResult pr = server.executeBrowser(null, "/CheckPluginServices.html"); evaluateApplet(pr); diff --git a/tests/jnlp_tests/simple/Spaces can be everywhere/testcases/SpacesCanBeEverywhereTests.java b/tests/jnlp_tests/simple/Spaces can be everywhere/testcases/SpacesCanBeEverywhereTests.java index 3741757..cb2a98f 100644 --- a/tests/jnlp_tests/simple/Spaces can be everywhere/testcases/SpacesCanBeEverywhereTests.java +++ b/tests/jnlp_tests/simple/Spaces can be everywhere/testcases/SpacesCanBeEverywhereTests.java @@ -40,14 +40,15 @@ import java.util.List; import net.sourceforge.jnlp.ServerAccess; import net.sourceforge.jnlp.annotations.Bug; import net.sourceforge.jnlp.annotations.NeedsDisplay; +import net.sourceforge.jnlp.browsertesting.BrowserTest; +import net.sourceforge.jnlp.browsertesting.Browsers; +import net.sourceforge.jnlp.annotations.TestInBrowsers; import org.junit.Assert; - import org.junit.Test; @Bug(id={"http://mail.openjdk.java.net/pipermail/distro-pkg-dev/2011-October/016127.html","PR804","PR811"}) -public class SpacesCanBeEverywhereTests { +public class SpacesCanBeEverywhereTests extends BrowserTest { - private static ServerAccess server = new ServerAccess(); @Bug(id="PR811") @Test @@ -104,6 +105,7 @@ public class SpacesCanBeEverywhereTests { @Bug(id="PR811") @Test @NeedsDisplay + @TestInBrowsers(testIn = {Browsers.all}) public void SpacesCanBeEverywhereRemoteAppletTestsHtml2() throws Exception { ServerAccess.ProcessResult pr = server.executeBrowser("/spaces+applet+Tests.html"); String s="Spaces can be everywhere.jsr was launched correctly"; diff --git a/tests/netx/jnlp_testsengine/net/sourceforge/jnlp/ResourcesTest.java b/tests/netx/jnlp_testsengine/net/sourceforge/jnlp/ResourcesTest.java index 89e2825..b8c7d5e 100644 --- a/tests/netx/jnlp_testsengine/net/sourceforge/jnlp/ResourcesTest.java +++ b/tests/netx/jnlp_testsengine/net/sourceforge/jnlp/ResourcesTest.java @@ -38,14 +38,179 @@ package net.sourceforge.jnlp; import java.io.File; import java.io.FileFilter; +import java.io.FileInputStream; +import java.io.IOException; import java.net.URI; +import java.util.Arrays; +import java.util.List; +import net.sourceforge.jnlp.browsertesting.Browser; +import net.sourceforge.jnlp.browsertesting.BrowserFactory; +import net.sourceforge.jnlp.browsertesting.BrowserTest; +import net.sourceforge.jnlp.browsertesting.Browsers; +import net.sourceforge.jnlp.annotations.NeedsDisplay; +import net.sourceforge.jnlp.annotations.TestInBrowsers; +import net.sourceforge.jnlp.browsertesting.browsers.LinuxBrowser; +import net.sourceforge.jnlp.annotations.TestInBrowsers; import org.junit.Assert; import org.junit.Test; -public class ResourcesTest { +public class ResourcesTest extends BrowserTest{ - private static ServerAccess server = new ServerAccess(); + + @Test + @NeedsDisplay + public void testNonExisitngBrowserWillNotDeadlock() throws Exception { + server.setCurrentBrowser(Browsers.none); + ServerAccess.ProcessResult pr = server.executeBrowser("simpletest1.jnlp"); + Assert.assertNull(pr.process); + Assert.assertEquals(pr.stderr, ""); + Assert.assertEquals(pr.stdout, ""); + Assert.assertTrue(pr.wasTerminated); + Assert.assertTrue(pr.returnValue < 0); + junit.framework.Assert.assertNotNull(pr.deadlyException); + } + + @Test + public void testUnexistingProcessWillFailRecognizedly() throws Exception { + server.setCurrentBrowser(Browsers.none); + List<String> al=Arrays.asList(new String[] {"definietly_not_Existing_process"}); + ServerAccess.ProcessResult pr = server.executeProcess(al); + Assert.assertNull(pr.process); + Assert.assertEquals(pr.stderr, ""); + Assert.assertEquals(pr.stdout, ""); + Assert.assertTrue(pr.wasTerminated); + Assert.assertTrue(pr.returnValue < 0); + junit.framework.Assert.assertNotNull(pr.deadlyException); + } + + @Test + @TestInBrowsers(testIn=Browsers.none) + public void testNonExisitngBrowserWillNotCauseMess() throws Exception { + ServerAccess.ProcessResult pr = server.executeBrowser("simpletest1.jnlp"); + Assert.assertNull(pr.process); + Assert.assertEquals(pr.stderr, ""); + Assert.assertEquals(pr.stdout, ""); + Assert.assertTrue(pr.wasTerminated); + Assert.assertTrue(pr.returnValue < 0); + junit.framework.Assert.assertNotNull(pr.deadlyException); + } + + @Test + public void testBrowsers2() throws Exception { + List<Browser> a = BrowserFactory.getFactory().getAllBrowsers(); + Assert.assertNotNull("returned browsers array must not be null", a); + Assert.assertTrue("at least one browser must be configured", a.size() > 0); + for (Browser b : a) { + testBrowser(b); + } + + } + + @Test + @TestInBrowsers(testIn = Browsers.all) + public void testBrowser3() throws Exception { + testBrowser(server.getCurrentBrowser()); + + + } + + @Test + public void testBrowsers1() throws Exception { + BrowserFactory bf = new BrowserFactory(null); + int expected = 0; + Assert.assertTrue("Created from null there must be " + expected + " browsers in factory. Is" + bf.getAllBrowsers().size(), bf.getAllBrowsers().size() == expected); + + bf = new BrowserFactory(""); + expected = 0; + Assert.assertTrue("Created from empty there must be " + expected + " browsers in factory. Is" + bf.getAllBrowsers().size(), bf.getAllBrowsers().size() == expected); + + String s = "dsgrdg"; + bf = new BrowserFactory(s); + expected = 0; + Assert.assertTrue("Created from nonsense " + s + " there must be " + expected + " browsers in factory. Is" + bf.getAllBrowsers().size(), bf.getAllBrowsers().size() == expected); + + s = "sgrg/jkik"; + bf = new BrowserFactory(s); + expected = 0; + Assert.assertTrue("Created from nonsense " + s + " there must be " + expected + " browsers in factory. Is" + bf.getAllBrowsers().size(), bf.getAllBrowsers().size() == expected); + + s = Browsers.firefox + "/jkik"; + bf = new BrowserFactory(s); + expected = 0; + Assert.assertTrue("Created from nonsense " + s + "there must be " + expected + " browsers in factory. Is" + bf.getAllBrowsers().size(), bf.getAllBrowsers().size() == expected); + + s = "sgrg/jkik:sege"; + bf = new BrowserFactory(s); + expected = 0; + Assert.assertTrue("Created from two nonsenses " + s + "there must be " + expected + " browsers in factory. Is" + bf.getAllBrowsers().size(), bf.getAllBrowsers().size() == expected); + + s = Browsers.firefox.toExec() + ":" + Browsers.firefox; + bf = new BrowserFactory(s); + expected = 2; + Assert.assertTrue("Created from " + s + "there must be " + expected + " browsers in factory. Is" + bf.getAllBrowsers().size(), bf.getAllBrowsers().size() == expected); + + s = Browsers.firefox.toExec(); + bf = new BrowserFactory(s); + expected = 1; + Assert.assertTrue("Created from " + s + "there must be " + expected + " browsers in factory. Is" + bf.getAllBrowsers().size(), bf.getAllBrowsers().size() == expected); + + s = "something/somewhere/" + Browsers.firefox.toExec(); + bf = new BrowserFactory(s); + expected = 1; + Assert.assertTrue("Created from " + s + "there must be " + expected + " browsers in factory. Is" + bf.getAllBrowsers().size(), bf.getAllBrowsers().size() == expected); + + s = "something/somewhere/" + Browsers.firefox.toExec() + ":" + "something/somewhere/" + Browsers.opera.toExec(); + bf = new BrowserFactory(s); + expected = 2; + Assert.assertTrue("Created from " + s + "there must be " + expected + " browsers in factory. Is" + bf.getAllBrowsers().size(), bf.getAllBrowsers().size() == expected); + + s = "something/somewhere/" + Browsers.firefox.toExec() + ":" + "something/somewhere/" + Browsers.opera.toExec() + ":" + Browsers.chromiumBrowser; + bf = new BrowserFactory(s); + expected = 3; + Assert.assertTrue("Created from " + s + "there must be " + expected + " browsers in factory. Is" + bf.getAllBrowsers().size(), bf.getAllBrowsers().size() == expected); + + s = Browsers.firefox.toExec() + ":" + "vfdgf" + ":" + Browsers.googleChrome.toExec(); + bf = new BrowserFactory(s); + expected = 2; + Assert.assertTrue("Created from " + s + "there must be " + expected + " browsers in factory. Is" + bf.getAllBrowsers().size(), bf.getAllBrowsers().size() == expected); + + s = Browsers.firefox.toExec() + ":" + Browsers.chromiumBrowser + ":" + Browsers.googleChrome.toExec() + ":" + Browsers.opera; + bf = new BrowserFactory(s); + expected = 4; + Assert.assertTrue("Created from " + s + "there must be " + expected + " browsers in factory. Is" + bf.getAllBrowsers().size(), bf.getAllBrowsers().size() == expected); + testFullFactory(bf); + + s = "fgfd/" + Browsers.firefox.toExec() + ":" + "/fgfd/" + Browsers.chromiumBrowser + ":" + "fgfd/dfsdf/" + Browsers.googleChrome.toExec() + ":" + "/g/fgfd/" + Browsers.opera; + bf = new BrowserFactory(s); + expected = 4; + Assert.assertTrue("Created from " + s + "there must be " + expected + " browsers in factory. Is" + bf.getAllBrowsers().size(), bf.getAllBrowsers().size() == expected); + testFullFactory(bf); + + s = Browsers.firefox.toExec() + ":" + ":" + Browsers.googleChrome.toExec() + ":" + Browsers.opera; + bf = new BrowserFactory(s); + expected = 3; + Assert.assertTrue("Created from " + s + "there must be " + expected + " browsers in factory. Is" + bf.getAllBrowsers().size(), bf.getAllBrowsers().size() == expected); + + s = Browsers.firefox.toExec() + ":" + ":" + ":" + Browsers.opera; + bf = new BrowserFactory(s); + expected = 2; + Assert.assertTrue("Created from " + s + "there must be " + expected + " browsers in factory. Is" + bf.getAllBrowsers().size(), bf.getAllBrowsers().size() == expected); + + s = ":" + ":" + Browsers.googleChrome.toExec() + ":"; + bf = new BrowserFactory(s); + expected = 1; + Assert.assertTrue("Created from " + s + "there must be " + expected + " browsers in factory. Is" + bf.getAllBrowsers().size(), bf.getAllBrowsers().size() == expected); + + s = ":" + Browsers.firefox.toExec() + ":bfgbfg/fddf/" + Browsers.googleChrome.toExec() + ":"; + bf = new BrowserFactory(s); + expected = 2; + Assert.assertTrue("Created from " + s + "there must be " + expected + " browsers in factory. Is" + bf.getAllBrowsers().size(), bf.getAllBrowsers().size() == expected); + + + + + } @Test public void testResourcesExists() throws Exception { @@ -68,9 +233,9 @@ public class ResourcesTest { //server port have in fact no usage in converting filename to uri-like-filename. //But if there is null, instead if some number, then nullpointer exception is thrown (Integer->int). //So I'm using "real" currently used port, instead of some random value. - URI u = new URI((String)null,(String)null,(String)null,server.getPort(),file.getName(),(String)null,null); + URI u = new URI((String) null, (String) null, (String) null, server.getPort(), file.getName(), (String) null, null); ServerAccess.logOutputReprint(" ("+u.toString()+")"); - String fname=u.toString(); + String fname = u.toString(); if (file.getName().toLowerCase().endsWith(".jnlp")) { String c = server.getResourceAsString("/" + fname); Assert.assertTrue(c.contains("<")); @@ -89,12 +254,14 @@ public class ResourcesTest { } @Test + @NeedsDisplay + @TestInBrowsers(testIn = Browsers.one) public void testListeners() throws Exception { - final StringBuilder o1=new StringBuilder(); - final StringBuilder e1=new StringBuilder(); - final StringBuilder o2=new StringBuilder(); - final StringBuilder e2=new StringBuilder(); - final ContentReaderListener lo=new ContentReaderListener() { + final StringBuilder o1 = new StringBuilder(); + final StringBuilder e1 = new StringBuilder(); + final StringBuilder o2 = new StringBuilder(); + final StringBuilder e2 = new StringBuilder(); + final ContentReaderListener lo = new ContentReaderListener() { @Override public void charReaded(char ch) { @@ -104,26 +271,28 @@ public class ResourcesTest { @Override public void lineReaded(String s) { - //ServerAccess.logOutputReprint("OO recieved line: "+s); + //ServerAccess.logOutputReprint("OO recieved line: "+s); o2.append(s).append("\n"); } }; - ContentReaderListener le=new ContentReaderListener() { + ContentReaderListener le = new ContentReaderListener() { @Override public void charReaded(char ch) { - //ServerAccess.logOutputReprint("EE recieved char: "+ch); - e1.append(ch); + //ServerAccess.logOutputReprint("EE recieved char: "+ch); + e1.append(ch); } @Override public void lineReaded(String s) { - //ServerAccess.logOutputReprint("EE recieved line: "+s); + //ServerAccess.logOutputReprint("EE recieved line: "+s); e2.append(s).append("\n"); } }; ServerAccess.ProcessResult pr=server.executeBrowser("simpletest1.jnlp",le,lo); - pr.process.destroy(); + server.setCurrentBrowser(BrowserFactory.getFactory().getFirst().getID()); + Assert.assertNotNull(server.getCurrentBrowsers()); + Assert.assertNotNull(server.getCurrentBrowser()); // ServerAccess.logOutputReprint("total o"); // ServerAccess.logOutputReprint(pr.stdout); // ServerAccess.logOutputReprint("total e"); @@ -135,4 +304,76 @@ public class ResourcesTest { Assert.assertEquals(pr.stderr.replace("\n", ""), e2.toString().replace("\n", "")); } + + private void testFullFactory(BrowserFactory bf) { + Assert.assertEquals(bf.getBrowser(Browsers.chromiumBrowser).getID(), Browsers.chromiumBrowser); + Assert.assertEquals(bf.getBrowser(Browsers.googleChrome).getID(), Browsers.googleChrome); + Assert.assertEquals(bf.getBrowser(Browsers.firefox).getID(), Browsers.firefox); + Assert.assertEquals(bf.getBrowser(Browsers.opera).getID(), Browsers.opera); + } + + private void testBrowser(Browser browser) throws IOException { + File f1 = null; + if (browser.getDefaultPluginExpectedLocation() != null) { + f1 = new File(browser.getDefaultPluginExpectedLocation()); + } + File f2 = null; + if (browser.getUserDefaultPluginExpectedLocation() != null) { + f2 = new File(browser.getUserDefaultPluginExpectedLocation()); + } + if (f1 != null) { + Assert.assertTrue("browser's plugins location should exist " + f1.toString() + " for " + browser.getID().toString(), f1.exists()); + } + if (f2 != null) { + Assert.assertTrue("browser's users-plugins location should exist " + f2.toString() + " for " + browser.getID().toString(), f2.exists()); + } + + File[] ff1 = new File[0]; + if (f1 != null) { + ff1 = f1.listFiles(); + } + + File[] ff2 = new File[0]; + if (f2 != null) { + ff2 = f2.listFiles(); + } + + Assert.assertTrue("at least one of browser's plugins directory should contains at least one file didn't. For " + browser.getID().toString(), ff1.length + ff2.length > 0); + + ff1 = new File[0]; + if (f1 != null) { + ff1 = f1.listFiles(new FileFilter() { + + @Override + public boolean accept(File pathname) { + return (pathname.getName().equals(LinuxBrowser.DEFAULT_PLUGIN_NAME)); + } + }); + } + + ff2 = new File[0]; + if (f2 != null) { + ff2 = f2.listFiles(new FileFilter() { + + @Override + public boolean accept(File pathname) { + return (pathname.getName().equals(LinuxBrowser.DEFAULT_PLUGIN_NAME)); + } + }); + } + + Assert.assertTrue("browser's plugins directories should contains exactly one " + LinuxBrowser.DEFAULT_PLUGIN_NAME + ", but didnt for " + browser.getID().toString(), + ff1.length + ff2.length == 1); + String currentPath = server.getJavawsFile().getParentFile().getParentFile().getAbsolutePath(); + + File[] ff; + if (ff1.length == 1) { + ff = ff1; + } else { + ff = ff2; + } + String s = ServerAccess.getContentOfStream(new FileInputStream(ff[0]), "ASCII"); + Assert.assertTrue("browser's plugins shoud points to" + currentPath + ", but didnt", + s.contains(s)); + } } |