Skip to content

Commit

Permalink
Merge pull request #7934 from porlan1/master
Browse files Browse the repository at this point in the history
Unit test files as modules
  • Loading branch information
yurydelendik authored Jan 9, 2017
2 parents aabfb77 + d9e1cb7 commit 049d7fa
Show file tree
Hide file tree
Showing 23 changed files with 727 additions and 129 deletions.
22 changes: 22 additions & 0 deletions external/umdutils/verifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -305,9 +305,30 @@ function validateFile(path, name, context) {
parts.shift();
}
while (parts[0] === '..') {
if (base.length === 0) {
error('Invalid relative CommonJS path');
}
parts.shift();
base.pop();
}
if (base.length === 0) {
// Reached the project root -- finding prefix matching subpath.
for (var prefix in context.paths) {
if (!context.paths.hasOwnProperty(prefix)) {
continue;
}
var prefixPath = context.paths[prefix];
if (!('./' + parts.join('/') + '/').startsWith(prefixPath + '/')) {
continue;
}
parts.splice(0, prefixPath.split('/').length - 1);
base.push(prefix);
break;
}
if (base.length === 0) {
error('Invalid relative CommonJS path prefix');
}
}
if (j !== base.concat(parts).join('/')) {
error('CommonJS path does not point to right AMD module: ' +
i + ' vs ' + j);
Expand Down Expand Up @@ -473,6 +494,7 @@ function validateFiles(paths, options) {
exports: Object.create(null),
imports: Object.create(null),
dependencies: Object.create(null),
paths: paths,
errorCallback: errorCallback,
warnCallback: warnCallback,
infoCallback: infoCallback
Expand Down
7 changes: 6 additions & 1 deletion gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,12 @@ gulp.task('lint', function (done) {
console.log();
console.log('### Checking UMD dependencies');
var umd = require('./external/umdutils/verifier.js');
if (!umd.validateFiles({'pdfjs': './src', 'pdfjs-web': './web'})) {
var paths = {
'pdfjs': './src',
'pdfjs-web': './web',
'pdfjs-test': './test'
};
if (!umd.validateFiles(paths)) {
done(new Error('UMD check failed.'));
return;
}
Expand Down
66 changes: 59 additions & 7 deletions test/unit/annotation_layer_spec.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,59 @@
/* globals isRef, AnnotationFactory, Dict, Name, Ref, AnnotationType,
AnnotationFlag, Annotation, AnnotationBorderStyle,
AnnotationBorderStyleType, StringStream, Lexer, Parser,
stringToUTF8String, AnnotationFieldFlag, PDFJS, stringToBytes */

/* Copyright 2017 Mozilla Foundation
*
* 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.
*/
'use strict';

(function (root, factory) {
if (typeof define === 'function' && define.amd) {
define('pdfjs-test/unit/annotation_layer_spec', ['exports',
'pdfjs/core/primitives', 'pdfjs/core/annotation',
'pdfjs/core/stream', 'pdfjs/core/parser',
'pdfjs/shared/util', 'pdfjs/display/global'], factory);
} else if (typeof exports !== 'undefined') {
factory(exports, require('../../src/core/primitives.js'),
require('../../src/core/annotation.js'),
require('../../src/core/stream.js'),
require('../../src/core/parser.js'),
require('../../src/shared/util.js'),
require('../../src/display/global.js'));
} else {
factory((root.pdfjsTestUnitAnnotationLayerSpec = {}),
root.pdfjsCorePrimitives, root.pdfjsCoreAnnotation,
root.pdfjsCoreStream, root.pdfjsCoreParser,
root.pdfjsSharedUtil, root.pdfjsDisplayGlobal);
}
}(this, function (exports, corePrimitives, coreAnnotation, coreStream,
coreParser, sharedUtil, displayGlobal) {

var Annotation = coreAnnotation.Annotation;
var AnnotationBorderStyle = coreAnnotation.AnnotationBorderStyle;
var AnnotationFactory = coreAnnotation.AnnotationFactory;
var Lexer = coreParser.Lexer;
var Parser = coreParser.Parser;
var isRef = corePrimitives.isRef;
var Dict = corePrimitives.Dict;
var Name = corePrimitives.Name;
var Ref = corePrimitives.Ref;
var StringStream = coreStream.StringStream;
var PDFJS = displayGlobal.PDFJS;
var AnnotationType = sharedUtil.AnnotationType;
var AnnotationFlag = sharedUtil.AnnotationFlag;
var AnnotationBorderStyleType = sharedUtil.AnnotationBorderStyleType;
var AnnotationFieldFlag = sharedUtil.AnnotationFieldFlag;
var stringToBytes = sharedUtil.stringToBytes;
var stringToUTF8String = sharedUtil.stringToUTF8String;

describe('Annotation layer', function() {
function XRefMock(array) {
this.map = Object.create(null);
Expand Down Expand Up @@ -349,9 +398,11 @@ describe('Annotation layer', function() {
expect(data.annotationType).toEqual(AnnotationType.LINK);

expect(data.url).toEqual(
new URL(stringToUTF8String('http://www.example.com/üöä')).href);
new URL(stringToUTF8String(
'http://www.example.com/\xC3\xBC\xC3\xB6\xC3\xA4')).href);
expect(data.unsafeUrl).toEqual(
stringToUTF8String('http://www.example.com/üöä'));
stringToUTF8String(
'http://www.example.com/\xC3\xBC\xC3\xB6\xC3\xA4'));
expect(data.dest).toBeUndefined();
});

Expand Down Expand Up @@ -1178,3 +1229,4 @@ describe('Annotation layer', function() {
});
});
});
}));
44 changes: 40 additions & 4 deletions test/unit/api_spec.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,44 @@
/* globals PDFJS, createPromiseCapability, PDFDocumentProxy,
InvalidPDFException, MissingPDFException, PasswordResponses,
PasswordException, PDFPageProxy, StreamType, FontType */

/* Copyright 2017 Mozilla Foundation
*
* 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.
*/
'use strict';

(function (root, factory) {
if (typeof define === 'function' && define.amd) {
define('pdfjs-test/unit/api_spec', ['exports', 'pdfjs/shared/util',
'pdfjs/display/global', 'pdfjs/display/api'], factory);
} else if (typeof exports !== 'undefined') {
factory(exports, require('../../src/shared/util.js'),
require('../../src/display/global.js'),
require('../../src/display/api.js'));
} else {
factory((root.pdfjsTestUnitApiSpec = {}), root.pdfjsSharedUtil,
root.pdfjsDisplayGlobal, root.pdfjsDisplayApi);
}
}(this, function (exports, sharedUtil, displayGlobal, displayApi) {

var PDFJS = displayGlobal.PDFJS;
var createPromiseCapability = sharedUtil.createPromiseCapability;
var PDFDocumentProxy = displayApi.PDFDocumentProxy;
var InvalidPDFException = sharedUtil.InvalidPDFException;
var MissingPDFException = sharedUtil.MissingPDFException;
var PasswordResponses = sharedUtil.PasswordResponses;
var PasswordException = sharedUtil.PasswordException;
var PDFPageProxy = displayApi.PDFPageProxy;
var StreamType = sharedUtil.StreamType;
var FontType = sharedUtil.FontType;

describe('api', function() {
var basicApiUrl = new URL('../pdfs/basicapi.pdf', window.location).href;
var basicApiFileLength = 105779; // bytes
Expand Down Expand Up @@ -1135,3 +1170,4 @@ describe('api', function() {
});
});
});
}));
40 changes: 37 additions & 3 deletions test/unit/cff_parser_spec.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,41 @@
/* globals Stream, CFFParser, SEAC_ANALYSIS_ENABLED, CFFIndex, CFFParser,
CFFStrings, CFFCompiler */

