com.gargoylesoftware.htmlunit
Class BrowserVersion

java.lang.Object
  extended by com.gargoylesoftware.htmlunit.BrowserVersion
All Implemented Interfaces:
Serializable, Cloneable

public class BrowserVersion
extends Object
implements Serializable, Cloneable

Objects of this class represent one specific version of a given browser. Predefined constants are provided for common browser versions.

You can change the constants by something like:

      String applicationName = "APPNAME";
      String applicationVersion = "APPVERSION";
      String userAgent = "USERAGENT";
      int browserVersionNumeric = NUMERIC;

      BrowserVersion browser = new BrowserVersion(applicationName, applicationVersion, userAgent, browserVersionNumeric) {
          public boolean hasFeature(BrowserVersionFeatures property) {

              // change features here
              return BrowserVersion.BROWSER.hasFeature(property);
          }
      };
 
However, note that the constants are not enough to fully customize the browser, you also need to look into the BrowserVersionFeatures and the classes inside "javascript" package.

Version:
$Revision: 9058 $
Author:
Mike Bowler, Daniel Gredler, Marc Guillemot, Chris Erskine, Ahmed Ashour, Frank Danek, Ronald Brill
See Also:
Serialized Form

Field Summary
static BrowserVersion CHROME
          Latest Chrome.
static BrowserVersion FIREFOX_17
          Deprecated. as of 2.14
static BrowserVersion FIREFOX_24
          Firefox 24 ESR.
static BrowserVersion INTERNET_EXPLORER_11
          Internet Explorer 11.
static BrowserVersion INTERNET_EXPLORER_8
          Deprecated. as of 2.14
static BrowserVersion INTERNET_EXPLORER_9
          Deprecated. as of 2.14
 
Constructor Summary
BrowserVersion(String applicationName, String applicationVersion, String userAgent, float browserVersionNumeric)
          Instantiates one.
BrowserVersion(String applicationName, String applicationVersion, String userAgent, float browserVersionNumeric, BrowserVersionFeatures[] features)
          Instantiates one.
 
Method Summary
 BrowserVersion clone()
          Creates and return a copy of this object.
 boolean equals(Object o)
          
 String getApplicationCodeName()
          Returns the application code name, for example "Mozilla".
 String getApplicationMinorVersion()
          Returns the application minor version, for example "0".
 String getApplicationName()
          Returns the application name, for example "Microsoft Internet Explorer".
 String getApplicationVersion()
          Returns the application version, for example "4.0 (compatible; MSIE 6.0b; Windows 98)".
 String getBrowserLanguage()
          Returns the browser application language, for example "en-us".
 float getBrowserVersionNumeric()
           
 String getBuildId()
          Returns the buildId.
 String getCpuClass()
          Returns the type of CPU in the machine, for example "x86".
 String getCssAcceptHeader()
          Returns the value used by the browser for the accept header if requesting a css declaration.
static BrowserVersion getDefault()
          Returns the default browser version that is used whenever a specific version isn't specified.
 String getHtmlAcceptHeader()
          Returns the value used by the browser for the accept header if requesting a page.
 String getImgAcceptHeader()
          Returns the value used by the browser for the accept header if requesting an image.
 String getNickname()
          Returns the short name of the browser like "FF3", "IE7", ...
 String getPlatform()
          Returns the platform on which the application is running, for example "Win32".
 Set<PluginConfiguration> getPlugins()
          Returns the available plugins.
 String getScriptAcceptHeader()
          Returns the value used by the browser for the accept header if requesting an script.
 String getSystemLanguage()
          Returns the system language, for example "en-us".
 String getUserAgent()
          Returns the user agent string, for example "Mozilla/4.0 (compatible; MSIE 6.0b; Windows 98)".
 String getUserLanguage()
          Returns the user language, for example "en-us".
 String getVendor()
           
 String getXmlHttpRequestAcceptHeader()
          Returns the value used by the browser for the accept header if performing an XMLHttpRequest.
 boolean hasFeature(BrowserVersionFeatures property)
          Indicates if this instance has the given feature.
 int hashCode()
          
 boolean isChrome()
          Returns true if this BrowserVersion instance represents some version of Google Chrome.
 boolean isFirefox()
          Returns true if this BrowserVersion instance represents some version of Firefox like FIREFOX_17 or FIREFOX_24.
 boolean isIE()
          Returns true if this BrowserVersion instance represents some version of Internet Explorer.
 boolean isOnLine()
          Returns true if the browser is currently online.
 void setApplicationCodeName(String applicationCodeName)
           
 void setApplicationMinorVersion(String applicationMinorVersion)
           
 void setApplicationName(String applicationName)
           
 void setApplicationVersion(String applicationVersion)
           
 void setBrowserLanguage(String browserLanguage)
           
 void setBrowserVersion(float browserVersion)
           
 void setCpuClass(String cpuClass)
           
 void setCssAcceptHeader(String cssAcceptHeader)
           
