Merge pull request #7197 from prakashpalanisamy/remove-combineurl-test

Remove `combineUrl` and replace it with `new URL`. Issue #7183, for reference.
This commit is contained in:
Tim van der Meij 2016-04-15 22:44:07 +02:00
commit 4a601ffc28
5 changed files with 7 additions and 78 deletions

View File

@ -45,7 +45,6 @@ var UnexpectedResponseException = sharedUtil.UnexpectedResponseException;
var UnknownErrorException = sharedUtil.UnknownErrorException; var UnknownErrorException = sharedUtil.UnknownErrorException;
var Util = sharedUtil.Util; var Util = sharedUtil.Util;
var createPromiseCapability = sharedUtil.createPromiseCapability; var createPromiseCapability = sharedUtil.createPromiseCapability;
var combineUrl = sharedUtil.combineUrl;
var error = sharedUtil.error; var error = sharedUtil.error;
var deprecated = sharedUtil.deprecated; var deprecated = sharedUtil.deprecated;
var getVerbosityLevel = sharedUtil.getVerbosityLevel; var getVerbosityLevel = sharedUtil.getVerbosityLevel;
@ -186,7 +185,7 @@ function getDocument(src, pdfDataRangeTransport,
for (var key in source) { for (var key in source) {
if (key === 'url' && typeof window !== 'undefined') { if (key === 'url' && typeof window !== 'undefined') {
// The full path is required in the 'url' field. // The full path is required in the 'url' field.
params[key] = combineUrl(window.location.href, source[key]); params[key] = new URL(source[key], window.location).href;
continue; continue;
} else if (key === 'range') { } else if (key === 'range') {
rangeTransport = source[key]; rangeTransport = source[key];
@ -1121,7 +1120,7 @@ var PDFWorker = (function PDFWorkerClosure() {
// // to the same origin. // // to the same origin.
// if (!isSameOrigin(window.location.href, workerSrc)) { // if (!isSameOrigin(window.location.href, workerSrc)) {
// workerSrc = createCDNWrapper( // workerSrc = createCDNWrapper(
// combineUrl(window.location.href, workerSrc)); // new URL(workerSrc, window.location).href);
// } // }
//#endif //#endif
// Some versions of FF can't create a worker on localhost, see: // Some versions of FF can't create a worker on localhost, see:

View File

@ -295,15 +295,6 @@ var UNSUPPORTED_FEATURES = {
font: 'font' font: 'font'
}; };
// Combines two URLs. The baseUrl shall be absolute URL. If the url is an
// absolute URL, it will be returned as is.
function combineUrl(baseUrl, url) {
if (!url) {
return baseUrl;
}
return new URL(url, baseUrl).href;
}
// Checks if URLs have the same origin. For non-HTTP based URLs, returns false. // Checks if URLs have the same origin. For non-HTTP based URLs, returns false.
function isSameOrigin(baseUrl, otherUrl) { function isSameOrigin(baseUrl, otherUrl) {
try { try {
@ -2338,7 +2329,6 @@ exports.arrayByteLength = arrayByteLength;
exports.arraysToBytes = arraysToBytes; exports.arraysToBytes = arraysToBytes;
exports.assert = assert; exports.assert = assert;
exports.bytesToString = bytesToString; exports.bytesToString = bytesToString;
exports.combineUrl = combineUrl;
exports.createBlob = createBlob; exports.createBlob = createBlob;
exports.createPromiseCapability = createPromiseCapability; exports.createPromiseCapability = createPromiseCapability;
exports.createObjectURL = createObjectURL; exports.createObjectURL = createObjectURL;

View File

@ -332,9 +332,7 @@ var Driver = (function DriverClosure() {
this._log('Loading file "' + task.file + '"\n'); this._log('Loading file "' + task.file + '"\n');
var absoluteUrl = pdfjsSharedUtil.combineUrl(window.location.href, var absoluteUrl = new URL(task.file, window.location).href;
task.file);
PDFJS.disableRange = task.disableRange; PDFJS.disableRange = task.disableRange;
PDFJS.disableAutoFetch = !task.enableAutoFetch; PDFJS.disableAutoFetch = !task.enableAutoFetch;
try { try {

View File

@ -1,5 +1,5 @@
/* globals expect, it, describe, Dict, Name, Annotation, AnnotationBorderStyle, /* globals expect, it, describe, Dict, Name, Annotation, AnnotationBorderStyle,
AnnotationBorderStyleType, AnnotationFlag, PDFJS, combineUrl, AnnotationBorderStyleType, AnnotationFlag, PDFJS,
beforeEach, afterEach, stringToBytes */ beforeEach, afterEach, stringToBytes */
'use strict'; 'use strict';
@ -179,8 +179,8 @@ describe('Annotation layer', function() {
var annotations; var annotations;
beforeEach(function(done) { beforeEach(function(done) {
var pdfUrl = combineUrl(window.location.href, var pdfUrl = new URL('../pdfs/annotation-fileattachment.pdf',
'../pdfs/annotation-fileattachment.pdf'); window.location).href;
loadingTask = PDFJS.getDocument(pdfUrl); loadingTask = PDFJS.getDocument(pdfUrl);
loadingTask.promise.then(function(pdfDocument) { loadingTask.promise.then(function(pdfDocument) {
return pdfDocument.getPage(1).then(function(pdfPage) { return pdfDocument.getPage(1).then(function(pdfPage) {

View File

@ -1,67 +1,9 @@
/* globals expect, it, describe, combineUrl, Dict, isDict, Name, PDFJS, /* globals expect, it, describe, Dict, isDict, Name, PDFJS,
stringToPDFString, removeNullCharacters */ stringToPDFString, removeNullCharacters */
'use strict'; 'use strict';
describe('util', function() { describe('util', function() {
describe('combineUrl', function() {
it('absolute url with protocol stays as is', function() {
var baseUrl = 'http://server/index.html';
var url = 'http://server2/test2.html';
var result = combineUrl(baseUrl, url);
var expected = 'http://server2/test2.html';
expect(result).toEqual(expected);
});
it('absolute url without protocol uses prefix from base', function() {
var baseUrl = 'http://server/index.html';
var url = '/test2.html';
var result = combineUrl(baseUrl, url);
var expected = 'http://server/test2.html';
expect(result).toEqual(expected);
});
it('combines relative url with base', function() {
var baseUrl = 'http://server/index.html';
var url = 'test2.html';
var result = combineUrl(baseUrl, url);
var expected = 'http://server/test2.html';
expect(result).toEqual(expected);
});
it('combines relative url (w/hash) with base', function() {
var baseUrl = 'http://server/index.html#!/test';
var url = 'test2.html';
var result = combineUrl(baseUrl, url);
var expected = 'http://server/test2.html';
expect(result).toEqual(expected);
});
it('combines relative url (w/query) with base', function() {
var baseUrl = 'http://server/index.html?search=/test';
var url = 'test2.html';
var result = combineUrl(baseUrl, url);
var expected = 'http://server/test2.html';
expect(result).toEqual(expected);
});
it('returns base url when url is empty', function() {
var baseUrl = 'http://server/index.html';
var url = '';
var result = combineUrl(baseUrl, url);
var expected = 'http://server/index.html';
expect(result).toEqual(expected);
});
it('returns base url when url is undefined', function() {
var baseUrl = 'http://server/index.html';
var url;
var result = combineUrl(baseUrl, url);
var expected = 'http://server/index.html';
expect(result).toEqual(expected);
});
});
describe('isDict', function() { describe('isDict', function() {
it('handles empty dictionaries with type check', function() { it('handles empty dictionaries with type check', function() {
var dict = new Dict(); var dict = new Dict();