/* Copyright 2017 Mozilla Foundation
*
* 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.
*/
'use strict';

(function (root, factory) {
if (typeof define === 'function' && define.amd) {
define('pdfjs-test/unit/cff_parser_spec', ['exports',
'pdfjs/core/cff_parser', 'pdfjs/core/fonts',
'pdfjs/core/stream'], factory);
} else if (typeof exports !== 'undefined') {
factory(exports, require('../../src/core/cff_parser.js'),
require('../../src/core/fonts.js'),
require('../../src/core/stream.js'));
} else {
factory((root.pdfjsTestUnitCFFParserSpec = {}), root.pdfjsCoreCFFParser,
root.pdfjsCoreFonts, root.pdfjsCoreStream);
}
}(this, function (exports, coreCFFParser, coreFonts, coreStream) {

var CFFParser = coreCFFParser.CFFParser;
var CFFIndex = coreCFFParser.CFFIndex;
var CFFStrings = coreCFFParser.CFFStrings;
var CFFCompiler = coreCFFParser.CFFCompiler;
var SEAC_ANALYSIS_ENABLED = coreFonts.SEAC_ANALYSIS_ENABLED;
var Stream = coreStream.Stream;

describe('CFFParser', function() {
function createWithNullProto(obj) {
var result = Object.create(null);
Expand Down Expand Up @@ -355,3 +388,4 @@ describe('CFFCompiler', function() {

// TODO a lot more compiler tests
});
}));
37 changes: 35 additions & 2 deletions test/unit/cmap_spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,39 @@
/* globals StringStream, CMapFactory, CMap, IdentityCMap, Name */

/* Copyright 2017 Mozilla Foundation
*
* 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.
*/
'use strict';

(function (root, factory) {
if (typeof define === 'function' && define.amd) {
define('pdfjs-test/unit/cmap_spec', ['exports', 'pdfjs/core/cmap',
'pdfjs/core/primitives', 'pdfjs/core/stream'], factory);
} else if (typeof exports !== 'undefined') {
factory(exports, require('../../src/core/cmap.js'),
require('../../src/core/primitives.js'),
require('../../src/core/stream.js'));
} else {
factory((root.pdfjsTestUnitCMapSpec = {}), root.pdfjsCoreCMap,
root.pdfjsCorePrimitives, root.pdfjsCoreStream);
}
}(this, function (exports, coreCMap, corePrimitives, coreStream) {

var CMapFactory = coreCMap.CMapFactory;
var CMap = coreCMap.CMap;
var IdentityCMap = coreCMap.IdentityCMap;
var Name = corePrimitives.Name;
var StringStream = coreStream.StringStream;

var cMapUrl = '../../external/bcmaps/';
var cMapPacked = true;

Expand Down Expand Up @@ -187,3 +219,4 @@ describe('cmap', function() {
});
});
});
}));
50 changes: 45 additions & 5 deletions test/unit/crypto_spec.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,49 @@
/* globals stringToBytes, calculateMD5, ARCFourCipher, calculateSHA256,
calculateSHA384, calculateSHA512, AES128Cipher, AES256Cipher, PDF17,
PDF20, Dict, CipherTransformFactory, PasswordException,
PasswordResponses, Name */