static void setDefault(BrowserVersion newBrowserVersion)
          Sets the default browser version that is used whenever a specific version isn't specified.
 void setHtmlAcceptHeader(String htmlAcceptHeader)
           
 void setImgAcceptHeader(String imgAcceptHeader)
           
 void setOnLine(boolean onLine)
           
 void setPlatform(String platform)
           
 void setScriptAcceptHeader(String scriptAcceptHeader)
           
 void setSystemLanguage(String systemLanguage)
           
 void setUserAgent(String userAgent)
           
 void setUserLanguage(String userLanguage)
           
 void setVendor(String vendor)
           
 void setXmlHttpRequestAcceptHeader(String xmlHttpRequestAcceptHeader)
           
 String toString()
           
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

FIREFOX_17

@Deprecated
public static final BrowserVersion FIREFOX_17
Deprecated. as of 2.14
Firefox 17 ESR.

Since:
2.12

FIREFOX_24

public static final BrowserVersion FIREFOX_24
Firefox 24 ESR.

Since:
2.14

INTERNET_EXPLORER_8

@Deprecated
public static final BrowserVersion INTERNET_EXPLORER_8
Deprecated. as of 2.14
Internet Explorer 8.


INTERNET_EXPLORER_9

@Deprecated
public static final BrowserVersion INTERNET_EXPLORER_9
Deprecated. as of 2.14
Internet Explorer 9. Work In Progress!!!


INTERNET_EXPLORER_11

public static final BrowserVersion INTERNET_EXPLORER_11
Internet Explorer 11. Work In Progress!!!


CHROME

public static final BrowserVersion CHROME
Latest Chrome. Work In Progress!!!

Constructor Detail

BrowserVersion

public BrowserVersion(String applicationName,
                      String applicationVersion,
                      String userAgent,
                      float browserVersionNumeric)
Instantiates one.

Parameters:
applicationName - the name of the application
applicationVersion - the version string of the application
userAgent - the user agent string that will be sent to the server
browserVersionNumeric - the floating number version of the browser

BrowserVersion

public BrowserVersion(String applicationName,
                      String applicationVersion,
                      String userAgent,
                      float browserVersionNumeric,
                      BrowserVersionFeatures[] features)
Instantiates one.

Parameters:
applicationName - the name of the application
applicationVersion - the version string of the application
userAgent - the user agent string that will be sent to the server
browserVersionNumeric - the floating number version of the browser
features - the browser features
Method Detail

getDefault

public static BrowserVersion getDefault()
Returns the default browser version that is used whenever a specific version isn't specified. Defaults to INTERNET_EXPLORER_8.

Returns:
the default browser version

setDefault

public static void setDefault(BrowserVersion newBrowserVersion)
Sets the default browser version that is used whenever a specific version isn't specified.

Parameters:
newBrowserVersion - the new default browser version

isIE

public final boolean isIE()
Returns true if this BrowserVersion instance represents some version of Internet Explorer.

Returns:
whether or not this version is a version of IE

isChrome

public final boolean isChrome()
Returns true if this BrowserVersion instance represents some version of Google Chrome. Note that Google Chrome does not return 'Chrome' in the application name, we have to look in the nickname.

Returns:
whether or not this version is a version of a Chrome browser.

isFirefox

public final boolean isFirefox()
Returns true if this BrowserVersion instance represents some version of Firefox like FIREFOX_17 or FIREFOX_24.

Returns:
whether or not this version is a version of a Firefox browser

getApplicationCodeName

public String getApplicationCodeName()
Returns the application code name, for example "Mozilla". Default value is "Mozilla" if not explicitly configured.

Returns:
the application code name
See Also:
MSDN documentation

getApplicationMinorVersion

public String getApplicationMinorVersion()
Returns the application minor version, for example "0". Default value is "0" if not explicitly configured.

Returns:
the application minor version
See Also:
MSDN documentation

getApplicationName

public String getApplicationName()
Returns the application name, for example "Microsoft Internet Explorer".

Returns:
the application name
See Also:
MSDN documentation

getApplicationVersion

public String getApplicationVersion()
Returns the application version, for example "4.0 (compatible; MSIE 6.0b; Windows 98)".

Returns:
the application version
See Also:
MSDN documentation

getVendor

public String getVendor()
Returns:
the vendor

getBrowserLanguage

public String getBrowserLanguage()
Returns the browser application language, for example "en-us". Default value is LANGUAGE_ENGLISH_US if not explicitly configured.

Returns:
the browser application language
See Also:
MSDN documentation

getCpuClass

public String getCpuClass()
Returns the type of CPU in the machine, for example "x86". Default value is CPU_CLASS_X86 if not explicitly configured.

Returns:
the type of CPU in the machine
See Also:
MSDN documentation

isOnLine

public boolean isOnLine()
Returns true if the browser is currently online. Default value is true if not explicitly configured.

Returns:
true if the browser is currently online
See Also:
MSDN documentation

getPlatform

public String getPlatform()
Returns the platform on which the application is running, for example "Win32". Default value is PLATFORM_WIN32 if not explicitly configured.

Returns:
the platform on which the application is running
See Also:
MSDN documentation

getSystemLanguage

