Merge pull request #13246 from timvandermeij/unit-test-async-await-pt2
Convert done callbacks to async/await in more unit test files
This commit is contained in:
commit
cba6a3f375
@ -17,7 +17,7 @@ import { AnnotationStorage } from "../../src/display/annotation_storage.js";
|
||||
|
||||
describe("AnnotationStorage", function () {
|
||||
describe("GetOrDefaultValue", function () {
|
||||
it("should get and set a new value in the annotation storage", function (done) {
|
||||
it("should get and set a new value in the annotation storage", function () {
|
||||
const annotationStorage = new AnnotationStorage();
|
||||
let value = annotationStorage.getValue("123A", {
|
||||
value: "hello world",
|
||||
@ -34,20 +34,18 @@ describe("AnnotationStorage", function () {
|
||||
value: "an other string",
|
||||
}).value;
|
||||
expect(value).toEqual("hello world");
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
describe("SetValue", function () {
|
||||
it("should set a new value in the annotation storage", function (done) {
|
||||
it("should set a new value in the annotation storage", function () {
|
||||
const annotationStorage = new AnnotationStorage();
|
||||
annotationStorage.setValue("123A", { value: "an other string" });
|
||||
const value = annotationStorage.getAll()["123A"].value;
|
||||
expect(value).toEqual("an other string");
|
||||
done();
|
||||
});
|
||||
|
||||
it("should call onSetModified() if value is changed", function (done) {
|
||||
it("should call onSetModified() if value is changed", function () {
|
||||
const annotationStorage = new AnnotationStorage();
|
||||
let called = false;
|
||||
const callback = function () {
|
||||
@ -66,12 +64,11 @@ describe("AnnotationStorage", function () {
|
||||
called = false;
|
||||
annotationStorage.setValue("asdf", { value: "modified" });
|
||||
expect(called).toBe(false);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
describe("ResetModified", function () {
|
||||
it("should call onResetModified() if set", function (done) {
|
||||
it("should call onResetModified() if set", function () {
|
||||
const annotationStorage = new AnnotationStorage();
|
||||
let called = false;
|
||||
const callback = function () {
|
||||
@ -92,7 +89,6 @@ describe("AnnotationStorage", function () {
|
||||
annotationStorage.setValue("asdf", { value: "modified" });
|
||||
annotationStorage.resetModified();
|
||||
expect(called).toBe(true);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -40,109 +40,77 @@ describe("cmap", function () {
|
||||
fetchBuiltInCMap = null;
|
||||
});
|
||||
|
||||
it("parses beginbfchar", function (done) {
|
||||
it("parses beginbfchar", async function () {
|
||||
// prettier-ignore
|
||||
const str = "2 beginbfchar\n" +
|
||||
"<03> <00>\n" +
|
||||
"<04> <01>\n" +
|
||||
"endbfchar\n";
|
||||
const stream = new StringStream(str);
|
||||
const cmapPromise = CMapFactory.create({ encoding: stream });
|
||||
cmapPromise
|
||||
.then(function (cmap) {
|
||||
const cmap = await CMapFactory.create({ encoding: stream });
|
||||
expect(cmap.lookup(0x03)).toEqual(String.fromCharCode(0x00));
|
||||
expect(cmap.lookup(0x04)).toEqual(String.fromCharCode(0x01));
|
||||
expect(cmap.lookup(0x05)).toBeUndefined();
|
||||
done();
|
||||
})
|
||||
.catch(function (reason) {
|
||||
done.fail(reason);
|
||||
});
|
||||
});
|
||||
it("parses beginbfrange with range", function (done) {
|
||||
|
||||
it("parses beginbfrange with range", async function () {
|
||||
// prettier-ignore
|
||||
const str = "1 beginbfrange\n" +
|
||||
"<06> <0B> 0\n" +
|
||||
"endbfrange\n";
|
||||
const stream = new StringStream(str);
|
||||
const cmapPromise = CMapFactory.create({ encoding: stream });
|
||||
cmapPromise
|
||||
.then(function (cmap) {
|
||||
const cmap = await CMapFactory.create({ encoding: stream });
|
||||
expect(cmap.lookup(0x05)).toBeUndefined();
|
||||
expect(cmap.lookup(0x06)).toEqual(String.fromCharCode(0x00));
|
||||
expect(cmap.lookup(0x0b)).toEqual(String.fromCharCode(0x05));
|
||||
expect(cmap.lookup(0x0c)).toBeUndefined();
|
||||
done();
|
||||
})
|
||||
.catch(function (reason) {
|
||||
done.fail(reason);
|
||||
});
|
||||
});
|
||||
it("parses beginbfrange with array", function (done) {
|
||||
|
||||
it("parses beginbfrange with array", async function () {
|
||||
// prettier-ignore
|
||||
const str = "1 beginbfrange\n" +
|
||||
"<0D> <12> [ 0 1 2 3 4 5 ]\n" +
|
||||
"endbfrange\n";
|
||||
const stream = new StringStream(str);
|
||||
const cmapPromise = CMapFactory.create({ encoding: stream });
|
||||
cmapPromise
|
||||
.then(function (cmap) {
|
||||
const cmap = await CMapFactory.create({ encoding: stream });
|
||||
expect(cmap.lookup(0x0c)).toBeUndefined();
|
||||
expect(cmap.lookup(0x0d)).toEqual(0x00);
|
||||
expect(cmap.lookup(0x12)).toEqual(0x05);
|
||||
expect(cmap.lookup(0x13)).toBeUndefined();
|
||||
done();
|
||||
})
|
||||
.catch(function (reason) {
|
||||
done.fail(reason);
|
||||
});
|
||||
});
|
||||
it("parses begincidchar", function (done) {
|
||||
|
||||
it("parses begincidchar", async function () {
|
||||
// prettier-ignore
|
||||
const str = "1 begincidchar\n" +
|
||||
"<14> 0\n" +
|
||||
"endcidchar\n";
|
||||
const stream = new StringStream(str);
|
||||
const cmapPromise = CMapFactory.create({ encoding: stream });
|
||||
cmapPromise
|
||||
.then(function (cmap) {
|
||||
const cmap = await CMapFactory.create({ encoding: stream });
|
||||
expect(cmap.lookup(0x14)).toEqual(0x00);
|
||||
expect(cmap.lookup(0x15)).toBeUndefined();
|
||||
done();
|
||||
})
|
||||
.catch(function (reason) {
|
||||
done.fail(reason);
|
||||
});
|
||||
});
|
||||
it("parses begincidrange", function (done) {
|
||||
|
||||
it("parses begincidrange", async function () {
|
||||
// prettier-ignore
|
||||
const str = "1 begincidrange\n" +
|
||||
"<0016> <001B> 0\n" +
|
||||
"endcidrange\n";
|
||||
const stream = new StringStream(str);
|
||||
const cmapPromise = CMapFactory.create({ encoding: stream });
|
||||
cmapPromise
|
||||
.then(function (cmap) {
|
||||
const cmap = await CMapFactory.create({ encoding: stream });
|
||||
expect(cmap.lookup(0x15)).toBeUndefined();
|
||||
expect(cmap.lookup(0x16)).toEqual(0x00);
|
||||
expect(cmap.lookup(0x1b)).toEqual(0x05);
|
||||
expect(cmap.lookup(0x1c)).toBeUndefined();
|
||||
done();
|
||||
})
|
||||
.catch(function (reason) {
|
||||
done.fail(reason);
|
||||
});
|
||||
});
|
||||
it("decodes codespace ranges", function (done) {
|
||||
|
||||
it("decodes codespace ranges", async function () {
|
||||
// prettier-ignore
|
||||
const str = "1 begincodespacerange\n" +
|
||||
"<01> <02>\n" +
|
||||
"<00000003> <00000004>\n" +
|
||||
"endcodespacerange\n";
|
||||
const stream = new StringStream(str);
|
||||
const cmapPromise = CMapFactory.create({ encoding: stream });
|
||||
cmapPromise
|
||||
.then(function (cmap) {
|
||||
const cmap = await CMapFactory.create({ encoding: stream });
|
||||
const c = {};
|
||||
cmap.readCharCode(String.fromCharCode(1), 0, c);
|
||||
expect(c.charcode).toEqual(1);
|
||||
@ -150,195 +118,140 @@ describe("cmap", function () {
|
||||
cmap.readCharCode(String.fromCharCode(0, 0, 0, 3), 0, c);
|
||||
expect(c.charcode).toEqual(3);
|
||||
expect(c.length).toEqual(4);
|
||||
done();
|
||||
})
|
||||
.catch(function (reason) {
|
||||
done.fail(reason);
|
||||
});
|
||||
});
|
||||
it("decodes 4 byte codespace ranges", function (done) {
|
||||
|
||||
it("decodes 4 byte codespace ranges", async function () {
|
||||
// prettier-ignore
|
||||
const str = "1 begincodespacerange\n" +
|
||||
"<8EA1A1A1> <8EA1FEFE>\n" +
|
||||
"endcodespacerange\n";
|
||||
const stream = new StringStream(str);
|
||||
const cmapPromise = CMapFactory.create({ encoding: stream });
|
||||
cmapPromise
|
||||
.then(function (cmap) {
|
||||
const cmap = await CMapFactory.create({ encoding: stream });
|
||||
const c = {};
|
||||
cmap.readCharCode(String.fromCharCode(0x8e, 0xa1, 0xa1, 0xa1), 0, c);
|
||||
expect(c.charcode).toEqual(0x8ea1a1a1);
|
||||
expect(c.length).toEqual(4);
|
||||
done();
|
||||
})
|
||||
.catch(function (reason) {
|
||||
done.fail(reason);
|
||||
});
|
||||
});
|
||||
it("read usecmap", function (done) {
|
||||
|
||||
it("read usecmap", async function () {
|
||||
const str = "/Adobe-Japan1-1 usecmap\n";
|
||||
const stream = new StringStream(str);
|
||||
const cmapPromise = CMapFactory.create({
|
||||
const cmap = await CMapFactory.create({
|
||||
encoding: stream,
|
||||
fetchBuiltInCMap,
|
||||
useCMap: null,
|
||||
});
|
||||
cmapPromise
|
||||
.then(function (cmap) {
|
||||
expect(cmap instanceof CMap).toEqual(true);
|
||||
expect(cmap.useCMap).not.toBeNull();
|
||||
expect(cmap.builtInCMap).toBeFalsy();
|
||||
expect(cmap.length).toEqual(0x20a7);
|
||||
expect(cmap.isIdentityCMap).toEqual(false);
|
||||
done();
|
||||
})
|
||||
.catch(function (reason) {
|
||||
done.fail(reason);
|
||||
});
|
||||
});
|
||||
it("parses cmapname", function (done) {
|
||||
|
||||
it("parses cmapname", async function () {
|
||||
const str = "/CMapName /Identity-H def\n";
|
||||
const stream = new StringStream(str);
|
||||
const cmapPromise = CMapFactory.create({ encoding: stream });
|
||||
cmapPromise
|
||||
.then(function (cmap) {
|
||||
const cmap = await CMapFactory.create({ encoding: stream });
|
||||
expect(cmap.name).toEqual("Identity-H");
|
||||
done();
|
||||
})
|
||||
.catch(function (reason) {
|
||||
done.fail(reason);
|
||||
});
|
||||
});
|
||||
it("parses wmode", function (done) {
|
||||
|
||||
it("parses wmode", async function () {
|
||||
const str = "/WMode 1 def\n";
|
||||
const stream = new StringStream(str);
|
||||
const cmapPromise = CMapFactory.create({ encoding: stream });
|
||||
cmapPromise
|
||||
.then(function (cmap) {
|
||||
const cmap = await CMapFactory.create({ encoding: stream });
|
||||
expect(cmap.vertical).toEqual(true);
|
||||
done();
|
||||
})
|
||||
.catch(function (reason) {
|
||||
done.fail(reason);
|
||||
});
|
||||
});
|
||||
it("loads built in cmap", function (done) {
|
||||
const cmapPromise = CMapFactory.create({
|
||||
|
||||
it("loads built in cmap", async function () {
|
||||
const cmap = await CMapFactory.create({
|
||||
encoding: Name.get("Adobe-Japan1-1"),
|
||||
fetchBuiltInCMap,
|
||||
useCMap: null,
|
||||
});
|
||||
cmapPromise
|
||||
.then(function (cmap) {
|
||||
expect(cmap instanceof CMap).toEqual(true);
|
||||
expect(cmap.useCMap).toBeNull();
|
||||
expect(cmap.builtInCMap).toBeTruthy();
|
||||
expect(cmap.length).toEqual(0x20a7);
|
||||
expect(cmap.isIdentityCMap).toEqual(false);
|
||||
done();
|
||||
})
|
||||
.catch(function (reason) {
|
||||
done.fail(reason);
|
||||
});
|
||||
});
|
||||
it("loads built in identity cmap", function (done) {
|
||||
const cmapPromise = CMapFactory.create({
|
||||
|
||||
it("loads built in identity cmap", async function () {
|
||||
const cmap = await CMapFactory.create({
|
||||
encoding: Name.get("Identity-H"),
|
||||
fetchBuiltInCMap,
|
||||
useCMap: null,
|
||||
});
|
||||
cmapPromise
|
||||
.then(function (cmap) {
|
||||
expect(cmap instanceof IdentityCMap).toEqual(true);
|
||||
expect(cmap.vertical).toEqual(false);
|
||||
expect(cmap.length).toEqual(0x10000);
|
||||
expect(function () {
|
||||
return cmap.isIdentityCMap;
|
||||
}).toThrow(new Error("should not access .isIdentityCMap"));
|
||||
done();
|
||||
})
|
||||
.catch(function (reason) {
|
||||
done.fail(reason);
|
||||
});
|
||||
});
|
||||
|
||||
it("attempts to load a non-existent built-in CMap", function (done) {
|
||||
const cmapPromise = CMapFactory.create({
|
||||
it("attempts to load a non-existent built-in CMap", async function () {
|
||||
try {
|
||||
await CMapFactory.create({
|
||||
encoding: Name.get("null"),
|
||||
fetchBuiltInCMap,
|
||||
useCMap: null,
|
||||
});
|
||||
cmapPromise.then(
|
||||
function () {
|
||||
done.fail("No CMap should be loaded");
|
||||
},
|
||||
function (reason) {
|
||||
|
||||
// Shouldn't get here.
|
||||
expect(false).toEqual(true);
|
||||
} catch (reason) {
|
||||
expect(reason instanceof Error).toEqual(true);
|
||||
expect(reason.message).toEqual("Unknown CMap name: null");
|
||||
done();
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
it("attempts to load a built-in CMap without the necessary API parameters", function (done) {
|
||||
it("attempts to load a built-in CMap without the necessary API parameters", async function () {
|
||||
function tmpFetchBuiltInCMap(name) {
|
||||
const CMapReaderFactory = new DefaultCMapReaderFactory({});
|
||||
|
||||
return CMapReaderFactory.fetch({
|
||||
name,
|
||||
});
|
||||
return CMapReaderFactory.fetch({ name });
|
||||
}
|
||||
|
||||
const cmapPromise = CMapFactory.create({
|
||||
try {
|
||||
await CMapFactory.create({
|
||||
encoding: Name.get("Adobe-Japan1-1"),
|
||||
fetchBuiltInCMap: tmpFetchBuiltInCMap,
|
||||
useCMap: null,
|
||||
});
|
||||
cmapPromise.then(
|
||||
function () {
|
||||
done.fail("No CMap should be loaded");
|
||||
},
|
||||
function (reason) {
|
||||
|
||||
// Shouldn't get here.
|
||||
expect(false).toEqual(true);
|
||||
} catch (reason) {
|
||||
expect(reason instanceof Error).toEqual(true);
|
||||
expect(reason.message).toEqual(
|
||||
'The CMap "baseUrl" parameter must be specified, ensure that ' +
|
||||
'the "cMapUrl" and "cMapPacked" API parameters are provided.'
|
||||
);
|
||||
done();
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
it("attempts to load a built-in CMap with inconsistent API parameters", function (done) {
|
||||
it("attempts to load a built-in CMap with inconsistent API parameters", async function () {
|
||||
function tmpFetchBuiltInCMap(name) {
|
||||
const CMapReaderFactory = new DefaultCMapReaderFactory({
|
||||
baseUrl: CMAP_PARAMS.cMapUrl,
|
||||
isCompressed: false,
|
||||
});
|
||||
|
||||
return CMapReaderFactory.fetch({
|
||||
name,
|
||||
});
|
||||
return CMapReaderFactory.fetch({ name });
|
||||
}
|
||||
|
||||
const cmapPromise = CMapFactory.create({
|
||||
try {
|
||||
await CMapFactory.create({
|
||||
encoding: Name.get("Adobe-Japan1-1"),
|
||||
fetchBuiltInCMap: tmpFetchBuiltInCMap,
|
||||
useCMap: null,
|
||||
});
|
||||
cmapPromise.then(
|
||||
function () {
|
||||
done.fail("No CMap should be loaded");
|
||||
},
|
||||
function (reason) {
|
||||
|
||||
// Shouldn't get here.
|
||||
expect(false).toEqual(true);
|
||||
} catch (reason) {
|
||||
expect(reason instanceof Error).toEqual(true);
|
||||
const message = reason.message;
|
||||
expect(message.startsWith("Unable to load CMap at: ")).toEqual(true);
|
||||
expect(message.endsWith("/external/bcmaps/Adobe-Japan1-1")).toEqual(
|
||||
true
|
||||
);
|
||||
done();
|
||||
expect(message.endsWith("/external/bcmaps/Adobe-Japan1-1")).toEqual(true);
|
||||
}
|
||||
);
|
||||
});
|
||||
});
|
||||
|
@ -588,43 +588,40 @@ describe("CipherTransformFactory", function () {
|
||||
return dict;
|
||||
}
|
||||
|
||||
function ensurePasswordCorrect(done, dict, fileId, password) {
|
||||
function ensurePasswordCorrect(dict, fileId, password) {
|
||||
try {
|
||||
const factory = new CipherTransformFactory(dict, fileId, password);
|
||||
expect("createCipherTransform" in factory).toEqual(true);
|
||||
} catch (ex) {
|
||||
done.fail("Password should be accepted: " + ex);
|
||||
return;
|
||||
// Shouldn't get here.
|
||||
expect(false).toEqual(true);
|
||||
}
|
||||
done();
|
||||
}
|
||||
|
||||
function ensurePasswordNeeded(done, dict, fileId, password) {
|
||||
function ensurePasswordNeeded(dict, fileId, password) {
|
||||
try {
|
||||
// eslint-disable-next-line no-new
|
||||
new CipherTransformFactory(dict, fileId, password);
|
||||
|
||||
// Shouldn't get here.
|
||||
expect(false).toEqual(true);
|
||||
} catch (ex) {
|
||||
expect(ex instanceof PasswordException).toEqual(true);
|
||||
expect(ex.code).toEqual(PasswordResponses.NEED_PASSWORD);
|
||||
|
||||
done();
|
||||
return;
|
||||
}
|
||||
done.fail("Password should be rejected.");
|
||||
}
|
||||
|
||||
function ensurePasswordIncorrect(done, dict, fileId, password) {
|
||||
function ensurePasswordIncorrect(dict, fileId, password) {
|
||||
try {
|
||||
// eslint-disable-next-line no-new
|
||||
new CipherTransformFactory(dict, fileId, password);
|
||||
|
||||
// Shouldn't get here.
|
||||
expect(false).toEqual(true);
|
||||
} catch (ex) {
|
||||
expect(ex instanceof PasswordException).toEqual(true);
|
||||
expect(ex.code).toEqual(PasswordResponses.INCORRECT_PASSWORD);
|
||||
|
||||
done();
|
||||
return;
|
||||
}
|
||||
done.fail("Password should be rejected.");
|
||||
}
|
||||
|
||||
function ensureEncryptDecryptIsIdentity(dict, fileId, password, string) {
|
||||
@ -784,55 +781,55 @@ describe("CipherTransformFactory", function () {
|
||||
|
||||
describe("#ctor", function () {
|
||||
describe("AES256 Revision 5", function () {
|
||||
it("should accept user password", function (done) {
|
||||
ensurePasswordCorrect(done, aes256Dict, fileId1, "user");
|
||||
it("should accept user password", function () {
|
||||
ensurePasswordCorrect(aes256Dict, fileId1, "user");
|
||||
});
|
||||
it("should accept owner password", function (done) {
|
||||
ensurePasswordCorrect(done, aes256Dict, fileId1, "owner");
|
||||
it("should accept owner password", function () {
|
||||
ensurePasswordCorrect(aes256Dict, fileId1, "owner");
|
||||
});
|
||||
it("should not accept blank password", function (done) {
|
||||
ensurePasswordNeeded(done, aes256Dict, fileId1);
|
||||
it("should not accept blank password", function () {
|
||||
ensurePasswordNeeded(aes256Dict, fileId1);
|
||||
});
|
||||
it("should not accept wrong password", function (done) {
|
||||
ensurePasswordIncorrect(done, aes256Dict, fileId1, "wrong");
|
||||
it("should not accept wrong password", function () {
|
||||
ensurePasswordIncorrect(aes256Dict, fileId1, "wrong");
|
||||
});
|
||||
it("should accept blank password", function (done) {
|
||||
ensurePasswordCorrect(done, aes256BlankDict, fileId1);
|
||||
it("should accept blank password", function () {
|
||||
ensurePasswordCorrect(aes256BlankDict, fileId1);
|
||||
});
|
||||
});
|
||||
|
||||
describe("AES256 Revision 6", function () {
|
||||
it("should accept user password", function (done) {
|
||||
ensurePasswordCorrect(done, aes256IsoDict, fileId1, "user");
|
||||
it("should accept user password", function () {
|
||||
ensurePasswordCorrect(aes256IsoDict, fileId1, "user");
|
||||
});
|
||||
it("should accept owner password", function (done) {
|
||||
ensurePasswordCorrect(done, aes256IsoDict, fileId1, "owner");
|
||||
it("should accept owner password", function () {
|
||||
ensurePasswordCorrect(aes256IsoDict, fileId1, "owner");
|
||||
});
|
||||
it("should not accept blank password", function (done) {
|
||||
ensurePasswordNeeded(done, aes256IsoDict, fileId1);
|
||||
it("should not accept blank password", function () {
|
||||
ensurePasswordNeeded(aes256IsoDict, fileId1);
|
||||
});
|
||||
it("should not accept wrong password", function (done) {
|
||||
ensurePasswordIncorrect(done, aes256IsoDict, fileId1, "wrong");
|
||||
it("should not accept wrong password", function () {
|
||||
ensurePasswordIncorrect(aes256IsoDict, fileId1, "wrong");
|
||||
});
|
||||
it("should accept blank password", function (done) {
|
||||
ensurePasswordCorrect(done, aes256IsoBlankDict, fileId1);
|
||||
it("should accept blank password", function () {
|
||||
ensurePasswordCorrect(aes256IsoBlankDict, fileId1);
|
||||
});
|
||||
});
|
||||
|
||||
it("should accept user password", function (done) {
|
||||
ensurePasswordCorrect(done, dict1, fileId1, "123456");
|
||||
it("should accept user password", function () {
|
||||
ensurePasswordCorrect(dict1, fileId1, "123456");
|
||||
});
|
||||
it("should accept owner password", function (done) {
|
||||
ensurePasswordCorrect(done, dict1, fileId1, "654321");
|
||||
it("should accept owner password", function () {
|
||||
ensurePasswordCorrect(dict1, fileId1, "654321");
|
||||
});
|
||||
it("should not accept blank password", function (done) {
|
||||
ensurePasswordNeeded(done, dict1, fileId1);
|
||||
it("should not accept blank password", function () {
|
||||
ensurePasswordNeeded(dict1, fileId1);
|
||||
});
|
||||
it("should not accept wrong password", function (done) {
|
||||
ensurePasswordIncorrect(done, dict1, fileId1, "wrong");
|
||||
it("should not accept wrong password", function () {
|
||||
ensurePasswordIncorrect(dict1, fileId1, "wrong");
|
||||
});
|
||||
it("should accept blank password", function (done) {
|
||||
ensurePasswordCorrect(done, dict2, fileId2);
|
||||
it("should accept blank password", function () {
|
||||
ensurePasswordCorrect(dict2, fileId2);
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -59,17 +59,15 @@ function withZlib(isZlibRequired, callback) {
|
||||
describe("SVGGraphics", function () {
|
||||
let loadingTask;
|
||||
let page;
|
||||
beforeAll(function (done) {
|
||||
|
||||
beforeAll(async function () {
|
||||
loadingTask = getDocument(buildGetDocumentParams("xobject-image.pdf"));
|
||||
loadingTask.promise.then(function (doc) {
|
||||
doc.getPage(1).then(function (firstPage) {
|
||||
page = firstPage;
|
||||
done();
|
||||
const doc = await loadingTask.promise;
|
||||
page = await doc.getPage(1);
|
||||
});
|
||||
});
|
||||
});
|
||||
afterAll(function (done) {
|
||||
loadingTask.destroy().then(done);
|
||||
|
||||
afterAll(async function () {
|
||||
await loadingTask.destroy();
|
||||
});
|
||||
|
||||
describe("paintImageXObject", function () {
|
||||
@ -129,12 +127,11 @@ describe("SVGGraphics", function () {
|
||||
}
|
||||
});
|
||||
|
||||
it("should produce a reasonably small svg:image", function (done) {
|
||||
it("should produce a reasonably small svg:image", async function () {
|
||||
if (!isNodeJS) {
|
||||
pending("zlib.deflateSync is not supported in non-Node environments.");
|
||||
}
|
||||
withZlib(true, getSVGImage)
|
||||
.then(function (svgImg) {
|
||||
const svgImg = await withZlib(true, getSVGImage);
|
||||
expect(svgImg.nodeName).toBe("svg:image");
|
||||
expect(svgImg.getAttributeNS(null, "width")).toBe("200px");
|
||||
expect(svgImg.getAttributeNS(null, "height")).toBe("100px");
|
||||
@ -146,13 +143,10 @@ describe("SVGGraphics", function () {
|
||||
// Without zlib (uncompressed), the size of the data URL was excessive
|
||||
// (80246).
|
||||
expect(imgUrl.length).toBeLessThan(367);
|
||||
})
|
||||
.then(done, done.fail);
|
||||
});
|
||||
|
||||
it("should be able to produce a svg:image without zlib", function (done) {
|
||||
withZlib(false, getSVGImage)
|
||||
.then(function (svgImg) {
|
||||
it("should be able to produce a svg:image without zlib", async function () {
|
||||
const svgImg = await withZlib(false, getSVGImage);
|
||||
expect(svgImg.nodeName).toBe("svg:image");
|
||||
expect(svgImg.getAttributeNS(null, "width")).toBe("200px");
|
||||
expect(svgImg.getAttributeNS(null, "height")).toBe("100px");
|
||||
@ -160,8 +154,6 @@ describe("SVGGraphics", function () {
|
||||
expect(imgUrl).toMatch(/^data:image\/png;base64,/);
|
||||
// The size of our naively generated PNG file is excessive :(
|
||||
expect(imgUrl.length).toBe(80246);
|
||||
})
|
||||
.then(done, done.fail);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -39,7 +39,7 @@ describe("message_handler", function () {
|
||||
expect(typeof readable.getReader).toEqual("function");
|
||||
});
|
||||
|
||||
it("should read using a reader", function (done) {
|
||||
it("should read using a reader", async function () {
|
||||
let log = "";
|
||||
const port = new LoopbackPort();
|
||||
const messageHandler1 = new MessageHandler("main", "worker", port);
|
||||
@ -71,29 +71,23 @@ describe("message_handler", function () {
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
const reader = readable.getReader();
|
||||
sleep(10)
|
||||
.then(() => {
|
||||
await sleep(10);
|
||||
expect(log).toEqual("");
|
||||
return reader.read();
|
||||
})
|
||||
.then(result => {
|
||||
|
||||
let result = await reader.read();
|
||||
expect(log).toEqual("p");
|
||||
expect(result.value).toEqual("hi");
|
||||
expect(result.done).toEqual(false);
|
||||
return sleep(10);
|
||||
})
|
||||
.then(() => {
|
||||
return reader.read();
|
||||
})
|
||||
.then(result => {
|
||||
|
||||
await sleep(10);
|
||||
result = await reader.read();
|
||||
expect(result.value).toEqual(undefined);
|
||||
expect(result.done).toEqual(true);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it("should not read any data when cancelled", function (done) {
|
||||
it("should not read any data when cancelled", async function () {
|
||||
let log = "";
|
||||
const port = new LoopbackPort();
|
||||
const messageHandler2 = new MessageHandler("worker", "main", port);
|
||||
@ -139,27 +133,21 @@ describe("message_handler", function () {
|
||||
);
|
||||
|
||||
const reader = readable.getReader();
|
||||
sleep(10)
|
||||
.then(() => {
|
||||
await sleep(10);
|
||||
expect(log).toEqual("01");
|
||||
return reader.read();
|
||||
})
|
||||
.then(result => {
|
||||
|
||||
const result = await reader.read();
|
||||
expect(result.value).toEqual([1, 2, 3, 4]);
|
||||
expect(result.done).toEqual(false);
|
||||
return sleep(10);
|
||||
})
|
||||
.then(() => {
|
||||
|
||||
await sleep(10);
|
||||
expect(log).toEqual("01p2");
|
||||
return reader.cancel(new AbortException("reader cancelled."));
|
||||
})
|
||||
.then(() => {
|
||||
|
||||
await reader.cancel(new AbortException("reader cancelled."));
|
||||
expect(log).toEqual("01p2c4");
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it("should not read when errored", function (done) {
|
||||
it("should not read when errored", async function () {
|
||||
let log = "";
|
||||
const port = new LoopbackPort();
|
||||
const messageHandler2 = new MessageHandler("worker", "main", port);
|
||||
@ -195,26 +183,26 @@ describe("message_handler", function () {
|
||||
);
|
||||
|
||||
const reader = readable.getReader();
|
||||
|
||||
sleep(10)
|
||||
.then(() => {
|
||||
await sleep(10);
|
||||
expect(log).toEqual("01");
|
||||
return reader.read();
|
||||
})
|
||||
.then(result => {
|
||||
|
||||
const result = await reader.read();
|
||||
expect(result.value).toEqual([1, 2, 3, 4]);
|
||||
expect(result.done).toEqual(false);
|
||||
return reader.read();
|
||||
})
|
||||
.catch(reason => {
|
||||
|
||||
try {
|
||||
await reader.read();
|
||||
|
||||
// Shouldn't get here.
|
||||
expect(false).toEqual(true);
|
||||
} catch (reason) {
|
||||
expect(log).toEqual("01pe");
|
||||
expect(reason instanceof UnknownErrorException).toEqual(true);
|
||||
expect(reason.message).toEqual("should not read when errored");
|
||||
done();
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
it("should read data with blocking promise", function (done) {
|
||||
it("should read data with blocking promise", async function () {
|
||||
let log = "";
|
||||
const port = new LoopbackPort();
|
||||
const messageHandler2 = new MessageHandler("worker", "main", port);
|
||||
@ -257,40 +245,32 @@ describe("message_handler", function () {
|
||||
const reader = readable.getReader();
|
||||
// Sleep for 10ms, so that read() is not unblocking the ready promise.
|
||||
// Chain all read() to stream in sequence.
|
||||
sleep(10)
|
||||
.then(() => {
|
||||
await sleep(10);
|
||||
expect(log).toEqual("01");
|
||||
return reader.read();
|
||||
})
|
||||
.then(result => {
|
||||
|
||||
let result = await reader.read();
|
||||
expect(result.value).toEqual([1, 2, 3, 4]);
|
||||
expect(result.done).toEqual(false);
|
||||
return sleep(10);
|
||||
})
|
||||
.then(() => {
|
||||
|
||||
await sleep(10);
|
||||
expect(log).toEqual("01p2");
|
||||
return reader.read();
|
||||
})
|
||||
.then(result => {
|
||||
|
||||
result = await reader.read();
|
||||
expect(result.value).toEqual([5, 6, 7, 8]);
|
||||
expect(result.done).toEqual(false);
|
||||
return sleep(10);
|
||||
})
|
||||
.then(() => {
|
||||
|
||||
await sleep(10);
|
||||
expect(log).toEqual("01p2p");
|
||||
return reader.read();
|
||||
})
|
||||
.then(result => {
|
||||
|
||||
result = await reader.read();
|
||||
expect(result.value).toEqual(undefined);
|
||||
expect(result.done).toEqual(true);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it(
|
||||
"should read data with blocking promise and buffer whole data" +
|
||||
" into stream",
|
||||
function (done) {
|
||||
async function () {
|
||||
let log = "";
|
||||
const port = new LoopbackPort();
|
||||
const messageHandler2 = new MessageHandler("worker", "main", port);
|
||||
@ -332,39 +312,30 @@ describe("message_handler", function () {
|
||||
);
|
||||
|
||||
const reader = readable.getReader();
|
||||
|
||||
sleep(10)
|
||||
.then(() => {
|
||||
await sleep(10);
|
||||
expect(log).toEqual("012");
|
||||
return reader.read();
|
||||
})
|
||||
.then(result => {
|
||||
|
||||
let result = await reader.read();
|
||||
expect(result.value).toEqual([1, 2, 3, 4]);
|
||||
expect(result.done).toEqual(false);
|
||||
return sleep(10);
|
||||
})
|
||||
.then(() => {
|
||||
|
||||
await sleep(10);
|
||||
expect(log).toEqual("012p");
|
||||
return reader.read();
|
||||
})
|
||||
.then(result => {
|
||||
|
||||
result = await reader.read();
|
||||
expect(result.value).toEqual([5, 6, 7, 8]);
|
||||
expect(result.done).toEqual(false);
|
||||
return sleep(10);
|
||||
})
|
||||
.then(() => {
|
||||
|
||||
await sleep(10);
|
||||
expect(log).toEqual("012p");
|
||||
return reader.read();
|
||||
})
|
||||
.then(result => {
|
||||
|
||||
result = await reader.read();
|
||||
expect(result.value).toEqual(undefined);
|
||||
expect(result.done).toEqual(true);
|
||||
done();
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
it("should ignore any pull after close is called", function (done) {
|
||||
it("should ignore any pull after close is called", async function () {
|
||||
let log = "";
|
||||
const port = new LoopbackPort();
|
||||
const capability = createPromiseCapability();
|
||||
@ -399,29 +370,22 @@ describe("message_handler", function () {
|
||||
);
|
||||
|
||||
const reader = readable.getReader();
|
||||
|
||||
sleep(10)
|
||||
.then(() => {
|
||||
await sleep(10);
|
||||
expect(log).toEqual("01");
|
||||
|
||||
capability.resolve();
|
||||
return capability.promise.then(() => {
|
||||
return reader.read();
|
||||
});
|
||||
})
|
||||
.then(result => {
|
||||
await capability.promise;
|
||||
|
||||
let result = await reader.read();
|
||||
expect(result.value).toEqual([1, 2, 3, 4]);
|
||||
expect(result.done).toEqual(false);
|
||||
return sleep(10);
|
||||
})
|
||||
.then(() => {
|
||||
|
||||
await sleep(10);
|
||||
expect(log).toEqual("01");
|
||||
return reader.read();
|
||||
})
|
||||
.then(result => {
|
||||
|
||||
result = await reader.read();
|
||||
expect(result.value).toEqual(undefined);
|
||||
expect(result.done).toEqual(true);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user