sku-pg
Version:
Skulpt is a Javascript implementation of Python 2.x. Python that runs in your browser!
108 lines (86 loc) • 3.38 kB
HTML
<html>
<!--
Copyright 2010 The Closure Library Authors. All Rights Reserved.
Use of this source code is governed by an Apache 2.0 License.
See the COPYING file for details.
-->
<!--
@author mpd@google.com (Michael Davidson)
-->
<head>
<title>Closure Unit Tests - goog.userAgent.platform</title>
<script src="../base.js"></script>
<script>
goog.require('goog.array');
goog.require('goog.testing.jsunit');
goog.require('goog.testing.MockUserAgent');
goog.require('goog.testing.PropertyReplacer');
goog.require('goog.userAgent.platform');
</script>
</head>
<body>
<script>
var mockAgent;
function setUp() {
mockAgent = new goog.testing.MockUserAgent();
mockAgent.install();
}
function tearDown() {
mockAgent.dispose();
updateUserAgentUtils();
}
function updateUserAgentUtils() {
goog.userAgent.PLATFORM = goog.userAgent.determinePlatform_();
goog.userAgent.initPlatform_();
// 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.MAC = goog.userAgent.detectedMac_;
goog.userAgent.WINDOWS = goog.userAgent.detectedWindows_;
goog.userAgent.LINUX = goog.userAgent.detectedLinux_;
goog.userAgent.X11 = goog.userAgent.detectedX11_;
goog.userAgent.platform.VERSION =
goog.userAgent.platform.determineVersion_();
}
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)';
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);
}
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"
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);
}
</script>
</body>
</html>