for (let i = 0; i < layers.length; i++) {
await ContentTaskUtils.waitForCondition(
() =>
layers[i].every(
name =>
!!document.querySelector(
`.page[data-page-number='${i + 1}'] .${name}`
)
),
`All the layers must be displayed on page ${i}`
);
}
});
/** * The text layer contains some spans with the text of the pdf. * @param {Object} browser * @param {string} text * @returns {Object} the bbox of the span containing the text.
*/
async function getSpanBox(browser, text, pageNumber = 1) { return SpecialPowers.spawn(
browser,
[text, pageNumber],
async function (text, number) { const { ContentTaskUtils } = ChromeUtils.importESModule( "resource://testing-common/ContentTaskUtils.sys.mjs"
); const { document } = content;
await ContentTaskUtils.waitForCondition(
() =>
!!document.querySelector(
`.page[data-page-number='${number}'] .textLayer .endOfContent`
), "The text layer must be displayed"
);
let targetSpan = null; for (const span of document.querySelectorAll(
`.page[data-page-number='${number}'] .textLayer span`
)) { if (span.innerText.includes(text)) {
targetSpan = span; break;
}
}
Assert.ok(!!targetSpan, `document must have a span containing '${text}'`);
const { x, y, width, height } = targetSpan.getBoundingClientRect(); return { x, y, width, height };
}
);
}
/** * Count the number of elements corresponding to the given selector. * @param {Object} browser * @param {string} selector * @returns
*/
async function countElements(browser, selector) { return SpecialPowers.spawn(browser, [selector], async function (selector) { returnnew Promise(resolve => {
content.setTimeout(() => {
resolve(content.document.querySelectorAll(selector).length);
}, 0);
});
});
}
/** * Click at the given coordinates. * @param {Object} browser * @param {number} x * @param {number} y * @param {number} n
*/
async function clickAt(browser, x, y, n = 1) {
info(`Click at: (${x}, ${y}), ${n} times`);
await BrowserTestUtils.synthesizeMouseAtPoint(
x,
y,
{
type: "mousedown",
button: 0,
clickCount: n,
},
browser
);
await BrowserTestUtils.synthesizeMouseAtPoint(
x,
y,
{
type: "mouseup",
button: 0,
clickCount: n,
},
browser
);
await TestUtils.waitForTick();
}
/** * Click on the element corresponding to the given selector. * @param {Object} browser * @param {string} selector
*/
async function clickOn(browser, selector) {
await waitForSelector(browser, selector); const [x, y] = await SpecialPowers.spawn(
browser,
[selector],
async selector => { const element = content.document.querySelector(selector); Assert.ok(
!!element,
`Element "${selector}" must be available in order to be clicked`
); const { x, y, width, height } = element.getBoundingClientRect(); return [x + width / 2, y + height / 2];
}
);
await clickAt(browser, x, y);
}
function focusEditorLayer(browser) { return focus(browser, ".annotationEditorLayer");
}
/** * Focus an element corresponding to the given selector. * @param {Object} browser * @param {string} selector * @returns
*/
async function focus(browser, selector) {
info("Focus: " + selector); return SpecialPowers.spawn(
browser,
[selector],
sel => new Promise(resolve => { const el = content.document.querySelector(sel); if (el === content.document.activeElement) {
resolve();
} else {
el.addEventListener("focus", () => resolve(), { once: true });
el.focus();
}
})
);
}
/** * Hit a key.
*/
async function hitKey(browser, char) {
await SpecialPowers.spawn(browser, [char], async function (char) { const { ContentTaskUtils } = ChromeUtils.importESModule( "resource://testing-common/ContentTaskUtils.sys.mjs"
); const EventUtils = ContentTaskUtils.getEventUtils(content);
await EventUtils.synthesizeKey(char, {}, content);
});
await TestUtils.waitForTick();
}
/** * Write some text using the keyboard. * @param {Object} browser * @param {string} text
*/
async function write(browser, text) {
info(`Write: ${text}`); for (constchar of text.split("")) {
hitKey(browser, char);
}
}
/** * Hit escape key.
*/
async function escape(browser) {
info("Escape");
await hitKey(browser, "KEY_Escape");
}
/** * Add a FreeText annotation and write some text inside. * @param {Object} browser * @param {string} text * @param {Object} box
*/
async function addFreeText(browser, text, box) {
info("Add FreeText: " + text); const { x, y, width, height } = box; const count = await countElements(browser, ".freeTextEditor");
await focusEditorLayer(browser);
await clickAt(browser, x + 0.1 * width, y + 0.5 * height);
await waitForEditors(browser, ".freeTextEditor", count + 1);
function createTemporarySaveDirectory(id = "") { var saveDir = Services.dirsvc.get("TmpD", Ci.nsIFile);
saveDir.append(`testsavedir${id}`); if (!saveDir.exists()) {
saveDir.create(Ci.nsIFile.DIRECTORY_TYPE, 0o755);
} return saveDir;
}
async function cleanupDownloads(listId = Downloads.PUBLIC) {
info("cleaning up downloads");
let downloadList = await Downloads.getList(listId); for (let download of await downloadList.getAll()) {
await download.finalize(true); try { if (Services.appinfo.OS === "WINNT") { // We need to make the file writable to delete it on Windows.
await IOUtils.setPermissions(download.target.path, 0o600);
}
await IOUtils.remove(download.target.path);
} catch (error) {
info("The file " + download.target.path + " is not removed, " + error);
}
function makePDFJSHandler() {
let mimeService = Cc["@mozilla.org/mime;1"].getService(Ci.nsIMIMEService);
let handlerInfo = mimeService.getFromTypeAndExtension( "application/pdf", "pdf"
);
// Make sure pdf.js is the default handler.
is(
handlerInfo.alwaysAskBeforeHandling, false, "pdf handler defaults to always-ask is false"
);
is(
handlerInfo.preferredAction,
Ci.nsIHandlerInfo.handleInternally, "pdf handler defaults to internal"
);
async function testTelemetryEventExtra(record, expected, clear = true) {
await Services.fog.testFlushAllChildren(); const values = record.testGetValue(); Assert.equal(values.length, expected.length, "Should have the length");
for (let i = 0; i < expected.length; i++) { const value = values[i]; Assert.deepEqual(
value?.extra ?? {},
expected[i],
`Should have the right value at index ${i}`
);
} if (clear) {
Services.fog.testResetFOG();
}
}
function waitForPreviewVisible() { return BrowserTestUtils.waitForCondition(function () {
let preview = document.querySelector(".printPreviewBrowser"); return preview && BrowserTestUtils.isVisible(preview);
});
}
Messung V0.5
¤ Dauer der Verarbeitung: 0.1 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.