/* Copyright 2017 Mozilla Foundation
*
* 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.
*/
'use strict';

(function (root, factory) {
if (typeof define === 'function' && define.amd) {
define('pdfjs-test/unit/crypto_spec', ['exports', 'pdfjs/core/crypto',
'pdfjs/core/primitives', 'pdfjs/shared/util'], factory);
} else if (typeof exports !== 'undefined') {
factory(exports, require('../../src/core/crypto.js'),
require('../../src/core/primitives.js'),
require('../../src/shared/util.js'));
} else {
factory((root.pdfjsTestUnitCryptoSpec = {}), root.pdfjsCoreCrypto,
root.pdfjsCorePrimitives, root.pdfjsSharedUtil);
}
}(this, function (exports, coreCrypto, corePrimitives, sharedUtil) {

var calculateMD5 = coreCrypto.calculateMD5;
var ARCFourCipher = coreCrypto.ARCFourCipher;
var calculateSHA256 = coreCrypto.calculateSHA256;
var calculateSHA384 = coreCrypto.calculateSHA384;
var calculateSHA512 = coreCrypto.calculateSHA512;
var AES128Cipher = coreCrypto.AES128Cipher;
var AES256Cipher = coreCrypto.AES256Cipher;
var PDF17 = coreCrypto.PDF17;
var PDF20 = coreCrypto.PDF20;
var CipherTransformFactory = coreCrypto.CipherTransformFactory;
var Name = corePrimitives.Name;
var Dict = corePrimitives.Dict;
var stringToBytes = sharedUtil.stringToBytes;
var PasswordException = sharedUtil.PasswordException;
var PasswordResponses = sharedUtil.PasswordResponses;

describe('crypto', function() {
function hex2binary(s) {
var digits = '0123456789ABCDEF';
Expand Down Expand Up @@ -669,3 +708,4 @@ describe('CipherTransformFactory', function() {
});
});
});
}));
35 changes: 33 additions & 2 deletions test/unit/dom_utils_spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,37 @@
/* globals getFilenameFromUrl, PDFJS, LinkTarget, isExternalLinkTargetSet */

/* Copyright 2017 Mozilla Foundation
*
* 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.
*/
'use strict';

(function (root, factory) {
if (typeof define === 'function' && define.amd) {
define('pdfjs-test/unit/dom_utils_spec', ['exports',
'pdfjs/display/dom_utils', 'pdfjs/display/global'], factory);
} else if (typeof exports !== 'undefined') {
factory(exports, require('../../src/display/dom_utils.js'),
require('../../src/display/global.js'));
} else {
factory((root.pdfjsTestUnitDOMUtilsSpec = {}), root.pdfjsDisplayDOMUtils,
root.pdfjsDisplayGlobal);
}
}(this, function (exports, displayDOMUtils, displayGlobal) {

var PDFJS = displayGlobal.PDFJS;
var getFilenameFromUrl = displayDOMUtils.getFilenameFromUrl;
var LinkTarget = displayDOMUtils.LinkTarget;
var isExternalLinkTargetSet = displayDOMUtils.isExternalLinkTargetSet;

describe('dom_utils', function() {
describe('getFilenameFromUrl', function() {
it('should get the filename from an absolute URL', function() {
Expand Down Expand Up @@ -52,3 +82,4 @@ describe('dom_utils', function() {
});
});
});
}));
Loading

0 comments on commit 049d7fa

Please sign in to comment.