package com.thoughtworks.selenium;

import junit.framework.Test;
import org.openqa.selenium.server.browserlaunchers.WindowsUtils;

/**
 * This class executes the same tests that ClientDriverSuite does, but it does so with proxy injection mode
 * turned on and with the default browser string set so as to use IE.  (ClientDriverSuite normally uses Firefox.)
 * 
 * @author nelsons
 *
 */

public class ClientDriverPISuite extends ClientDriverSuite {
    public static Test suite() {
        String oldProxyInjectionModeSetting = System.getProperty("selenium.proxyInjectionMode");
        try {
            System.setProperty("selenium.proxyInjectionMode", "true");

            String forcedBrowserMode = System.getProperty("selenium.forcedBrowserMode");
            if (forcedBrowserMode==null) {
                if (WindowsUtils.thisIsWindows()) {
                    System.setProperty("selenium.forcedBrowserMode", "*piiexplore");
                } else {
                    System.setProperty("selenium.forcedBrowserMode", "*pifirefox");
                }
            }
            return ClientDriverSuite.suite();
        }
        finally {
            if (oldProxyInjectionModeSetting==null) {
                oldProxyInjectionModeSetting = "false";
            }
            System.setProperty("selenium.proxyInjectionMode", oldProxyInjectionModeSetting);
        }
    }
}

@@ -48,23 +48,96 @@
 nit.
-framework.Test;
+extensions.TestSetup;%0D%0Aimport junit.framework.Test;%0D%0Aimport junit.framework.TestSuite;%0D%0A
 %0D%0Aim
@@ -575,191 +575,984 @@
     
-String oldProxyInjectionModeSetting = System.getProperty(%22selenium.proxyInjectionMode%22);%0D%0A        try %7B%0D%0A            System.setProperty(%22selenium.proxyInjectionMode%22, %22true%22);%0D%0A%0D%0A    
+TestSuite supersuite = new TestSuite(ClientDriverPISuite.class.getName());%0D%0A        TestSuite suite = new TestSuite(ClientDriverPISuite.class.getName());%0D%0A        suite.addTest(ClientDriverSuite.suite());%0D%0A%0D%0A        InitSystemPropertiesForPImodeTesting setup = new InitSystemPropertiesForPImodeTesting(suite);%0D%0A        supersuite.addTest(setup);%0D%0A        return supersuite;%0D%0A    %7D%0D%0A%0D%0A%0D%0A    /** A TestSetup decorator that runs a super setUp and tearDown at the%0D%0A     * beginning and end of the entire run: in this case, we use it to%0D%0A     * set and clear the PI mode property, and rename the suite.%0D%0A     *%0D%0A     *%0D%0A     *  @author nelsons%0D%0A     *%0D%0A     */%0D%0A    static class InitSystemPropertiesForPImodeTesting extends TestSetup %7B%0D%0A        private static final String SELENIUM_PROXY_INJECTION_MODE = %22selenium.proxyInjectionMode%22;%0D%0A        private static final String SELENIUM_FORCED_BROWSER_MODE = %22selenium.forcedBrowserMode%22;%0D%0A        String oldProxyInjectionModeSetting;%0D%0A
     
@@ -1562,17 +1562,20 @@
  String 
-f
+oldF
 orcedBro
@@ -1586,58 +1586,433 @@
 Mode
- = System.getProperty(%22selenium.forcedBrowserMode%22
+Setting;%0D%0A%0D%0A        public InitSystemPropertiesForPImodeTesting(Test test) %7B%0D%0A            super(test);%0D%0A        %7D%0D%0A%0D%0A        public void setUp() throws Exception %7B%0D%0A%0D%0A            oldProxyInjectionModeSetting = System.getProperty(SELENIUM_PROXY_INJECTION_MODE);%0D%0A            System.setProperty(SELENIUM_PROXY_INJECTION_MODE, %22true%22);%0D%0A%0D%0A            oldForcedBrowserModeSetting = System.getProperty(SELENIUM_FORCED_BROWSER_MODE
 );%0D%0A
@@ -2027,17 +2027,20 @@
     if (
-f
+oldF
 orcedBro
@@ -2047,16 +2047,23 @@
 wserMode
+Setting
 ==null) 
@@ -2161,36 +2161,36 @@
 rty(
-%22selenium.forcedBrowserMode%22
+SELENIUM_FORCED_BROWSER_MODE
 , %22*
@@ -2273,36 +2273,36 @@
 rty(
-%22selenium.forcedBrowserMode%22
+SELENIUM_FORCED_BROWSER_MODE
 , %22*
@@ -2361,43 +2361,238 @@
     
-    return ClientDriverSuite.suite(
+%7D%0D%0A%0D%0A        public void tearDown() throws Exception %7B%0D%0A            revertProperty(SELENIUM_PROXY_INJECTION_MODE, oldProxyInjectionModeSetting);%0D%0A            revertProperty(SELENIUM_FORCED_BROWSER_MODE, oldForcedBrowserModeSetting
 );%0D%0A
@@ -2602,24 +2602,26 @@
      %7D%0D%0A
+%0D%0A
         
 finally 
@@ -2616,129 +2616,160 @@
     
-finally %7B%0D%0A            if (oldProxyInjectionModeSetting==null) %7B%0D%0A                oldProxyInjectionModeSetting = %22false%22;
+private void revertProperty(String key, String oldValue) %7B%0D%0A            if (oldValue==null) %7B%0D%0A                System.clearProperty(key);%0D%0A            %7D
 %0D%0A  
@@ -2770,35 +2770,44 @@
  %7D%0D%0A            
-%7D%0D%0A
+else %7B%0D%0A    
             Syst
@@ -2825,69 +2825,38 @@
 rty(
-%22selenium.proxyInjectionMode%22, oldProxyInjectionModeSetting);
+key, oldValue);%0D%0A            %7D
 %0D%0A  

Use a decorator to temporarily set and unset system properties which govern proxy injection mode