File: platform_test.js

package info (click to toggle)
aseba-plugin-blockly 20180211%2Bgit-2
  • links: PTS
  • area: non-free
  • in suites: buster
  • size: 64,472 kB
  • sloc: xml: 7,976; python: 2,314; sh: 261; lisp: 24; makefile: 10
file content (180 lines) | stat: -rw-r--r-- 6,363 bytes parent folder | download | duplicates (2)
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
// 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';

  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);
}

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);
}

function testIPod22() {
  // Borrowing from webserver/browser_rules for user agents
  var uaString = 'Mozilla/5.0 (iPod; U; CPU iPhone OS 2_2 like ' +
      'Mac OS X; en-us) AppleWebKit/525.18.1 (KHTML, like Gecko) Mobile/5G77a';

  // Need to set this lest the testing platform be used for detection.
  mockAgent.setNavigator({platform: 'iPod'});

  mockAgent.setUserAgentString(uaString);
  updateUserAgentUtils();
  assertTrue(goog.userAgent.IPOD);
  assertEquals('2.2', goog.userAgent.platform.VERSION);
}

function testIPod91() {
  // Borrowing from webserver/browser_rules for user agents
  var uaString = 'Mozilla/5.0 (iPod; CPU iPhone OS 9_1 like ' +
      'Mac OS X) AppleWebKit/601.1 (KHTML, like Gecko) ' +
      'CriOS/47.0.2526.70 Mobile/13B143 Safari/601.1.46,gzip(gfe)';

  // Need to set this lest the testing platform be used for detection.
  mockAgent.setNavigator({platform: 'iPod'});

  mockAgent.setUserAgentString(uaString);
  updateUserAgentUtils();
  assertTrue(goog.userAgent.IPOD);
  assertEquals('9.1', goog.userAgent.platform.VERSION);
}