public String getSystemLanguage()
Returns the system language, for example "en-us". Default value is LANGUAGE_ENGLISH_US if not explicitly configured.

Returns:
the system language
See Also:
MSDN documentation

getUserAgent

public String getUserAgent()
Returns the user agent string, for example "Mozilla/4.0 (compatible; MSIE 6.0b; Windows 98)".

Returns:
the user agent string

getUserLanguage

public String getUserLanguage()
Returns the user language, for example "en-us". Default value is LANGUAGE_ENGLISH_US if not explicitly configured.

Returns:
the user language
See Also:
MSDN documentation

getHtmlAcceptHeader

public String getHtmlAcceptHeader()
Returns the value used by the browser for the accept header if requesting a page.

Returns:
the accept header string

getScriptAcceptHeader

public String getScriptAcceptHeader()
Returns the value used by the browser for the accept header if requesting an script.

Returns:
the accept header string

getXmlHttpRequestAcceptHeader

public String getXmlHttpRequestAcceptHeader()
Returns the value used by the browser for the accept header if performing an XMLHttpRequest.

Returns:
the accept header string

getImgAcceptHeader

public String getImgAcceptHeader()
Returns the value used by the browser for the accept header if requesting an image.

Returns:
the accept header string

getCssAcceptHeader

public String getCssAcceptHeader()
Returns the value used by the browser for the accept header if requesting a css declaration.

Returns:
the accept header string

setApplicationCodeName

public void setApplicationCodeName(String applicationCodeName)
Parameters:
applicationCodeName - the applicationCodeName to set

setApplicationMinorVersion

public void setApplicationMinorVersion(String applicationMinorVersion)
Parameters:
applicationMinorVersion - the applicationMinorVersion to set

setApplicationName

public void setApplicationName(String applicationName)
Parameters:
applicationName - the applicationName to set

setApplicationVersion

public void setApplicationVersion(String applicationVersion)
Parameters:
applicationVersion - the applicationVersion to set

setVendor

public void setVendor(String vendor)
Parameters:
vendor - the vendor to set

setBrowserLanguage

public void setBrowserLanguage(String browserLanguage)
Parameters:
browserLanguage - the browserLanguage to set

setCpuClass

public void setCpuClass(String cpuClass)
Parameters:
cpuClass - the cpuClass to set

setOnLine

public void setOnLine(boolean onLine)
Parameters:
onLine - the onLine to set

setPlatform

public void setPlatform(String platform)
Parameters:
platform - the platform to set

setSystemLanguage

public void setSystemLanguage(String systemLanguage)
Parameters:
systemLanguage - the systemLanguage to set

setUserAgent

public void setUserAgent(String userAgent)
Parameters:
userAgent - the userAgent to set

setUserLanguage

public void setUserLanguage(String userLanguage)
Parameters:
userLanguage - the userLanguage to set

setBrowserVersion

public void setBrowserVersion(float browserVersion)
Parameters:
browserVersion - the browserVersion to set

setHtmlAcceptHeader

public void setHtmlAcceptHeader(String htmlAcceptHeader)
Parameters:
htmlAcceptHeader - the accept header to be used when retrieving pages

setImgAcceptHeader

public void setImgAcceptHeader(String imgAcceptHeader)
Parameters:
imgAcceptHeader - the accept header to be used when retrieving images

setCssAcceptHeader

public void setCssAcceptHeader(String cssAcceptHeader)
Parameters:
cssAcceptHeader - the accept header to be used when retrieving pages

setScriptAcceptHeader

public void setScriptAcceptHeader(String scriptAcceptHeader)
Parameters:
scriptAcceptHeader - the accept header to be used when retrieving scripts

setXmlHttpRequestAcceptHeader

public void setXmlHttpRequestAcceptHeader(String xmlHttpRequestAcceptHeader)
Parameters:
xmlHttpRequestAcceptHeader - the accept header to be used when performing XMLHttpRequests

getBrowserVersionNumeric

public float getBrowserVersionNumeric()
Returns:
the browserVersionNumeric

equals

public boolean equals(Object o)

Overrides:
equals in class Object

hashCode

public int hashCode()

Overrides:
hashCode in class Object

getPlugins

public Set<PluginConfiguration> getPlugins()
Returns the available plugins. This makes only sense for Firefox as only this browser makes this kind of information available via JavaScript.

Returns:
the available plugins

hasFeature

public boolean hasFeature(BrowserVersionFeatures property)
Indicates if this instance has the given feature. Used for HtmlUnit internal processing.

Parameters:
property - the property name
Returns:
false if this browser doesn't have this feature

getNickname

public String getNickname()
Returns the short name of the browser like "FF3", "IE7", ... This is used in different tests to reference the browser to which it applies.

Returns:
the short name (if any)

getBuildId

public String getBuildId()
Returns the buildId.

Returns:
the buildId

toString

public String toString()
Overrides:
toString in class Object

clone

public BrowserVersion clone()
Creates and return a copy of this object. Current instance and cloned object can be modified independently.

Overrides:
clone in class Object
Returns:
a clone of this instance.


Copyright © 2002–2014 Gargoyle Software Inc.. All rights reserved.