1 |
4307
|
leinfelder
|
/*
|
2 |
|
|
* Copyright 2004 ThoughtWorks, Inc
|
3 |
|
|
*
|
4 |
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
5 |
|
|
* you may not use this file except in compliance with the License.
|
6 |
|
|
* You may obtain a copy of the License at
|
7 |
|
|
*
|
8 |
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
9 |
|
|
*
|
10 |
|
|
* Unless required by applicable law or agreed to in writing, software
|
11 |
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
12 |
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13 |
|
|
* See the License for the specific language governing permissions and
|
14 |
|
|
* limitations under the License.
|
15 |
|
|
*
|
16 |
|
|
*/
|
17 |
|
|
|
18 |
|
|
// Although it's generally better web development practice not to use
|
19 |
|
|
// browser-detection (feature detection is better), the subtle browser
|
20 |
|
|
// differences that Selenium has to work around seem to make it
|
21 |
|
|
// necessary. Maybe as we learn more about what we need, we can do this in
|
22 |
|
|
// a more "feature-centric" rather than "browser-centric" way.
|
23 |
|
|
|
24 |
|
|
var BrowserVersion = function() {
|
25 |
|
|
this.name = navigator.appName;
|
26 |
|
|
|
27 |
|
|
if (window.opera != null) {
|
28 |
|
|
this.browser = BrowserVersion.OPERA;
|
29 |
|
|
this.isOpera = true;
|
30 |
|
|
return;
|
31 |
|
|
}
|
32 |
|
|
|
33 |
|
|
var _getQueryParameter = function(searchKey) {
|
34 |
|
|
var str = location.search.substr(1);
|
35 |
|
|
if (str == null) return null;
|
36 |
|
|
var clauses = str.split('&');
|
37 |
|
|
for (var i = 0; i < clauses.length; i++) {
|
38 |
|
|
var keyValuePair = clauses[i].split('=', 2);
|
39 |
|
|
var key = unescape(keyValuePair[0]);
|
40 |
|
|
if (key == searchKey) {
|
41 |
|
|
return unescape(keyValuePair[1]);
|
42 |
|
|
}
|
43 |
|
|
}
|
44 |
|
|
return null;
|
45 |
|
|
};
|
46 |
|
|
|
47 |
|
|
var self = this;
|
48 |
|
|
|
49 |
|
|
var checkChrome = function() {
|
50 |
|
|
var loc = window.document.location.href;
|
51 |
|
|
try {
|
52 |
|
|
loc = window.top.document.location.href;
|
53 |
|
|
if (/^chrome:\/\//.test(loc)) {
|
54 |
|
|
self.isChrome = true;
|
55 |
|
|
} else {
|
56 |
|
|
self.isChrome = false;
|
57 |
|
|
}
|
58 |
|
|
} catch (e) {
|
59 |
|
|
// can't see the top (that means we might be chrome, but it's impossible to be sure)
|
60 |
|
|
self.isChromeDetectable = "no, top location couldn't be read in this window";
|
61 |
|
|
if (_getQueryParameter('thisIsChrome')) {
|
62 |
|
|
self.isChrome = true;
|
63 |
|
|
} else {
|
64 |
|
|
self.isChrome = false;
|
65 |
|
|
}
|
66 |
|
|
}
|
67 |
|
|
|
68 |
|
|
|
69 |
|
|
}
|
70 |
|
|
|
71 |
|
|
|
72 |
|
|
|
73 |
|
|
if (this.name == "Microsoft Internet Explorer") {
|
74 |
|
|
this.browser = BrowserVersion.IE;
|
75 |
|
|
this.isIE = true;
|
76 |
|
|
try {
|
77 |
|
|
if (window.top.SeleniumHTARunner && window.top.document.location.pathname.match(/.hta$/i)) {
|
78 |
|
|
this.isHTA = true;
|
79 |
|
|
}
|
80 |
|
|
} catch (e) {
|
81 |
|
|
this.isHTADetectable = "no, top location couldn't be read in this window";
|
82 |
|
|
if (_getQueryParameter('thisIsHTA')) {
|
83 |
|
|
self.isHTA = true;
|
84 |
|
|
} else {
|
85 |
|
|
self.isHTA = false;
|
86 |
|
|
}
|
87 |
|
|
}
|
88 |
|
|
if ("0" == navigator.appMinorVersion) {
|
89 |
|
|
this.preSV1 = true;
|
90 |
|
|
if (navigator.appVersion.match(/MSIE 6.0/)) {
|
91 |
|
|
this.appearsToBeBrokenInitialIE6 = true;
|
92 |
|
|
}
|
93 |
|
|
}
|
94 |
|
|
return;
|
95 |
|
|
}
|
96 |
|
|
|
97 |
|
|
if (navigator.userAgent.indexOf('Safari') != -1) {
|
98 |
|
|
this.browser = BrowserVersion.SAFARI;
|
99 |
|
|
this.isSafari = true;
|
100 |
|
|
this.khtml = true;
|
101 |
|
|
return;
|
102 |
|
|
}
|
103 |
|
|
|
104 |
|
|
if (navigator.userAgent.indexOf('Konqueror') != -1) {
|
105 |
|
|
this.browser = BrowserVersion.KONQUEROR;
|
106 |
|
|
this.isKonqueror = true;
|
107 |
|
|
this.khtml = true;
|
108 |
|
|
return;
|
109 |
|
|
}
|
110 |
|
|
|
111 |
|
|
if (navigator.userAgent.indexOf('Firefox') != -1) {
|
112 |
|
|
this.browser = BrowserVersion.FIREFOX;
|
113 |
|
|
this.isFirefox = true;
|
114 |
|
|
this.isGecko = true;
|
115 |
|
|
var result = /.*Firefox\/([\d\.]+).*/.exec(navigator.userAgent);
|
116 |
|
|
if (result) {
|
117 |
|
|
this.firefoxVersion = result[1];
|
118 |
|
|
}
|
119 |
|
|
checkChrome();
|
120 |
|
|
return;
|
121 |
|
|
}
|
122 |
|
|
|
123 |
|
|
if (navigator.userAgent.indexOf('Gecko') != -1) {
|
124 |
|
|
this.browser = BrowserVersion.MOZILLA;
|
125 |
|
|
this.isMozilla = true;
|
126 |
|
|
this.isGecko = true;
|
127 |
|
|
checkChrome();
|
128 |
|
|
return;
|
129 |
|
|
}
|
130 |
|
|
|
131 |
|
|
this.browser = BrowserVersion.UNKNOWN;
|
132 |
|
|
}
|
133 |
|
|
|
134 |
|
|
BrowserVersion.OPERA = "Opera";
|
135 |
|
|
BrowserVersion.IE = "IE";
|
136 |
|
|
BrowserVersion.KONQUEROR = "Konqueror";
|
137 |
|
|
BrowserVersion.SAFARI = "Safari";
|
138 |
|
|
BrowserVersion.FIREFOX = "Firefox";
|
139 |
|
|
BrowserVersion.MOZILLA = "Mozilla";
|
140 |
|
|
BrowserVersion.UNKNOWN = "Unknown";
|
141 |
|
|
|
142 |
|
|
var browserVersion = new BrowserVersion();
|