Chromium Code Reviews| Index: remoting/webapp/base/js/platform_unittest.js |
| diff --git a/remoting/webapp/base/js/platform_unittest.js b/remoting/webapp/base/js/platform_unittest.js |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..5b9a7f13fdb81152b23aae64dc26007502eac486 |
| --- /dev/null |
| +++ b/remoting/webapp/base/js/platform_unittest.js |
| @@ -0,0 +1,148 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +(function() { |
| + |
| +'use strict'; |
| + |
| +var testData = [{ |
| + userAgent: 'Mozilla/5.0 (X11; CrOS x86_64 6457.107.0) AppleWebKit/537.36 ' + |
| + '(KHTML, like Gecko) Chrome/40.0.2214.115 Safari/537.36,gzip(gfe)', |
| + os_name: 'ChromeOS', |
| + os_version: '6457.107.0', |
| + cpu: 'x86_64', |
| + chrome_version: '40.0.2214.115' |
| + }, { |
| + userAgent: 'Mozilla/5.0 (X11; CrOS i686 6812.88.0) AppleWebKit/537.36 ' + |
| + '(KHTML, like Gecko) Chrome/42.0.2311.153 Safari/537.36,gzip(gfe)', |
| + os_name: 'ChromeOS', |
| + os_version: '6812.88.0', |
| + cpu: 'i686', |
| + chrome_version: '42.0.2311.153' |
| + }, { |
| + userAgent: 'Mozilla/5.0 (X11; CrOS armv7l 6946.52.0) AppleWebKit/537.36 ' + |
| + '(KHTML, like Gecko) Chrome/43.0.2357.73 Safari/537.36,gzip(gfe)', |
| + os_name: 'ChromeOS', |
| + os_version: '6946.52.0', |
| + cpu: 'armv7l', |
| + chrome_version: '43.0.2357.73' |
| + }, { |
| + userAgent: 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 ' + |
| + '(KHTML, like Gecko) Chrome/45.0.2414.0 Safari/537.36,gzip(gfe)', |
| + os_name: 'Linux', |
| + os_version: '', |
| + cpu: 'x86_64', |
| + chrome_version: '45.0.2414.0' |
| + },{ |
| + userAgent: 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 ' + |
| + '(KHTML, like Gecko) Chrome/43.0.2357.81 Safari/537.36,gzip(gfe)', |
| + os_name: 'Windows', |
| + os_version: '6.1', |
| + cpu: '', |
| + chrome_version: '43.0.2357.81' |
| + },{ |
| + userAgent: 'Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 ' + |
| + '(KHTML, like Gecko) Chrome/42.0.2311.152 Safari/537.36,gzip(gfe)', |
| + os_name: 'Windows', |
| + os_version: '6.3', |
| + cpu: '', |
| + chrome_version: '42.0.2311.152' |
| + },{ |
| + userAgent: 'Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 ' + |
| + '(KHTML, like Gecko) Chrome/43.0.2357.81 Safari/537.36,gzip(gfe)', |
| + os_name: 'Windows', |
| + os_version: '6.3', |
| + cpu: '', |
| + chrome_version: '43.0.2357.81' |
| + }, { |
| + userAgent: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 '+ |
| + '(KHTML, like Gecko) Chrome/43.0.2357.81 Safari/537.36,gzip(gfe)', |
| + os_name: 'Windows', |
| + os_version: '10.0', |
| + cpu: '', |
| + chrome_version: '43.0.2357.81' |
| + },{ |
| + userAgent: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_5) AppleWebKit' + |
| + '/537.36 (KHTML, like Gecko) Chrome/43.0.2357.81 Safari/537.36,gzip(gfe)', |
| + os_name: 'Mac', |
| + os_version: '10.9.5', |
| + cpu: 'Intel', |
| + chrome_version: '43.0.2357.81' |
| + },{ |
| + userAgent: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit' + |
| + '/537.36 (KHTML, like Gecko) Chrome/43.0.2357.81 Safari/537.36,gzip(gfe)', |
| + os_name: 'Mac', |
| + os_version: '10.10.1', |
| + cpu: 'Intel', |
| + chrome_version: '43.0.2357.81' |
| + },{ |
| + userAgent: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_2) AppleWebKit' + |
| + '/537.36 (KHTML, like Gecko) Chrome/43.0.2357.81 Safari/537.36,gzip(gfe)', |
| + os_name: 'Mac', |
| + os_version: '10.10.2', |
| + cpu: 'Intel', |
| + chrome_version: '43.0.2357.81' |
| + },{ |
| + userAgent: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_3) AppleWebKit' + |
| + '/537.36 (KHTML, like Gecko) Chrome/43.0.2357.81 Safari/537.36,gzip(gfe)', |
| + os_name: 'Mac', |
| + os_version: '10.10.3', |
| + cpu: 'Intel', |
| + chrome_version: '43.0.2357.81' |
| + } |
| +]; |
| + |
| +QUnit.module('platform'); |
| + |
| +function forEachTest(/** function(Object<string>, string) */ callback) { |
|
Jamie
2015/06/06 01:05:41
This should be called something like "forEachUserA
kelvinp
2015/06/06 02:09:54
Done.
|
| + testData.forEach(function(/** Object<string>*/ testCase) { |
| + var message = 'userAgent: ' + testCase['userAgent'] |
| + var userAgentStub = sinon.stub(remoting, 'getUserAgent'); |
| + userAgentStub.returns(testCase['userAgent']); |
| + var result = remoting.getSystemInfo(); |
| + callback(testCase, message); |
| + userAgentStub.restore(); |
| + }); |
| +} |
| + |
| +QUnit.test('OS name, OS version, chrome version and cpu detection', |
| + function(assert) { |
| + forEachTest(function(/** Object<string> */ testCase, /** string */ message) { |
| + var result = remoting.getSystemInfo(); |
| + assert.equal(result.os_name, testCase['os_name'], message); |
| + assert.equal(result.os_version, testCase['os_version'], message); |
| + assert.equal(result.cpu, testCase['cpu'], message); |
| + assert.equal(result.chrome_version, testCase['chrome_version'], message); |
| + }); |
| +}); |
| + |
| +QUnit.test('platform is Mac', function(assert) { |
| + forEachTest(function(/** Object<string> */ testCase, /** string */ message) { |
| + assert.equal(remoting.platformIsMac(), |
| + testCase['os_name'] === 'Mac', message); |
| + }); |
| +}); |
| + |
| +QUnit.test('platform is Windows', function(assert) { |
| + forEachTest(function(/** Object<string> */ testCase, /** string */ message) { |
| + assert.equal(remoting.platformIsWindows(), |
| + testCase['os_name'] === 'Windows', message); |
| + }); |
| +}); |
| + |
| +QUnit.test('platform is Linux', function(assert) { |
| + forEachTest(function(/** Object<string> */ testCase, /** string */ message) { |
| + assert.equal(remoting.platformIsLinux(), |
| + testCase['os_name'] === 'Linux', message); |
| + }); |
| +}); |
| + |
| +QUnit.test('platform is ChromeOS', function(assert) { |
| + forEachTest(function(/** Object<string> */ testCase, /** string */ message) { |
| + assert.equal(remoting.platformIsChromeOS(), |
| + testCase['os_name'] === 'ChromeOS', message); |
| + }); |
| +}); |
| + |
| +})(); |