package org.openqa.selenium;

import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.LocalFileDetector;
import org.openqa.selenium.remote.RemoteWebDriver;

import com.google.common.base.Supplier;

// This is a particularly ugly class.  I will tidy it up, I swear.
public class SauceBackedDriverSupplier implements Supplier<WebDriver> {
  private final Class<? extends WebDriver> driverClass;

  public SauceBackedDriverSupplier(Class<? extends WebDriver> driverClass) {
    this.driverClass = driverClass;
  }

  public WebDriver get() {
    DesiredCapabilities capabilities;
    if (driverClass.getName() == "org.openqa.selenium.firefox.FirefoxDriver") {
      capabilities = DesiredCapabilities.firefox();
    } else if (driverClass.getName() == "org.openqa.selenium.firefox.SynthesizedFirefoxDriver") {
      capabilities = DesiredCapabilities.firefox();
      capabilities.setCapability(CapabilityType.HAS_NATIVE_EVENTS, false);
    } else if (driverClass.getName() == "org.openqa.selenium.firefox.NativeEventsFirefoxDriver") {
      capabilities = DesiredCapabilities.firefox();
      capabilities.setCapability(CapabilityType.HAS_NATIVE_EVENTS, true);
    } else if (driverClass.getName() ==
        "org.openqa.selenium.ie.InternetExplorerDriverTestSuite$TestInternetExplorerDriver") {
      capabilities = DesiredCapabilities.internetExplorer();
    } else if (driverClass.getName() ==
        "org.openqa.selenium.chrome.ChromeDriverTestSuite$DriverForTest") {
      capabilities = DesiredCapabilities.chrome();
    } else if (driverClass.getName() == "com.opera.core.systems.OperaDriver") {
      capabilities = DesiredCapabilities.opera();
    } else {
      throw new UnsupportedOperationException(
        "Didn't know how to create sauce-backed driver for class " +
            driverClass.getCanonicalName());
    }
    RemoteWebDriver driver = new SauceDriver(capabilities);
    driver.setFileDetector(new LocalFileDetector());
    return driver;
  }
}

@@ -23,16 +23,72 @@
 enium;%0A%0A
+import javax.management.modelmbean.RequiredModelMBean;%0A%0A
 import o
@@ -717,33 +717,79 @@
     
-if (driverClass.getName()
+String requestedDriver = driverClass.getName();%0A    if (requestedDriver
  == 
@@ -902,37 +902,31 @@
 lse if (
-driverClass.getName()
+requestedDriver
  == %22org
@@ -1121,37 +1121,31 @@
 lse if (
-driverClass.getName()
+requestedDriver
  == %22org
@@ -1340,37 +1340,31 @@
 lse if (
-driverClass.getName()
+requestedDriver
  ==%0A    
@@ -1446,24 +1446,102 @@
 lorerDriver%22
+ %7C%7C%0A        requestedDriver == %22org.openqa.selenium.ie.InternetExplorerDriver%22
 ) %7B%0A      ca
@@ -1608,37 +1608,31 @@
 lse if (
-driverClass.getName()
+requestedDriver
  ==%0A    
@@ -1699,16 +1699,89 @@
 ForTest%22
+ %7C%7C %0A        requestedDriver == %22org.openqa.selenium.chrome.ChromeDriver%22
 ) %7B%0A    
@@ -1842,37 +1842,31 @@
 lse if (
-driverClass.getName()
+requestedDriver
  == %22com

Allow sauce-backed implementations of the non-test browsers, too