Adding mapbox-gl branch
This commit is contained in:
@@ -0,0 +1,310 @@
|
||||
// Copyright 2013 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 Closure user agent detection (Browser).
|
||||
* @see <a href="http://www.useragentstring.com/">User agent strings</a>
|
||||
* For more information on rendering engine, platform, or device see the other
|
||||
* sub-namespaces in goog.labs.userAgent, goog.labs.userAgent.platform,
|
||||
* goog.labs.userAgent.device respectively.)
|
||||
*
|
||||
* @author martone@google.com (Andy Martone)
|
||||
*/
|
||||
|
||||
goog.provide('goog.labs.userAgent.browser');
|
||||
|
||||
goog.require('goog.array');
|
||||
goog.require('goog.labs.userAgent.util');
|
||||
goog.require('goog.object');
|
||||
goog.require('goog.string');
|
||||
|
||||
|
||||
/**
|
||||
* @return {boolean} Whether the user's browser is Opera.
|
||||
* @private
|
||||
*/
|
||||
goog.labs.userAgent.browser.matchOpera_ = function() {
|
||||
return goog.labs.userAgent.util.matchUserAgent('Opera') ||
|
||||
goog.labs.userAgent.util.matchUserAgent('OPR');
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @return {boolean} Whether the user's browser is IE.
|
||||
* @private
|
||||
*/
|
||||
goog.labs.userAgent.browser.matchIE_ = function() {
|
||||
return goog.labs.userAgent.util.matchUserAgent('Trident') ||
|
||||
goog.labs.userAgent.util.matchUserAgent('MSIE');
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @return {boolean} Whether the user's browser is Firefox.
|
||||
* @private
|
||||
*/
|
||||
goog.labs.userAgent.browser.matchFirefox_ = function() {
|
||||
return goog.labs.userAgent.util.matchUserAgent('Firefox');
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @return {boolean} Whether the user's browser is Safari.
|
||||
* @private
|
||||
*/
|
||||
goog.labs.userAgent.browser.matchSafari_ = function() {
|
||||
return goog.labs.userAgent.util.matchUserAgent('Safari') &&
|
||||
!goog.labs.userAgent.util.matchUserAgent('Chrome') &&
|
||||
!goog.labs.userAgent.util.matchUserAgent('CriOS') &&
|
||||
!goog.labs.userAgent.util.matchUserAgent('Android');
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @return {boolean} Whether the user's browser is Coast (Opera's Webkit-based
|
||||
* iOS browser).
|
||||
* @private
|
||||
*/
|
||||
goog.labs.userAgent.browser.matchCoast_ = function() {
|
||||
return goog.labs.userAgent.util.matchUserAgent('Coast');
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @return {boolean} Whether the user's browser is iOS Webview.
|
||||
* @private
|
||||
*/
|
||||
goog.labs.userAgent.browser.matchIosWebview_ = function() {
|
||||
// iOS Webview does not show up as Chrome or Safari. Also check for Opera's
|
||||
// WebKit-based iOS browser, Coast.
|
||||
return (goog.labs.userAgent.util.matchUserAgent('iPad') ||
|
||||
goog.labs.userAgent.util.matchUserAgent('iPhone')) &&
|
||||
!goog.labs.userAgent.browser.matchSafari_() &&
|
||||
!goog.labs.userAgent.browser.matchChrome_() &&
|
||||
!goog.labs.userAgent.browser.matchCoast_() &&
|
||||
goog.labs.userAgent.util.matchUserAgent('AppleWebKit');
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @return {boolean} Whether the user's browser is Chrome.
|
||||
* @private
|
||||
*/
|
||||
goog.labs.userAgent.browser.matchChrome_ = function() {
|
||||
return goog.labs.userAgent.util.matchUserAgent('Chrome') ||
|
||||
goog.labs.userAgent.util.matchUserAgent('CriOS');
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @return {boolean} Whether the user's browser is the Android browser.
|
||||
* @private
|
||||
*/
|
||||
goog.labs.userAgent.browser.matchAndroidBrowser_ = function() {
|
||||
// Android can appear in the user agent string for Chrome on Android.
|
||||
// This is not the Android standalone browser if it does.
|
||||
return !goog.labs.userAgent.browser.isChrome() &&
|
||||
goog.labs.userAgent.util.matchUserAgent('Android');
|
||||
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @return {boolean} Whether the user's browser is Opera.
|
||||
*/
|
||||
goog.labs.userAgent.browser.isOpera = goog.labs.userAgent.browser.matchOpera_;
|
||||
|
||||
|
||||
/**
|
||||
* @return {boolean} Whether the user's browser is IE.
|
||||
*/
|
||||
goog.labs.userAgent.browser.isIE = goog.labs.userAgent.browser.matchIE_;
|
||||
|
||||
|
||||
/**
|
||||
* @return {boolean} Whether the user's browser is Firefox.
|
||||
*/
|
||||
goog.labs.userAgent.browser.isFirefox =
|
||||
goog.labs.userAgent.browser.matchFirefox_;
|
||||
|
||||
|
||||
/**
|
||||
* @return {boolean} Whether the user's browser is Safari.
|
||||
*/
|
||||
goog.labs.userAgent.browser.isSafari =
|
||||
goog.labs.userAgent.browser.matchSafari_;
|
||||
|
||||
|
||||
/**
|
||||
* @return {boolean} Whether the user's browser is Coast (Opera's Webkit-based
|
||||
* iOS browser).
|
||||
*/
|
||||
goog.labs.userAgent.browser.isCoast =
|
||||
goog.labs.userAgent.browser.matchCoast_;
|
||||
|
||||
|
||||
/**
|
||||
* @return {boolean} Whether the user's browser is iOS Webview.
|
||||
*/
|
||||
goog.labs.userAgent.browser.isIosWebview =
|
||||
goog.labs.userAgent.browser.matchIosWebview_;
|
||||
|
||||
|
||||
/**
|
||||
* @return {boolean} Whether the user's browser is Chrome.
|
||||
*/
|
||||
goog.labs.userAgent.browser.isChrome =
|
||||
goog.labs.userAgent.browser.matchChrome_;
|
||||
|
||||
|
||||
/**
|
||||
* @return {boolean} Whether the user's browser is the Android browser.
|
||||
*/
|
||||
goog.labs.userAgent.browser.isAndroidBrowser =
|
||||
goog.labs.userAgent.browser.matchAndroidBrowser_;
|
||||
|
||||
|
||||
/**
|
||||
* For more information, see:
|
||||
* http://docs.aws.amazon.com/silk/latest/developerguide/user-agent.html
|
||||
* @return {boolean} Whether the user's browser is Silk.
|
||||
*/
|
||||
goog.labs.userAgent.browser.isSilk = function() {
|
||||
return goog.labs.userAgent.util.matchUserAgent('Silk');
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @return {string} The browser version or empty string if version cannot be
|
||||
* determined. Note that for Internet Explorer, this returns the version of
|
||||
* the browser, not the version of the rendering engine. (IE 8 in
|
||||
* compatibility mode will return 8.0 rather than 7.0. To determine the
|
||||
* rendering engine version, look at document.documentMode instead. See
|
||||
* http://msdn.microsoft.com/en-us/library/cc196988(v=vs.85).aspx for more
|
||||
* details.)
|
||||
*/
|
||||
goog.labs.userAgent.browser.getVersion = function() {
|
||||
var userAgentString = goog.labs.userAgent.util.getUserAgent();
|
||||
// Special case IE since IE's version is inside the parenthesis and
|
||||
// without the '/'.
|
||||
if (goog.labs.userAgent.browser.isIE()) {
|
||||
return goog.labs.userAgent.browser.getIEVersion_(userAgentString);
|
||||
}
|
||||
|
||||
var versionTuples = goog.labs.userAgent.util.extractVersionTuples(
|
||||
userAgentString);
|
||||
|
||||
// Construct a map for easy lookup.
|
||||
var versionMap = {};
|
||||
goog.array.forEach(versionTuples, function(tuple) {
|
||||
// Note that the tuple is of length three, but we only care about the
|
||||
// first two.
|
||||
var key = tuple[0];
|
||||
var value = tuple[1];
|
||||
versionMap[key] = value;
|
||||
});
|
||||
|
||||
var versionMapHasKey = goog.partial(goog.object.containsKey, versionMap);
|
||||
|
||||
// Gives the value with the first key it finds, otherwise empty string.
|
||||
function lookUpValueWithKeys(keys) {
|
||||
var key = goog.array.find(keys, versionMapHasKey);
|
||||
return versionMap[key] || '';
|
||||
}
|
||||
|
||||
// Check Opera before Chrome since Opera 15+ has "Chrome" in the string.
|
||||
// See
|
||||
// http://my.opera.com/ODIN/blog/2013/07/15/opera-user-agent-strings-opera-15-and-beyond
|
||||
if (goog.labs.userAgent.browser.isOpera()) {
|
||||
// Opera 10 has Version/10.0 but Opera/9.8, so look for "Version" first.
|
||||
// Opera uses 'OPR' for more recent UAs.
|
||||
return lookUpValueWithKeys(['Version', 'Opera', 'OPR']);
|
||||
}
|
||||
|
||||
if (goog.labs.userAgent.browser.isChrome()) {
|
||||
return lookUpValueWithKeys(['Chrome', 'CriOS']);
|
||||
}
|
||||
|
||||
// Usually products browser versions are in the third tuple after "Mozilla"
|
||||
// and the engine.
|
||||
var tuple = versionTuples[2];
|
||||
return tuple && tuple[1] || '';
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {string|number} version The version to check.
|
||||
* @return {boolean} Whether the browser version is higher or the same as the
|
||||
* given version.
|
||||
*/
|
||||
goog.labs.userAgent.browser.isVersionOrHigher = function(version) {
|
||||
return goog.string.compareVersions(goog.labs.userAgent.browser.getVersion(),
|
||||
version) >= 0;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Determines IE version. More information:
|
||||
* http://msdn.microsoft.com/en-us/library/ie/bg182625(v=vs.85).aspx#uaString
|
||||
* http://msdn.microsoft.com/en-us/library/hh869301(v=vs.85).aspx
|
||||
* http://blogs.msdn.com/b/ie/archive/2010/03/23/introducing-ie9-s-user-agent-string.aspx
|
||||
* http://blogs.msdn.com/b/ie/archive/2009/01/09/the-internet-explorer-8-user-agent-string-updated-edition.aspx
|
||||
*
|
||||
* @param {string} userAgent the User-Agent.
|
||||
* @return {string}
|
||||
* @private
|
||||
*/
|
||||
goog.labs.userAgent.browser.getIEVersion_ = function(userAgent) {
|
||||
// IE11 may identify itself as MSIE 9.0 or MSIE 10.0 due to an IE 11 upgrade
|
||||
// bug. Example UA:
|
||||
// Mozilla/5.0 (MSIE 9.0; Windows NT 6.1; WOW64; Trident/7.0; rv:11.0)
|
||||
// like Gecko.
|
||||
// See http://www.whatismybrowser.com/developers/unknown-user-agent-fragments.
|
||||
var rv = /rv: *([\d\.]*)/.exec(userAgent);
|
||||
if (rv && rv[1]) {
|
||||
return rv[1];
|
||||
}
|
||||
|
||||
var version = '';
|
||||
var msie = /MSIE +([\d\.]+)/.exec(userAgent);
|
||||
if (msie && msie[1]) {
|
||||
// IE in compatibility mode usually identifies itself as MSIE 7.0; in this
|
||||
// case, use the Trident version to determine the version of IE. For more
|
||||
// details, see the links above.
|
||||
var tridentVersion = /Trident\/(\d.\d)/.exec(userAgent);
|
||||
if (msie[1] == '7.0') {
|
||||
if (tridentVersion && tridentVersion[1]) {
|
||||
switch (tridentVersion[1]) {
|
||||
case '4.0':
|
||||
version = '8.0';
|
||||
break;
|
||||
case '5.0':
|
||||
version = '9.0';
|
||||
break;
|
||||
case '6.0':
|
||||
version = '10.0';
|
||||
break;
|
||||
case '7.0':
|
||||
version = '11.0';
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
version = '7.0';
|
||||
}
|
||||
} else {
|
||||
version = msie[1];
|
||||
}
|
||||
}
|
||||
return version;
|
||||
};
|
||||
@@ -0,0 +1,21 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<!--
|
||||
Copyright 2013 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.labs.userAgent.browser</title>
|
||||
<script src="../../base.js"></script>
|
||||
<script>
|
||||
goog.require('goog.labs.userAgent.browserTest');
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,291 @@
|
||||
// Copyright 2013 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 Unit tests for goog.labs.userAgent.browser.
|
||||
*/
|
||||
|
||||
goog.provide('goog.labs.userAgent.browserTest');
|
||||
|
||||
goog.require('goog.labs.userAgent.browser');
|
||||
goog.require('goog.labs.userAgent.testAgents');
|
||||
goog.require('goog.labs.userAgent.util');
|
||||
goog.require('goog.testing.jsunit');
|
||||
|
||||
goog.setTestOnly('goog.labs.userAgent.browserTest');
|
||||
|
||||
function setUp() {
|
||||
goog.labs.userAgent.util.setUserAgent(null);
|
||||
}
|
||||
|
||||
function testOpera10() {
|
||||
goog.labs.userAgent.util.setUserAgent(
|
||||
goog.labs.userAgent.testAgents.OPERA_10);
|
||||
assertTrue(goog.labs.userAgent.browser.isOpera());
|
||||
assertVersion('10.00');
|
||||
assertVersionBetween('10.00', '10.10');
|
||||
}
|
||||
|
||||
function testOperaMac() {
|
||||
goog.labs.userAgent.util.setUserAgent(
|
||||
goog.labs.userAgent.testAgents.OPERA_MAC);
|
||||
assertTrue(goog.labs.userAgent.browser.isOpera());
|
||||
assertVersion('11.52');
|
||||
assertVersionBetween('11.50', '12.00');
|
||||
}
|
||||
|
||||
function testOperaLinux() {
|
||||
goog.labs.userAgent.util.setUserAgent(
|
||||
goog.labs.userAgent.testAgents.OPERA_LINUX);
|
||||
assertTrue(goog.labs.userAgent.browser.isOpera());
|
||||
assertVersion('11.50');
|
||||
assertVersionBetween('11.00', '12.00');
|
||||
}
|
||||
|
||||
function testOpera15() {
|
||||
goog.labs.userAgent.util.setUserAgent(
|
||||
goog.labs.userAgent.testAgents.OPERA_15);
|
||||
assertTrue(goog.labs.userAgent.browser.isOpera());
|
||||
assertVersion('15.0.1147.100');
|
||||
assertVersionBetween('15.00', '16.00');
|
||||
}
|
||||
|
||||
function testIE6() {
|
||||
goog.labs.userAgent.util.setUserAgent(goog.labs.userAgent.testAgents.IE_6);
|
||||
assertTrue(goog.labs.userAgent.browser.isIE());
|
||||
assertVersion('6.0');
|
||||
assertVersionBetween('5.0', '7.0');
|
||||
}
|
||||
|
||||
function testIE7() {
|
||||
goog.labs.userAgent.util.setUserAgent(goog.labs.userAgent.testAgents.IE_7);
|
||||
assertTrue(goog.labs.userAgent.browser.isIE());
|
||||
assertVersion('7.0');
|
||||
}
|
||||
|
||||
function testIE8() {
|
||||
goog.labs.userAgent.util.setUserAgent(goog.labs.userAgent.testAgents.IE_8);
|
||||
assertTrue(goog.labs.userAgent.browser.isIE());
|
||||
assertVersion('8.0');
|
||||
assertVersionBetween('7.0', '9.0');
|
||||
}
|
||||
|
||||
function testIE8Compatibility() {
|
||||
goog.labs.userAgent.util.setUserAgent(
|
||||
goog.labs.userAgent.testAgents.IE_8_COMPATIBILITY);
|
||||
assertTrue(goog.labs.userAgent.browser.isIE());
|
||||
assertVersion('8.0');
|
||||
}
|
||||
|
||||
function testIE9() {
|
||||
goog.labs.userAgent.util.setUserAgent(goog.labs.userAgent.testAgents.IE_9);
|
||||
assertTrue(goog.labs.userAgent.browser.isIE());
|
||||
assertVersion('9.0');
|
||||
assertVersionBetween('8.0', '10.0');
|
||||
}
|
||||
|
||||
function testIE9Compatibility() {
|
||||
goog.labs.userAgent.util.setUserAgent(
|
||||
goog.labs.userAgent.testAgents.IE_9_COMPATIBILITY);
|
||||
assertTrue(goog.labs.userAgent.browser.isIE());
|
||||
assertVersion('9.0');
|
||||
}
|
||||
|
||||
function testIE10() {
|
||||
goog.labs.userAgent.util.setUserAgent(goog.labs.userAgent.testAgents.IE_10);
|
||||
assertTrue(goog.labs.userAgent.browser.isIE());
|
||||
assertVersion('10.0');
|
||||
assertVersionBetween('10.0', '11.0');
|
||||
}
|
||||
|
||||
function testIE10Compatibility() {
|
||||
goog.labs.userAgent.util.setUserAgent(
|
||||
goog.labs.userAgent.testAgents.IE_10_COMPATIBILITY);
|
||||
assertTrue(goog.labs.userAgent.browser.isIE());
|
||||
assertVersion('10.0');
|
||||
}
|
||||
|
||||
function testIE10Mobile() {
|
||||
goog.labs.userAgent.util.setUserAgent(
|
||||
goog.labs.userAgent.testAgents.IE_10_MOBILE);
|
||||
assertTrue(goog.labs.userAgent.browser.isIE());
|
||||
assertVersion('10.0');
|
||||
}
|
||||
|
||||
function testIE11() {
|
||||
goog.labs.userAgent.util.setUserAgent(goog.labs.userAgent.testAgents.IE_11);
|
||||
assertTrue(goog.labs.userAgent.browser.isIE());
|
||||
assertVersion('11.0');
|
||||
assertVersionBetween('10.0', '12.0');
|
||||
}
|
||||
|
||||
function testIE11CompatibilityMSIE7() {
|
||||
goog.labs.userAgent.util.setUserAgent(
|
||||
goog.labs.userAgent.testAgents.IE_11_COMPATIBILITY_MSIE_7);
|
||||
assertTrue(goog.labs.userAgent.browser.isIE());
|
||||
assertVersion('11.0');
|
||||
}
|
||||
|
||||
function testIE11CompatibilityMSIE9() {
|
||||
goog.labs.userAgent.util.setUserAgent(
|
||||
goog.labs.userAgent.testAgents.IE_11_COMPATIBILITY_MSIE_9);
|
||||
assertTrue(goog.labs.userAgent.browser.isIE());
|
||||
assertVersion('11.0');
|
||||
}
|
||||
|
||||
function testFirefox19() {
|
||||
goog.labs.userAgent.util.setUserAgent(
|
||||
goog.labs.userAgent.testAgents.FIREFOX_19);
|
||||
assertTrue(goog.labs.userAgent.browser.isFirefox());
|
||||
assertVersion('19.0');
|
||||
assertVersionBetween('18.0', '20.0');
|
||||
}
|
||||
|
||||
function testFirefoxWindows() {
|
||||
goog.labs.userAgent.util.setUserAgent(
|
||||
goog.labs.userAgent.testAgents.FIREFOX_WINDOWS);
|
||||
assertTrue(goog.labs.userAgent.browser.isFirefox());
|
||||
assertVersion('14.0.1');
|
||||
assertVersionBetween('14.0', '15.0');
|
||||
}
|
||||
|
||||
function testFirefoxLinux() {
|
||||
goog.labs.userAgent.util.setUserAgent(
|
||||
goog.labs.userAgent.testAgents.FIREFOX_LINUX);
|
||||
assertTrue(goog.labs.userAgent.browser.isFirefox());
|
||||
assertVersion('15.0.1');
|
||||
}
|
||||
|
||||
function testChromeAndroid() {
|
||||
goog.labs.userAgent.util.setUserAgent(
|
||||
goog.labs.userAgent.testAgents.CHROME_ANDROID);
|
||||
assertTrue(goog.labs.userAgent.browser.isChrome());
|
||||
assertVersion('18.0.1025.133');
|
||||
assertVersionBetween('18.0', '19.0');
|
||||
assertVersionBetween('17.0', '18.1');
|
||||
}
|
||||
|
||||
function testChromeIphone() {
|
||||
goog.labs.userAgent.util.setUserAgent(
|
||||
goog.labs.userAgent.testAgents.CHROME_IPHONE);
|
||||
assertTrue(goog.labs.userAgent.browser.isChrome());
|
||||
assertVersion('22.0.1194.0');
|
||||
assertVersionBetween('22.0', '23.0');
|
||||
assertVersionBetween('22.0', '22.10');
|
||||
}
|
||||
|
||||
function testChromeMac() {
|
||||
goog.labs.userAgent.util.setUserAgent(
|
||||
goog.labs.userAgent.testAgents.CHROME_MAC);
|
||||
assertTrue(goog.labs.userAgent.browser.isChrome());
|
||||
assertVersion('24.0.1309.0');
|
||||
assertVersionBetween('24.0', '25.0');
|
||||
assertVersionBetween('24.0', '24.10');
|
||||
}
|
||||
|
||||
function testSafariIpad() {
|
||||
goog.labs.userAgent.util.setUserAgent(goog.labs.userAgent.testAgents.IPAD_6);
|
||||
assertTrue(goog.labs.userAgent.browser.isSafari());
|
||||
assertVersion('6.0');
|
||||
assertVersionBetween('5.1', '7.0');
|
||||
}
|
||||
|
||||
function testSafari6() {
|
||||
goog.labs.userAgent.util.setUserAgent(
|
||||
goog.labs.userAgent.testAgents.SAFARI_6);
|
||||
assertTrue(goog.labs.userAgent.browser.isSafari());
|
||||
assertVersion('6.0');
|
||||
assertVersionBetween('6.0', '7.0');
|
||||
}
|
||||
|
||||
function testSafariIphone() {
|
||||
goog.labs.userAgent.util.setUserAgent(
|
||||
goog.labs.userAgent.testAgents.SAFARI_IPHONE_6);
|
||||
assertTrue(goog.labs.userAgent.browser.isSafari());
|
||||
assertVersion('6.0');
|
||||
assertVersionBetween('5.0', '7.0');
|
||||
}
|
||||
|
||||
function testCoast() {
|
||||
goog.labs.userAgent.util.setUserAgent(
|
||||
goog.labs.userAgent.testAgents.COAST);
|
||||
assertTrue(goog.labs.userAgent.browser.isCoast());
|
||||
}
|
||||
|
||||
function testWebviewIOS() {
|
||||
goog.labs.userAgent.util.setUserAgent(
|
||||
goog.labs.userAgent.testAgents.WEBVIEW_IPHONE);
|
||||
assertTrue(goog.labs.userAgent.browser.isIosWebview());
|
||||
goog.labs.userAgent.util.setUserAgent(
|
||||
goog.labs.userAgent.testAgents.WEBVIEW_IPAD);
|
||||
assertTrue(goog.labs.userAgent.browser.isIosWebview());
|
||||
}
|
||||
|
||||
function testAndroidBrowser235() {
|
||||
goog.labs.userAgent.util.setUserAgent(
|
||||
goog.labs.userAgent.testAgents.ANDROID_BROWSER_235);
|
||||
assertTrue(goog.labs.userAgent.browser.isAndroidBrowser());
|
||||
assertVersion('4.0');
|
||||
assertVersionBetween('3.0', '5.0');
|
||||
}
|
||||
|
||||
function testAndroidBrowser403() {
|
||||
goog.labs.userAgent.util.setUserAgent(
|
||||
goog.labs.userAgent.testAgents.ANDROID_BROWSER_403);
|
||||
assertTrue(goog.labs.userAgent.browser.isAndroidBrowser());
|
||||
assertVersion('4.0');
|
||||
assertVersionBetween('3.0', '5.0');
|
||||
}
|
||||
|
||||
function testAndroidBrowser233() {
|
||||
goog.labs.userAgent.util.setUserAgent(
|
||||
goog.labs.userAgent.testAgents.ANDROID_BROWSER_233);
|
||||
assertTrue(goog.labs.userAgent.browser.isAndroidBrowser());
|
||||
assertVersion('4.0');
|
||||
assertVersionBetween('3.0', '5.0');
|
||||
}
|
||||
|
||||
function testAndroidWebView411() {
|
||||
goog.labs.userAgent.util.setUserAgent(
|
||||
goog.labs.userAgent.testAgents.ANDROID_WEB_VIEW_4_1_1);
|
||||
assertFalse(goog.labs.userAgent.browser.isChrome());
|
||||
assertTrue(goog.labs.userAgent.browser.isAndroidBrowser());
|
||||
assertVersion('4.0');
|
||||
assertVersionBetween('3.0', '5.0');
|
||||
}
|
||||
|
||||
function testAndroidWebView44() {
|
||||
goog.labs.userAgent.util.setUserAgent(
|
||||
goog.labs.userAgent.testAgents.ANDROID_WEB_VIEW_4_4);
|
||||
assertTrue(goog.labs.userAgent.browser.isChrome());
|
||||
assertFalse(goog.labs.userAgent.browser.isAndroidBrowser());
|
||||
assertVersion('30.0.0.0');
|
||||
assertVersionBetween('29.0', '31.0');
|
||||
}
|
||||
|
||||
function testSilk() {
|
||||
goog.labs.userAgent.util.setUserAgent(
|
||||
goog.labs.userAgent.testAgents.KINDLE_FIRE);
|
||||
assertTrue(goog.labs.userAgent.browser.isSilk());
|
||||
assertVersion('2.1');
|
||||
}
|
||||
|
||||
function assertVersion(version) {
|
||||
assertEquals(version, goog.labs.userAgent.browser.getVersion());
|
||||
}
|
||||
|
||||
function assertVersionBetween(lowVersion, highVersion) {
|
||||
assertTrue(goog.labs.userAgent.browser.isVersionOrHigher(lowVersion));
|
||||
assertFalse(goog.labs.userAgent.browser.isVersionOrHigher(highVersion));
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
// Copyright 2013 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 Closure user device detection (based on user agent).
|
||||
* @see http://en.wikipedia.org/wiki/User_agent
|
||||
* For more information on browser brand, platform, or engine see the other
|
||||
* sub-namespaces in goog.labs.userAgent (browser, platform, and engine).
|
||||
*
|
||||
*/
|
||||
|
||||
goog.provide('goog.labs.userAgent.device');
|
||||
|
||||
goog.require('goog.labs.userAgent.util');
|
||||
|
||||
|
||||
/**
|
||||
* Currently we detect the iPhone, iPod and Android mobiles (devices that have
|
||||
* both Android and Mobile in the user agent string).
|
||||
*
|
||||
* @return {boolean} Whether the user is using a mobile device.
|
||||
*/
|
||||
goog.labs.userAgent.device.isMobile = function() {
|
||||
return !goog.labs.userAgent.device.isTablet() &&
|
||||
(goog.labs.userAgent.util.matchUserAgent('iPod') ||
|
||||
goog.labs.userAgent.util.matchUserAgent('iPhone') ||
|
||||
goog.labs.userAgent.util.matchUserAgent('Android') ||
|
||||
goog.labs.userAgent.util.matchUserAgent('IEMobile'));
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Currently we detect Kindle Fire, iPad, and Android tablets (devices that have
|
||||
* Android but not Mobile in the user agent string).
|
||||
*
|
||||
* @return {boolean} Whether the user is using a tablet.
|
||||
*/
|
||||
goog.labs.userAgent.device.isTablet = function() {
|
||||
return goog.labs.userAgent.util.matchUserAgent('iPad') ||
|
||||
(goog.labs.userAgent.util.matchUserAgent('Android') &&
|
||||
!goog.labs.userAgent.util.matchUserAgent('Mobile')) ||
|
||||
goog.labs.userAgent.util.matchUserAgent('Silk');
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @return {boolean} Whether the user is using a desktop computer (which we
|
||||
* assume to be the case if they are not using either a mobile or tablet
|
||||
* device).
|
||||
*/
|
||||
goog.labs.userAgent.device.isDesktop = function() {
|
||||
return !goog.labs.userAgent.device.isMobile() &&
|
||||
!goog.labs.userAgent.device.isTablet();
|
||||
};
|
||||
@@ -0,0 +1,21 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<!--
|
||||
Copyright 2013 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.labs.userAgent</title>
|
||||
<script src="../../base.js"></script>
|
||||
<script>
|
||||
goog.require('goog.labs.userAgent.deviceTest');
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,73 @@
|
||||
// Copyright 2013 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 Unit tests for goog.labs.userAgent.device.
|
||||
*/
|
||||
|
||||
goog.provide('goog.labs.userAgent.deviceTest');
|
||||
|
||||
goog.require('goog.labs.userAgent.device');
|
||||
goog.require('goog.labs.userAgent.testAgents');
|
||||
goog.require('goog.labs.userAgent.util');
|
||||
goog.require('goog.testing.jsunit');
|
||||
|
||||
goog.setTestOnly('goog.labs.userAgent.deviceTest');
|
||||
|
||||
function setUp() {
|
||||
goog.labs.userAgent.util.setUserAgent(null);
|
||||
}
|
||||
|
||||
function testMobile() {
|
||||
assertIsMobile(goog.labs.userAgent.testAgents.ANDROID_BROWSER_235);
|
||||
assertIsMobile(goog.labs.userAgent.testAgents.CHROME_ANDROID);
|
||||
assertIsMobile(goog.labs.userAgent.testAgents.SAFARI_IPHONE_6);
|
||||
assertIsMobile(goog.labs.userAgent.testAgents.IE_10_MOBILE);
|
||||
}
|
||||
|
||||
function testTablet() {
|
||||
assertIsTablet(goog.labs.userAgent.testAgents.CHROME_ANDROID_TABLET);
|
||||
assertIsTablet(goog.labs.userAgent.testAgents.KINDLE_FIRE);
|
||||
assertIsTablet(goog.labs.userAgent.testAgents.IPAD_6);
|
||||
}
|
||||
|
||||
function testDesktop() {
|
||||
assertIsDesktop(goog.labs.userAgent.testAgents.CHROME_25);
|
||||
assertIsDesktop(goog.labs.userAgent.testAgents.OPERA_10);
|
||||
assertIsDesktop(goog.labs.userAgent.testAgents.FIREFOX_19);
|
||||
assertIsDesktop(goog.labs.userAgent.testAgents.IE_9);
|
||||
assertIsDesktop(goog.labs.userAgent.testAgents.IE_10);
|
||||
assertIsDesktop(goog.labs.userAgent.testAgents.IE_11);
|
||||
}
|
||||
|
||||
function assertIsMobile(uaString) {
|
||||
goog.labs.userAgent.util.setUserAgent(uaString);
|
||||
assertTrue(goog.labs.userAgent.device.isMobile());
|
||||
assertFalse(goog.labs.userAgent.device.isTablet());
|
||||
assertFalse(goog.labs.userAgent.device.isDesktop());
|
||||
}
|
||||
|
||||
function assertIsTablet(uaString) {
|
||||
goog.labs.userAgent.util.setUserAgent(uaString);
|
||||
assertTrue(goog.labs.userAgent.device.isTablet());
|
||||
assertFalse(goog.labs.userAgent.device.isMobile());
|
||||
assertFalse(goog.labs.userAgent.device.isDesktop());
|
||||
}
|
||||
|
||||
function assertIsDesktop(uaString) {
|
||||
goog.labs.userAgent.util.setUserAgent(uaString);
|
||||
assertTrue(goog.labs.userAgent.device.isDesktop());
|
||||
assertFalse(goog.labs.userAgent.device.isMobile());
|
||||
assertFalse(goog.labs.userAgent.device.isTablet());
|
||||
}
|
||||
@@ -0,0 +1,130 @@
|
||||
// Copyright 2013 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 Closure user agent detection.
|
||||
* @see http://en.wikipedia.org/wiki/User_agent
|
||||
* For more information on browser brand, platform, or device see the other
|
||||
* sub-namespaces in goog.labs.userAgent (browser, platform, and device).
|
||||
*
|
||||
*/
|
||||
|
||||
goog.provide('goog.labs.userAgent.engine');
|
||||
|
||||
goog.require('goog.array');
|
||||
goog.require('goog.labs.userAgent.util');
|
||||
goog.require('goog.string');
|
||||
|
||||
|
||||
/**
|
||||
* @return {boolean} Whether the rendering engine is Presto.
|
||||
*/
|
||||
goog.labs.userAgent.engine.isPresto = function() {
|
||||
return goog.labs.userAgent.util.matchUserAgent('Presto');
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @return {boolean} Whether the rendering engine is Trident.
|
||||
*/
|
||||
goog.labs.userAgent.engine.isTrident = function() {
|
||||
// IE only started including the Trident token in IE8.
|
||||
return goog.labs.userAgent.util.matchUserAgent('Trident') ||
|
||||
goog.labs.userAgent.util.matchUserAgent('MSIE');
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @return {boolean} Whether the rendering engine is WebKit.
|
||||
*/
|
||||
goog.labs.userAgent.engine.isWebKit = function() {
|
||||
return goog.labs.userAgent.util.matchUserAgentIgnoreCase('WebKit');
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @return {boolean} Whether the rendering engine is Gecko.
|
||||
*/
|
||||
goog.labs.userAgent.engine.isGecko = function() {
|
||||
return goog.labs.userAgent.util.matchUserAgent('Gecko') &&
|
||||
!goog.labs.userAgent.engine.isWebKit() &&
|
||||
!goog.labs.userAgent.engine.isTrident();
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @return {string} The rendering engine's version or empty string if version
|
||||
* can't be determined.
|
||||
*/
|
||||
goog.labs.userAgent.engine.getVersion = function() {
|
||||
var userAgentString = goog.labs.userAgent.util.getUserAgent();
|
||||
if (userAgentString) {
|
||||
var tuples = goog.labs.userAgent.util.extractVersionTuples(
|
||||
userAgentString);
|
||||
|
||||
var engineTuple = tuples[1];
|
||||
if (engineTuple) {
|
||||
// In Gecko, the version string is either in the browser info or the
|
||||
// Firefox version. See Gecko user agent string reference:
|
||||
// http://goo.gl/mULqa
|
||||
if (engineTuple[0] == 'Gecko') {
|
||||
return goog.labs.userAgent.engine.getVersionForKey_(
|
||||
tuples, 'Firefox');
|
||||
}
|
||||
|
||||
return engineTuple[1];
|
||||
}
|
||||
|
||||
// IE has only one version identifier, and the Trident version is
|
||||
// specified in the parenthetical.
|
||||
var browserTuple = tuples[0];
|
||||
var info;
|
||||
if (browserTuple && (info = browserTuple[2])) {
|
||||
var match = /Trident\/([^\s;]+)/.exec(info);
|
||||
if (match) {
|
||||
return match[1];
|
||||
}
|
||||
}
|
||||
}
|
||||
return '';
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {string|number} version The version to check.
|
||||
* @return {boolean} Whether the rendering engine version is higher or the same
|
||||
* as the given version.
|
||||
*/
|
||||
goog.labs.userAgent.engine.isVersionOrHigher = function(version) {
|
||||
return goog.string.compareVersions(goog.labs.userAgent.engine.getVersion(),
|
||||
version) >= 0;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {!Array<!Array<string>>} tuples Version tuples.
|
||||
* @param {string} key The key to look for.
|
||||
* @return {string} The version string of the given key, if present.
|
||||
* Otherwise, the empty string.
|
||||
* @private
|
||||
*/
|
||||
goog.labs.userAgent.engine.getVersionForKey_ = function(tuples, key) {
|
||||
// TODO(nnaze): Move to util if useful elsewhere.
|
||||
|
||||
var pair = goog.array.find(tuples, function(pair) {
|
||||
return key == pair[0];
|
||||
});
|
||||
|
||||
return pair && pair[1] || '';
|
||||
};
|
||||
@@ -0,0 +1,21 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<!--
|
||||
Copyright 2013 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.labs.userAgent</title>
|
||||
<script src="../../base.js"></script>
|
||||
<script>
|
||||
goog.require('goog.labs.userAgent.engineTest');
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,148 @@
|
||||
// Copyright 2013 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 Unit tests for goog.labs.userAgent.engine.
|
||||
*/
|
||||
|
||||
goog.provide('goog.labs.userAgent.engineTest');
|
||||
|
||||
goog.require('goog.labs.userAgent.engine');
|
||||
goog.require('goog.labs.userAgent.testAgents');
|
||||
goog.require('goog.labs.userAgent.util');
|
||||
goog.require('goog.testing.jsunit');
|
||||
|
||||
goog.setTestOnly('goog.labs.userAgent.engineTest');
|
||||
|
||||
var testAgents = goog.labs.userAgent.testAgents;
|
||||
|
||||
function setUp() {
|
||||
goog.labs.userAgent.util.setUserAgent(null);
|
||||
}
|
||||
|
||||
function assertVersion(version) {
|
||||
assertEquals(version, goog.labs.userAgent.engine.getVersion());
|
||||
}
|
||||
|
||||
function assertLowAndHighVersions(lowVersion, highVersion) {
|
||||
assertTrue(goog.labs.userAgent.engine.isVersionOrHigher(lowVersion));
|
||||
assertFalse(goog.labs.userAgent.engine.isVersionOrHigher(highVersion));
|
||||
}
|
||||
|
||||
function testPresto() {
|
||||
goog.labs.userAgent.util.setUserAgent(testAgents.OPERA_LINUX);
|
||||
assertTrue(goog.labs.userAgent.engine.isPresto());
|
||||
assertFalse(goog.labs.userAgent.engine.isGecko());
|
||||
assertVersion('2.9.168');
|
||||
assertLowAndHighVersions('2.9', '2.10');
|
||||
|
||||
goog.labs.userAgent.util.setUserAgent(testAgents.OPERA_MAC);
|
||||
assertTrue(goog.labs.userAgent.engine.isPresto());
|
||||
assertFalse(goog.labs.userAgent.engine.isGecko());
|
||||
assertVersion('2.9.168');
|
||||
assertLowAndHighVersions('2.9', '2.10');
|
||||
}
|
||||
|
||||
function testTrident() {
|
||||
goog.labs.userAgent.util.setUserAgent(testAgents.IE_6);
|
||||
assertTrue(goog.labs.userAgent.engine.isTrident());
|
||||
assertFalse(goog.labs.userAgent.engine.isGecko());
|
||||
assertVersion('');
|
||||
|
||||
goog.labs.userAgent.util.setUserAgent(testAgents.IE_10);
|
||||
assertTrue(goog.labs.userAgent.engine.isTrident());
|
||||
assertFalse(goog.labs.userAgent.engine.isGecko());
|
||||
assertVersion('6.0');
|
||||
assertLowAndHighVersions('6.0', '7.0');
|
||||
|
||||
goog.labs.userAgent.util.setUserAgent(testAgents.IE_8);
|
||||
assertTrue(goog.labs.userAgent.engine.isTrident());
|
||||
assertFalse(goog.labs.userAgent.engine.isGecko());
|
||||
assertVersion('4.0');
|
||||
assertLowAndHighVersions('4.0', '5.0');
|
||||
|
||||
goog.labs.userAgent.util.setUserAgent(testAgents.IE_9_COMPATIBILITY);
|
||||
assertTrue(goog.labs.userAgent.engine.isTrident());
|
||||
assertFalse(goog.labs.userAgent.engine.isGecko());
|
||||
assertVersion('5.0');
|
||||
assertLowAndHighVersions('5.0', '6.0');
|
||||
|
||||
goog.labs.userAgent.util.setUserAgent(goog.labs.userAgent.testAgents.IE_11);
|
||||
assertTrue(goog.labs.userAgent.engine.isTrident());
|
||||
assertFalse(goog.labs.userAgent.engine.isGecko());
|
||||
assertVersion('7.0');
|
||||
assertLowAndHighVersions('6.0', '8.0');
|
||||
|
||||
goog.labs.userAgent.util.setUserAgent(
|
||||
goog.labs.userAgent.testAgents.IE_10_MOBILE);
|
||||
assertTrue(goog.labs.userAgent.engine.isTrident());
|
||||
assertVersion('6.0');
|
||||
}
|
||||
|
||||
function testWebKit() {
|
||||
goog.labs.userAgent.util.setUserAgent(testAgents.ANDROID_BROWSER_235);
|
||||
assertTrue(goog.labs.userAgent.engine.isWebKit());
|
||||
assertFalse(goog.labs.userAgent.engine.isGecko());
|
||||
assertVersion('533.1');
|
||||
assertLowAndHighVersions('533.0', '534.0');
|
||||
|
||||
goog.labs.userAgent.util.setUserAgent(testAgents.ANDROID_BROWSER_403_ALT);
|
||||
assertTrue(goog.labs.userAgent.engine.isWebKit());
|
||||
assertFalse(goog.labs.userAgent.engine.isGecko());
|
||||
assertVersion('534.30');
|
||||
assertLowAndHighVersions('533.0', '535.0');
|
||||
|
||||
goog.labs.userAgent.util.setUserAgent(testAgents.CHROME_25);
|
||||
assertTrue(goog.labs.userAgent.engine.isWebKit());
|
||||
assertFalse(goog.labs.userAgent.engine.isGecko());
|
||||
assertVersion('535.8');
|
||||
assertLowAndHighVersions('535.0', '536.0');
|
||||
|
||||
goog.labs.userAgent.util.setUserAgent(testAgents.SAFARI_6);
|
||||
assertTrue(goog.labs.userAgent.engine.isWebKit());
|
||||
assertFalse(goog.labs.userAgent.engine.isGecko());
|
||||
assertVersion('536.25');
|
||||
assertLowAndHighVersions('536.0', '537.0');
|
||||
|
||||
goog.labs.userAgent.util.setUserAgent(testAgents.SAFARI_IPHONE_6);
|
||||
assertTrue(goog.labs.userAgent.engine.isWebKit());
|
||||
assertFalse(goog.labs.userAgent.engine.isGecko());
|
||||
assertVersion('536.26');
|
||||
assertLowAndHighVersions('536.0', '537.0');
|
||||
}
|
||||
|
||||
function testOpera15() {
|
||||
goog.labs.userAgent.util.setUserAgent(testAgents.OPERA_15);
|
||||
assertTrue(goog.labs.userAgent.engine.isWebKit());
|
||||
assertFalse(goog.labs.userAgent.engine.isPresto());
|
||||
assertVersion('537.36');
|
||||
}
|
||||
|
||||
function testGecko() {
|
||||
goog.labs.userAgent.util.setUserAgent(testAgents.FIREFOX_LINUX);
|
||||
assertTrue(goog.labs.userAgent.engine.isGecko());
|
||||
assertVersion('15.0.1');
|
||||
assertLowAndHighVersions('14.0', '16.0');
|
||||
|
||||
goog.labs.userAgent.util.setUserAgent(testAgents.FIREFOX_19);
|
||||
assertTrue(goog.labs.userAgent.engine.isGecko());
|
||||
assertVersion('19.0');
|
||||
assertLowAndHighVersions('18.0', '20.0');
|
||||
|
||||
goog.labs.userAgent.util.setUserAgent(testAgents.FIREFOX_WINDOWS);
|
||||
assertTrue(goog.labs.userAgent.engine.isGecko());
|
||||
assertVersion('14.0.1');
|
||||
assertLowAndHighVersions('14.0', '15.0');
|
||||
}
|
||||
|
||||
@@ -0,0 +1,160 @@
|
||||
// Copyright 2013 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 Closure user agent platform detection.
|
||||
* @see <a href="http://www.useragentstring.com/">User agent strings</a>
|
||||
* For more information on browser brand, rendering engine, or device see the
|
||||
* other sub-namespaces in goog.labs.userAgent (browser, engine, and device
|
||||
* respectively).
|
||||
*
|
||||
*/
|
||||
|
||||
goog.provide('goog.labs.userAgent.platform');
|
||||
|
||||
goog.require('goog.labs.userAgent.util');
|
||||
goog.require('goog.string');
|
||||
|
||||
|
||||
/**
|
||||
* @return {boolean} Whether the platform is Android.
|
||||
*/
|
||||
goog.labs.userAgent.platform.isAndroid = function() {
|
||||
return goog.labs.userAgent.util.matchUserAgent('Android');
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @return {boolean} Whether the platform is iPod.
|
||||
*/
|
||||
goog.labs.userAgent.platform.isIpod = function() {
|
||||
return goog.labs.userAgent.util.matchUserAgent('iPod');
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @return {boolean} Whether the platform is iPhone.
|
||||
*/
|
||||
goog.labs.userAgent.platform.isIphone = function() {
|
||||
return goog.labs.userAgent.util.matchUserAgent('iPhone') &&
|
||||
!goog.labs.userAgent.util.matchUserAgent('iPod') &&
|
||||
!goog.labs.userAgent.util.matchUserAgent('iPad');
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @return {boolean} Whether the platform is iPad.
|
||||
*/
|
||||
goog.labs.userAgent.platform.isIpad = function() {
|
||||
return goog.labs.userAgent.util.matchUserAgent('iPad');
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @return {boolean} Whether the platform is iOS.
|
||||
*/
|
||||
goog.labs.userAgent.platform.isIos = function() {
|
||||
return goog.labs.userAgent.platform.isIphone() ||
|
||||
goog.labs.userAgent.platform.isIpad() ||
|
||||
goog.labs.userAgent.platform.isIpod();
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @return {boolean} Whether the platform is Mac.
|
||||
*/
|
||||
goog.labs.userAgent.platform.isMacintosh = function() {
|
||||
return goog.labs.userAgent.util.matchUserAgent('Macintosh');
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Note: ChromeOS is not considered to be Linux as it does not report itself
|
||||
* as Linux in the user agent string.
|
||||
* @return {boolean} Whether the platform is Linux.
|
||||
*/
|
||||
goog.labs.userAgent.platform.isLinux = function() {
|
||||
return goog.labs.userAgent.util.matchUserAgent('Linux');
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @return {boolean} Whether the platform is Windows.
|
||||
*/
|
||||
goog.labs.userAgent.platform.isWindows = function() {
|
||||
return goog.labs.userAgent.util.matchUserAgent('Windows');
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @return {boolean} Whether the platform is ChromeOS.
|
||||
*/
|
||||
goog.labs.userAgent.platform.isChromeOS = function() {
|
||||
return goog.labs.userAgent.util.matchUserAgent('CrOS');
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* The version of the platform. We only determine the version for Windows,
|
||||
* Mac, and Chrome OS. 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.
|
||||
*
|
||||
* @return {string} The platform version or empty string if version cannot be
|
||||
* determined.
|
||||
*/
|
||||
goog.labs.userAgent.platform.getVersion = function() {
|
||||
var userAgentString = goog.labs.userAgent.util.getUserAgent();
|
||||
var version = '', re;
|
||||
if (goog.labs.userAgent.platform.isWindows()) {
|
||||
re = /Windows (?:NT|Phone) ([0-9.]+)/;
|
||||
var match = re.exec(userAgentString);
|
||||
if (match) {
|
||||
version = match[1];
|
||||
} else {
|
||||
version = '0.0';
|
||||
}
|
||||
} else if (goog.labs.userAgent.platform.isIos()) {
|
||||
re = /(?:iPhone|iPod|iPad|CPU)\s+OS\s+(\S+)/;
|
||||
var match = re.exec(userAgentString);
|
||||
// Report the version as x.y.z and not x_y_z
|
||||
version = match && match[1].replace(/_/g, '.');
|
||||
} else if (goog.labs.userAgent.platform.isMacintosh()) {
|
||||
re = /Mac OS X ([0-9_.]+)/;
|
||||
var match = re.exec(userAgentString);
|
||||
// Note: some old versions of Camino do not report an OSX version.
|
||||
// Default to 10.
|
||||
version = match ? match[1].replace(/_/g, '.') : '10';
|
||||
} else if (goog.labs.userAgent.platform.isAndroid()) {
|
||||
re = /Android\s+([^\);]+)(\)|;)/;
|
||||
var match = re.exec(userAgentString);
|
||||
version = match && match[1];
|
||||
} else if (goog.labs.userAgent.platform.isChromeOS()) {
|
||||
re = /(?:CrOS\s+(?:i686|x86_64)\s+([0-9.]+))/;
|
||||
var match = re.exec(userAgentString);
|
||||
version = match && match[1];
|
||||
}
|
||||
return version || '';
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {string|number} version The version to check.
|
||||
* @return {boolean} Whether the browser version is higher or the same as the
|
||||
* given version.
|
||||
*/
|
||||
goog.labs.userAgent.platform.isVersionOrHigher = function(version) {
|
||||
return goog.string.compareVersions(goog.labs.userAgent.platform.getVersion(),
|
||||
version) >= 0;
|
||||
};
|
||||
@@ -0,0 +1,21 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<!--
|
||||
Copyright 2013 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.labs.userAgent.platform</title>
|
||||
<script src="../../base.js"></script>
|
||||
<script>
|
||||
goog.require('goog.labs.userAgent.platformTest');
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,247 @@
|
||||
// Copyright 2013 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 Unit tests for goog.labs.userAgent.platform.
|
||||
*/
|
||||
|
||||
goog.provide('goog.labs.userAgent.platformTest');
|
||||
|
||||
goog.require('goog.labs.userAgent.platform');
|
||||
goog.require('goog.labs.userAgent.testAgents');
|
||||
goog.require('goog.labs.userAgent.util');
|
||||
goog.require('goog.testing.jsunit');
|
||||
|
||||
goog.setTestOnly('goog.labs.userAgent.platformTest');
|
||||
|
||||
function setUp() {
|
||||
goog.labs.userAgent.util.setUserAgent(null);
|
||||
}
|
||||
|
||||
function testAndroid() {
|
||||
var uaString = goog.labs.userAgent.testAgents.ANDROID_BROWSER_233;
|
||||
|
||||
goog.labs.userAgent.util.setUserAgent(uaString);
|
||||
assertTrue(goog.labs.userAgent.platform.isAndroid());
|
||||
assertVersion('2.3.3');
|
||||
assertVersionBetween('2.3.0', '2.3.5');
|
||||
assertVersionBetween('2.3', '2.4');
|
||||
assertVersionBetween('2', '3');
|
||||
|
||||
uaString = goog.labs.userAgent.testAgents.ANDROID_BROWSER_221;
|
||||
|
||||
goog.labs.userAgent.util.setUserAgent(uaString);
|
||||
assertTrue(goog.labs.userAgent.platform.isAndroid());
|
||||
assertVersion('2.2.1');
|
||||
assertVersionBetween('2.2.0', '2.2.5');
|
||||
assertVersionBetween('2.2', '2.3');
|
||||
assertVersionBetween('2', '3');
|
||||
|
||||
uaString = goog.labs.userAgent.testAgents.CHROME_ANDROID;
|
||||
|
||||
goog.labs.userAgent.util.setUserAgent(uaString);
|
||||
assertTrue(goog.labs.userAgent.platform.isAndroid());
|
||||
assertVersion('4.0.2');
|
||||
assertVersionBetween('4.0.0', '4.1.0');
|
||||
assertVersionBetween('4.0', '4.1');
|
||||
assertVersionBetween('4', '5');
|
||||
}
|
||||
|
||||
function testKindleFire() {
|
||||
uaString = goog.labs.userAgent.testAgents.KINDLE_FIRE;
|
||||
goog.labs.userAgent.util.setUserAgent(uaString);
|
||||
assertTrue(goog.labs.userAgent.platform.isAndroid());
|
||||
assertVersion('4.0.3');
|
||||
}
|
||||
|
||||
function testIpod() {
|
||||
var uaString = goog.labs.userAgent.testAgents.SAFARI_IPOD;
|
||||
|
||||
goog.labs.userAgent.util.setUserAgent(uaString);
|
||||
assertTrue(goog.labs.userAgent.platform.isIpod());
|
||||
assertTrue(goog.labs.userAgent.platform.isIos());
|
||||
assertVersion('');
|
||||
}
|
||||
|
||||
function testIphone() {
|
||||
var uaString = goog.labs.userAgent.testAgents.SAFARI_IPHONE_421;
|
||||
goog.labs.userAgent.util.setUserAgent(uaString);
|
||||
assertTrue(goog.labs.userAgent.platform.isIphone());
|
||||
assertTrue(goog.labs.userAgent.platform.isIos());
|
||||
assertVersion('4.2.1');
|
||||
assertVersionBetween('4', '5');
|
||||
assertVersionBetween('4.2', '4.3');
|
||||
|
||||
uaString = goog.labs.userAgent.testAgents.SAFARI_IPHONE_6;
|
||||
goog.labs.userAgent.util.setUserAgent(uaString);
|
||||
assertTrue(goog.labs.userAgent.platform.isIphone());
|
||||
assertTrue(goog.labs.userAgent.platform.isIos());
|
||||
assertVersion('6.0');
|
||||
assertVersionBetween('5', '7');
|
||||
|
||||
uaString = goog.labs.userAgent.testAgents.SAFARI_IPHONE_32;
|
||||
goog.labs.userAgent.util.setUserAgent(uaString);
|
||||
assertTrue(goog.labs.userAgent.platform.isIphone());
|
||||
assertTrue(goog.labs.userAgent.platform.isIos());
|
||||
assertVersion('3.2');
|
||||
assertVersionBetween('3', '4');
|
||||
|
||||
uaString = goog.labs.userAgent.testAgents.WEBVIEW_IPAD;
|
||||
goog.labs.userAgent.util.setUserAgent(uaString);
|
||||
assertFalse(goog.labs.userAgent.platform.isIphone());
|
||||
assertTrue(goog.labs.userAgent.platform.isIpad());
|
||||
assertTrue(goog.labs.userAgent.platform.isIos());
|
||||
assertVersion('6.0');
|
||||
assertVersionBetween('5', '7');
|
||||
}
|
||||
|
||||
function testIpad() {
|
||||
var uaString = goog.labs.userAgent.testAgents.IPAD_4;
|
||||
|
||||
goog.labs.userAgent.util.setUserAgent(uaString);
|
||||
assertTrue(goog.labs.userAgent.platform.isIpad());
|
||||
assertTrue(goog.labs.userAgent.platform.isIos());
|
||||
assertVersion('3.2');
|
||||
assertVersionBetween('3', '4');
|
||||
assertVersionBetween('3.1', '4');
|
||||
|
||||
uaString = goog.labs.userAgent.testAgents.IPAD_5;
|
||||
|
||||
goog.labs.userAgent.util.setUserAgent(uaString);
|
||||
assertTrue(goog.labs.userAgent.platform.isIpad());
|
||||
assertTrue(goog.labs.userAgent.platform.isIos());
|
||||
assertVersion('5.1');
|
||||
assertVersionBetween('5', '6');
|
||||
|
||||
uaString = goog.labs.userAgent.testAgents.IPAD_6;
|
||||
|
||||
goog.labs.userAgent.util.setUserAgent(uaString);
|
||||
assertTrue(goog.labs.userAgent.platform.isIpad());
|
||||
assertTrue(goog.labs.userAgent.platform.isIos());
|
||||
assertVersion('6.0');
|
||||
assertVersionBetween('5', '7');
|
||||
}
|
||||
|
||||
function testMac() {
|
||||
var uaString = goog.labs.userAgent.testAgents.CHROME_MAC;
|
||||
var platform = 'IntelMac';
|
||||
goog.labs.userAgent.util.setUserAgent(uaString, platform);
|
||||
assertTrue(goog.labs.userAgent.platform.isMacintosh());
|
||||
assertVersion('10.8.2');
|
||||
assertVersionBetween('10', '11');
|
||||
assertVersionBetween('10.8', '10.9');
|
||||
assertVersionBetween('10.8.1', '10.8.3');
|
||||
|
||||
uaString = goog.labs.userAgent.testAgents.OPERA_MAC;
|
||||
goog.labs.userAgent.util.setUserAgent(uaString, platform);
|
||||
assertTrue(goog.labs.userAgent.platform.isMacintosh());
|
||||
assertVersion('10.6.8');
|
||||
assertVersionBetween('10', '11');
|
||||
assertVersionBetween('10.6', '10.7');
|
||||
assertVersionBetween('10.6.5', '10.7.0');
|
||||
|
||||
uaString = goog.labs.userAgent.testAgents.SAFARI_MAC;
|
||||
goog.labs.userAgent.util.setUserAgent(uaString, platform);
|
||||
assertTrue(goog.labs.userAgent.platform.isMacintosh());
|
||||
assertVersionBetween('10', '11');
|
||||
assertVersionBetween('10.6', '10.7');
|
||||
assertVersionBetween('10.6.5', '10.7.0');
|
||||
|
||||
uaString = goog.labs.userAgent.testAgents.FIREFOX_MAC;
|
||||
goog.labs.userAgent.util.setUserAgent(uaString, platform);
|
||||
assertTrue(goog.labs.userAgent.platform.isMacintosh());
|
||||
assertVersion('11.7.9');
|
||||
assertVersionBetween('11', '12');
|
||||
assertVersionBetween('11.7', '11.8');
|
||||
assertVersionBetween('11.7.9', '11.8.0');
|
||||
}
|
||||
|
||||
function testLinux() {
|
||||
var uaString = goog.labs.userAgent.testAgents.FIREFOX_LINUX;
|
||||
goog.labs.userAgent.util.setUserAgent(uaString);
|
||||
assertTrue(goog.labs.userAgent.platform.isLinux());
|
||||
assertVersion('');
|
||||
|
||||
uaString = goog.labs.userAgent.testAgents.CHROME_LINUX;
|
||||
goog.labs.userAgent.util.setUserAgent(uaString);
|
||||
assertTrue(goog.labs.userAgent.platform.isLinux());
|
||||
assertVersion('');
|
||||
|
||||
uaString = goog.labs.userAgent.testAgents.OPERA_LINUX;
|
||||
goog.labs.userAgent.util.setUserAgent(uaString);
|
||||
assertTrue(goog.labs.userAgent.platform.isLinux());
|
||||
assertVersion('');
|
||||
}
|
||||
|
||||
function testWindows() {
|
||||
var uaString = goog.labs.userAgent.testAgents.SAFARI_WINDOWS;
|
||||
goog.labs.userAgent.util.setUserAgent(uaString);
|
||||
assertTrue(goog.labs.userAgent.platform.isWindows());
|
||||
assertVersion('6.1');
|
||||
assertVersionBetween('6', '7');
|
||||
|
||||
uaString = goog.labs.userAgent.testAgents.IE_10;
|
||||
goog.labs.userAgent.util.setUserAgent(uaString);
|
||||
assertTrue(goog.labs.userAgent.platform.isWindows());
|
||||
assertVersion('6.2');
|
||||
assertVersionBetween('6', '6.5');
|
||||
|
||||
uaString = goog.labs.userAgent.testAgents.CHROME_25;
|
||||
goog.labs.userAgent.util.setUserAgent(uaString);
|
||||
assertTrue(goog.labs.userAgent.platform.isWindows());
|
||||
assertVersion('5.1');
|
||||
assertVersionBetween('5', '6');
|
||||
|
||||
uaString = goog.labs.userAgent.testAgents.FIREFOX_WINDOWS;
|
||||
goog.labs.userAgent.util.setUserAgent(uaString);
|
||||
assertTrue(goog.labs.userAgent.platform.isWindows());
|
||||
assertVersion('6.1');
|
||||
assertVersionBetween('6', '7');
|
||||
|
||||
uaString = goog.labs.userAgent.testAgents.IE_11;
|
||||
goog.labs.userAgent.util.setUserAgent(uaString);
|
||||
assertTrue(goog.labs.userAgent.platform.isWindows());
|
||||
assertVersion('6.3');
|
||||
assertVersionBetween('6', '6.5');
|
||||
|
||||
uaString = goog.labs.userAgent.testAgents.IE_10_MOBILE;
|
||||
goog.labs.userAgent.util.setUserAgent(uaString);
|
||||
assertTrue(goog.labs.userAgent.platform.isWindows());
|
||||
assertVersion('8.0');
|
||||
}
|
||||
|
||||
function testChromeOS() {
|
||||
var uaString = goog.labs.userAgent.testAgents.CHROME_OS_910;
|
||||
|
||||
goog.labs.userAgent.util.setUserAgent(uaString);
|
||||
assertTrue(goog.labs.userAgent.platform.isChromeOS());
|
||||
assertVersion('9.10.0');
|
||||
assertVersionBetween('9', '10');
|
||||
|
||||
uaString = goog.labs.userAgent.testAgents.CHROME_OS;
|
||||
|
||||
goog.labs.userAgent.util.setUserAgent(uaString);
|
||||
assertTrue(goog.labs.userAgent.platform.isChromeOS());
|
||||
assertVersion('3701.62.0');
|
||||
assertVersionBetween('3701', '3702');
|
||||
}
|
||||
|
||||
function assertVersion(version) {
|
||||
assertEquals(version, goog.labs.userAgent.platform.getVersion());
|
||||
}
|
||||
|
||||
function assertVersionBetween(lowVersion, highVersion) {
|
||||
assertTrue(goog.labs.userAgent.platform.isVersionOrHigher(lowVersion));
|
||||
assertFalse(goog.labs.userAgent.platform.isVersionOrHigher(highVersion));
|
||||
}
|
||||
@@ -0,0 +1,348 @@
|
||||
// Copyright 2013 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 Various User-Agent strings.
|
||||
* See http://go/useragentexamples and http://www.useragentstring.com/ for
|
||||
* examples.
|
||||
*
|
||||
* @author martone@google.com (Andy Martone)
|
||||
*/
|
||||
|
||||
goog.provide('goog.labs.userAgent.testAgents');
|
||||
goog.setTestOnly('goog.labs.userAgent.testAgents');
|
||||
|
||||
goog.scope(function() {
|
||||
var testAgents = goog.labs.userAgent.testAgents;
|
||||
|
||||
|
||||
/** @const {string} */
|
||||
testAgents.ANDROID_BROWSER_235 =
|
||||
'Mozilla/5.0 (Linux; U; Android 2.3.5; en-us; ' +
|
||||
'HTC Vision Build/GRI40) AppleWebKit/533.1 (KHTML, like Gecko) ' +
|
||||
'Version/4.0 Mobile Safari/533.1';
|
||||
|
||||
|
||||
/** @const {string} */
|
||||
testAgents.ANDROID_BROWSER_221 =
|
||||
'Mozilla/5.0 (Linux; U; Android 2.2.1; en-ca; LG-P505R Build/FRG83)' +
|
||||
' AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1';
|
||||
|
||||
|
||||
/** @const {string} */
|
||||
testAgents.ANDROID_BROWSER_233 =
|
||||
'Mozilla/5.0 (Linux; U; Android 2.3.3; en-us; HTC_DesireS_S510e' +
|
||||
' Build/GRI40) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0' +
|
||||
' Mobile Safari/533.1';
|
||||
|
||||
|
||||
/** @const {string} */
|
||||
testAgents.ANDROID_BROWSER_403 =
|
||||
'Mozilla/5.0 (Linux; U; Android 4.0.3; de-ch; HTC Sensation Build/IML74K)' +
|
||||
' AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30';
|
||||
|
||||
|
||||
/** @const {string} */
|
||||
// User agent retrieved from dremel queries for cases matching b/13222688
|
||||
testAgents.ANDROID_BROWSER_403_ALT =
|
||||
'Mozilla/5.0 (Linux; U; Android 4.0.3; ko-kr; LG-L160L Build/IML74K)' +
|
||||
' AppleWebkit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30';
|
||||
|
||||
|
||||
// See https://developer.chrome.com/multidevice/user-agent
|
||||
/** @const {string} */
|
||||
testAgents.ANDROID_WEB_VIEW_4_1_1 =
|
||||
'Mozilla/5.0 (Linux; U; Android 4.1.1; en-gb; Build/KLP) ' +
|
||||
'AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Safari/534.30';
|
||||
|
||||
|
||||
// See https://developer.chrome.com/multidevice/user-agent
|
||||
/** @const {string} */
|
||||
testAgents.ANDROID_WEB_VIEW_4_4 =
|
||||
'Mozilla/5.0 (Linux; Android 4.4; Nexus 5 Build/_BuildID_) ' +
|
||||
'AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 ' +
|
||||
'Chrome/30.0.0.0 Mobile Safari/537.36';
|
||||
|
||||
|
||||
/** @const {string} */
|
||||
testAgents.IE_6 =
|
||||
'Mozilla/5.0 (Windows; U; MSIE 6.0; Windows NT 5.1; SV1;' +
|
||||
'.NET CLR 2.0.50727)';
|
||||
|
||||
|
||||
/** @const {string} */
|
||||
testAgents.IE_7 =
|
||||
'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)';
|
||||
|
||||
|
||||
/** @const {string} */
|
||||
testAgents.IE_8 =
|
||||
'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0)';
|
||||
|
||||
|
||||
/** @const {string} */
|
||||
testAgents.IE_8_COMPATIBILITY =
|
||||
'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; Trident/4.0)';
|
||||
|
||||
|
||||
/** @const {string} */
|
||||
testAgents.IE_9 =
|
||||
'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)';
|
||||
|
||||
|
||||
/** @const {string} */
|
||||
testAgents.IE_9_COMPATIBILITY =
|
||||
'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; Trident/5.0)';
|
||||
|
||||
|
||||
/** @const {string} */
|
||||
testAgents.IE_10 =
|
||||
'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; Trident/6.0)';
|
||||
|
||||
|
||||
/** @const {string} */
|
||||
testAgents.IE_10_COMPATIBILITY =
|
||||
'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; Trident/6.0)';
|
||||
|
||||
|
||||
/**
|
||||
* http://blogs.windows.com/windows_phone/b/wpdev/archive/2012/10/17/getting-websites-ready-for-internet-explorer-10-on-windows-phone-8.aspx
|
||||
* @const {string}
|
||||
*/
|
||||
testAgents.IE_10_MOBILE =
|
||||
'Mozilla/5.0 (compatible; MSIE 10.0; Windows Phone 8.0; Trident/6.0; ' +
|
||||
'IEMobile/10.0; ARM; Touch; NOKIA; Lumia 820)';
|
||||
|
||||
|
||||
/** @const {string} */
|
||||
testAgents.IE_11 =
|
||||
'Mozilla/5.0 (Windows NT 6.3; Trident/7.0; rv:11.0) like Gecko';
|
||||
|
||||
|
||||
/** @const {string} */
|
||||
testAgents.IE_11_COMPATIBILITY_MSIE_7 =
|
||||
'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.3; Trident/7.0; ' +
|
||||
'.NET4.0E; .NET4.0C)';
|
||||
|
||||
|
||||
/** @const {string} */
|
||||
testAgents.IE_11_COMPATIBILITY_MSIE_9 =
|
||||
'Mozilla/5.0 (MSIE 9.0; Windows NT 6.1; WOW64; Trident/7.0; ' +
|
||||
'rv:11.0) like Gecko';
|
||||
|
||||
|
||||
/** @const {string} */
|
||||
testAgents.FIREFOX_19 =
|
||||
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:19.0) ' +
|
||||
'Gecko/20100101 Firefox/19.0';
|
||||
|
||||
|
||||
/** @const {string} */
|
||||
testAgents.FIREFOX_LINUX =
|
||||
'Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:15.0) Gecko/20100101' +
|
||||
' Firefox/15.0.1';
|
||||
|
||||
|
||||
/** @const {string} */
|
||||
testAgents.FIREFOX_MAC =
|
||||
'Mozilla/6.0 (Macintosh; I; Intel Mac OS X 11_7_9; de-LI; rv:1.9b4)' +
|
||||
' Gecko/2012010317 Firefox/10.0a4';
|
||||
|
||||
|
||||
/** @const {string} */
|
||||
testAgents.FIREFOX_WINDOWS =
|
||||
'Mozilla/5.0 (Windows NT 6.1; rv:12.0) Gecko/20120403211507' +
|
||||
' Firefox/14.0.1';
|
||||
|
||||
|
||||
/** @const {string} */
|
||||
testAgents.SAFARI_6 =
|
||||
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_1) ' +
|
||||
'AppleWebKit/536.25 (KHTML, like Gecko) ' +
|
||||
'Version/6.0 Safari/536.25';
|
||||
|
||||
|
||||
/** @const {string} */
|
||||
testAgents.SAFARI_IPHONE_32 =
|
||||
'Mozilla/5.0(iPhone; U; CPU iPhone OS 3_2 like Mac OS X; en-us)' +
|
||||
' AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7B314' +
|
||||
' Safari/531.21.10';
|
||||
|
||||
|
||||
/** @const {string} */
|
||||
testAgents.SAFARI_IPHONE_421 =
|
||||
'Mozilla/5.0 (iPhone; U; ru; CPU iPhone OS 4_2_1 like Mac OS X; ru)' +
|
||||
' AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8C148a' +
|
||||
' Safari/6533.18.5';
|
||||
|
||||
|
||||
/** @const {string} */
|
||||
testAgents.SAFARI_IPHONE_431 =
|
||||
'Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_3_1 like Mac OS X; zh-tw)' +
|
||||
' AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8G4' +
|
||||
' Safari/6533.18.5';
|
||||
|
||||
|
||||
/** @const {string} */
|
||||
testAgents.SAFARI_IPHONE_6 =
|
||||
'Mozilla/5.0 (iPhone; CPU iPhone OS 6_0 like Mac OS X)' +
|
||||
' AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A5376e' +
|
||||
' Safari/8536.25';
|
||||
|
||||
|
||||
/** @const {string} */
|
||||
testAgents.SAFARI_IPOD =
|
||||
'Mozila/5.0 (iPod; U; CPU like Mac OS X; en) AppleWebKit/420.1' +
|
||||
' (KHTML, like Gecko) Version/3.0 Mobile/3A101a Safari/419.3';
|
||||
|
||||
|
||||
/** @const {string} */
|
||||
testAgents.SAFARI_MAC =
|
||||
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8) AppleWebKit/537.13+' +
|
||||
' (KHTML, like Gecko) Version/5.1.7 Safari/534.57.2';
|
||||
|
||||
|
||||
/** @const {string} */
|
||||
testAgents.SAFARI_WINDOWS =
|
||||
'Mozilla/5.0 (Windows; U; Windows NT 6.1; tr-TR) AppleWebKit/533.20.25' +
|
||||
' (KHTML, like Gecko) Version/5.0.4 Safari/533.20.27';
|
||||
|
||||
|
||||
/** @const {string} */
|
||||
testAgents.COAST =
|
||||
'Mozilla/5.0 (iPad; CPU OS 7_0_2 like Mac OS X) AppleWebKit/537.51.1' +
|
||||
' (KHTML like Gecko) Coast/1.1.2.64598 Mobile/11B511 Safari/7534.48.3';
|
||||
|
||||
|
||||
/** @const {string} */
|
||||
testAgents.WEBVIEW_IPHONE =
|
||||
'Mozilla/5.0 (iPhone; CPU iPhone OS 6_0 like Mac OS X) AppleWebKit/536.26' +
|
||||
' (KHTML, like Gecko) Mobile/10A403';
|
||||
|
||||
|
||||
/** @const {string} */
|
||||
testAgents.WEBVIEW_IPAD =
|
||||
'Mozilla/5.0 (iPad; CPU iPhone OS 6_0 like Mac OS X) AppleWebKit/536.26' +
|
||||
' (KHTML, like Gecko) Mobile/10A403';
|
||||
|
||||
|
||||
/** @const {string} */
|
||||
testAgents.OPERA_10 =
|
||||
'Opera/9.80 (S60; SymbOS; Opera Mobi/447; U; en) ' +
|
||||
'Presto/2.4.18 Version/10.00';
|
||||
|
||||
|
||||
/** @const {string} */
|
||||
testAgents.OPERA_LINUX =
|
||||
'Opera/9.80 (X11; Linux x86_64; U; fr) Presto/2.9.168 Version/11.50';
|
||||
|
||||
|
||||
/** @const {string} */
|
||||
testAgents.OPERA_MAC =
|
||||
'Opera/9.80 (Macintosh; Intel Mac OS X 10.6.8; U; fr) Presto/2.9.168' +
|
||||
' Version/11.52';
|
||||
|
||||
|
||||
/** @const {string} */
|
||||
testAgents.OPERA_15 =
|
||||
'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 ' +
|
||||
'(KHTML, like Gecko) Chrome/28.0.1500.52 Safari/537.36 OPR/15.0.1147.100';
|
||||
|
||||
|
||||
/** @const {string} */
|
||||
testAgents.IPAD_4 =
|
||||
'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';
|
||||
|
||||
|
||||
/** @const {string} */
|
||||
testAgents.IPAD_5 =
|
||||
'Mozilla/5.0 (iPad; CPU OS 5_1 like Mac OS X; en-us) AppleWebKit/534.46' +
|
||||
' (KHTML, like Gecko) Version/5.1 Mobile/9B176 Safari/7534.48.3';
|
||||
|
||||
|
||||
/** @const {string} */
|
||||
testAgents.IPAD_6 =
|
||||
'Mozilla/5.0 (iPad; CPU OS 6_0 like Mac OS X) ' +
|
||||
'AppleWebKit/536.26 (KHTML, like Gecko) ' +
|
||||
'Version/6.0 Mobile/10A403 Safari/8536.25';
|
||||
|
||||
|
||||
/** @const {string} */
|
||||
testAgents.CHROME_25 =
|
||||
'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) ' +
|
||||
'AppleWebKit/535.8 (KHTML, like Gecko) ' +
|
||||
'Chrome/25.0.1000.10 Safari/535.8';
|
||||
|
||||
|
||||
/** @const {string} */
|
||||
testAgents.CHROME_ANDROID =
|
||||
'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';
|
||||
|
||||
|
||||
/** @const {string} */
|
||||
testAgents.CHROME_ANDROID_TABLET =
|
||||
'Mozilla/5.0 (Linux; Android 4.0.4; Galaxy Nexus Build/IMM76B) ' +
|
||||
'AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.133 Safari/535.19';
|
||||
|
||||
|
||||
/** @const {string} */
|
||||
testAgents.CHROME_IPHONE =
|
||||
'Mozilla/5.0 (iPhone; CPU iPhone OS 5_1_1 like Mac OS X; en-us) ' +
|
||||
'AppleWebKit/534.46.0 (KHTML, like Gecko) CriOS/22.0.1194.0 Mobile/11E53 ' +
|
||||
'Safari/7534.48.3';
|
||||
|
||||
|
||||
/** @const {string} */
|
||||
testAgents.CHROME_LINUX =
|
||||
'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.31 (KHTML, like Gecko)' +
|
||||
' Chrome/26.0.1410.33 Safari/537.31';
|
||||
|
||||
|
||||
/**
|
||||
* We traditionally use Appversion to detect X11
|
||||
* @const {string}
|
||||
*/
|
||||
testAgents.CHROME_LINUX_APPVERVERSION =
|
||||
'5.0 (X11; Linux x86_64) AppleWebKit/537.31 (KHTML, like Gecko)' +
|
||||
' Chrome/26.0.1410.33 Safari/537.31';
|
||||
|
||||
|
||||
/** @const {string} */
|
||||
testAgents.CHROME_MAC =
|
||||
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/537.17' +
|
||||
' (KHTML, like Gecko) Chrome/24.0.1309.0 Safari/537.17';
|
||||
|
||||
|
||||
/** @const {string} */
|
||||
testAgents.CHROME_OS =
|
||||
'Mozilla/5.0 (X11; CrOS x86_64 3701.62.0) AppleWebKit/537.31 ' +
|
||||
'(KHTML, like Gecko) Chrome/26.0.1410.40 Safari/537.31';
|
||||
|
||||
|
||||
/** @const {string} */
|
||||
testAgents.CHROME_OS_910 =
|
||||
'Mozilla/5.0 (X11; U; CrOS i686 9.10.0; en-US) AppleWebKit/532.5' +
|
||||
' (KHTML, like Gecko) Chrome/4.0.253.0 Safari/532.5';
|
||||
|
||||
|
||||
/** @const {string} */
|
||||
testAgents.KINDLE_FIRE =
|
||||
'Mozilla/5.0 (Linux; U; Android 4.0.3; en-us; KFTT Build/IML74K)' +
|
||||
' AppleWebKit/535.19 (KHTML, like Gecko) Silk/2.1 Mobile Safari/535.19' +
|
||||
' Silk-Accelerated=true';
|
||||
}); // goog.scope
|
||||
@@ -0,0 +1,148 @@
|
||||
// Copyright 2013 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 used by goog.labs.userAgent tools. These functions
|
||||
* should not be used outside of goog.labs.userAgent.*.
|
||||
*
|
||||
*
|
||||
* @author nnaze@google.com (Nathan Naze)
|
||||
*/
|
||||
|
||||
goog.provide('goog.labs.userAgent.util');
|
||||
|
||||
goog.require('goog.string');
|
||||
|
||||
|
||||
/**
|
||||
* Gets the native userAgent string from navigator if it exists.
|
||||
* If navigator or navigator.userAgent string is missing, returns an empty
|
||||
* string.
|
||||
* @return {string}
|
||||
* @private
|
||||
*/
|
||||
goog.labs.userAgent.util.getNativeUserAgentString_ = function() {
|
||||
var navigator = goog.labs.userAgent.util.getNavigator_();
|
||||
if (navigator) {
|
||||
var userAgent = navigator.userAgent;
|
||||
if (userAgent) {
|
||||
return userAgent;
|
||||
}
|
||||
}
|
||||
return '';
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Getter for the native navigator.
|
||||
* This is a separate function so it can be stubbed out in testing.
|
||||
* @return {Navigator}
|
||||
* @private
|
||||
*/
|
||||
goog.labs.userAgent.util.getNavigator_ = function() {
|
||||
return goog.global.navigator;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* A possible override for applications which wish to not check
|
||||
* navigator.userAgent but use a specified value for detection instead.
|
||||
* @private {string}
|
||||
*/
|
||||
goog.labs.userAgent.util.userAgent_ =
|
||||
goog.labs.userAgent.util.getNativeUserAgentString_();
|
||||
|
||||
|
||||
/**
|
||||
* Applications may override browser detection on the built in
|
||||
* navigator.userAgent object by setting this string. Set to null to use the
|
||||
* browser object instead.
|
||||
* @param {?string=} opt_userAgent The User-Agent override.
|
||||
*/
|
||||
goog.labs.userAgent.util.setUserAgent = function(opt_userAgent) {
|
||||
goog.labs.userAgent.util.userAgent_ = opt_userAgent ||
|
||||
goog.labs.userAgent.util.getNativeUserAgentString_();
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @return {string} The user agent string.
|
||||
*/
|
||||
goog.labs.userAgent.util.getUserAgent = function() {
|
||||
return goog.labs.userAgent.util.userAgent_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {string} str
|
||||
* @return {boolean} Whether the user agent contains the given string, ignoring
|
||||
* case.
|
||||
*/
|
||||
goog.labs.userAgent.util.matchUserAgent = function(str) {
|
||||
var userAgent = goog.labs.userAgent.util.getUserAgent();
|
||||
return goog.string.contains(userAgent, str);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {string} str
|
||||
* @return {boolean} Whether the user agent contains the given string.
|
||||
*/
|
||||
goog.labs.userAgent.util.matchUserAgentIgnoreCase = function(str) {
|
||||
var userAgent = goog.labs.userAgent.util.getUserAgent();
|
||||
return goog.string.caseInsensitiveContains(userAgent, str);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Parses the user agent into tuples for each section.
|
||||
* @param {string} userAgent
|
||||
* @return {!Array<!Array<string>>} Tuples of key, version, and the contents
|
||||
* of the parenthetical.
|
||||
*/
|
||||
goog.labs.userAgent.util.extractVersionTuples = function(userAgent) {
|
||||
// Matches each section of a user agent string.
|
||||
// Example UA:
|
||||
// Mozilla/5.0 (iPad; U; CPU OS 3_2_1 like Mac OS X; en-us)
|
||||
// AppleWebKit/531.21.10 (KHTML, like Gecko) Mobile/7B405
|
||||
// This has three version tuples: Mozilla, AppleWebKit, and Mobile.
|
||||
|
||||
var versionRegExp = new RegExp(
|
||||
// Key. Note that a key may have a space.
|
||||
// (i.e. 'Mobile Safari' in 'Mobile Safari/5.0')
|
||||
'(\\w[\\w ]+)' +
|
||||
|
||||
'/' + // slash
|
||||
'([^\\s]+)' + // version (i.e. '5.0b')
|
||||
'\\s*' + // whitespace
|
||||
'(?:\\((.*?)\\))?', // parenthetical info. parentheses not matched.
|
||||
'g');
|
||||
|
||||
var data = [];
|
||||
var match;
|
||||
|
||||
// Iterate and collect the version tuples. Each iteration will be the
|
||||
// next regex match.
|
||||
while (match = versionRegExp.exec(userAgent)) {
|
||||
data.push([
|
||||
match[1], // key
|
||||
match[2], // value
|
||||
// || undefined as this is not undefined in IE7 and IE8
|
||||
match[3] || undefined // info
|
||||
]);
|
||||
}
|
||||
|
||||
return data;
|
||||
};
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<!--
|
||||
Copyright 2013 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: nnaze@google.com (Nathan Naze)
|
||||
-->
|
||||
<head>
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<title>Closure Unit Tests - goog.labs.userAgent.util</title>
|
||||
<script src="../../base.js"></script>
|
||||
<script>
|
||||
goog.require('goog.labs.userAgent.utilTest');
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,105 @@
|
||||
// Copyright 2013 The Closure Library Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file frexcept 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 Unit tests for goog.labs.userAgent.engine.
|
||||
*/
|
||||
|
||||
goog.provide('goog.labs.userAgent.utilTest');
|
||||
|
||||
goog.require('goog.functions');
|
||||
goog.require('goog.labs.userAgent.testAgents');
|
||||
goog.require('goog.labs.userAgent.util');
|
||||
goog.require('goog.testing.PropertyReplacer');
|
||||
goog.require('goog.testing.jsunit');
|
||||
|
||||
goog.setTestOnly('goog.labs.userAgent.utilTest');
|
||||
|
||||
|
||||
var stubs = new goog.testing.PropertyReplacer();
|
||||
|
||||
function tearDown() {
|
||||
stubs.reset();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Tests parsing a few example UA strings.
|
||||
*/
|
||||
function testExtractVersionTuples() {
|
||||
// Old Android
|
||||
var tuples = goog.labs.userAgent.util.extractVersionTuples(
|
||||
goog.labs.userAgent.testAgents.ANDROID_BROWSER_235);
|
||||
|
||||
assertEquals(4, tuples.length);
|
||||
assertSameElements(
|
||||
['Mozilla', '5.0',
|
||||
'Linux; U; Android 2.3.5; en-us; HTC Vision Build/GRI40'], tuples[0]);
|
||||
assertSameElements(['AppleWebKit', '533.1', 'KHTML, like Gecko'], tuples[1]);
|
||||
assertSameElements(['Version', '4.0', undefined], tuples[2]);
|
||||
assertSameElements(['Mobile Safari', '533.1', undefined], tuples[3]);
|
||||
|
||||
// IE 9
|
||||
tuples = goog.labs.userAgent.util.extractVersionTuples(
|
||||
goog.labs.userAgent.testAgents.IE_9);
|
||||
assertEquals(1, tuples.length);
|
||||
assertSameElements(
|
||||
['Mozilla', '5.0',
|
||||
'compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0'], tuples[0]);
|
||||
|
||||
// Opera
|
||||
tuples = goog.labs.userAgent.util.extractVersionTuples(
|
||||
goog.labs.userAgent.testAgents.OPERA_10);
|
||||
assertEquals(3, tuples.length);
|
||||
assertSameElements(['Opera', '9.80', 'S60; SymbOS; Opera Mobi/447; U; en'],
|
||||
tuples[0]);
|
||||
assertSameElements(['Presto', '2.4.18', undefined], tuples[1]);
|
||||
assertSameElements(['Version', '10.00', undefined], tuples[2]);
|
||||
}
|
||||
|
||||
function testSetUserAgent() {
|
||||
var ua = 'Five Finger Death Punch';
|
||||
goog.labs.userAgent.util.setUserAgent(ua);
|
||||
assertEquals(ua, goog.labs.userAgent.util.getUserAgent());
|
||||
assertTrue(goog.labs.userAgent.util.matchUserAgent('Punch'));
|
||||
assertFalse(goog.labs.userAgent.util.matchUserAgent('punch'));
|
||||
assertFalse(goog.labs.userAgent.util.matchUserAgent('Mozilla'));
|
||||
}
|
||||
|
||||
function testSetUserAgentIgnoreCase() {
|
||||
var ua = 'Five Finger Death Punch';
|
||||
goog.labs.userAgent.util.setUserAgent(ua);
|
||||
assertEquals(ua, goog.labs.userAgent.util.getUserAgent());
|
||||
assertTrue(goog.labs.userAgent.util.matchUserAgentIgnoreCase('Punch'));
|
||||
assertTrue(goog.labs.userAgent.util.matchUserAgentIgnoreCase('punch'));
|
||||
assertFalse(goog.labs.userAgent.util.matchUserAgentIgnoreCase('Mozilla'));
|
||||
}
|
||||
|
||||
function testNoNavigator() {
|
||||
stubs.set(goog.labs.userAgent.util, 'getNavigator_',
|
||||
goog.functions.constant(undefined));
|
||||
assertEquals('', goog.labs.userAgent.util.getNativeUserAgentString_());
|
||||
}
|
||||
|
||||
function testNavigatorWithNoUserAgent() {
|
||||
stubs.set(goog.labs.userAgent.util, 'getNavigator_',
|
||||
goog.functions.constant(undefined));
|
||||
assertEquals('', goog.labs.userAgent.util.getNativeUserAgentString_());
|
||||
}
|
||||
|
||||
function testNavigatorWithUserAgent() {
|
||||
stubs.set(goog.labs.userAgent.util, 'getNavigator_',
|
||||
goog.functions.constant({'userAgent': 'moose'}));
|
||||
assertEquals('moose', goog.labs.userAgent.util.getNativeUserAgentString_());
|
||||
}
|
||||
Reference in New Issue
Block a user