changeset 1050:cd2bcad72cd5

AppTrustWarningPanelTest.java: Backuped, reset and restored .appletTrustSettings so its content can not affect test
author Jiri Vanek <jvanek@redhat.com>
date Thu, 10 Sep 2015 17:54:57 +0200
parents 38218c5268d4
children 09d813dec15c
files ChangeLog tests/netx/unit/net/sourceforge/jnlp/security/dialogs/apptrustwarningpanel/AppTrustWarningPanelTest.java
diffstat 2 files changed, 33 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Thu Sep 10 12:17:47 2015 +0200
+++ b/ChangeLog	Thu Sep 10 17:54:57 2015 +0200
@@ -1,3 +1,8 @@
+2015-09-10  Jiri Vanek  <jvanek@redhat.com>
+
+	* tests/netx/unit/net/sourceforge/jnlp/security/dialogs/apptrustwarningpanel/AppTrustWarningPanelTest.java:
+	Backuped, reset and restored .appletTrustSettings so its content can not affect test
+
 2015-09-10  Jiri Vanek  <jvanek@redhat.com>
 
 	* netx/net/sourceforge/jnlp/security/appletextendedsecurity/UnsignedAppletTrustConfirmation.java:
--- a/tests/netx/unit/net/sourceforge/jnlp/security/dialogs/apptrustwarningpanel/AppTrustWarningPanelTest.java	Thu Sep 10 12:17:47 2015 +0200
+++ b/tests/netx/unit/net/sourceforge/jnlp/security/dialogs/apptrustwarningpanel/AppTrustWarningPanelTest.java	Thu Sep 10 17:54:57 2015 +0200
@@ -1,5 +1,7 @@
 package net.sourceforge.jnlp.security.dialogs.apptrustwarningpanel;
 
+import java.io.File;
+import java.io.IOException;
 import net.sourceforge.jnlp.security.dialogs.apptrustwarningpanel.UnsignedAppletTrustWarningPanel;
 import net.sourceforge.jnlp.security.dialogs.apptrustwarningpanel.AppTrustWarningPanel;
 import java.net.URL;
@@ -10,6 +12,8 @@
 import javax.swing.JButton;
 import net.sourceforge.jnlp.PluginBridge;
 import net.sourceforge.jnlp.PluginParameters;
+import net.sourceforge.jnlp.browsertesting.browsers.firefox.FirefoxProfilesOperator;
+import org.junit.AfterClass;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
@@ -31,9 +35,33 @@
 
     /* Should contain an instance of each AppTrustWarningPanel subclass */
     private static List<AppTrustWarningPanel> panelList = new ArrayList<AppTrustWarningPanel>();
+    private static File appletSecurityBackup;
+    private static final File trustFile = new File(System.getProperty("user.home") + "/.config/icedtea-web/.appletTrustSettings");
+    
+    public static void backupAppletSecurity() throws IOException {
+        appletSecurityBackup = File.createTempFile("appletSecurity", "itwTestBAckup");
+        FirefoxProfilesOperator.copyFile(trustFile, appletSecurityBackup);
+    }
 
+    public static void removeAppletSecurityImpl() throws IOException {
+        if (appletSecurityBackup.exists()) {
+            trustFile.delete();
+        }
+    }
+
+    @AfterClass
+    public static void restoreAppletSecurity() throws IOException {
+        if (appletSecurityBackup.exists()) {
+            removeAppletSecurityImpl();
+            FirefoxProfilesOperator.copyFile(appletSecurityBackup, trustFile);
+            appletSecurityBackup.delete();
+        }
+    }
     @BeforeClass
     public static void setup() throws Exception {
+        backupAppletSecurity();
+        //emptying  .appletTrustSettings to not affect run of this test
+        removeAppletSecurityImpl();
         mockCodebase = new URL("http://www.example.com");
         mockDocumentBase = new URL("http://www.example.com");
         mockJar = "ApplicationName.jar";