From b6dfb6c447cf502e694d299dbda1b2e092c3312d Mon Sep 17 00:00:00 2001 From: wei <> Date: Wed, 5 Jul 2006 07:35:50 +0000 Subject: move tests to test_tools --- .../core/scripts/selenium-browserdetect.js | 115 +++++++++++++++++++++ 1 file changed, 115 insertions(+) create mode 100644 test_tools/selenium/core/scripts/selenium-browserdetect.js (limited to 'test_tools/selenium/core/scripts/selenium-browserdetect.js') diff --git a/test_tools/selenium/core/scripts/selenium-browserdetect.js b/test_tools/selenium/core/scripts/selenium-browserdetect.js new file mode 100644 index 00000000..137a1518 --- /dev/null +++ b/test_tools/selenium/core/scripts/selenium-browserdetect.js @@ -0,0 +1,115 @@ +/* +* Copyright 2004 ThoughtWorks, Inc +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +*/ + +// Although it's generally better web development practice not to use browser-detection +// (feature detection is better), the subtle browser differences that Selenium has to +// work around seem to make it necessary. Maybe as we learn more about what we need, +// we can do this in a more "feature-centric" rather than "browser-centric" way. + +BrowserVersion = function() { + this.name = navigator.appName; + + if (window.opera != null) + { + this.browser = BrowserVersion.OPERA; + this.isOpera = true; + return; + } + + var self = this; + + var checkChrome = function() { + var loc = window.document.location.href; + try { + loc = window.top.document.location.href; + } catch (e) { + // can't see the top (that means we might be chrome, but it's impossible to be sure) + self.isChromeDetectable = "no, top location couldn't be read in this window"; + } + + if (/^chrome:\/\//.test(loc)) { + self.isChrome = true; + } else { + self.isChrome = false; + } + } + + if (this.name == "Microsoft Internet Explorer") + { + this.browser = BrowserVersion.IE; + this.isIE = true; + if (window.top.SeleniumHTARunner && window.top.document.location.pathname.match(/.hta$/i)) { + this.isHTA = true; + } + if ("0" == navigator.appMinorVersion) { + this.preSV1 = true; + } + return; + } + + if (navigator.userAgent.indexOf('Safari') != -1) + { + this.browser = BrowserVersion.SAFARI; + this.isSafari = true; + this.khtml = true; + return; + } + + if (navigator.userAgent.indexOf('Konqueror') != -1) + { + this.browser = BrowserVersion.KONQUEROR; + this.isKonqueror = true; + this.khtml = true; + return; + } + + if (navigator.userAgent.indexOf('Firefox') != -1) + { + this.browser = BrowserVersion.FIREFOX; + this.isFirefox = true; + this.isGecko = true; + var result = /.*Firefox\/([\d\.]+).*/.exec(navigator.userAgent); + if (result) + { + this.firefoxVersion = result[1]; + } + checkChrome(); + return; + } + + if (navigator.userAgent.indexOf('Gecko') != -1) + { + this.browser = BrowserVersion.MOZILLA; + this.isMozilla = true; + this.isGecko = true; + checkChrome(); + return; + } + + this.browser = BrowserVersion.UNKNOWN; +} + +BrowserVersion.OPERA = "Opera"; +BrowserVersion.IE = "IE"; +BrowserVersion.KONQUEROR = "Konqueror"; +BrowserVersion.SAFARI = "Safari"; +BrowserVersion.FIREFOX = "Firefox"; +BrowserVersion.MOZILLA = "Mozilla"; +BrowserVersion.UNKNOWN = "Unknown"; + +browserVersion = new BrowserVersion(); + -- cgit v1.2.3