From 10d3825efb6c6037aff044f1ed7fa13dc444ebf2 Mon Sep 17 00:00:00 2001 From: Chris Williams Date: Thu, 3 Oct 2019 10:11:13 -0400 Subject: [PATCH] test: migrate override tests to suite --- tests/Resources/string_decoder.addontest.js | 172 ------------------ .../Resources/ti.filesystem.file.addontest.js | 22 --- .../ti.network.httpclient.addontest.js | 35 ---- tests/Resources/ti.network.test.js | 94 ---------- 4 files changed, 323 deletions(-) delete mode 100644 tests/Resources/string_decoder.addontest.js delete mode 100644 tests/Resources/ti.filesystem.file.addontest.js delete mode 100644 tests/Resources/ti.network.httpclient.addontest.js delete mode 100644 tests/Resources/ti.network.test.js diff --git a/tests/Resources/string_decoder.addontest.js b/tests/Resources/string_decoder.addontest.js deleted file mode 100644 index 2a1428c4e61..00000000000 --- a/tests/Resources/string_decoder.addontest.js +++ /dev/null @@ -1,172 +0,0 @@ -/* - * Appcelerator Titanium Mobile - * Copyright (c) 2019-Present by Appcelerator, Inc. All Rights Reserved. - * Licensed under the terms of the Apache Public License - * Please see the LICENSE included with this distribution for details. - */ -/* eslint-env mocha */ -/* eslint no-unused-expressions: "off" */ -'use strict'; -const should = require('./utilities/assertions'); -let StringDecoder; - -describe('string_decoder', () => { - it('can be loaded as a core module', () => { - StringDecoder = require('string_decoder').StringDecoder; - should(StringDecoder).exist; - }); - - it('uses \'utf8\' as the default encoding', () => { - const decoder = new StringDecoder(); - should(decoder.encoding).eql('utf8'); - }); - - describe('#end()', () => { - it('is a Function', () => { - const decoder = new StringDecoder(); - should(decoder.end).be.a.Function; - }); - - it('handles base64 with single byte', () => { - const decoder = new StringDecoder('base64'); - should(decoder.write(Buffer.from([ 0x61 ]))).eql(''); - should(decoder.end()).eql('YQ=='); - // resets internals so writing empty buffer doesn't output anything anymore - should(decoder.write(Buffer.from([]))).eql(''); - should(decoder.end()).eql(''); - }); - - it('handles base64 with single byte, writing again', () => { - const decoder = new StringDecoder('base64'); - should(decoder.write(Buffer.from([ 0x61 ]))).eql(''); - should(decoder.end()).eql('YQ=='); - // resets internals so writing empty buffer doesn't output anything anymore - should(decoder.write(Buffer.from([]))).eql(''); - should(decoder.end()).eql(''); - - should(decoder.write(Buffer.from([ 0x61 ]))).eql(''); - should(decoder.end()).eql('YQ=='); - // resets internals so writing empty buffer doesn't output anything anymore - should(decoder.write(Buffer.from([]))).eql(''); - should(decoder.end()).eql(''); - }); - - it('handles base64 with two bytes', () => { - const decoder = new StringDecoder('base64'); - should(decoder.write(Buffer.from([ 0x61, 0x61 ]))).eql(''); - should(decoder.end()).eql('YWE='); - // resets internals so writing empty buffer doesn't output anything anymore - should(decoder.write(Buffer.from([]))).eql(''); - should(decoder.end()).eql(''); - }); - - it('handles base64 with two bytes, writing again', () => { - const decoder = new StringDecoder('base64'); - should(decoder.write(Buffer.from([ 0x61, 0x61 ]))).eql(''); - should(decoder.end()).eql('YWE='); - // resets internals so writing empty buffer doesn't output anything anymore - should(decoder.write(Buffer.from([]))).eql(''); - should(decoder.end()).eql(''); - - should(decoder.write(Buffer.from([ 0x61 ]))).eql(''); - should(decoder.end()).eql('YQ=='); - // resets internals so writing empty buffer doesn't output anything anymore - should(decoder.write(Buffer.from([]))).eql(''); - should(decoder.end()).eql(''); - }); - - it('handles base64 with three bytes', () => { - const decoder = new StringDecoder('base64'); - should(decoder.write(Buffer.from([ 0x61, 0x61, 0x61 ]))).eql('YWFh'); // we got our 3 bytes! - should(decoder.end()).eql(''); // don't add anything else - // resets internals so writing empty buffer doesn't output anything anymore - should(decoder.write(Buffer.from([]))).eql(''); - should(decoder.end()).eql(''); - }); - - it('handles base64 with three bytes, wirting again', () => { - const decoder = new StringDecoder('base64'); - should(decoder.write(Buffer.from([ 0x61, 0x61, 0x61 ]))).eql('YWFh'); // we got our 3 bytes! - should(decoder.end()).eql(''); // don't add anything else - // resets internals so writing empty buffer doesn't output anything anymore - should(decoder.write(Buffer.from([]))).eql(''); - should(decoder.end()).eql(''); - - should(decoder.write(Buffer.from([ 0x61 ]))).eql(''); - should(decoder.end()).eql('YQ=='); - // resets internals so writing empty buffer doesn't output anything anymore - should(decoder.write(Buffer.from([]))).eql(''); - should(decoder.end()).eql(''); - }); - }); - - describe('#write()', () => { - it('is a Function', () => { - const decoder = new StringDecoder(); - should(decoder.write).be.a.Function; - }); - - it('holds multi-byte utf-8 characters until end is reached', () => { - const decoder = new StringDecoder('utf8'); - should(decoder.write(Buffer.from([ 0xE2 ]))).eql(''); - should(decoder.write(Buffer.from([ 0x82 ]))).eql(''); - should(decoder.end(Buffer.from([ 0xAC ]))).eql('€'); // FIXME: Failing! - }); - }); - - it('works without new keyword', () => { - const decoder2 = {}; - StringDecoder.call(decoder2); - should(decoder2.encoding).eql('utf8'); - should(decoder2.write).be.a.Function; - should(decoder2.end).be.a.Function; - }); - - it('handles standard utf-8 buffers', () => { - decodeTest('utf8', Buffer.from('$', 'utf8'), '$'); - decodeTest('utf-8', Buffer.from('¢', 'utf-8'), '¢'); - decodeTest('utf-8', Buffer.from('€', 'utf-8'), '€'); - decodeTest('utf-8', Buffer.from('𤭢', 'utf-8'), '𤭢'); - }); - - it('handles mixed ascii and non-ascii', () => { - decodeTest( - 'utf-8', - Buffer.from([ 0xCB, 0xA4, 0x64, 0xE1, 0x8B, 0xA4, 0x30, 0xE3, 0x81, 0x85 ]), - '\u02e4\u0064\u12e4\u0030\u3045' - ); - }); - - // FIXMEL Requires native fix in iOS for Ti.Buffer, see https://github.com/appcelerator/titanium_mobile/pull/11095#issue-302964559 - it.allBroken('handles invalid utf-8 input', () => { - decodeTest('utf-8', Buffer.from('C9B5A941', 'hex'), '\u0275\ufffdA'); - decodeTest('utf-8', Buffer.from('E2', 'hex'), '\ufffd'); - decodeTest('utf-8', Buffer.from('E241', 'hex'), '\ufffdA'); // FIXME: Failing! - decodeTest('utf-8', Buffer.from('CCCCB8', 'hex'), '\ufffd\u0338'); - decodeTest('utf-8', Buffer.from('F0B841', 'hex'), '\ufffdA'); - decodeTest('utf-8', Buffer.from('F1CCB8', 'hex'), '\ufffd\u0338'); - decodeTest('utf-8', Buffer.from('F0FB00', 'hex'), '\ufffd\ufffd\0'); - decodeTest('utf-8', Buffer.from('CCE2B8B8', 'hex'), '\ufffd\u2e38'); - decodeTest('utf-8', Buffer.from('E2B8CCB8', 'hex'), '\ufffd\u0338'); - decodeTest('utf-8', Buffer.from('E2FBCC01', 'hex'), '\ufffd\ufffd\ufffd\u0001'); - decodeTest('utf-8', Buffer.from('CCB8CDB9', 'hex'), '\u0338\u0379'); - }); - - // UCS-2 - it('handles UCS-2', () => { - decodeTest('ucs2', Buffer.from('ababc', 'ucs2'), 'ababc'); - }); - - // UTF-16LE - it('handles UTF-16LE', () => { - decodeTest('utf16le', Buffer.from('3DD84DDC', 'hex'), '\ud83d\udc4d'); // thumbs up - }); -}); - -function decodeTest(encoding, input, expected) { - const decoder = new StringDecoder(encoding); - let output = ''; - output += decoder.write(input); - output += decoder.end(); - should(output).eql(expected); -} diff --git a/tests/Resources/ti.filesystem.file.addontest.js b/tests/Resources/ti.filesystem.file.addontest.js deleted file mode 100644 index 2dd060bfa89..00000000000 --- a/tests/Resources/ti.filesystem.file.addontest.js +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Appcelerator Titanium Mobile - * Copyright (c) 2019-Present by Appcelerator, Inc. All Rights Reserved. - * Licensed under the terms of the Apache Public License - * Please see the LICENSE included with this distribution for details. - */ -/* eslint-env mocha */ -/* eslint no-unused-expressions: "off" */ -'use strict'; -const should = require('./utilities/assertions'); - -describe('Ti.Filesystem', () => { - it.android('TIMOB-27193', () => { - const filename = `TIMOB-27193_${Date.now()}.txt`; - const file = Ti.Filesystem.getFile(Ti.Filesystem.tempDirectory, filename); - const originalPath = file.nativePath; - file.createFile(); - should(file.exists()).eql(true); - // make sure we're not getting swindled by having the underlying file inside the proxy get changed on us! - should(file.nativePath).eql(originalPath); - }); -}); diff --git a/tests/Resources/ti.network.httpclient.addontest.js b/tests/Resources/ti.network.httpclient.addontest.js deleted file mode 100644 index 580f7213b7a..00000000000 --- a/tests/Resources/ti.network.httpclient.addontest.js +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Appcelerator Titanium Mobile - * Copyright (c) 2019 Axway, Inc. All Rights Reserved. - * Licensed under the terms of the Apache Public License - * Please see the LICENSE included with this distribution for details. - */ -/* eslint-env mocha */ -/* eslint no-unused-expressions: "off" */ -'use strict'; -var should = require('./utilities/assertions'); - -describe('Titanium.Network.HTTPClient', function () { - this.timeout(6e4); - - it.android('TLSv3 support', function (finish) { - // Only supported on Android 10+ - if (parseInt(Ti.Platform.version.split('.')[0]) < 10) { - return finish(); - } - - const client = Ti.Network.createHTTPClient({ - onload: e => { - const html = e.source.responseText; - if (html.includes('protocol_tls1_3">Yes')) { - finish(); - } - }, - onerror: - e => { finish(new Error('Could not determine TLSv3 support.')); }, - timeout: 8000 - }); - client.open('GET', 'https://ssllabs.com/ssltest/viewMyClient.html'); - client.send(); - }); -}); diff --git a/tests/Resources/ti.network.test.js b/tests/Resources/ti.network.test.js deleted file mode 100644 index 0cdfcec3ae5..00000000000 --- a/tests/Resources/ti.network.test.js +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Appcelerator Titanium Mobile - * Copyright (c) 2011-Present by Appcelerator, Inc. All Rights Reserved. - * Licensed under the terms of the Apache Public License - * Please see the LICENSE included with this distribution for details. - */ -/* eslint-env mocha */ -/* eslint no-unused-expressions: "off" */ -'use strict'; -var should = require('./utilities/assertions'); - -describe('Titanium.Network', function () { - - // Constants - const NETWORK_TYPES = [ 'NETWORK_LAN', 'NETWORK_MOBILE', 'NETWORK_NONE', 'NETWORK_UNKNOWN', 'NETWORK_WIFI' ], - NOTIFICATION_TYPES = [ 'NOTIFICATION_TYPE_ALERT', 'NOTIFICATION_TYPE_BADGE', 'NOTIFICATION_TYPE_NEWSSTAND', 'NOTIFICATION_TYPE_SOUND' ], - TLS_VERSIONS = [ 'TLS_VERSION_1_0', 'TLS_VERSION_1_1', 'TLS_VERSION_1_2', 'TLS_VERSION_1_3' ]; - // TODO Test that each group has unique values! - for (let i = 0; i < NETWORK_TYPES.length; i++) { - it(NETWORK_TYPES[i], function () { // eslint-disable-line no-loop-func - should(Ti.Network).have.constant(NETWORK_TYPES[i]).which.is.a.Number; - }); - } - for (let i = 0; i < NOTIFICATION_TYPES.length; i++) { - // iOS-specific properties - it.ios(NOTIFICATION_TYPES[i], function () { // eslint-disable-line no-loop-func - should(Ti.Network).have.constant(NOTIFICATION_TYPES[i]).which.is.a.Number; - }); - } - for (let i = 0; i < TLS_VERSIONS.length; i++) { - // FIXME Fails on Android and iOS for some reason! They say they're undefined, not Number - // FIXME Windows fails to find the property up the prototype chain in utilities/assertions, line 33 - it.allBroken(TLS_VERSIONS[i], function () { // eslint-disable-line no-loop-func - should(Ti.Network).have.constant(TLS_VERSIONS[i]).which.is.a.Number; - }); - } - - it('PROGRESS_UNKNOWN', function () { - should(Ti.Network).have.constant('PROGRESS_UNKNOWN').which.is.a.Number; - }); - - // Properties - it('apiName', function () { - should(Ti.Network).have.a.readOnlyProperty('apiName').which.is.a.String; - should(Ti.Network.apiName).be.eql('Ti.Network'); - }); - - it('networkType', function () { - should(Ti.Network).have.a.readOnlyProperty('networkType').which.is.a.Number; - // Has to be one of the defined constants - should([ Ti.Network.NETWORK_LAN, - Ti.Network.NETWORK_MOBILE, - Ti.Network.NETWORK_NONE, - Ti.Network.NETWORK_UNKNOWN, - Ti.Network.NETWORK_WIFI ].indexOf(Ti.Network.networkType)).not.eql(-1); - }); - - it('networkTypeName', function () { - should(Ti.Network).have.a.readOnlyProperty('networkTypeName').which.is.a.String; - if (Ti.Network.networkType == Ti.Network.NETWORK_LAN) { // eslint-disable-line eqeqeq - Ti.Network.networkTypeName.should.eql('LAN'); - } else if (Ti.Network.networkType == Ti.Network.NETWORK_MOBILE) { // eslint-disable-line eqeqeq - Ti.Network.networkTypeName.should.eql('MOBILE'); - } else if (Ti.Network.networkType == Ti.Network.NETWORK_NONE) { // eslint-disable-line eqeqeq - Ti.Network.networkTypeName.should.eql('NONE'); - } else if (Ti.Network.networkType == Ti.Network.NETWORK_UNKNOWN) { // eslint-disable-line eqeqeq - Ti.Network.networkTypeName.should.eql('UNKNOWN'); - } else if (Ti.Network.networkType == Ti.Network.NETWORK_WIFI) { // eslint-disable-line eqeqeq - Ti.Network.networkTypeName.should.eql('WIFI'); - } - }); - - it('online', function () { - should(Ti.Network).have.a.readOnlyProperty('online').which.is.a.Boolean; - }); - - // Methods - // These seem to "intermittently" be unefined on Windows! - it.windowsBroken('encodeURIComponent()', function () { - should(Ti.Network.encodeURIComponent).be.a.Function; - const text = Ti.Network.encodeURIComponent('Look what I found! I like this:'); - text.should.eql('Look%20what%20I%20found!%20I%20like%20this%3A'); - }); - - it.windowsBroken('decodeURIComponent()', function () { - should(Ti.Network.decodeURIComponent).be.a.Function; - const text = Ti.Network.decodeURIComponent('Look%20what%20I%20found!%20I%20like%20this%3A'); - text.should.eql('Look what I found! I like this:'); - }); - - it('createHTTPClient()', function () { - should(Ti.Network.createHTTPClient).be.a.Function; - }); -});