PageRenderTime 27ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/testing/selenium-core/scripts/selenium-browserdetect.js

http://datanucleus-appengine.googlecode.com/
JavaScript | 153 lines | 111 code | 20 blank | 22 comment | 34 complexity | ed38f4726ca7227b7da20a77f3845579 MD5 | raw file
Possible License(s): Apache-2.0
  1. /*
  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. // Although it's generally better web development practice not to use
  18. // browser-detection (feature detection is better), the subtle browser
  19. // differences that Selenium has to work around seem to make it
  20. // necessary. Maybe as we learn more about what we need, we can do this in
  21. // a more "feature-centric" rather than "browser-centric" way.
  22. var BrowserVersion = function() {
  23. this.name = navigator.appName;
  24. if (navigator.userAgent.indexOf('Mac OS X') != -1) {
  25. this.isOSX = true;
  26. }
  27. if (navigator.userAgent.indexOf('Windows NT 6') != -1) {
  28. this.isVista = true;
  29. }
  30. if (window.opera != null) {
  31. this.browser = BrowserVersion.OPERA;
  32. this.isOpera = true;
  33. return;
  34. }
  35. var _getQueryParameter = function(searchKey) {
  36. var str = location.search.substr(1);
  37. if (str == null) return null;
  38. var clauses = str.split('&');
  39. for (var i = 0; i < clauses.length; i++) {
  40. var keyValuePair = clauses[i].split('=', 2);
  41. var key = unescape(keyValuePair[0]);
  42. if (key == searchKey) {
  43. return unescape(keyValuePair[1]);
  44. }
  45. }
  46. return null;
  47. };
  48. var self = this;
  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. if (this.name == "Microsoft Internet Explorer") {
  69. this.browser = BrowserVersion.IE;
  70. this.isIE = true;
  71. try {
  72. if (window.top.SeleniumHTARunner && window.top.document.location.pathname.match(/.hta$/i)) {
  73. this.isHTA = true;
  74. }
  75. } catch (e) {
  76. this.isHTADetectable = "no, top location couldn't be read in this window";
  77. if (_getQueryParameter('thisIsHTA')) {
  78. self.isHTA = true;
  79. } else {
  80. self.isHTA = false;
  81. }
  82. }
  83. if (navigator.appVersion.match(/MSIE 6.0/)) {
  84. this.isIE6 = true;
  85. }
  86. if ("0" == navigator.appMinorVersion) {
  87. this.preSV1 = true;
  88. if (this.isIE6) {
  89. this.appearsToBeBrokenInitialIE6 = true;
  90. }
  91. }
  92. return;
  93. }
  94. if (navigator.userAgent.indexOf('Safari') != -1) {
  95. this.browser = BrowserVersion.SAFARI;
  96. this.isSafari = true;
  97. this.khtml = true;
  98. return;
  99. }
  100. if (navigator.userAgent.indexOf('Konqueror') != -1) {
  101. this.browser = BrowserVersion.KONQUEROR;
  102. this.isKonqueror = true;
  103. this.khtml = true;
  104. return;
  105. }
  106. if (navigator.userAgent.indexOf('Firefox') != -1) {
  107. this.browser = BrowserVersion.FIREFOX;
  108. this.isFirefox = true;
  109. this.isGecko = true;
  110. var result = /.*Firefox\/([\d\.]+).*/.exec(navigator.userAgent);
  111. if (result) {
  112. this.firefoxVersion = result[1];
  113. }
  114. checkChrome();
  115. return;
  116. }
  117. if (navigator.userAgent.indexOf('Gecko') != -1) {
  118. this.browser = BrowserVersion.MOZILLA;
  119. this.isMozilla = true;
  120. this.isGecko = true;
  121. checkChrome();
  122. return;
  123. }
  124. this.browser = BrowserVersion.UNKNOWN;
  125. }
  126. BrowserVersion.OPERA = "Opera";
  127. BrowserVersion.IE = "IE";
  128. BrowserVersion.KONQUEROR = "Konqueror";
  129. BrowserVersion.SAFARI = "Safari";
  130. BrowserVersion.FIREFOX = "Firefox";
  131. BrowserVersion.MOZILLA = "Mozilla";
  132. BrowserVersion.UNKNOWN = "Unknown";
  133. var browserVersion = new BrowserVersion();