1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
|
<!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.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";
// 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);
}
</script>
</body>
</html>
|