Adding mapbox-gl branch
This commit is contained in:
@@ -0,0 +1,90 @@
|
||||
// Copyright 2008 The Closure Library Authors. All Rights Reserved.
|
||||
//
|
||||
// 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.
|
||||
|
||||
/**
|
||||
* @fileoverview Detects the Adobe Reader PDF browser plugin.
|
||||
*
|
||||
* @author chrisn@google.com (Chris Nokleberg)
|
||||
* @see ../demos/useragent.html
|
||||
*/
|
||||
|
||||
/** @suppress {extraProvide} */
|
||||
goog.provide('goog.userAgent.adobeReader');
|
||||
|
||||
goog.require('goog.string');
|
||||
goog.require('goog.userAgent');
|
||||
|
||||
|
||||
(function() {
|
||||
var version = '';
|
||||
if (goog.userAgent.IE) {
|
||||
var detectOnIe = function(classId) {
|
||||
/** @preserveTry */
|
||||
try {
|
||||
new ActiveXObject(classId);
|
||||
return true;
|
||||
} catch (ex) {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
if (detectOnIe('AcroPDF.PDF.1')) {
|
||||
version = '7';
|
||||
} else if (detectOnIe('PDF.PdfCtrl.6')) {
|
||||
version = '6';
|
||||
}
|
||||
// TODO(chrisn): Add detection for previous versions if anyone needs them.
|
||||
} else {
|
||||
if (navigator.mimeTypes && navigator.mimeTypes.length > 0) {
|
||||
var mimeType = navigator.mimeTypes['application/pdf'];
|
||||
if (mimeType && mimeType.enabledPlugin) {
|
||||
var description = mimeType.enabledPlugin.description;
|
||||
if (description && description.indexOf('Adobe') != -1) {
|
||||
// Newer plugins do not include the version in the description, so we
|
||||
// default to 7.
|
||||
version = description.indexOf('Version') != -1 ?
|
||||
description.split('Version')[1] : '7';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether we detect the user has the Adobe Reader browser plugin installed.
|
||||
* @type {boolean}
|
||||
*/
|
||||
goog.userAgent.adobeReader.HAS_READER = !!version;
|
||||
|
||||
|
||||
/**
|
||||
* The version of the installed Adobe Reader plugin. Versions after 7
|
||||
* will all be reported as '7'.
|
||||
* @type {string}
|
||||
*/
|
||||
goog.userAgent.adobeReader.VERSION = version;
|
||||
|
||||
|
||||
/**
|
||||
* On certain combinations of platform/browser/plugin, a print dialog
|
||||
* can be shown for PDF files without a download dialog or making the
|
||||
* PDF visible to the user, by loading the PDF into a hidden iframe.
|
||||
*
|
||||
* Currently this variable is true if Adobe Reader version 6 or later
|
||||
* is detected on Windows.
|
||||
*
|
||||
* @type {boolean}
|
||||
*/
|
||||
goog.userAgent.adobeReader.SILENT_PRINT = goog.userAgent.WINDOWS &&
|
||||
goog.string.compareVersions(version, '6') >= 0;
|
||||
|
||||
})();
|
||||
@@ -0,0 +1,22 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<!--
|
||||
Copyright 2008 The Closure Library Authors. All Rights Reserved.
|
||||
|
||||
Use of this source code is governed by the Apache License, Version 2.0.
|
||||
See the COPYING file for details.
|
||||
-->
|
||||
<head>
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
||||
<title>
|
||||
Closure Unit Tests - goog.userAgent.adobeReader
|
||||
</title>
|
||||
<script src="../base.js">
|
||||
</script>
|
||||
<script>
|
||||
goog.require('goog.userAgent.adobeReaderTest');
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,29 @@
|
||||
// Copyright 2008 The Closure Library Authors. All Rights Reserved.
|
||||
//
|
||||
// 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.
|
||||
|
||||
goog.provide('goog.userAgent.adobeReaderTest');
|
||||
goog.setTestOnly('goog.userAgent.adobeReaderTest');
|
||||
|
||||
goog.require('goog.testing.jsunit');
|
||||
goog.require('goog.userAgent.adobeReader');
|
||||
|
||||
// For now, just test that the variables exist, the test runner will
|
||||
// pick up any runtime errors.
|
||||
// TODO(chrisn): Mock out each browser implementation and test the code path
|
||||
// correctly detects the version for each case.
|
||||
function testAdobeReader() {
|
||||
assertNotUndefined(goog.userAgent.adobeReader.HAS_READER);
|
||||
assertNotUndefined(goog.userAgent.adobeReader.VERSION);
|
||||
assertNotUndefined(goog.userAgent.adobeReader.SILENT_PRINT);
|
||||
}
|
||||
@@ -0,0 +1,156 @@
|
||||
// Copyright 2006 The Closure Library Authors. All Rights Reserved.
|
||||
//
|
||||
// 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.
|
||||
|
||||
/**
|
||||
* @fileoverview Flash detection.
|
||||
* @see ../demos/useragent.html
|
||||
*/
|
||||
|
||||
goog.provide('goog.userAgent.flash');
|
||||
|
||||
goog.require('goog.string');
|
||||
|
||||
|
||||
/**
|
||||
* @define {boolean} Whether we know at compile-time that the browser doesn't
|
||||
* have flash.
|
||||
*/
|
||||
goog.define('goog.userAgent.flash.ASSUME_NO_FLASH', false);
|
||||
|
||||
|
||||
/**
|
||||
* Whether we can detect that the browser has flash
|
||||
* @type {boolean}
|
||||
* @private
|
||||
*/
|
||||
goog.userAgent.flash.detectedFlash_ = false;
|
||||
|
||||
|
||||
/**
|
||||
* Full version information of flash installed, in form 7.0.61
|
||||
* @type {string}
|
||||
* @private
|
||||
*/
|
||||
goog.userAgent.flash.detectedFlashVersion_ = '';
|
||||
|
||||
|
||||
/**
|
||||
* Initializer for goog.userAgent.flash
|
||||
*
|
||||
* This is a named function so that it can be stripped via the jscompiler if
|
||||
* goog.userAgent.flash.ASSUME_NO_FLASH is true.
|
||||
* @private
|
||||
*/
|
||||
goog.userAgent.flash.init_ = function() {
|
||||
if (navigator.plugins && navigator.plugins.length) {
|
||||
var plugin = navigator.plugins['Shockwave Flash'];
|
||||
if (plugin) {
|
||||
goog.userAgent.flash.detectedFlash_ = true;
|
||||
if (plugin.description) {
|
||||
goog.userAgent.flash.detectedFlashVersion_ =
|
||||
goog.userAgent.flash.getVersion_(plugin.description);
|
||||
}
|
||||
}
|
||||
|
||||
if (navigator.plugins['Shockwave Flash 2.0']) {
|
||||
goog.userAgent.flash.detectedFlash_ = true;
|
||||
goog.userAgent.flash.detectedFlashVersion_ = '2.0.0.11';
|
||||
}
|
||||
|
||||
} else if (navigator.mimeTypes && navigator.mimeTypes.length) {
|
||||
var mimeType = navigator.mimeTypes['application/x-shockwave-flash'];
|
||||
goog.userAgent.flash.detectedFlash_ = mimeType && mimeType.enabledPlugin;
|
||||
if (goog.userAgent.flash.detectedFlash_) {
|
||||
goog.userAgent.flash.detectedFlashVersion_ =
|
||||
goog.userAgent.flash.getVersion_(mimeType.enabledPlugin.description);
|
||||
}
|
||||
|
||||
} else {
|
||||
/** @preserveTry */
|
||||
try {
|
||||
// Try 7 first, since we know we can use GetVariable with it
|
||||
var ax = new ActiveXObject('ShockwaveFlash.ShockwaveFlash.7');
|
||||
goog.userAgent.flash.detectedFlash_ = true;
|
||||
goog.userAgent.flash.detectedFlashVersion_ =
|
||||
goog.userAgent.flash.getVersion_(ax.GetVariable('$version'));
|
||||
} catch (e) {
|
||||
// Try 6 next, some versions are known to crash with GetVariable calls
|
||||
/** @preserveTry */
|
||||
try {
|
||||
var ax = new ActiveXObject('ShockwaveFlash.ShockwaveFlash.6');
|
||||
goog.userAgent.flash.detectedFlash_ = true;
|
||||
// First public version of Flash 6
|
||||
goog.userAgent.flash.detectedFlashVersion_ = '6.0.21';
|
||||
} catch (e2) {
|
||||
/** @preserveTry */
|
||||
try {
|
||||
// Try the default activeX
|
||||
var ax = new ActiveXObject('ShockwaveFlash.ShockwaveFlash');
|
||||
goog.userAgent.flash.detectedFlash_ = true;
|
||||
goog.userAgent.flash.detectedFlashVersion_ =
|
||||
goog.userAgent.flash.getVersion_(ax.GetVariable('$version'));
|
||||
} catch (e3) {
|
||||
// No flash
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Derived from Apple's suggested sniffer.
|
||||
* @param {string} desc e.g. Shockwave Flash 7.0 r61.
|
||||
* @return {string} 7.0.61.
|
||||
* @private
|
||||
*/
|
||||
goog.userAgent.flash.getVersion_ = function(desc) {
|
||||
var matches = desc.match(/[\d]+/g);
|
||||
if (!matches) {
|
||||
return '';
|
||||
}
|
||||
matches.length = 3; // To standardize IE vs FF
|
||||
return matches.join('.');
|
||||
};
|
||||
|
||||
|
||||
if (!goog.userAgent.flash.ASSUME_NO_FLASH) {
|
||||
goog.userAgent.flash.init_();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Whether we can detect that the browser has flash
|
||||
* @type {boolean}
|
||||
*/
|
||||
goog.userAgent.flash.HAS_FLASH = goog.userAgent.flash.detectedFlash_;
|
||||
|
||||
|
||||
/**
|
||||
* Full version information of flash installed, in form 7.0.61
|
||||
* @type {string}
|
||||
*/
|
||||
goog.userAgent.flash.VERSION = goog.userAgent.flash.detectedFlashVersion_;
|
||||
|
||||
|
||||
/**
|
||||
* Whether the installed flash version is as new or newer than a given version.
|
||||
* @param {string} version The version to check.
|
||||
* @return {boolean} Whether the installed flash version is as new or newer
|
||||
* than a given version.
|
||||
*/
|
||||
goog.userAgent.flash.isVersion = function(version) {
|
||||
return goog.string.compareVersions(goog.userAgent.flash.VERSION,
|
||||
version) >= 0;
|
||||
};
|
||||
@@ -0,0 +1,22 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<!--
|
||||
Copyright 2006 The Closure Library Authors. All Rights Reserved.
|
||||
|
||||
Use of this source code is governed by the Apache License, Version 2.0.
|
||||
See the COPYING file for details.
|
||||
-->
|
||||
<head>
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
||||
<title>
|
||||
Closure Unit Tests - goog.userAgent.flash
|
||||
</title>
|
||||
<script src="../base.js">
|
||||
</script>
|
||||
<script>
|
||||
goog.require('goog.userAgent.flashTest');
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,29 @@
|
||||
// Copyright 2006 The Closure Library Authors. All Rights Reserved.
|
||||
//
|
||||
// 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.
|
||||
|
||||
goog.provide('goog.userAgent.flashTest');
|
||||
goog.setTestOnly('goog.userAgent.flashTest');
|
||||
|
||||
goog.require('goog.testing.jsunit');
|
||||
goog.require('goog.userAgent.flash');
|
||||
|
||||
// For now, just test that the flash variables exist, the test runner will
|
||||
// pick up any runtime errors.
|
||||
// TODO(user): Mock out each browser implementation and test the code path
|
||||
// correctly detects the flash version for each case.
|
||||
function testFlash() {
|
||||
assertNotUndefined(goog.userAgent.flash.HAS_FLASH);
|
||||
assertNotUndefined(goog.userAgent.flash.VERSION);
|
||||
assertEquals(typeof goog.userAgent.flash.isVersion('5'), 'boolean');
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
// Copyright 2007 The Closure Library Authors. All Rights Reserved.
|
||||
//
|
||||
// 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.
|
||||
|
||||
/**
|
||||
* @fileoverview Newer versions of iPhoto include a Safari plugin which allows
|
||||
* the browser to detect if iPhoto is installed. Adapted from detection code
|
||||
* built into the Mac.com Gallery RSS feeds.
|
||||
* @author brenneman@google.com (Shawn Brenneman)
|
||||
* @see ../demos/useragent.html
|
||||
*/
|
||||
|
||||
|
||||
goog.provide('goog.userAgent.iphoto');
|
||||
|
||||
goog.require('goog.string');
|
||||
goog.require('goog.userAgent');
|
||||
|
||||
|
||||
(function() {
|
||||
var hasIphoto = false;
|
||||
var version = '';
|
||||
|
||||
/**
|
||||
* The plugin description string contains the version number as in the form
|
||||
* 'iPhoto 700'. This returns just the version number as a dotted string,
|
||||
* e.g., '7.0.0', compatible with {@code goog.string.compareVersions}.
|
||||
* @param {string} desc The version string.
|
||||
* @return {string} The dotted version.
|
||||
*/
|
||||
function getIphotoVersion(desc) {
|
||||
var matches = desc.match(/\d/g);
|
||||
return matches.join('.');
|
||||
}
|
||||
|
||||
if (goog.userAgent.WEBKIT &&
|
||||
navigator.mimeTypes &&
|
||||
navigator.mimeTypes.length > 0) {
|
||||
var iphoto = navigator.mimeTypes['application/photo'];
|
||||
|
||||
if (iphoto) {
|
||||
hasIphoto = true;
|
||||
var description = iphoto['description'];
|
||||
|
||||
if (description) {
|
||||
version = getIphotoVersion(description);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether we can detect that the user has iPhoto installed.
|
||||
* @type {boolean}
|
||||
*/
|
||||
goog.userAgent.iphoto.HAS_IPHOTO = hasIphoto;
|
||||
|
||||
|
||||
/**
|
||||
* The version of iPhoto installed if found.
|
||||
* @type {string}
|
||||
*/
|
||||
goog.userAgent.iphoto.VERSION = version;
|
||||
|
||||
})();
|
||||
|
||||
|
||||
/**
|
||||
* Whether the installed version of iPhoto is as new or newer than a given
|
||||
* version.
|
||||
* @param {string} version The version to check.
|
||||
* @return {boolean} Whether the installed version of iPhoto is as new or newer
|
||||
* than a given version.
|
||||
*/
|
||||
goog.userAgent.iphoto.isVersion = function(version) {
|
||||
return goog.string.compareVersions(
|
||||
goog.userAgent.iphoto.VERSION, version) >= 0;
|
||||
};
|
||||
@@ -0,0 +1,95 @@
|
||||
// Copyright 2007 The Closure Library Authors. All Rights Reserved.
|
||||
//
|
||||
// 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.
|
||||
|
||||
/**
|
||||
* @fileoverview Detection of JScript version.
|
||||
*
|
||||
* @author arv@google.com (Erik Arvidsson)
|
||||
*/
|
||||
|
||||
|
||||
goog.provide('goog.userAgent.jscript');
|
||||
|
||||
goog.require('goog.string');
|
||||
|
||||
|
||||
/**
|
||||
* @define {boolean} True if it is known at compile time that the runtime
|
||||
* environment will not be using JScript.
|
||||
*/
|
||||
goog.define('goog.userAgent.jscript.ASSUME_NO_JSCRIPT', false);
|
||||
|
||||
|
||||
/**
|
||||
* Initializer for goog.userAgent.jscript. Detects if the user agent is using
|
||||
* Microsoft JScript and which version of it.
|
||||
*
|
||||
* This is a named function so that it can be stripped via the jscompiler
|
||||
* option for stripping types.
|
||||
* @private
|
||||
*/
|
||||
goog.userAgent.jscript.init_ = function() {
|
||||
var hasScriptEngine = 'ScriptEngine' in goog.global;
|
||||
|
||||
/**
|
||||
* @type {boolean}
|
||||
* @private
|
||||
*/
|
||||
goog.userAgent.jscript.DETECTED_HAS_JSCRIPT_ =
|
||||
hasScriptEngine && goog.global['ScriptEngine']() == 'JScript';
|
||||
|
||||
/**
|
||||
* @type {string}
|
||||
* @private
|
||||
*/
|
||||
goog.userAgent.jscript.DETECTED_VERSION_ =
|
||||
goog.userAgent.jscript.DETECTED_HAS_JSCRIPT_ ?
|
||||
(goog.global['ScriptEngineMajorVersion']() + '.' +
|
||||
goog.global['ScriptEngineMinorVersion']() + '.' +
|
||||
goog.global['ScriptEngineBuildVersion']()) :
|
||||
'0';
|
||||
};
|
||||
|
||||
if (!goog.userAgent.jscript.ASSUME_NO_JSCRIPT) {
|
||||
goog.userAgent.jscript.init_();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Whether we detect that the user agent is using Microsoft JScript.
|
||||
* @type {boolean}
|
||||
*/
|
||||
goog.userAgent.jscript.HAS_JSCRIPT = goog.userAgent.jscript.ASSUME_NO_JSCRIPT ?
|
||||
false : goog.userAgent.jscript.DETECTED_HAS_JSCRIPT_;
|
||||
|
||||
|
||||
/**
|
||||
* The installed version of JScript.
|
||||
* @type {string}
|
||||
*/
|
||||
goog.userAgent.jscript.VERSION = goog.userAgent.jscript.ASSUME_NO_JSCRIPT ?
|
||||
'0' : goog.userAgent.jscript.DETECTED_VERSION_;
|
||||
|
||||
|
||||
/**
|
||||
* Whether the installed version of JScript is as new or newer than a given
|
||||
* version.
|
||||
* @param {string} version The version to check.
|
||||
* @return {boolean} Whether the installed version of JScript is as new or
|
||||
* newer than the given version.
|
||||
*/
|
||||
goog.userAgent.jscript.isVersion = function(version) {
|
||||
return goog.string.compareVersions(goog.userAgent.jscript.VERSION,
|
||||
version) >= 0;
|
||||
};
|
||||
@@ -0,0 +1,41 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<!--
|
||||
Copyright 2006 The Closure Library Authors. All Rights Reserved.
|
||||
|
||||
Use of this source code is governed by the Apache License, Version 2.0.
|
||||
See the COPYING file for details.
|
||||
-->
|
||||
<head>
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
||||
<title>
|
||||
Closure Unit Tests - goog.userAgent.jscript
|
||||
</title>
|
||||
<script>
|
||||
// Mock JScript functions
|
||||
|
||||
function ScriptEngine() {
|
||||
return 'JScript';
|
||||
}
|
||||
|
||||
function ScriptEngineMajorVersion() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
function ScriptEngineMinorVersion() {
|
||||
return 2;
|
||||
}
|
||||
|
||||
function ScriptEngineBuildVersion() {
|
||||
return 3456;
|
||||
}
|
||||
</script>
|
||||
<script src="../base.js">
|
||||
</script>
|
||||
<script>
|
||||
goog.require('goog.userAgent.jscriptTest');
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,54 @@
|
||||
// Copyright 2006 The Closure Library Authors. All Rights Reserved.
|
||||
//
|
||||
// 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.
|
||||
|
||||
// Mock JScript functions
|
||||
goog.provide('goog.userAgent.jscriptTest');
|
||||
goog.setTestOnly('goog.userAgent.jscriptTest');
|
||||
|
||||
goog.require('goog.testing.jsunit');
|
||||
goog.require('goog.userAgent.jscript');
|
||||
|
||||
function ScriptEngine() {
|
||||
return 'JScript';
|
||||
}
|
||||
|
||||
function ScriptEngineMajorVersion() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
function ScriptEngineMinorVersion() {
|
||||
return 2;
|
||||
}
|
||||
|
||||
function ScriptEngineBuildVersion() {
|
||||
return 3456;
|
||||
}
|
||||
|
||||
function testHasJscript() {
|
||||
assertTrue('Should have jscript', goog.userAgent.jscript.HAS_JSCRIPT);
|
||||
}
|
||||
|
||||
function testVersion() {
|
||||
assertEquals('Version should be 1.2.3456', '1.2.3456',
|
||||
goog.userAgent.jscript.VERSION);
|
||||
}
|
||||
|
||||
function testIsVersion() {
|
||||
assertTrue('Should be version 1.2.3456 or larger',
|
||||
goog.userAgent.jscript.isVersion('1.2.3456'));
|
||||
assertTrue('Should be version 1.2 or larger',
|
||||
goog.userAgent.jscript.isVersion('1.2'));
|
||||
assertFalse('Should not be version 8.9 or larger',
|
||||
goog.userAgent.jscript.isVersion('8.9'));
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
// Copyright 2014 The Closure Library Authors. All Rights Reserved.
|
||||
//
|
||||
// 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.
|
||||
|
||||
/**
|
||||
* @fileoverview Constants for determining keyboard support.
|
||||
*/
|
||||
|
||||
goog.provide('goog.userAgent.keyboard');
|
||||
|
||||
goog.require('goog.labs.userAgent.platform');
|
||||
|
||||
|
||||
/**
|
||||
* @define {boolean} Whether the user agent is running with in an environment
|
||||
* that should use Mac-based keyboard shortcuts (Meta instead of Ctrl, etc.).
|
||||
*/
|
||||
goog.define('goog.userAgent.keyboard.ASSUME_MAC_KEYBOARD', false);
|
||||
|
||||
|
||||
/**
|
||||
* Determines whether Mac-based keyboard shortcuts should be used.
|
||||
* @return {boolean}
|
||||
* @private
|
||||
*/
|
||||
goog.userAgent.keyboard.determineMacKeyboard_ = function() {
|
||||
return goog.labs.userAgent.platform.isMacintosh() ||
|
||||
goog.labs.userAgent.platform.isIos();
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Whether the user agent is running in an environment that uses Mac-based
|
||||
* keyboard shortcuts.
|
||||
* @type {boolean}
|
||||
*/
|
||||
goog.userAgent.keyboard.MAC_KEYBOARD =
|
||||
goog.userAgent.keyboard.ASSUME_MAC_KEYBOARD ||
|
||||
goog.userAgent.keyboard.determineMacKeyboard_();
|
||||
@@ -0,0 +1,225 @@
|
||||
// Copyright 2014 The Closure Library Authors. All Rights Reserved.
|
||||
//
|
||||
// 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.
|
||||
|
||||
goog.provide('goog.userAgent.keyboardTest');
|
||||
goog.setTestOnly('goog.userAgent.keyboardTest');
|
||||
|
||||
goog.require('goog.labs.userAgent.testAgents');
|
||||
goog.require('goog.labs.userAgent.util');
|
||||
goog.require('goog.testing.MockUserAgent');
|
||||
goog.require('goog.testing.jsunit');
|
||||
goog.require('goog.userAgent.keyboard');
|
||||
goog.require('goog.userAgentTestUtil');
|
||||
|
||||
|
||||
var mockAgent;
|
||||
|
||||
function setUp() {
|
||||
mockAgent = new goog.testing.MockUserAgent();
|
||||
mockAgent.install();
|
||||
}
|
||||
|
||||
function tearDown() {
|
||||
mockAgent.dispose();
|
||||
goog.labs.userAgent.util.setUserAgent(null);
|
||||
goog.userAgentTestUtil.reinitializeUserAgent();
|
||||
}
|
||||
|
||||
function testAndroid() {
|
||||
mockAgent.setNavigator({platform: 'Linux'});
|
||||
|
||||
setUserAgent(goog.labs.userAgent.testAgents.ANDROID_BROWSER_235);
|
||||
assertFalse(goog.userAgent.keyboard.MAC_KEYBOARD);
|
||||
|
||||
setUserAgent(goog.labs.userAgent.testAgents.ANDROID_BROWSER_221);
|
||||
assertFalse(goog.userAgent.keyboard.MAC_KEYBOARD);
|
||||
|
||||
setUserAgent(goog.labs.userAgent.testAgents.ANDROID_BROWSER_233);
|
||||
assertFalse(goog.userAgent.keyboard.MAC_KEYBOARD);
|
||||
|
||||
setUserAgent(goog.labs.userAgent.testAgents.ANDROID_BROWSER_403);
|
||||
assertFalse(goog.userAgent.keyboard.MAC_KEYBOARD);
|
||||
|
||||
setUserAgent(goog.labs.userAgent.testAgents.ANDROID_BROWSER_403_ALT);
|
||||
assertFalse(goog.userAgent.keyboard.MAC_KEYBOARD);
|
||||
}
|
||||
|
||||
function testIe() {
|
||||
mockAgent.setNavigator({platform: 'Windows'});
|
||||
|
||||
setUserAgent(goog.labs.userAgent.testAgents.IE_6);
|
||||
assertFalse(goog.userAgent.keyboard.MAC_KEYBOARD);
|
||||
|
||||
setUserAgent(goog.labs.userAgent.testAgents.IE_7);
|
||||
assertFalse(goog.userAgent.keyboard.MAC_KEYBOARD);
|
||||
|
||||
setUserAgent(goog.labs.userAgent.testAgents.IE_8);
|
||||
assertFalse(goog.userAgent.keyboard.MAC_KEYBOARD);
|
||||
|
||||
setUserAgent(
|
||||
goog.labs.userAgent.testAgents.IE_8_COMPATIBILITY);
|
||||
assertFalse(goog.userAgent.keyboard.MAC_KEYBOARD);
|
||||
|
||||
setUserAgent(goog.labs.userAgent.testAgents.IE_9);
|
||||
assertFalse(goog.userAgent.keyboard.MAC_KEYBOARD);
|
||||
|
||||
setUserAgent(goog.labs.userAgent.testAgents.IE_10);
|
||||
assertFalse(goog.userAgent.keyboard.MAC_KEYBOARD);
|
||||
|
||||
setUserAgent(
|
||||
goog.labs.userAgent.testAgents.IE_10_COMPATIBILITY);
|
||||
assertFalse(goog.userAgent.keyboard.MAC_KEYBOARD);
|
||||
|
||||
setUserAgent(goog.labs.userAgent.testAgents.IE_11);
|
||||
assertFalse(goog.userAgent.keyboard.MAC_KEYBOARD);
|
||||
|
||||
setUserAgent(
|
||||
goog.labs.userAgent.testAgents.IE_11_COMPATIBILITY_MSIE_7);
|
||||
assertFalse(goog.userAgent.keyboard.MAC_KEYBOARD);
|
||||
|
||||
setUserAgent(
|
||||
goog.labs.userAgent.testAgents.IE_11_COMPATIBILITY_MSIE_9);
|
||||
assertFalse(goog.userAgent.keyboard.MAC_KEYBOARD);
|
||||
}
|
||||
|
||||
function testFirefoxMac() {
|
||||
mockAgent.setNavigator({platform: 'Macintosh'});
|
||||
setUserAgent(
|
||||
goog.labs.userAgent.testAgents.FIREFOX_MAC);
|
||||
assertTrue(goog.userAgent.keyboard.MAC_KEYBOARD);
|
||||
}
|
||||
|
||||
function testFirefoxNotMac() {
|
||||
mockAgent.setNavigator({platform: 'X11'});
|
||||
setUserAgent(
|
||||
goog.labs.userAgent.testAgents.FIREFOX_LINUX);
|
||||
assertFalse(goog.userAgent.keyboard.MAC_KEYBOARD);
|
||||
|
||||
mockAgent.setNavigator({platform: 'Windows'});
|
||||
setUserAgent(
|
||||
goog.labs.userAgent.testAgents.FIREFOX_WINDOWS);
|
||||
assertFalse(goog.userAgent.keyboard.MAC_KEYBOARD);
|
||||
}
|
||||
|
||||
function testSafari() {
|
||||
mockAgent.setNavigator({platform: 'Macintosh'});
|
||||
setUserAgent(
|
||||
goog.labs.userAgent.testAgents.SAFARI_6);
|
||||
assertTrue(goog.userAgent.keyboard.MAC_KEYBOARD);
|
||||
|
||||
setUserAgent(
|
||||
goog.labs.userAgent.testAgents.SAFARI_MAC);
|
||||
assertTrue(goog.userAgent.keyboard.MAC_KEYBOARD);
|
||||
|
||||
mockAgent.setNavigator({platform: 'iPhone'});
|
||||
setUserAgent(
|
||||
goog.labs.userAgent.testAgents.SAFARI_IPHONE_32);
|
||||
assertTrue(goog.userAgent.keyboard.MAC_KEYBOARD);
|
||||
|
||||
setUserAgent(
|
||||
goog.labs.userAgent.testAgents.SAFARI_IPHONE_421);
|
||||
assertTrue(goog.userAgent.keyboard.MAC_KEYBOARD);
|
||||
|
||||
setUserAgent(
|
||||
goog.labs.userAgent.testAgents.SAFARI_IPHONE_431);
|
||||
assertTrue(goog.userAgent.keyboard.MAC_KEYBOARD);
|
||||
|
||||
setUserAgent(
|
||||
goog.labs.userAgent.testAgents.SAFARI_IPHONE_6);
|
||||
assertTrue(goog.userAgent.keyboard.MAC_KEYBOARD);
|
||||
|
||||
mockAgent.setNavigator({platform: 'iPod'});
|
||||
setUserAgent(
|
||||
goog.labs.userAgent.testAgents.SAFARI_IPOD);
|
||||
assertTrue(goog.userAgent.keyboard.MAC_KEYBOARD);
|
||||
}
|
||||
|
||||
function testSafariWndows() {
|
||||
mockAgent.setNavigator({platform: 'Macintosh'});
|
||||
setUserAgent(
|
||||
goog.labs.userAgent.testAgents.SAFARI_WINDOWS);
|
||||
assertFalse(goog.userAgent.keyboard.MAC_KEYBOARD);
|
||||
}
|
||||
|
||||
function testOperaMac() {
|
||||
mockAgent.setNavigator({platform: 'Macintosh'});
|
||||
setUserAgent(
|
||||
goog.labs.userAgent.testAgents.OPERA_MAC);
|
||||
assertTrue(goog.userAgent.keyboard.MAC_KEYBOARD);
|
||||
}
|
||||
|
||||
function testOperaNonMac() {
|
||||
mockAgent.setNavigator({platform: 'X11'});
|
||||
setUserAgent(
|
||||
goog.labs.userAgent.testAgents.OPERA_LINUX);
|
||||
assertFalse(goog.userAgent.keyboard.MAC_KEYBOARD);
|
||||
|
||||
mockAgent.setNavigator({platform: 'Windows'});
|
||||
setUserAgent(
|
||||
goog.labs.userAgent.testAgents.OPERA_15);
|
||||
assertFalse(goog.userAgent.keyboard.MAC_KEYBOARD);
|
||||
}
|
||||
|
||||
function testIPad() {
|
||||
mockAgent.setNavigator({platform: 'iPad'});
|
||||
setUserAgent(goog.labs.userAgent.testAgents.IPAD_4);
|
||||
assertTrue(goog.userAgent.keyboard.MAC_KEYBOARD);
|
||||
|
||||
setUserAgent(goog.labs.userAgent.testAgents.IPAD_5);
|
||||
assertTrue(goog.userAgent.keyboard.MAC_KEYBOARD);
|
||||
|
||||
setUserAgent(goog.labs.userAgent.testAgents.IPAD_6);
|
||||
assertTrue(goog.userAgent.keyboard.MAC_KEYBOARD);
|
||||
}
|
||||
|
||||
function testChromeMac() {
|
||||
mockAgent.setNavigator({platform: 'Macintosh'});
|
||||
setUserAgent(
|
||||
goog.labs.userAgent.testAgents.CHROME_MAC);
|
||||
assertTrue(goog.userAgent.keyboard.MAC_KEYBOARD);
|
||||
|
||||
mockAgent.setNavigator({platform: 'iPhone'});
|
||||
setUserAgent(
|
||||
goog.labs.userAgent.testAgents.CHROME_IPHONE);
|
||||
assertTrue(goog.userAgent.keyboard.MAC_KEYBOARD);
|
||||
}
|
||||
|
||||
function testChromeNonMac() {
|
||||
mockAgent.setNavigator({platform: 'Linux'});
|
||||
setUserAgent(
|
||||
goog.labs.userAgent.testAgents.CHROME_ANDROID);
|
||||
assertFalse(goog.userAgent.keyboard.MAC_KEYBOARD);
|
||||
|
||||
mockAgent.setNavigator({platform: 'X11'});
|
||||
setUserAgent(
|
||||
goog.labs.userAgent.testAgents.CHROME_OS);
|
||||
assertFalse(goog.userAgent.keyboard.MAC_KEYBOARD);
|
||||
|
||||
mockAgent.setNavigator({platform: 'X11'});
|
||||
setUserAgent(
|
||||
goog.labs.userAgent.testAgents.CHROME_LINUX);
|
||||
assertFalse(goog.userAgent.keyboard.MAC_KEYBOARD);
|
||||
|
||||
mockAgent.setNavigator({platform: 'Windows'});
|
||||
setUserAgent(
|
||||
goog.labs.userAgent.testAgents.CHROME_25);
|
||||
|
||||
assertFalse(goog.userAgent.keyboard.MAC_KEYBOARD);
|
||||
}
|
||||
|
||||
function setUserAgent(ua) {
|
||||
mockAgent.setUserAgentString(ua);
|
||||
goog.labs.userAgent.util.setUserAgent(ua);
|
||||
goog.userAgentTestUtil.reinitializeUserAgent();
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
// Copyright 2007 The Closure Library Authors. All Rights Reserved.
|
||||
//
|
||||
// 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.
|
||||
|
||||
/**
|
||||
* @fileoverview Detection for whether the user has Picasa installed.
|
||||
* Only Picasa versions 2 and later can be detected, and only from Firefox or
|
||||
* Internet Explorer. Picasa for Linux cannot be detected.
|
||||
*
|
||||
* In the future, Picasa may provide access to the installed version number,
|
||||
* but until then we can only detect that Picasa 2 or later is present.
|
||||
*
|
||||
* To check for Picasa on Internet Explorer requires using document.write, so
|
||||
* this file must be included at page rendering time and cannot be imported
|
||||
* later as part of a dynamically loaded module.
|
||||
*
|
||||
* @author brenneman@google.com (Shawn Brenneman)
|
||||
* @see ../demos/useragent.html
|
||||
*/
|
||||
|
||||
|
||||
goog.provide('goog.userAgent.picasa');
|
||||
|
||||
goog.require('goog.string');
|
||||
goog.require('goog.userAgent');
|
||||
|
||||
|
||||
/**
|
||||
* Variable name used to temporarily save the Picasa state in the global object
|
||||
* in Internet Explorer.
|
||||
* @type {string}
|
||||
* @private
|
||||
*/
|
||||
goog.userAgent.picasa.IE_HAS_PICASA_ = 'hasPicasa';
|
||||
|
||||
|
||||
(function() {
|
||||
var hasPicasa = false;
|
||||
|
||||
if (goog.userAgent.IE) {
|
||||
// In Internet Explorer, Picasa 2 can be detected using conditional comments
|
||||
// due to some nice registry magic. The precise version number is not
|
||||
// available, only the major version. This may be updated for Picasa 3. This
|
||||
// check must pollute the global namespace.
|
||||
goog.global[goog.userAgent.picasa.IE_HAS_PICASA_] = hasPicasa;
|
||||
|
||||
// NOTE(user): Some browsers do not like seeing
|
||||
// slash-script anywhere in the text even if it's inside a string
|
||||
// and escaped with a backslash, make a string in a way that
|
||||
// avoids problems.
|
||||
|
||||
document.write(goog.string.subs(
|
||||
'<!--[if gte Picasa 2]>' +
|
||||
'<%s>' +
|
||||
'this.%s=true;' +
|
||||
'</%s>' +
|
||||
'<![endif]-->',
|
||||
'script', goog.userAgent.picasa.IE_HAS_PICASA_, 'script'));
|
||||
|
||||
hasPicasa = goog.global[goog.userAgent.picasa.IE_HAS_PICASA_];
|
||||
|
||||
// Unset the variable in a crude attempt to leave no trace.
|
||||
goog.global[goog.userAgent.picasa.IE_HAS_PICASA_] = undefined;
|
||||
|
||||
} else if (navigator.mimeTypes &&
|
||||
navigator.mimeTypes['application/x-picasa-detect']) {
|
||||
// Picasa 2.x registers a file handler for the MIME-type
|
||||
// 'application/x-picasa-detect' for detection in Firefox. Future versions
|
||||
// may make precise version detection possible.
|
||||
hasPicasa = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether we detect the user has Picasa installed.
|
||||
* @type {boolean}
|
||||
*/
|
||||
goog.userAgent.picasa.HAS_PICASA = hasPicasa;
|
||||
|
||||
|
||||
/**
|
||||
* The installed version of Picasa. If Picasa is detected, this means it is
|
||||
* version 2 or later. The precise version number is not yet available to the
|
||||
* browser, this is a placeholder for later versions of Picasa.
|
||||
* @type {string}
|
||||
*/
|
||||
goog.userAgent.picasa.VERSION = hasPicasa ? '2' : '';
|
||||
|
||||
})();
|
||||
|
||||
|
||||
/**
|
||||
* Whether the installed Picasa version is as new or newer than a given version.
|
||||
* This is not yet relevant, we can't detect the true Picasa version number yet,
|
||||
* but this may be possible in future Picasa releases.
|
||||
* @param {string} version The version to check.
|
||||
* @return {boolean} Whether the installed Picasa version is as new or newer
|
||||
* than a given version.
|
||||
*/
|
||||
goog.userAgent.picasa.isVersion = function(version) {
|
||||
return goog.string.compareVersions(
|
||||
goog.userAgent.picasa.VERSION, version) >= 0;
|
||||
};
|
||||
@@ -0,0 +1,83 @@
|
||||
// Copyright 2010 The Closure Library Authors. All Rights Reserved.
|
||||
//
|
||||
// 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.
|
||||
|
||||
/**
|
||||
* @fileoverview Utilities for getting details about the user's platform.
|
||||
*/
|
||||
|
||||
goog.provide('goog.userAgent.platform');
|
||||
|
||||
goog.require('goog.string');
|
||||
goog.require('goog.userAgent');
|
||||
|
||||
|
||||
/**
|
||||
* Detects the version of Windows or Mac OS that is running.
|
||||
*
|
||||
* @private
|
||||
* @return {string} The platform version.
|
||||
*/
|
||||
goog.userAgent.platform.determineVersion_ = function() {
|
||||
var version = '', re;
|
||||
if (goog.userAgent.WINDOWS) {
|
||||
re = /Windows NT ([0-9.]+)/;
|
||||
var match = re.exec(goog.userAgent.getUserAgentString());
|
||||
if (match) {
|
||||
return match[1];
|
||||
} else {
|
||||
return '0';
|
||||
}
|
||||
} else if (goog.userAgent.MAC) {
|
||||
re = /10[_.][0-9_.]+/;
|
||||
var match = re.exec(goog.userAgent.getUserAgentString());
|
||||
// Note: some old versions of Camino do not report an OSX version.
|
||||
// Default to 10.
|
||||
return match ? match[0].replace(/_/g, '.') : '10';
|
||||
} else if (goog.userAgent.ANDROID) {
|
||||
re = /Android\s+([^\);]+)(\)|;)/;
|
||||
var match = re.exec(goog.userAgent.getUserAgentString());
|
||||
return match ? match[1] : '';
|
||||
} else if (goog.userAgent.IPHONE || goog.userAgent.IPAD) {
|
||||
re = /(?:iPhone|CPU)\s+OS\s+(\S+)/;
|
||||
var match = re.exec(goog.userAgent.getUserAgentString());
|
||||
// Report the version as x.y.z and not x_y_z
|
||||
return match ? match[1].replace(/_/g, '.') : '';
|
||||
}
|
||||
|
||||
return '';
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* The version of the platform. We only determine the version for Windows and
|
||||
* Mac, since it doesn't make much sense on Linux. For Windows, we only look at
|
||||
* the NT version. Non-NT-based versions (e.g. 95, 98, etc.) are given version
|
||||
* 0.0
|
||||
* @type {string}
|
||||
*/
|
||||
goog.userAgent.platform.VERSION = goog.userAgent.platform.determineVersion_();
|
||||
|
||||
|
||||
/**
|
||||
* Whether the user agent platform version is higher or the same as the given
|
||||
* version.
|
||||
*
|
||||
* @param {string|number} version The version to check.
|
||||
* @return {boolean} Whether the user agent platform version is higher or the
|
||||
* same as the given version.
|
||||
*/
|
||||
goog.userAgent.platform.isVersion = function(version) {
|
||||
return goog.string.compareVersions(
|
||||
goog.userAgent.platform.VERSION, version) >= 0;
|
||||
};
|
||||
@@ -0,0 +1,26 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<!--
|
||||
Copyright 2010 The Closure Library Authors. All Rights Reserved.
|
||||
|
||||
Use of this source code is governed by the Apache License, Version 2.0.
|
||||
See the COPYING file for details.
|
||||
-->
|
||||
<!--
|
||||
|
||||
@author mpd@google.com (Michael Davidson)
|
||||
-->
|
||||
<head>
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
||||
<title>
|
||||
Closure Unit Tests - goog.userAgent.platform
|
||||
</title>
|
||||
<script src="../base.js">
|
||||
</script>
|
||||
<script>
|
||||
goog.require('goog.userAgent.platformTest');
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,159 @@
|
||||
// Copyright 2010 The Closure Library Authors. All Rights Reserved.
|
||||
//
|
||||
// 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.
|
||||
|
||||
goog.provide('goog.userAgent.platformTest');
|
||||
goog.setTestOnly('goog.userAgent.platformTest');
|
||||
|
||||
goog.require('goog.testing.MockUserAgent');
|
||||
goog.require('goog.testing.jsunit');
|
||||
goog.require('goog.userAgent');
|
||||
goog.require('goog.userAgent.platform');
|
||||
goog.require('goog.userAgentTestUtil');
|
||||
|
||||
var mockAgent;
|
||||
|
||||
function setUp() {
|
||||
mockAgent = new goog.testing.MockUserAgent();
|
||||
mockAgent.install();
|
||||
}
|
||||
|
||||
function tearDown() {
|
||||
mockAgent.dispose();
|
||||
updateUserAgentUtils();
|
||||
}
|
||||
|
||||
function updateUserAgentUtils() {
|
||||
goog.userAgentTestUtil.reinitializeUserAgent();
|
||||
}
|
||||
|
||||
function testWindows() {
|
||||
mockAgent.setNavigator({platform: 'Win32'});
|
||||
|
||||
var win98 = 'Mozilla/4.0 (compatible; MSIE 6.0b; Windows 98; Win 9x 4.90)';
|
||||
var win2k = 'Mozilla/5.0 (Windows; U; MSIE 7.0; Windows NT 5.0; en-US)';
|
||||
var xp = 'Mozilla/5.0 (Windows; U; MSIE 7.0; Windows NT 5.1; en-US)';
|
||||
var vista = 'Mozilla/5.0 (Windows; U; MSIE 7.0; Windows NT 6.0; en-US)';
|
||||
var win7 = 'Mozilla/5.0 (Windows; U; MSIE 7.0; Windows NT 6.1; en-US)';
|
||||
var win81 = 'Mozilla/5.0 (Windows NT 6.3; Trident/7.0; rv:11.0) like Gecko';
|
||||
|
||||
mockAgent.setUserAgentString(win98);
|
||||
updateUserAgentUtils();
|
||||
assertEquals('0', goog.userAgent.platform.VERSION);
|
||||
|
||||
mockAgent.setUserAgentString(win2k);
|
||||
updateUserAgentUtils();
|
||||
assertEquals('5.0', goog.userAgent.platform.VERSION);
|
||||
|
||||
mockAgent.setUserAgentString(xp);
|
||||
updateUserAgentUtils();
|
||||
assertEquals('5.1', goog.userAgent.platform.VERSION);
|
||||
|
||||
mockAgent.setUserAgentString(vista);
|
||||
updateUserAgentUtils();
|
||||
assertEquals('6.0', goog.userAgent.platform.VERSION);
|
||||
|
||||
mockAgent.setUserAgentString(win7);
|
||||
updateUserAgentUtils();
|
||||
assertEquals('6.1', goog.userAgent.platform.VERSION);
|
||||
|
||||
mockAgent.setUserAgentString(win81);
|
||||
updateUserAgentUtils();
|
||||
assertEquals('6.3', goog.userAgent.platform.VERSION);
|
||||
}
|
||||
|
||||
function testMac() {
|
||||
// For some reason Chrome substitutes _ for . in the OS version.
|
||||
var chrome = 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_8; en-US)' +
|
||||
'AppleWebKit/532.5 (KHTML, like Gecko) Chrome/4.0.249.49 Safari/532.5';
|
||||
|
||||
var ff = 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US;' +
|
||||
'rv:1.9.1.7) Gecko/20091221 Firefox/3.5.7 GTB6';
|
||||
|
||||
// An old camino version that doesn't report a Mac version.
|
||||
var camino = 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en; rv:1.8.1.11)' +
|
||||
'Gecko/20071128 Camino/1.5.4';
|
||||
|
||||
mockAgent.setNavigator({platform: 'IntelMac'});
|
||||
|
||||
mockAgent.setUserAgentString(chrome);
|
||||
updateUserAgentUtils();
|
||||
assertEquals('10.5.8', goog.userAgent.platform.VERSION);
|
||||
|
||||
mockAgent.setUserAgentString(ff);
|
||||
updateUserAgentUtils();
|
||||
assertEquals('10.5', goog.userAgent.platform.VERSION);
|
||||
|
||||
mockAgent.setUserAgentString(camino);
|
||||
updateUserAgentUtils();
|
||||
assertEquals('10', goog.userAgent.platform.VERSION);
|
||||
}
|
||||
|
||||
function testChromeOnAndroid() {
|
||||
// Borrowing search's test user agent string for android.
|
||||
var uaString = 'Mozilla/5.0 (Linux; U; Android 4.0.2; en-us; Galaxy Nexus' +
|
||||
' Build/ICL53F) AppleWebKit/535.7 (KHTML, like Gecko) ' +
|
||||
'Chrome/18.0.1025.133 Mobile Safari/535.7';
|
||||
|
||||
// Need to set this lest the testing platform be used for detection.
|
||||
mockAgent.setNavigator({platform: 'Android'});
|
||||
|
||||
mockAgent.setUserAgentString(uaString);
|
||||
updateUserAgentUtils();
|
||||
assertTrue(goog.userAgent.ANDROID);
|
||||
assertEquals('4.0.2', goog.userAgent.platform.VERSION);
|
||||
}
|
||||
|
||||
function testAndroidBrowser() {
|
||||
var uaString = 'Mozilla/5.0 (Linux; U; Android 2.3.4; fr-fr;' +
|
||||
'HTC Desire Build/GRJ22) AppleWebKit/533.1 (KHTML, like Gecko)' +
|
||||
'Version/4.0 Mobile Safari/533.1';
|
||||
|
||||
// Need to set this lest the testing platform be used for detection.
|
||||
mockAgent.setNavigator({platform: 'Android'});
|
||||
|
||||
mockAgent.setUserAgentString(uaString);
|
||||
updateUserAgentUtils();
|
||||
assertTrue(goog.userAgent.ANDROID);
|
||||
assertEquals('2.3.4', goog.userAgent.platform.VERSION);
|
||||
}
|
||||
|
||||
function testIPhone() {
|
||||
// Borrowing search's test user agent string for the iPhone.
|
||||
var uaString = 'Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_0 like Mac OS X; ' +
|
||||
'en-us) AppleWebKit/532.9 (KHTML, like Gecko) Version/4.0.5 ' +
|
||||
'Mobile/8A293 Safari/6531.22.7';
|
||||
|
||||
// Need to set this lest the testing platform be used for detection.
|
||||
mockAgent.setNavigator({platform: 'iPhone'});
|
||||
|
||||
mockAgent.setUserAgentString(uaString);
|
||||
updateUserAgentUtils();
|
||||
assertTrue(goog.userAgent.IPHONE);
|
||||
assertEquals('4.0', goog.userAgent.platform.VERSION);
|
||||
}
|
||||
|
||||
function testIPad() {
|
||||
// Borrowing search's test user agent string for the iPad.
|
||||
var uaString = 'Mozilla/5.0 (iPad; U; CPU OS 4_2_1 like Mac OS X; ja-jp) ' +
|
||||
'AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8C148 ' +
|
||||
'Safari/6533.18.5';
|
||||
|
||||
// Need to set this lest the testing platform be used for detection.
|
||||
mockAgent.setNavigator({platform: 'iPad'});
|
||||
|
||||
mockAgent.setUserAgentString(uaString);
|
||||
updateUserAgentUtils();
|
||||
assertTrue(goog.userAgent.IPAD);
|
||||
assertEquals('4.2.1', goog.userAgent.platform.VERSION);
|
||||
}
|
||||
@@ -0,0 +1,253 @@
|
||||
// Copyright 2008 The Closure Library Authors. All Rights Reserved.
|
||||
//
|
||||
// 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.
|
||||
|
||||
/**
|
||||
* @fileoverview Detects the specific browser and not just the rendering engine.
|
||||
*
|
||||
*/
|
||||
|
||||
goog.provide('goog.userAgent.product');
|
||||
|
||||
goog.require('goog.userAgent');
|
||||
|
||||
|
||||
/**
|
||||
* @define {boolean} Whether the code is running on the Firefox web browser.
|
||||
*/
|
||||
goog.define('goog.userAgent.product.ASSUME_FIREFOX', false);
|
||||
|
||||
|
||||
/**
|
||||
* @define {boolean} Whether the code is running on the Camino web browser.
|
||||
*/
|
||||
goog.define('goog.userAgent.product.ASSUME_CAMINO', false);
|
||||
|
||||
|
||||
/**
|
||||
* @define {boolean} Whether we know at compile-time that the product is an
|
||||
* iPhone.
|
||||
*/
|
||||
goog.define('goog.userAgent.product.ASSUME_IPHONE', false);
|
||||
|
||||
|
||||
/**
|
||||
* @define {boolean} Whether we know at compile-time that the product is an
|
||||
* iPad.
|
||||
*/
|
||||
goog.define('goog.userAgent.product.ASSUME_IPAD', false);
|
||||
|
||||
|
||||
/**
|
||||
* @define {boolean} Whether we know at compile-time that the product is an
|
||||
* Android phone.
|
||||
*/
|
||||
goog.define('goog.userAgent.product.ASSUME_ANDROID', false);
|
||||
|
||||
|
||||
/**
|
||||
* @define {boolean} Whether the code is running on the Chrome web browser.
|
||||
*/
|
||||
goog.define('goog.userAgent.product.ASSUME_CHROME', false);
|
||||
|
||||
|
||||
/**
|
||||
* @define {boolean} Whether the code is running on the Safari web browser.
|
||||
*/
|
||||
goog.define('goog.userAgent.product.ASSUME_SAFARI', false);
|
||||
|
||||
|
||||
/**
|
||||
* Whether we know the product type at compile-time.
|
||||
* @type {boolean}
|
||||
* @private
|
||||
*/
|
||||
goog.userAgent.product.PRODUCT_KNOWN_ =
|
||||
goog.userAgent.ASSUME_IE ||
|
||||
goog.userAgent.ASSUME_OPERA ||
|
||||
goog.userAgent.product.ASSUME_FIREFOX ||
|
||||
goog.userAgent.product.ASSUME_CAMINO ||
|
||||
goog.userAgent.product.ASSUME_IPHONE ||
|
||||
goog.userAgent.product.ASSUME_IPAD ||
|
||||
goog.userAgent.product.ASSUME_ANDROID ||
|
||||
goog.userAgent.product.ASSUME_CHROME ||
|
||||
goog.userAgent.product.ASSUME_SAFARI;
|
||||
|
||||
|
||||
/**
|
||||
* Right now we just focus on Tier 1-3 browsers at:
|
||||
* http://wiki/Nonconf/ProductPlatformGuidelines
|
||||
* As well as the YUI grade A browsers at:
|
||||
* http://developer.yahoo.com/yui/articles/gbs/
|
||||
*
|
||||
* @private
|
||||
*/
|
||||
goog.userAgent.product.init_ = function() {
|
||||
|
||||
/**
|
||||
* Whether the code is running on the Firefox web browser.
|
||||
* @type {boolean}
|
||||
* @private
|
||||
*/
|
||||
goog.userAgent.product.detectedFirefox_ = false;
|
||||
|
||||
/**
|
||||
* Whether the code is running on the Camino web browser.
|
||||
* @type {boolean}
|
||||
* @private
|
||||
*/
|
||||
goog.userAgent.product.detectedCamino_ = false;
|
||||
|
||||
/**
|
||||
* Whether the code is running on an iPhone or iPod touch.
|
||||
* @type {boolean}
|
||||
* @private
|
||||
*/
|
||||
goog.userAgent.product.detectedIphone_ = false;
|
||||
|
||||
/**
|
||||
* Whether the code is running on an iPad
|
||||
* @type {boolean}
|
||||
* @private
|
||||
*/
|
||||
goog.userAgent.product.detectedIpad_ = false;
|
||||
|
||||
/**
|
||||
* Whether the code is running on the default browser on an Android phone.
|
||||
* @type {boolean}
|
||||
* @private
|
||||
*/
|
||||
goog.userAgent.product.detectedAndroid_ = false;
|
||||
|
||||
/**
|
||||
* Whether the code is running on the Chrome web browser.
|
||||
* @type {boolean}
|
||||
* @private
|
||||
*/
|
||||
goog.userAgent.product.detectedChrome_ = false;
|
||||
|
||||
/**
|
||||
* Whether the code is running on the Safari web browser.
|
||||
* @type {boolean}
|
||||
* @private
|
||||
*/
|
||||
goog.userAgent.product.detectedSafari_ = false;
|
||||
|
||||
var ua = goog.userAgent.getUserAgentString();
|
||||
if (!ua) {
|
||||
return;
|
||||
}
|
||||
|
||||
// The order of the if-statements in the following code is important.
|
||||
// For example, in the WebKit section, we put Chrome in front of Safari
|
||||
// because the string 'Safari' is present on both of those browsers'
|
||||
// userAgent strings as well as the string we are looking for.
|
||||
// The idea is to prevent accidental detection of more than one client.
|
||||
|
||||
if (ua.indexOf('Firefox') != -1) {
|
||||
goog.userAgent.product.detectedFirefox_ = true;
|
||||
} else if (ua.indexOf('Camino') != -1) {
|
||||
goog.userAgent.product.detectedCamino_ = true;
|
||||
} else if (ua.indexOf('iPad') != -1) {
|
||||
goog.userAgent.product.detectedIpad_ = true;
|
||||
} else if (ua.indexOf('iPhone') != -1 || ua.indexOf('iPod') != -1) {
|
||||
goog.userAgent.product.detectedIphone_ = true;
|
||||
} else if (ua.indexOf('Chrome') != -1) {
|
||||
goog.userAgent.product.detectedChrome_ = true;
|
||||
} else if (ua.indexOf('Android') != -1) {
|
||||
goog.userAgent.product.detectedAndroid_ = true;
|
||||
} else if (ua.indexOf('Safari') != -1) {
|
||||
goog.userAgent.product.detectedSafari_ = true;
|
||||
}
|
||||
};
|
||||
|
||||
if (!goog.userAgent.product.PRODUCT_KNOWN_) {
|
||||
goog.userAgent.product.init_();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Whether the code is running on the Opera web browser.
|
||||
* @type {boolean}
|
||||
*/
|
||||
goog.userAgent.product.OPERA = goog.userAgent.OPERA;
|
||||
|
||||
|
||||
/**
|
||||
* Whether the code is running on an IE web browser.
|
||||
* @type {boolean}
|
||||
*/
|
||||
goog.userAgent.product.IE = goog.userAgent.IE;
|
||||
|
||||
|
||||
/**
|
||||
* Whether the code is running on the Firefox web browser.
|
||||
* @type {boolean}
|
||||
*/
|
||||
goog.userAgent.product.FIREFOX = goog.userAgent.product.PRODUCT_KNOWN_ ?
|
||||
goog.userAgent.product.ASSUME_FIREFOX :
|
||||
goog.userAgent.product.detectedFirefox_;
|
||||
|
||||
|
||||
/**
|
||||
* Whether the code is running on the Camino web browser.
|
||||
* @type {boolean}
|
||||
*/
|
||||
goog.userAgent.product.CAMINO = goog.userAgent.product.PRODUCT_KNOWN_ ?
|
||||
goog.userAgent.product.ASSUME_CAMINO :
|
||||
goog.userAgent.product.detectedCamino_;
|
||||
|
||||
|
||||
/**
|
||||
* Whether the code is running on an iPhone or iPod touch.
|
||||
* @type {boolean}
|
||||
*/
|
||||
goog.userAgent.product.IPHONE = goog.userAgent.product.PRODUCT_KNOWN_ ?
|
||||
goog.userAgent.product.ASSUME_IPHONE :
|
||||
goog.userAgent.product.detectedIphone_;
|
||||
|
||||
|
||||
/**
|
||||
* Whether the code is running on an iPad.
|
||||
* @type {boolean}
|
||||
*/
|
||||
goog.userAgent.product.IPAD = goog.userAgent.product.PRODUCT_KNOWN_ ?
|
||||
goog.userAgent.product.ASSUME_IPAD :
|
||||
goog.userAgent.product.detectedIpad_;
|
||||
|
||||
|
||||
/**
|
||||
* Whether the code is running on the default browser on an Android phone.
|
||||
* @type {boolean}
|
||||
*/
|
||||
goog.userAgent.product.ANDROID = goog.userAgent.product.PRODUCT_KNOWN_ ?
|
||||
goog.userAgent.product.ASSUME_ANDROID :
|
||||
goog.userAgent.product.detectedAndroid_;
|
||||
|
||||
|
||||
/**
|
||||
* Whether the code is running on the Chrome web browser.
|
||||
* @type {boolean}
|
||||
*/
|
||||
goog.userAgent.product.CHROME = goog.userAgent.product.PRODUCT_KNOWN_ ?
|
||||
goog.userAgent.product.ASSUME_CHROME :
|
||||
goog.userAgent.product.detectedChrome_;
|
||||
|
||||
|
||||
/**
|
||||
* Whether the code is running on the Safari web browser.
|
||||
* @type {boolean}
|
||||
*/
|
||||
goog.userAgent.product.SAFARI = goog.userAgent.product.PRODUCT_KNOWN_ ?
|
||||
goog.userAgent.product.ASSUME_SAFARI :
|
||||
goog.userAgent.product.detectedSafari_;
|
||||
@@ -0,0 +1,142 @@
|
||||
// Copyright 2009 The Closure Library Authors. All Rights Reserved.
|
||||
//
|
||||
// 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.
|
||||
|
||||
/**
|
||||
* @fileoverview Functions for understanding the version of the browser.
|
||||
* This is pulled out of product.js to ensure that only builds that need
|
||||
* this functionality actually get it, without having to rely on the compiler
|
||||
* to strip out unneeded pieces.
|
||||
*
|
||||
* TODO(nnaze): Move to more appropriate filename/namespace.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
goog.provide('goog.userAgent.product.isVersion');
|
||||
|
||||
|
||||
goog.require('goog.string');
|
||||
goog.require('goog.userAgent');
|
||||
goog.require('goog.userAgent.product');
|
||||
|
||||
|
||||
/**
|
||||
* @return {string} The string that describes the version number of the user
|
||||
* agent product. This is a string rather than a number because it may
|
||||
* contain 'b', 'a', and so on.
|
||||
* @private
|
||||
*/
|
||||
goog.userAgent.product.determineVersion_ = function() {
|
||||
// All browsers have different ways to detect the version and they all have
|
||||
// different naming schemes.
|
||||
|
||||
if (goog.userAgent.product.FIREFOX) {
|
||||
// Firefox/2.0.0.1 or Firefox/3.5.3
|
||||
return goog.userAgent.product.getFirstRegExpGroup_(/Firefox\/([0-9.]+)/);
|
||||
}
|
||||
|
||||
if (goog.userAgent.product.IE || goog.userAgent.product.OPERA) {
|
||||
return goog.userAgent.VERSION;
|
||||
}
|
||||
|
||||
if (goog.userAgent.product.CHROME) {
|
||||
// Chrome/4.0.223.1
|
||||
return goog.userAgent.product.getFirstRegExpGroup_(/Chrome\/([0-9.]+)/);
|
||||
}
|
||||
|
||||
if (goog.userAgent.product.SAFARI) {
|
||||
// Version/5.0.3
|
||||
//
|
||||
// NOTE: Before version 3, Safari did not report a product version number.
|
||||
// The product version number for these browsers will be the empty string.
|
||||
// They may be differentiated by WebKit version number in goog.userAgent.
|
||||
return goog.userAgent.product.getFirstRegExpGroup_(/Version\/([0-9.]+)/);
|
||||
}
|
||||
|
||||
if (goog.userAgent.product.IPHONE || goog.userAgent.product.IPAD) {
|
||||
// Mozilla/5.0 (iPod; U; CPU like Mac OS X; en) AppleWebKit/420.1
|
||||
// (KHTML, like Gecko) Version/3.0 Mobile/3A100a Safari/419.3
|
||||
// Version is the browser version, Mobile is the build number. We combine
|
||||
// the version string with the build number: 3.0.3A100a for the example.
|
||||
var arr = goog.userAgent.product.execRegExp_(
|
||||
/Version\/(\S+).*Mobile\/(\S+)/);
|
||||
if (arr) {
|
||||
return arr[1] + '.' + arr[2];
|
||||
}
|
||||
} else if (goog.userAgent.product.ANDROID) {
|
||||
// Mozilla/5.0 (Linux; U; Android 0.5; en-us) AppleWebKit/522+
|
||||
// (KHTML, like Gecko) Safari/419.3
|
||||
//
|
||||
// Mozilla/5.0 (Linux; U; Android 1.0; en-us; dream) AppleWebKit/525.10+
|
||||
// (KHTML, like Gecko) Version/3.0.4 Mobile Safari/523.12.2
|
||||
//
|
||||
// Prefer Version number if present, else make do with the OS number
|
||||
var version = goog.userAgent.product.getFirstRegExpGroup_(
|
||||
/Android\s+([0-9.]+)/);
|
||||
if (version) {
|
||||
return version;
|
||||
}
|
||||
|
||||
return goog.userAgent.product.getFirstRegExpGroup_(/Version\/([0-9.]+)/);
|
||||
} else if (goog.userAgent.product.CAMINO) {
|
||||
return goog.userAgent.product.getFirstRegExpGroup_(/Camino\/([0-9.]+)/);
|
||||
}
|
||||
|
||||
return '';
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Return the first group of the given regex.
|
||||
* @param {!RegExp} re Regular expression with at least one group.
|
||||
* @return {string} Contents of the first group or an empty string if no match.
|
||||
* @private
|
||||
*/
|
||||
goog.userAgent.product.getFirstRegExpGroup_ = function(re) {
|
||||
var arr = goog.userAgent.product.execRegExp_(re);
|
||||
return arr ? arr[1] : '';
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Run regexp's exec() on the userAgent string.
|
||||
* @param {!RegExp} re Regular expression.
|
||||
* @return {Array<?>} A result array, or null for no match.
|
||||
* @private
|
||||
*/
|
||||
goog.userAgent.product.execRegExp_ = function(re) {
|
||||
return re.exec(goog.userAgent.getUserAgentString());
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* The version of the user agent. This is a string because it might contain
|
||||
* 'b' (as in beta) as well as multiple dots.
|
||||
* @type {string}
|
||||
*/
|
||||
goog.userAgent.product.VERSION = goog.userAgent.product.determineVersion_();
|
||||
|
||||
|
||||
/**
|
||||
* Whether the user agent product version is higher or the same as the given
|
||||
* version.
|
||||
*
|
||||
* @param {string|number} version The version to check.
|
||||
* @return {boolean} Whether the user agent product version is higher or the
|
||||
* same as the given version.
|
||||
*/
|
||||
goog.userAgent.product.isVersion = function(version) {
|
||||
return goog.string.compareVersions(
|
||||
goog.userAgent.product.VERSION, version) >= 0;
|
||||
};
|
||||
@@ -0,0 +1,30 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<!--
|
||||
Copyright 2008 The Closure Library Authors. All Rights Reserved.
|
||||
|
||||
Use of this source code is governed by the Apache License, Version 2.0.
|
||||
See the COPYING file for details.
|
||||
-->
|
||||
<!--
|
||||
|
||||
@author andybons@google.com (Andrew Boneventre)
|
||||
-->
|
||||
<head>
|
||||
<!--
|
||||
This test has not yet been updated to run on IE8. See http://b/hotlist?id=36311
|
||||
-->
|
||||
<!--meta http-equiv="X-UA-Compatible" content="IE=edge"-->
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
|
||||
<title>
|
||||
Closure Unit Tests - goog.userAgent.product
|
||||
</title>
|
||||
<script src="../base.js">
|
||||
</script>
|
||||
<script>
|
||||
goog.require('goog.userAgent.productTest');
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,380 @@
|
||||
// Copyright 2008 The Closure Library Authors. All Rights Reserved.
|
||||
//
|
||||
// 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.
|
||||
|
||||
goog.provide('goog.userAgent.productTest');
|
||||
goog.setTestOnly('goog.userAgent.productTest');
|
||||
|
||||
goog.require('goog.array');
|
||||
goog.require('goog.labs.userAgent.util');
|
||||
goog.require('goog.testing.MockUserAgent');
|
||||
goog.require('goog.testing.PropertyReplacer');
|
||||
goog.require('goog.testing.jsunit');
|
||||
goog.require('goog.userAgent');
|
||||
goog.require('goog.userAgent.product');
|
||||
goog.require('goog.userAgent.product.isVersion');
|
||||
goog.require('goog.userAgentTestUtil');
|
||||
|
||||
var mockAgent;
|
||||
var replacer;
|
||||
|
||||
function setUp() {
|
||||
mockAgent = new goog.testing.MockUserAgent();
|
||||
mockAgent.install();
|
||||
replacer = new goog.testing.PropertyReplacer();
|
||||
}
|
||||
|
||||
function tearDown() {
|
||||
replacer.reset();
|
||||
mockAgent.dispose();
|
||||
updateUserAgentUtils();
|
||||
}
|
||||
|
||||
function updateUserAgentUtils() {
|
||||
goog.labs.userAgent.util.setUserAgent(null);
|
||||
goog.userAgentTestUtil.reinitializeUserAgent();
|
||||
|
||||
goog.userAgent.product.init_();
|
||||
// In an ideal world, this assignment would be just a function in
|
||||
// product.js that we could call, but putting it into a function causes
|
||||
// the compiler to fail to compile product.js to nothing when one of
|
||||
// the ASSUME flags is set.
|
||||
goog.userAgent.product.OPERA = goog.userAgent.OPERA;
|
||||
goog.userAgent.product.IE = goog.userAgent.IE;
|
||||
goog.userAgent.product.FIREFOX = goog.userAgent.product.detectedFirefox_;
|
||||
goog.userAgent.product.CAMINO = goog.userAgent.product.detectedCamino_;
|
||||
goog.userAgent.product.IPHONE = goog.userAgent.product.detectedIphone_;
|
||||
goog.userAgent.product.IPAD = goog.userAgent.product.detectedIpad_;
|
||||
goog.userAgent.product.ANDROID = goog.userAgent.product.detectedAndroid_;
|
||||
goog.userAgent.product.CHROME = goog.userAgent.product.detectedChrome_;
|
||||
goog.userAgent.product.SAFARI = goog.userAgent.product.detectedSafari_;
|
||||
goog.userAgent.product.VERSION = goog.userAgent.product.determineVersion_();
|
||||
}
|
||||
|
||||
// The set of products whose corresponding goog.userAgent.product value is set
|
||||
// in goog.userAgent.product.init_().
|
||||
var DETECTED_BROWSER_KEYS =
|
||||
['FIREFOX', 'CAMINO', 'IPHONE', 'IPAD', 'ANDROID', 'CHROME', 'SAFARI'];
|
||||
|
||||
function assertIsBrowser(browser) {
|
||||
function createDetectedBrowserKey(browser) {
|
||||
switch (browser) {
|
||||
case 'FIREFOX': return 'detectedFirefox_';
|
||||
case 'CAMINO': return 'detectedCamino_';
|
||||
case 'IPHONE': return 'detectedIphone_';
|
||||
case 'IPAD': return 'detectedIpad_';
|
||||
case 'ANDROID': return 'detectedAndroid_';
|
||||
case 'CHROME': return 'detectedChrome_';
|
||||
case 'SAFARI': return 'detectedSafari_';
|
||||
case 'IE': return 'IE';
|
||||
case 'OPERA': return 'OPERA';
|
||||
}
|
||||
throw Error('Unknown browser: ' + browser);
|
||||
}
|
||||
|
||||
var productKey = createDetectedBrowserKey(browser);
|
||||
assertTrue(goog.userAgent.product[productKey]);
|
||||
// Make sure we don't have any false positives for other browsers.
|
||||
goog.array.forEach(DETECTED_BROWSER_KEYS, function(el) {
|
||||
if (el != browser) {
|
||||
assertFalse('useragent should not match: ' + el,
|
||||
goog.userAgent.product[createDetectedBrowserKey(el)]);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function assertBrowserAndVersion(userAgent, browser, version) {
|
||||
mockAgent.setUserAgentString(userAgent);
|
||||
updateUserAgentUtils();
|
||||
assertIsBrowser(browser);
|
||||
assertEquals('User agent should have this version',
|
||||
version, goog.userAgent.VERSION);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Array<{
|
||||
* ua: string,
|
||||
* versions: Array<{
|
||||
* num: {string|number}, truth: boolean}>}>} userAgents
|
||||
* @param {string} browser
|
||||
*/
|
||||
function checkEachUserAgentDetected(userAgents, browser) {
|
||||
goog.array.forEach(userAgents, function(ua) {
|
||||
mockAgent.setUserAgentString(ua.ua);
|
||||
updateUserAgentUtils();
|
||||
assertIsBrowser(browser);
|
||||
goog.array.forEach(ua.versions, function(v) {
|
||||
assertEquals(
|
||||
'Expected version ' + v.num + ' from ' + ua.ua + ' but got ' +
|
||||
goog.userAgent.product.VERSION,
|
||||
v.truth, goog.userAgent.product.isVersion(v.num));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function testInternetExplorer() {
|
||||
var userAgents = [
|
||||
{ua: 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; GTB6; ' +
|
||||
'chromeframe; .NET CLR 1.1.4322; InfoPath.1; ' +
|
||||
'.NET CLR 3.0.04506.30; .NET CLR 3.0.04506.648; ' +
|
||||
'.NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; .NET CLR 2.0.50727)',
|
||||
versions: [
|
||||
{num: 6, truth: true},
|
||||
{num: '7.0', truth: true},
|
||||
{num: 7.1, truth: false},
|
||||
{num: 8, truth: false}
|
||||
]
|
||||
},
|
||||
{ua: 'Mozilla/5.0 (Windows NT 6.3; Trident/7.0; rv:11.0) like Gecko',
|
||||
versions: [
|
||||
{num: 10, truth: true},
|
||||
{num: 11, truth: true},
|
||||
{num: '11.0', truth: true},
|
||||
{num: '12', truth: false}
|
||||
]
|
||||
}
|
||||
];
|
||||
// hide any navigator.product value by putting in a navigator with no
|
||||
// properties.
|
||||
mockAgent.setNavigator({});
|
||||
checkEachUserAgentDetected(userAgents, 'IE');
|
||||
}
|
||||
|
||||
function testOpera() {
|
||||
var opera = {};
|
||||
var userAgents = [
|
||||
{ua: 'Opera/9.80 (Windows NT 5.1; U; en) Presto/2.2.15 Version/10.01',
|
||||
versions: [
|
||||
{num: 9, truth: true},
|
||||
{num: '10.1', truth: true},
|
||||
{num: 11, truth: false}
|
||||
]}
|
||||
];
|
||||
replacer.set(goog.global, 'opera', opera);
|
||||
opera.version = '10.01';
|
||||
checkEachUserAgentDetected(userAgents, 'OPERA');
|
||||
userAgents = [
|
||||
{ua: 'Opera/9.63 (Windows NT 5.1; U; en) Presto/2.1.1',
|
||||
versions: [
|
||||
{num: 9, truth: true},
|
||||
{num: '10.1', truth: false},
|
||||
{num: '9.80', truth: false},
|
||||
{num: '9.60', truth: true}
|
||||
]}
|
||||
];
|
||||
opera.version = '9.63';
|
||||
checkEachUserAgentDetected(userAgents, 'OPERA');
|
||||
}
|
||||
|
||||
function testFirefox() {
|
||||
var userAgents = [
|
||||
{ua: 'Mozilla/6.0 (Macintosh; U; PPC Mac OS X Mach-O; en-US; ' +
|
||||
'rv:2.0.0.0) Gecko/20061028 Firefox/3.0',
|
||||
versions: [
|
||||
{num: 2, truth: true},
|
||||
{num: '3.0', truth: true},
|
||||
{num: '3.5.3', truth: false}
|
||||
]},
|
||||
{ua: 'Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en-US; ' +
|
||||
'rv:1.8.1.4) Gecko/20070515 Firefox/2.0.4',
|
||||
versions: [
|
||||
{num: 2, truth: true},
|
||||
{num: '2.0.4', truth: true},
|
||||
{num: 3, truth: false},
|
||||
{num: '3.5.3', truth: false}
|
||||
]},
|
||||
{ua: 'Mozilla/5.0 (X11; Linux i686; rv:6.0) Gecko/6.0 Firefox/6.0',
|
||||
versions: [
|
||||
{num: 6, truth: true},
|
||||
{num: '6.0', truth: true},
|
||||
{num: 7, truth: false},
|
||||
{num: '7.0', truth: false}
|
||||
]}
|
||||
];
|
||||
|
||||
checkEachUserAgentDetected(userAgents, 'FIREFOX');
|
||||
|
||||
// Mozilla reported to us that they plan this UA format starting
|
||||
// in Firefox 13.
|
||||
// See bug at https://bugzilla.mozilla.org/show_bug.cgi?id=588909
|
||||
// and thread at http://goto.google.com/pfltz
|
||||
mockAgent.setNavigator({product: 'Gecko'});
|
||||
assertBrowserAndVersion(
|
||||
'Mozilla/5.0 (X11; Linux i686; rv:6.0) Gecko/6.0 Firefox/6.0',
|
||||
'FIREFOX', '6.0');
|
||||
}
|
||||
|
||||
function testCamino() {
|
||||
var userAgents = [
|
||||
{ua: 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en; rv:1.8.1.11) ' +
|
||||
'Gecko/20071128 Camino/1.5.4',
|
||||
versions: [
|
||||
{num: '1.5.4', truth: true},
|
||||
{num: 1, truth: true},
|
||||
{num: '2.0', truth: false}
|
||||
]},
|
||||
{ua: 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en-US; rv:1.8.0.10) ' +
|
||||
'Gecko/20070228 Camino/1.0.4',
|
||||
versions: [
|
||||
{num: '1.5.4', truth: false},
|
||||
{num: 1, truth: true},
|
||||
{num: '2.0', truth: false}
|
||||
]}
|
||||
];
|
||||
mockAgent.setNavigator({vendor: 'Camino', product: 'Gecko'});
|
||||
checkEachUserAgentDetected(userAgents, 'CAMINO');
|
||||
}
|
||||
|
||||
function testChrome() {
|
||||
var userAgents = [
|
||||
{ua: 'Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US) ' +
|
||||
'AppleWebKit/525.19 (KHTML, like Gecko) Chrome/0.2.153.0 ' +
|
||||
'Safari/525.19',
|
||||
versions: [
|
||||
{num: '0.2.153', truth: true},
|
||||
{num: 1, truth: false}
|
||||
]},
|
||||
{ua: 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) ' +
|
||||
'AppleWebKit/532.3 (KHTML, like Gecko) Chrome/4.0.223.11 ' +
|
||||
'Safari/532.3',
|
||||
versions: [
|
||||
{num: 4, truth: true},
|
||||
{num: '0.2.153', truth: true},
|
||||
{num: '4.1.223.13', truth: false},
|
||||
{num: '4.0.223.10', truth: true}
|
||||
]},
|
||||
{ua: 'Mozilla/5.0 (Linux; Android 4.0.4; Galaxy Nexus Build/IMM76B)' +
|
||||
'AppleWebKit/535.19 (KHTML, like Gecko) ' +
|
||||
'Chrome/18.0.1025.133 Mobile' +
|
||||
'Safari/535.19',
|
||||
versions: [
|
||||
{num: 18, truth: true},
|
||||
{num: '0.2.153', truth: true},
|
||||
{num: 29, truth: false},
|
||||
{num: '18.0.1025.133', truth: true}
|
||||
]}
|
||||
];
|
||||
checkEachUserAgentDetected(userAgents, 'CHROME');
|
||||
}
|
||||
|
||||
function testSafari() {
|
||||
var userAgents = [
|
||||
{ua: 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_7; de-de) ' +
|
||||
'AppleWebKit/534.16+ (KHTML, like Gecko) Version/5.0.3 ' +
|
||||
'Safari/533.19.4',
|
||||
versions: [
|
||||
{num: 5, truth: true},
|
||||
{num: '5.0.3', truth: true},
|
||||
{num: '5.0.4', truth: false},
|
||||
{num: '533', truth: false}
|
||||
]},
|
||||
{ua: 'Mozilla/5.0 (Windows; U; Windows NT 6.0; pl-PL) ' +
|
||||
'AppleWebKit/525.19 (KHTML, like Gecko) Version/3.1.2 Safari/525.21',
|
||||
versions: [
|
||||
{num: 3, truth: true},
|
||||
{num: '3.0', truth: true},
|
||||
{num: '3.1.2', truth: true}
|
||||
]},
|
||||
{ua: 'Mozilla/5.0 (Macintosh; U; PPC Mac OS X 10_5_3; en-us) ' +
|
||||
'AppleWebKit/525.18 (KHTML, like Gecko) Version/3.1.1 Safari/525.20',
|
||||
versions: [
|
||||
{num: 3, truth: true},
|
||||
{num: '3.1.1', truth: true},
|
||||
{num: '3.1.2', truth: false},
|
||||
{num: '525.21', truth: false}
|
||||
]},
|
||||
|
||||
// Safari 1 and 2 do not report product version numbers in their
|
||||
// user-agent strings. VERSION for these browsers will be set to ''.
|
||||
{ua: 'Mozilla/5.0 (Macintosh; U; PPC Mac OS X; ja-jp) ' +
|
||||
'AppleWebKit/418.9.1 (KHTML, like Gecko) Safari/419.3',
|
||||
versions: [
|
||||
{num: 3, truth: false},
|
||||
{num: 2, truth: false},
|
||||
{num: 1, truth: false},
|
||||
{num: 0, truth: true},
|
||||
{num: '0', truth: true},
|
||||
{num: '', truth: true}
|
||||
]}
|
||||
];
|
||||
checkEachUserAgentDetected(userAgents, 'SAFARI');
|
||||
}
|
||||
|
||||
function testIphone() {
|
||||
var userAgents = [
|
||||
{ua: 'Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420+ ' +
|
||||
'(KHTML, like Gecko) Version/3.0 Mobile/1A543a Safari/419.3',
|
||||
versions: [
|
||||
{num: '3.0.1A543a', truth: true},
|
||||
{num: '3.0', truth: true},
|
||||
{num: '3.0.1B543a', truth: false},
|
||||
{num: '3.1.1A543a', truth: false},
|
||||
{num: '3.0.1A320c', truth: true},
|
||||
{num: '3.0.3A100a', truth: false}
|
||||
]},
|
||||
{ua: 'Mozilla/5.0 (iPod; U; CPU like Mac OS X; en) AppleWebKit/420.1 ' +
|
||||
'(KHTML, like Gecko) Version/3.0 Mobile/3A100a Safari/419.3',
|
||||
versions: [
|
||||
{num: '3.0.1A543a', truth: true},
|
||||
{num: '3.0.3A100a', truth: true}
|
||||
]}
|
||||
];
|
||||
checkEachUserAgentDetected(userAgents, 'IPHONE');
|
||||
}
|
||||
|
||||
function testIpad() {
|
||||
var userAgents = [
|
||||
{ua: 'Mozilla/5.0 (iPad; U; CPU OS 3_2 like Mac OS X; en-us) ' +
|
||||
'AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 ' +
|
||||
'Mobile/7B334b Safari/531.21.10',
|
||||
versions: [
|
||||
{num: '4.0.4.7B334b', truth: true},
|
||||
{num: '4.0', truth: true},
|
||||
{num: '4.0.4.7C334b', truth: false},
|
||||
{num: '4.1.7B334b', truth: false},
|
||||
{num: '4.0.4.7B320c', truth: true},
|
||||
{num: '4.0.4.8B334b', truth: false}
|
||||
]},
|
||||
// Webview in the Facebook iOS app
|
||||
{ua: 'Mozilla/5.0 (iPad; CPU OS 8_1 like Mac OS X) AppleWebKit/600.1.4' +
|
||||
'(KHTML, like Gecko) Mobile/12B410 [FBAN/FBIOS;FBAV/16.0.0.13.22;' +
|
||||
'FBBV/4697910;FBDV/iPad3,4;FBMD/iPad;FBSN/iPhone OS;FBSV/8.1;' +
|
||||
'FBSS/2; FBCR/;FBID/tablet;FBLC/ja_JP;FBOP/1]',
|
||||
versions: [
|
||||
{num: '', truth: true}
|
||||
]}
|
||||
];
|
||||
checkEachUserAgentDetected(userAgents, 'IPAD');
|
||||
}
|
||||
|
||||
function testAndroid() {
|
||||
var userAgents = [
|
||||
{ua: 'Mozilla/5.0 (Linux; U; Android 0.5; en-us) AppleWebKit/522+ ' +
|
||||
'(KHTML, like Gecko) Safari/419.3',
|
||||
versions: [
|
||||
{num: 0.5, truth: true},
|
||||
{num: '1.0', truth: false}
|
||||
]},
|
||||
{ua: 'Mozilla/5.0 (Linux; U; Android 1.0; en-us; dream) ' +
|
||||
'AppleWebKit/525.10+ (KHTML, like Gecko) Version/3.0.4 Mobile ' +
|
||||
'Safari/523.12.2',
|
||||
versions: [
|
||||
{num: 0.5, truth: true},
|
||||
{num: 1, truth: true},
|
||||
{num: '1.0', truth: true},
|
||||
{num: '3.0.12', truth: false}
|
||||
]}
|
||||
];
|
||||
checkEachUserAgentDetected(userAgents, 'ANDROID');
|
||||
}
|
||||
@@ -0,0 +1,519 @@
|
||||
// Copyright 2006 The Closure Library Authors. All Rights Reserved.
|
||||
//
|
||||
// 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.
|
||||
|
||||
/**
|
||||
* @fileoverview Rendering engine detection.
|
||||
* @see <a href="http://www.useragentstring.com/">User agent strings</a>
|
||||
* For information on the browser brand (such as Safari versus Chrome), see
|
||||
* goog.userAgent.product.
|
||||
* @author arv@google.com (Erik Arvidsson)
|
||||
* @see ../demos/useragent.html
|
||||
*/
|
||||
|
||||
goog.provide('goog.userAgent');
|
||||
|
||||
goog.require('goog.labs.userAgent.browser');
|
||||
goog.require('goog.labs.userAgent.engine');
|
||||
goog.require('goog.labs.userAgent.platform');
|
||||
goog.require('goog.labs.userAgent.util');
|
||||
goog.require('goog.string');
|
||||
|
||||
|
||||
/**
|
||||
* @define {boolean} Whether we know at compile-time that the browser is IE.
|
||||
*/
|
||||
goog.define('goog.userAgent.ASSUME_IE', false);
|
||||
|
||||
|
||||
/**
|
||||
* @define {boolean} Whether we know at compile-time that the browser is GECKO.
|
||||
*/
|
||||
goog.define('goog.userAgent.ASSUME_GECKO', false);
|
||||
|
||||
|
||||
/**
|
||||
* @define {boolean} Whether we know at compile-time that the browser is WEBKIT.
|
||||
*/
|
||||
goog.define('goog.userAgent.ASSUME_WEBKIT', false);
|
||||
|
||||
|
||||
/**
|
||||
* @define {boolean} Whether we know at compile-time that the browser is a
|
||||
* mobile device running WebKit e.g. iPhone or Android.
|
||||
*/
|
||||
goog.define('goog.userAgent.ASSUME_MOBILE_WEBKIT', false);
|
||||
|
||||
|
||||
/**
|
||||
* @define {boolean} Whether we know at compile-time that the browser is OPERA.
|
||||
*/
|
||||
goog.define('goog.userAgent.ASSUME_OPERA', false);
|
||||
|
||||
|
||||
/**
|
||||
* @define {boolean} Whether the
|
||||
* {@code goog.userAgent.isVersionOrHigher}
|
||||
* function will return true for any version.
|
||||
*/
|
||||
goog.define('goog.userAgent.ASSUME_ANY_VERSION', false);
|
||||
|
||||
|
||||
/**
|
||||
* Whether we know the browser engine at compile-time.
|
||||
* @type {boolean}
|
||||
* @private
|
||||
*/
|
||||
goog.userAgent.BROWSER_KNOWN_ =
|
||||
goog.userAgent.ASSUME_IE ||
|
||||
goog.userAgent.ASSUME_GECKO ||
|
||||
goog.userAgent.ASSUME_MOBILE_WEBKIT ||
|
||||
goog.userAgent.ASSUME_WEBKIT ||
|
||||
goog.userAgent.ASSUME_OPERA;
|
||||
|
||||
|
||||
/**
|
||||
* Returns the userAgent string for the current browser.
|
||||
*
|
||||
* @return {string} The userAgent string.
|
||||
*/
|
||||
goog.userAgent.getUserAgentString = function() {
|
||||
return goog.labs.userAgent.util.getUserAgent();
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* TODO(nnaze): Change type to "Navigator" and update compilation targets.
|
||||
* @return {Object} The native navigator object.
|
||||
*/
|
||||
goog.userAgent.getNavigator = function() {
|
||||
// Need a local navigator reference instead of using the global one,
|
||||
// to avoid the rare case where they reference different objects.
|
||||
// (in a WorkerPool, for example).
|
||||
return goog.global['navigator'] || null;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Whether the user agent is Opera.
|
||||
* @type {boolean}
|
||||
*/
|
||||
goog.userAgent.OPERA = goog.userAgent.BROWSER_KNOWN_ ?
|
||||
goog.userAgent.ASSUME_OPERA :
|
||||
goog.labs.userAgent.browser.isOpera();
|
||||
|
||||
|
||||
/**
|
||||
* Whether the user agent is Internet Explorer.
|
||||
* @type {boolean}
|
||||
*/
|
||||
goog.userAgent.IE = goog.userAgent.BROWSER_KNOWN_ ?
|
||||
goog.userAgent.ASSUME_IE :
|
||||
goog.labs.userAgent.browser.isIE();
|
||||
|
||||
|
||||
/**
|
||||
* Whether the user agent is Gecko. Gecko is the rendering engine used by
|
||||
* Mozilla, Firefox, and others.
|
||||
* @type {boolean}
|
||||
*/
|
||||
goog.userAgent.GECKO = goog.userAgent.BROWSER_KNOWN_ ?
|
||||
goog.userAgent.ASSUME_GECKO :
|
||||
goog.labs.userAgent.engine.isGecko();
|
||||
|
||||
|
||||
/**
|
||||
* Whether the user agent is WebKit. WebKit is the rendering engine that
|
||||
* Safari, Android and others use.
|
||||
* @type {boolean}
|
||||
*/
|
||||
goog.userAgent.WEBKIT = goog.userAgent.BROWSER_KNOWN_ ?
|
||||
goog.userAgent.ASSUME_WEBKIT || goog.userAgent.ASSUME_MOBILE_WEBKIT :
|
||||
goog.labs.userAgent.engine.isWebKit();
|
||||
|
||||
|
||||
/**
|
||||
* Whether the user agent is running on a mobile device.
|
||||
*
|
||||
* This is a separate function so that the logic can be tested.
|
||||
*
|
||||
* TODO(nnaze): Investigate swapping in goog.labs.userAgent.device.isMobile().
|
||||
*
|
||||
* @return {boolean} Whether the user agent is running on a mobile device.
|
||||
* @private
|
||||
*/
|
||||
goog.userAgent.isMobile_ = function() {
|
||||
return goog.userAgent.WEBKIT &&
|
||||
goog.labs.userAgent.util.matchUserAgent('Mobile');
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Whether the user agent is running on a mobile device.
|
||||
*
|
||||
* TODO(nnaze): Consider deprecating MOBILE when labs.userAgent
|
||||
* is promoted as the gecko/webkit logic is likely inaccurate.
|
||||
*
|
||||
* @type {boolean}
|
||||
*/
|
||||
goog.userAgent.MOBILE = goog.userAgent.ASSUME_MOBILE_WEBKIT ||
|
||||
goog.userAgent.isMobile_();
|
||||
|
||||
|
||||
/**
|
||||
* Used while transitioning code to use WEBKIT instead.
|
||||
* @type {boolean}
|
||||
* @deprecated Use {@link goog.userAgent.product.SAFARI} instead.
|
||||
* TODO(nicksantos): Delete this from goog.userAgent.
|
||||
*/
|
||||
goog.userAgent.SAFARI = goog.userAgent.WEBKIT;
|
||||
|
||||
|
||||
/**
|
||||
* @return {string} the platform (operating system) the user agent is running
|
||||
* on. Default to empty string because navigator.platform may not be defined
|
||||
* (on Rhino, for example).
|
||||
* @private
|
||||
*/
|
||||
goog.userAgent.determinePlatform_ = function() {
|
||||
var navigator = goog.userAgent.getNavigator();
|
||||
return navigator && navigator.platform || '';
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* The platform (operating system) the user agent is running on. Default to
|
||||
* empty string because navigator.platform may not be defined (on Rhino, for
|
||||
* example).
|
||||
* @type {string}
|
||||
*/
|
||||
goog.userAgent.PLATFORM = goog.userAgent.determinePlatform_();
|
||||
|
||||
|
||||
/**
|
||||
* @define {boolean} Whether the user agent is running on a Macintosh operating
|
||||
* system.
|
||||
*/
|
||||
goog.define('goog.userAgent.ASSUME_MAC', false);
|
||||
|
||||
|
||||
/**
|
||||
* @define {boolean} Whether the user agent is running on a Windows operating
|
||||
* system.
|
||||
*/
|
||||
goog.define('goog.userAgent.ASSUME_WINDOWS', false);
|
||||
|
||||
|
||||
/**
|
||||
* @define {boolean} Whether the user agent is running on a Linux operating
|
||||
* system.
|
||||
*/
|
||||
goog.define('goog.userAgent.ASSUME_LINUX', false);
|
||||
|
||||
|
||||
/**
|
||||
* @define {boolean} Whether the user agent is running on a X11 windowing
|
||||
* system.
|
||||
*/
|
||||
goog.define('goog.userAgent.ASSUME_X11', false);
|
||||
|
||||
|
||||
/**
|
||||
* @define {boolean} Whether the user agent is running on Android.
|
||||
*/
|
||||
goog.define('goog.userAgent.ASSUME_ANDROID', false);
|
||||
|
||||
|
||||
/**
|
||||
* @define {boolean} Whether the user agent is running on an iPhone.
|
||||
*/
|
||||
goog.define('goog.userAgent.ASSUME_IPHONE', false);
|
||||
|
||||
|
||||
/**
|
||||
* @define {boolean} Whether the user agent is running on an iPad.
|
||||
*/
|
||||
goog.define('goog.userAgent.ASSUME_IPAD', false);
|
||||
|
||||
|
||||
/**
|
||||
* @type {boolean}
|
||||
* @private
|
||||
*/
|
||||
goog.userAgent.PLATFORM_KNOWN_ =
|
||||
goog.userAgent.ASSUME_MAC ||
|
||||
goog.userAgent.ASSUME_WINDOWS ||
|
||||
goog.userAgent.ASSUME_LINUX ||
|
||||
goog.userAgent.ASSUME_X11 ||
|
||||
goog.userAgent.ASSUME_ANDROID ||
|
||||
goog.userAgent.ASSUME_IPHONE ||
|
||||
goog.userAgent.ASSUME_IPAD;
|
||||
|
||||
|
||||
/**
|
||||
* Whether the user agent is running on a Macintosh operating system.
|
||||
* @type {boolean}
|
||||
*/
|
||||
goog.userAgent.MAC = goog.userAgent.PLATFORM_KNOWN_ ?
|
||||
goog.userAgent.ASSUME_MAC : goog.labs.userAgent.platform.isMacintosh();
|
||||
|
||||
|
||||
/**
|
||||
* Whether the user agent is running on a Windows operating system.
|
||||
* @type {boolean}
|
||||
*/
|
||||
goog.userAgent.WINDOWS = goog.userAgent.PLATFORM_KNOWN_ ?
|
||||
goog.userAgent.ASSUME_WINDOWS :
|
||||
goog.labs.userAgent.platform.isWindows();
|
||||
|
||||
|
||||
/**
|
||||
* Whether the user agent is Linux per the legacy behavior of
|
||||
* goog.userAgent.LINUX, which considered ChromeOS to also be
|
||||
* Linux.
|
||||
* @return {boolean}
|
||||
* @private
|
||||
*/
|
||||
goog.userAgent.isLegacyLinux_ = function() {
|
||||
return goog.labs.userAgent.platform.isLinux() ||
|
||||
goog.labs.userAgent.platform.isChromeOS();
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Whether the user agent is running on a Linux operating system.
|
||||
*
|
||||
* Note that goog.userAgent.LINUX considers ChromeOS to be Linux,
|
||||
* while goog.labs.userAgent.platform considers ChromeOS and
|
||||
* Linux to be different OSes.
|
||||
*
|
||||
* @type {boolean}
|
||||
*/
|
||||
goog.userAgent.LINUX = goog.userAgent.PLATFORM_KNOWN_ ?
|
||||
goog.userAgent.ASSUME_LINUX :
|
||||
goog.userAgent.isLegacyLinux_();
|
||||
|
||||
|
||||
/**
|
||||
* @return {boolean} Whether the user agent is an X11 windowing system.
|
||||
* @private
|
||||
*/
|
||||
goog.userAgent.isX11_ = function() {
|
||||
var navigator = goog.userAgent.getNavigator();
|
||||
return !!navigator &&
|
||||
goog.string.contains(navigator['appVersion'] || '', 'X11');
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Whether the user agent is running on a X11 windowing system.
|
||||
* @type {boolean}
|
||||
*/
|
||||
goog.userAgent.X11 = goog.userAgent.PLATFORM_KNOWN_ ?
|
||||
goog.userAgent.ASSUME_X11 :
|
||||
goog.userAgent.isX11_();
|
||||
|
||||
|
||||
/**
|
||||
* Whether the user agent is running on Android.
|
||||
* @type {boolean}
|
||||
*/
|
||||
goog.userAgent.ANDROID = goog.userAgent.PLATFORM_KNOWN_ ?
|
||||
goog.userAgent.ASSUME_ANDROID :
|
||||
goog.labs.userAgent.platform.isAndroid();
|
||||
|
||||
|
||||
/**
|
||||
* Whether the user agent is running on an iPhone.
|
||||
* @type {boolean}
|
||||
*/
|
||||
goog.userAgent.IPHONE = goog.userAgent.PLATFORM_KNOWN_ ?
|
||||
goog.userAgent.ASSUME_IPHONE :
|
||||
goog.labs.userAgent.platform.isIphone();
|
||||
|
||||
|
||||
/**
|
||||
* Whether the user agent is running on an iPad.
|
||||
* @type {boolean}
|
||||
*/
|
||||
goog.userAgent.IPAD = goog.userAgent.PLATFORM_KNOWN_ ?
|
||||
goog.userAgent.ASSUME_IPAD :
|
||||
goog.labs.userAgent.platform.isIpad();
|
||||
|
||||
|
||||
/**
|
||||
* @return {string} The string that describes the version number of the user
|
||||
* agent.
|
||||
* @private
|
||||
*/
|
||||
goog.userAgent.determineVersion_ = function() {
|
||||
// All browsers have different ways to detect the version and they all have
|
||||
// different naming schemes.
|
||||
|
||||
// version is a string rather than a number because it may contain 'b', 'a',
|
||||
// and so on.
|
||||
var version = '', re;
|
||||
|
||||
if (goog.userAgent.OPERA && goog.global['opera']) {
|
||||
var operaVersion = goog.global['opera'].version;
|
||||
return goog.isFunction(operaVersion) ? operaVersion() : operaVersion;
|
||||
}
|
||||
|
||||
if (goog.userAgent.GECKO) {
|
||||
re = /rv\:([^\);]+)(\)|;)/;
|
||||
} else if (goog.userAgent.IE) {
|
||||
re = /\b(?:MSIE|rv)[: ]([^\);]+)(\)|;)/;
|
||||
} else if (goog.userAgent.WEBKIT) {
|
||||
// WebKit/125.4
|
||||
re = /WebKit\/(\S+)/;
|
||||
}
|
||||
|
||||
if (re) {
|
||||
var arr = re.exec(goog.userAgent.getUserAgentString());
|
||||
version = arr ? arr[1] : '';
|
||||
}
|
||||
|
||||
if (goog.userAgent.IE) {
|
||||
// IE9 can be in document mode 9 but be reporting an inconsistent user agent
|
||||
// version. If it is identifying as a version lower than 9 we take the
|
||||
// documentMode as the version instead. IE8 has similar behavior.
|
||||
// It is recommended to set the X-UA-Compatible header to ensure that IE9
|
||||
// uses documentMode 9.
|
||||
var docMode = goog.userAgent.getDocumentMode_();
|
||||
if (docMode > parseFloat(version)) {
|
||||
return String(docMode);
|
||||
}
|
||||
}
|
||||
|
||||
return version;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @return {number|undefined} Returns the document mode (for testing).
|
||||
* @private
|
||||
*/
|
||||
goog.userAgent.getDocumentMode_ = function() {
|
||||
// NOTE(user): goog.userAgent may be used in context where there is no DOM.
|
||||
var doc = goog.global['document'];
|
||||
return doc ? doc['documentMode'] : undefined;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* The version of the user agent. This is a string because it might contain
|
||||
* 'b' (as in beta) as well as multiple dots.
|
||||
* @type {string}
|
||||
*/
|
||||
goog.userAgent.VERSION = goog.userAgent.determineVersion_();
|
||||
|
||||
|
||||
/**
|
||||
* Compares two version numbers.
|
||||
*
|
||||
* @param {string} v1 Version of first item.
|
||||
* @param {string} v2 Version of second item.
|
||||
*
|
||||
* @return {number} 1 if first argument is higher
|
||||
* 0 if arguments are equal
|
||||
* -1 if second argument is higher.
|
||||
* @deprecated Use goog.string.compareVersions.
|
||||
*/
|
||||
goog.userAgent.compare = function(v1, v2) {
|
||||
return goog.string.compareVersions(v1, v2);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Cache for {@link goog.userAgent.isVersionOrHigher}.
|
||||
* Calls to compareVersions are surprisingly expensive and, as a browser's
|
||||
* version number is unlikely to change during a session, we cache the results.
|
||||
* @const
|
||||
* @private
|
||||
*/
|
||||
goog.userAgent.isVersionOrHigherCache_ = {};
|
||||
|
||||
|
||||
/**
|
||||
* Whether the user agent version is higher or the same as the given version.
|
||||
* NOTE: When checking the version numbers for Firefox and Safari, be sure to
|
||||
* use the engine's version, not the browser's version number. For example,
|
||||
* Firefox 3.0 corresponds to Gecko 1.9 and Safari 3.0 to Webkit 522.11.
|
||||
* Opera and Internet Explorer versions match the product release number.<br>
|
||||
* @see <a href="http://en.wikipedia.org/wiki/Safari_version_history">
|
||||
* Webkit</a>
|
||||
* @see <a href="http://en.wikipedia.org/wiki/Gecko_engine">Gecko</a>
|
||||
*
|
||||
* @param {string|number} version The version to check.
|
||||
* @return {boolean} Whether the user agent version is higher or the same as
|
||||
* the given version.
|
||||
*/
|
||||
goog.userAgent.isVersionOrHigher = function(version) {
|
||||
return goog.userAgent.ASSUME_ANY_VERSION ||
|
||||
goog.userAgent.isVersionOrHigherCache_[version] ||
|
||||
(goog.userAgent.isVersionOrHigherCache_[version] =
|
||||
goog.string.compareVersions(goog.userAgent.VERSION, version) >= 0);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Deprecated alias to {@code goog.userAgent.isVersionOrHigher}.
|
||||
* @param {string|number} version The version to check.
|
||||
* @return {boolean} Whether the user agent version is higher or the same as
|
||||
* the given version.
|
||||
* @deprecated Use goog.userAgent.isVersionOrHigher().
|
||||
*/
|
||||
goog.userAgent.isVersion = goog.userAgent.isVersionOrHigher;
|
||||
|
||||
|
||||
/**
|
||||
* Whether the IE effective document mode is higher or the same as the given
|
||||
* document mode version.
|
||||
* NOTE: Only for IE, return false for another browser.
|
||||
*
|
||||
* @param {number} documentMode The document mode version to check.
|
||||
* @return {boolean} Whether the IE effective document mode is higher or the
|
||||
* same as the given version.
|
||||
*/
|
||||
goog.userAgent.isDocumentModeOrHigher = function(documentMode) {
|
||||
return goog.userAgent.IE && goog.userAgent.DOCUMENT_MODE >= documentMode;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Deprecated alias to {@code goog.userAgent.isDocumentModeOrHigher}.
|
||||
* @param {number} version The version to check.
|
||||
* @return {boolean} Whether the IE effective document mode is higher or the
|
||||
* same as the given version.
|
||||
* @deprecated Use goog.userAgent.isDocumentModeOrHigher().
|
||||
*/
|
||||
goog.userAgent.isDocumentMode = goog.userAgent.isDocumentModeOrHigher;
|
||||
|
||||
|
||||
/**
|
||||
* For IE version < 7, documentMode is undefined, so attempt to use the
|
||||
* CSS1Compat property to see if we are in standards mode. If we are in
|
||||
* standards mode, treat the browser version as the document mode. Otherwise,
|
||||
* IE is emulating version 5.
|
||||
* @type {number|undefined}
|
||||
* @const
|
||||
*/
|
||||
goog.userAgent.DOCUMENT_MODE = (function() {
|
||||
var doc = goog.global['document'];
|
||||
if (!doc || !goog.userAgent.IE) {
|
||||
return undefined;
|
||||
}
|
||||
var mode = goog.userAgent.getDocumentMode_();
|
||||
return mode || (doc['compatMode'] == 'CSS1Compat' ?
|
||||
parseInt(goog.userAgent.VERSION, 10) : 5);
|
||||
})();
|
||||
@@ -0,0 +1,21 @@
|
||||
<html>
|
||||
<!--
|
||||
Copyright 2012 The Closure Library Authors. All Rights Reserved.
|
||||
|
||||
Use of this source code is governed by the Apache License, Version 2.0.
|
||||
See the COPYING file for details.
|
||||
-->
|
||||
<head>
|
||||
<title>
|
||||
Closure Unit Tests - goog.userAgent quirks
|
||||
</title>
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=5">
|
||||
<script src="../base.js">
|
||||
</script>
|
||||
<script>
|
||||
goog.require('goog.userAgentQuirksTest');
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,25 @@
|
||||
// Copyright 2012 The Closure Library Authors. All Rights Reserved.
|
||||
//
|
||||
// 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.
|
||||
|
||||
goog.provide('goog.userAgentQuirksTest');
|
||||
goog.setTestOnly('goog.userAgentQuirksTest');
|
||||
|
||||
goog.require('goog.testing.jsunit');
|
||||
goog.require('goog.userAgent');
|
||||
|
||||
function testGetDocumentModeInQuirksMode() {
|
||||
// This test file is forcing quirks mode.
|
||||
var expected = goog.userAgent.IE ? 5 : undefined;
|
||||
assertEquals(expected, goog.userAgent.DOCUMENT_MODE);
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<!--
|
||||
Copyright 2006 The Closure Library Authors. All Rights Reserved.
|
||||
|
||||
Use of this source code is governed by the Apache License, Version 2.0.
|
||||
See the COPYING file for details.
|
||||
-->
|
||||
<head>
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
||||
<title>
|
||||
Closure Unit Tests - goog.userAgent
|
||||
</title>
|
||||
<script src="../base.js">
|
||||
</script>
|
||||
<script>
|
||||
goog.require('goog.userAgentTest');
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,290 @@
|
||||
// Copyright 2006 The Closure Library Authors. All Rights Reserved.
|
||||
//
|
||||
// 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.
|
||||
|
||||
goog.provide('goog.userAgentTest');
|
||||
goog.setTestOnly('goog.userAgentTest');
|
||||
|
||||
goog.require('goog.array');
|
||||
goog.require('goog.labs.userAgent.platform');
|
||||
goog.require('goog.labs.userAgent.testAgents');
|
||||
goog.require('goog.labs.userAgent.util');
|
||||
goog.require('goog.testing.PropertyReplacer');
|
||||
goog.require('goog.testing.jsunit');
|
||||
goog.require('goog.userAgent');
|
||||
goog.require('goog.userAgentTestUtil');
|
||||
|
||||
|
||||
var documentMode;
|
||||
goog.userAgent.getDocumentMode_ = function() {
|
||||
return documentMode;
|
||||
};
|
||||
|
||||
|
||||
var propertyReplacer = new goog.testing.PropertyReplacer();
|
||||
|
||||
var UserAgents = {
|
||||
GECKO: 'GECKO',
|
||||
IE: 'IE',
|
||||
OPERA: 'OPERA',
|
||||
WEBKIT: 'WEBKIT'
|
||||
};
|
||||
|
||||
|
||||
function tearDown() {
|
||||
goog.labs.userAgent.util.setUserAgent(null);
|
||||
documentMode = undefined;
|
||||
propertyReplacer.reset();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Test browser detection for a user agent configuration.
|
||||
* @param {Array<number>} expectedAgents Array of expected userAgents.
|
||||
* @param {string} uaString User agent string.
|
||||
* @param {string=} opt_product Navigator product string.
|
||||
* @param {string=} opt_vendor Navigator vendor string.
|
||||
*/
|
||||
function assertUserAgent(expectedAgents, uaString, opt_product, opt_vendor) {
|
||||
var mockGlobal = {
|
||||
'navigator': {
|
||||
'userAgent': uaString,
|
||||
'product': opt_product,
|
||||
'vendor': opt_vendor
|
||||
}
|
||||
};
|
||||
propertyReplacer.set(goog, 'global', mockGlobal);
|
||||
|
||||
goog.labs.userAgent.util.setUserAgent(null);
|
||||
|
||||
goog.userAgentTestUtil.reinitializeUserAgent();
|
||||
for (var ua in UserAgents) {
|
||||
var isExpected = goog.array.contains(expectedAgents, UserAgents[ua]);
|
||||
assertEquals(isExpected,
|
||||
goog.userAgentTestUtil.getUserAgentDetected(UserAgents[ua]));
|
||||
}
|
||||
}
|
||||
|
||||
function testOperaInit() {
|
||||
var mockOpera = {
|
||||
'version': function() {
|
||||
return '9.20';
|
||||
}
|
||||
};
|
||||
|
||||
var mockGlobal = {
|
||||
'navigator': {
|
||||
'userAgent': 'Opera/9.20 (Windows NT 5.1; U; de),gzip(gfe)'
|
||||
},
|
||||
'opera': mockOpera
|
||||
};
|
||||
propertyReplacer.set(goog, 'global', mockGlobal);
|
||||
|
||||
propertyReplacer.set(goog.userAgent, 'getUserAgentString', function() {
|
||||
return 'Opera/9.20 (Windows NT 5.1; U; de),gzip(gfe)';
|
||||
});
|
||||
|
||||
goog.labs.userAgent.util.setUserAgent(null);
|
||||
goog.userAgentTestUtil.reinitializeUserAgent();
|
||||
assertTrue(goog.userAgent.OPERA);
|
||||
assertEquals('9.20', goog.userAgent.VERSION);
|
||||
|
||||
// What if 'opera' global has been overwritten?
|
||||
// We must degrade gracefully (rather than throwing JS errors).
|
||||
propertyReplacer.set(goog.global, 'opera', 'bobloblaw');
|
||||
|
||||
// NOTE(nnaze): window.opera is now ignored with the migration to
|
||||
// goog.labs.userAgent.*. Version is expected to should stay the same.
|
||||
goog.labs.userAgent.util.setUserAgent(null);
|
||||
goog.userAgentTestUtil.reinitializeUserAgent();
|
||||
assertUndefined(goog.userAgent.VERSION);
|
||||
}
|
||||
|
||||
function testCompare() {
|
||||
assertTrue('exact equality broken',
|
||||
goog.userAgent.compare('1.0', '1.0') == 0);
|
||||
assertTrue('mutlidot equality broken',
|
||||
goog.userAgent.compare('1.0.0.0', '1.0') == 0);
|
||||
assertTrue('less than broken',
|
||||
goog.userAgent.compare('1.0.2.1', '1.1') < 0);
|
||||
assertTrue('greater than broken',
|
||||
goog.userAgent.compare('1.1', '1.0.2.1') > 0);
|
||||
|
||||
assertTrue('b broken', goog.userAgent.compare('1.1', '1.1b') > 0);
|
||||
assertTrue('b broken', goog.userAgent.compare('1.1b', '1.1') < 0);
|
||||
assertTrue('b broken', goog.userAgent.compare('1.1b', '1.1b') == 0);
|
||||
|
||||
assertTrue('b>a broken', goog.userAgent.compare('1.1b', '1.1a') > 0);
|
||||
assertTrue('a<b broken', goog.userAgent.compare('1.1a', '1.1b') < 0);
|
||||
}
|
||||
|
||||
function testGecko() {
|
||||
|
||||
assertGecko('Mozilla/5.0 (Windows; U; Windows NT 5.1; nl-NL; rv:1.7.5)' +
|
||||
'Gecko/20041202 Gecko/1.0', '1.7.5');
|
||||
assertGecko('Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.7.6)' +
|
||||
'Gecko/20050512 Gecko', '1.7.6');
|
||||
assertGecko('Mozilla/5.0 (X11; U; FreeBSD i386; en-US; rv:1.7.8)' +
|
||||
'Gecko/20050609 Gecko/1.0.4', '1.7.8');
|
||||
assertGecko('Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.9)' +
|
||||
'Gecko/20050711 Gecko/1.0.5', '1.7.9');
|
||||
assertGecko('Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.10)' +
|
||||
'Gecko/20050716 Gecko/1.0.6', '1.7.10');
|
||||
assertGecko('Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en-GB;' +
|
||||
'rv:1.7.10) Gecko/20050717 Gecko/1.0.6', '1.7.10');
|
||||
assertGecko('Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.12)' +
|
||||
'Gecko/20050915 Gecko/1.0.7', '1.7.12');
|
||||
assertGecko('Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en-US;' +
|
||||
'rv:1.7.12) Gecko/20050915 Gecko/1.0.7', '1.7.12');
|
||||
assertGecko('Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8b4)' +
|
||||
'Gecko/20050908 Gecko/1.4', '1.8b4');
|
||||
assertGecko('Mozilla/5.0 (Windows; U; Windows NT 5.1; nl; rv:1.8)' +
|
||||
'Gecko/20051107 Gecko/1.5', '1.8');
|
||||
assertGecko('Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.8.0.1)' +
|
||||
'Gecko/20060111 Gecko/1.5.0.1', '1.8.0.1');
|
||||
assertGecko('Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.8.0.1)' +
|
||||
'Gecko/20060111 Gecko/1.5.0.1', '1.8.0.1');
|
||||
assertGecko('Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.0.2)' +
|
||||
'Gecko/20060308 Gecko/1.5.0.2', '1.8.0.2');
|
||||
assertGecko('Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en-US;' +
|
||||
'rv:1.8.0.3) Gecko/20060426 Gecko/1.5.0.3', '1.8.0.3');
|
||||
assertGecko('Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.0.3)' +
|
||||
'Gecko/20060426 Gecko/1.5.0.3', '1.8.0.3');
|
||||
assertGecko('Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.0.4)' +
|
||||
'Gecko/20060508 Gecko/1.5.0.4', '1.8.0.4');
|
||||
assertGecko('Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.4)' +
|
||||
'Gecko/20060508 Gecko/1.5.0.4', '1.8.0.4');
|
||||
assertGecko('Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.8.0.4)' +
|
||||
'Gecko/20060508 Gecko/1.5.0.4', '1.8.0.4');
|
||||
assertGecko('Mozilla/5.0 (Windows; U; Windows NT 5.1; es-ES; rv:1.8.0.6)' +
|
||||
'Gecko/20060728 Gecko/1.5.0.6', '1.8.0.6');
|
||||
assertGecko('Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.0.6)' +
|
||||
'Gecko/20060808 Fedora/1.5.0.6-2.fc5 Gecko/1.5.0.6 pango-text',
|
||||
'1.8.0.6');
|
||||
assertGecko('Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8)' +
|
||||
'Gecko/20060321 Gecko/2.0a1', '1.8');
|
||||
assertGecko('Mozilla/5.0 (X11; Linux i686; rv:6.0) Gecko/6.0 Firefox/6.0',
|
||||
'6.0');
|
||||
}
|
||||
|
||||
function testIe() {
|
||||
assertIe('Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)', '5.01');
|
||||
assertIe('Mozilla/4.0 (compatible; MSIE 5.17; Mac_PowerPC)', '5.17');
|
||||
assertIe('Mozilla/4.0 (compatible; MSIE 5.23; Mac_PowerPC)', '5.23');
|
||||
assertIe('Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.0)', '5.5');
|
||||
assertIe('Mozilla/4.0 (compatible; MSIE 6.0; MSN 2.5; Windows 98)', '6.0');
|
||||
assertIe('Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)', '6.0');
|
||||
assertIe('Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; ' +
|
||||
'.NET CLR 1.1.4322)', '6.0');
|
||||
assertIe('Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; ' +
|
||||
'.NET CLR 2.0.50727)', '6.0');
|
||||
assertIe('Mozilla/4.0 (compatible; MSIE 7.0b; Windows NT 5.1)', '7.0b');
|
||||
assertIe('Mozilla/4.0 (compatible; MSIE 7.0b; Win32)', '7.0b');
|
||||
assertIe('Mozilla/4.0 (compatible; MSIE 7.0b; Windows NT 6.0)', '7.0b');
|
||||
assertIe('Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; SV1;' +
|
||||
'Arcor 5.005; .NET CLR 1.0.3705; .NET CLR 1.1.4322)', '7.0');
|
||||
assertIe(
|
||||
'Mozilla/5.0 (Windows NT 6.3; Trident/7.0; rv:11.0) like Gecko', '11.0');
|
||||
}
|
||||
|
||||
function testIeDocumentModeOverride() {
|
||||
documentMode = 9;
|
||||
assertIe('Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; Trident/5.0',
|
||||
'9');
|
||||
assertIe('Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/5.0',
|
||||
'9');
|
||||
|
||||
documentMode = 8;
|
||||
assertIe('Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/5.0',
|
||||
'8.0');
|
||||
}
|
||||
|
||||
function testDocumentModeInStandardsMode() {
|
||||
goog.userAgentTestUtil.reinitializeUserAgent();
|
||||
var expectedMode = goog.userAgent.IE ? parseInt(goog.userAgent.VERSION) :
|
||||
undefined;
|
||||
assertEquals(expectedMode, goog.userAgent.DOCUMENT_MODE);
|
||||
}
|
||||
|
||||
function testOpera() {
|
||||
var assertOpera = function(uaString) {
|
||||
assertUserAgent([UserAgents.OPERA], uaString);
|
||||
};
|
||||
assertOpera('Opera/7.23 (Windows 98; U) [en]');
|
||||
assertOpera('Opera/8.00 (Windows NT 5.1; U; en)');
|
||||
assertOpera('Opera/8.0 (X11; Linux i686; U; cs)');
|
||||
assertOpera('Opera/8.02 (Windows NT 5.1; U; en)');
|
||||
assertOpera('Opera/8.50 (Windows NT 5.1; U; en)');
|
||||
assertOpera('Opera/8.5 (X11; Linux i686; U; cs)');
|
||||
assertOpera('Opera/8.51 (Windows NT 5.1; U; en)');
|
||||
assertOpera('Opera/9.0 (Windows NT 5.0; U; en)');
|
||||
assertOpera('Opera/9.00 (Macintosh; PPC Mac OS X; U; en)');
|
||||
assertOpera('Opera/9.00 (Windows NT 5.1; U; en)');
|
||||
assertOpera('Opera/9.00 (Windows NT 5.2; U; en)');
|
||||
assertOpera('Opera/9.00 (Windows NT 6.0; U; en)');
|
||||
}
|
||||
|
||||
function testWebkit() {
|
||||
var testAgents = goog.labs.userAgent.testAgents;
|
||||
assertWebkit(testAgents.ANDROID_BROWSER_403);
|
||||
assertWebkit(testAgents.ANDROID_BROWSER_403_ALT);
|
||||
}
|
||||
|
||||
function testUnknownBrowser() {
|
||||
assertUserAgent([], 'MyWebBrowser');
|
||||
assertUserAgent([], undefined);
|
||||
}
|
||||
|
||||
function testNoNavigator() {
|
||||
// global object has no "navigator" property.
|
||||
var mockGlobal = {};
|
||||
propertyReplacer.set(goog, 'global', mockGlobal);
|
||||
goog.labs.userAgent.util.setUserAgent(null);
|
||||
goog.userAgentTestUtil.reinitializeUserAgent();
|
||||
|
||||
assertEquals('Platform should be the empty string', '',
|
||||
goog.userAgent.PLATFORM);
|
||||
assertEquals('Version should be the empty string', '',
|
||||
goog.userAgent.VERSION);
|
||||
}
|
||||
|
||||
function testLegacyChromeOsAndLinux() {
|
||||
// As a legacy behavior, goog.userAgent.LINUX considers
|
||||
// ChromeOS to be Linux.
|
||||
// goog.labs.userAgent.platform.isLinux() does not.
|
||||
goog.labs.userAgent.util.setUserAgent(
|
||||
goog.labs.userAgent.testAgents.CHROME_OS);
|
||||
goog.userAgentTestUtil.reinitializeUserAgent();
|
||||
assertTrue(goog.userAgent.LINUX);
|
||||
assertFalse(goog.labs.userAgent.platform.isLinux());
|
||||
}
|
||||
|
||||
function assertIe(uaString, expectedVersion) {
|
||||
assertUserAgent([UserAgents.IE], uaString);
|
||||
assertEquals('User agent ' + uaString + ' should have had version ' +
|
||||
expectedVersion + ' but had ' + goog.userAgent.VERSION,
|
||||
expectedVersion,
|
||||
goog.userAgent.VERSION);
|
||||
}
|
||||
|
||||
function assertGecko(uaString, expectedVersion) {
|
||||
assertUserAgent([UserAgents.GECKO], uaString, 'Gecko');
|
||||
assertEquals('User agent ' + uaString + ' should have had version ' +
|
||||
expectedVersion + ' but had ' + goog.userAgent.VERSION,
|
||||
expectedVersion,
|
||||
goog.userAgent.VERSION);
|
||||
}
|
||||
|
||||
function assertWebkit(uaString) {
|
||||
assertUserAgent([UserAgents.WEBKIT], uaString, 'WebKit');
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
// Copyright 2006 The Closure Library Authors. All Rights Reserved.
|
||||
//
|
||||
// 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.
|
||||
|
||||
/**
|
||||
* @fileoverview Shared test function to reset the constants in
|
||||
* goog.userAgent.*
|
||||
*/
|
||||
|
||||
goog.provide('goog.userAgentTestUtil');
|
||||
goog.provide('goog.userAgentTestUtil.UserAgents');
|
||||
|
||||
goog.require('goog.labs.userAgent.browser');
|
||||
goog.require('goog.labs.userAgent.engine');
|
||||
goog.require('goog.labs.userAgent.platform');
|
||||
goog.require('goog.userAgent');
|
||||
goog.require('goog.userAgent.keyboard');
|
||||
goog.require('goog.userAgent.platform');
|
||||
goog.require('goog.userAgent.product');
|
||||
/** @suppress {extraRequire} */
|
||||
goog.require('goog.userAgent.product.isVersion');
|
||||
|
||||
goog.setTestOnly('goog.userAgentTestUtil');
|
||||
|
||||
|
||||
/**
|
||||
* Rerun the initialization code to set all of the goog.userAgent constants.
|
||||
* @suppress {accessControls}
|
||||
*/
|
||||
goog.userAgentTestUtil.reinitializeUserAgent = function() {
|
||||
// Unfortunately we can't isolate the useragent setting in a function
|
||||
// we can call, because things rely on it compiling to nothing when
|
||||
// one of the ASSUME flags is set, and the compiler isn't smart enough
|
||||
// to do that when the setting is done inside a function that's inlined.
|
||||
goog.userAgent.OPERA = goog.labs.userAgent.browser.isOpera();
|
||||
goog.userAgent.IE = goog.labs.userAgent.browser.isIE();
|
||||
goog.userAgent.GECKO = goog.labs.userAgent.engine.isGecko();
|
||||
goog.userAgent.WEBKIT = goog.labs.userAgent.engine.isWebKit();
|
||||
goog.userAgent.MOBILE = goog.userAgent.isMobile_();
|
||||
goog.userAgent.SAFARI = goog.userAgent.WEBKIT;
|
||||
|
||||
// Platform in goog.userAgent.
|
||||
goog.userAgent.PLATFORM = goog.userAgent.determinePlatform_();
|
||||
|
||||
goog.userAgent.MAC = goog.labs.userAgent.platform.isMacintosh();
|
||||
goog.userAgent.WINDOWS = goog.labs.userAgent.platform.isWindows();
|
||||
goog.userAgent.LINUX = goog.userAgent.isLegacyLinux_();
|
||||
goog.userAgent.X11 = goog.userAgent.isX11_();
|
||||
goog.userAgent.ANDROID = goog.labs.userAgent.platform.isAndroid();
|
||||
goog.userAgent.IPAD = goog.labs.userAgent.platform.isIpad();
|
||||
goog.userAgent.IPHONE = goog.labs.userAgent.platform.isIphone();
|
||||
goog.userAgent.VERSION = goog.userAgent.determineVersion_();
|
||||
|
||||
// Platform in goog.userAgent.platform.
|
||||
goog.userAgent.platform.VERSION = goog.userAgent.platform.determineVersion_();
|
||||
|
||||
// Update goog.userAgent.product
|
||||
goog.userAgent.product.init_();
|
||||
goog.userAgent.product.ANDROID = goog.userAgent.product.detectedAndroid_;
|
||||
goog.userAgent.product.CAMINO = goog.userAgent.product.detectedCamino_;
|
||||
goog.userAgent.product.CHROME = goog.userAgent.product.detectedChrome_;
|
||||
goog.userAgent.product.FIREFOX = goog.userAgent.product.detectedFirefox_;
|
||||
goog.userAgent.product.IE = goog.userAgent.IE;
|
||||
goog.userAgent.product.IPAD = goog.userAgent.product.detectedIpad_;
|
||||
goog.userAgent.product.IPHONE = goog.userAgent.product.detectedIphone_;
|
||||
goog.userAgent.product.OPERA = goog.userAgent.OPERA;
|
||||
goog.userAgent.product.SAFARI = goog.userAgent.product.detectedSafari_;
|
||||
goog.userAgent.product.VERSION = goog.userAgent.product.determineVersion_();
|
||||
|
||||
// goog.userAgent.keyboard
|
||||
goog.userAgent.keyboard.MAC_KEYBOARD =
|
||||
goog.userAgent.keyboard.determineMacKeyboard_();
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Browser definitions.
|
||||
* @enum {string}
|
||||
*/
|
||||
goog.userAgentTestUtil.UserAgents = {
|
||||
GECKO: 'GECKO',
|
||||
IE: 'IE',
|
||||
OPERA: 'OPERA',
|
||||
WEBKIT: 'WEBKIT'
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Return whether a given user agent has been detected.
|
||||
* @param {string} agent Value in UserAgents.
|
||||
* @return {boolean} Whether the user agent has been detected.
|
||||
*/
|
||||
goog.userAgentTestUtil.getUserAgentDetected = function(agent) {
|
||||
switch (agent) {
|
||||
case goog.userAgentTestUtil.UserAgents.GECKO:
|
||||
return goog.userAgent.GECKO;
|
||||
case goog.userAgentTestUtil.UserAgents.IE:
|
||||
return goog.userAgent.IE;
|
||||
case goog.userAgentTestUtil.UserAgents.OPERA:
|
||||
return goog.userAgent.OPERA;
|
||||
case goog.userAgentTestUtil.UserAgents.WEBKIT:
|
||||
return goog.userAgent.WEBKIT;
|
||||
}
|
||||
|
||||
throw Error('Unrecognized user agent');
|
||||
};
|
||||
Reference in New Issue
Block a user