2020-12-11 06:45:14 +09:00
|
|
|
/* Copyright 2020 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
exports.loadAndWait = (filename, selector) =>
|
|
|
|
Promise.all(
|
|
|
|
global.integrationSessions.map(async session => {
|
|
|
|
const page = await session.browser.newPage();
|
2021-09-09 01:00:03 +09:00
|
|
|
|
|
|
|
// In order to avoid errors because of checks which depend on
|
|
|
|
// a locale.
|
|
|
|
await page.evaluateOnNewDocument(() => {
|
|
|
|
Object.defineProperty(navigator, "language", {
|
|
|
|
get() {
|
|
|
|
return "en-US";
|
|
|
|
},
|
|
|
|
});
|
|
|
|
Object.defineProperty(navigator, "languages", {
|
|
|
|
get() {
|
|
|
|
return ["en-US", "en"];
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-12-11 06:45:14 +09:00
|
|
|
await page.goto(
|
|
|
|
`${global.integrationBaseUrl}?file=/test/pdfs/${filename}`
|
|
|
|
);
|
|
|
|
await page.bringToFront();
|
|
|
|
await page.waitForSelector(selector, {
|
|
|
|
timeout: 0,
|
|
|
|
});
|
|
|
|
return [session.name, page];
|
|
|
|
})
|
|
|
|
);
|
|
|
|
|
|
|
|
exports.closePages = pages =>
|
|
|
|
Promise.all(
|
|
|
|
pages.map(async ([_, page]) => {
|
|
|
|
await page.close();
|
|
|
|
})
|
|
|
|
);
|
2020-11-19 02:54:26 +09:00
|
|
|
|
|
|
|
exports.clearInput = async (page, selector) => {
|
|
|
|
await page.click(selector);
|
|
|
|
await page.keyboard.down("Control");
|
|
|
|
await page.keyboard.press("A");
|
|
|
|
await page.keyboard.up("Control");
|
|
|
|
await page.keyboard.press("Backspace");
|
|
|
|
};
|
2022-06-18 05:01:20 +09:00
|
|
|
|
|
|
|
function getSelector(id) {
|
|
|
|
return `[data-element-id="${id}"]`;
|
|
|
|
}
|
|
|
|
exports.getSelector = getSelector;
|
|
|
|
|
|
|
|
function getQuerySelector(id) {
|
|
|
|
return `document.querySelector('${getSelector(id)}')`;
|
|
|
|
}
|
|
|
|
exports.getQuerySelector = getQuerySelector;
|
|
|
|
|
|
|
|
function getComputedStyleSelector(id) {
|
|
|
|
return `getComputedStyle(${getQuerySelector(id)})`;
|
|
|
|
}
|
|
|
|
exports.getComputedStyleSelector = getComputedStyleSelector;
|
2022-07-22 19:13:47 +09:00
|
|
|
|
|
|
|
const editorPrefix = "#pdfjs_internal_editor_";
|
|
|
|
exports.editorPrefix = editorPrefix;
|
|
|
|
|
|
|
|
function getSelectedEditors(page) {
|
|
|
|
return page.evaluate(prefix => {
|
|
|
|
const elements = document.querySelectorAll(".selectedEditor");
|
|
|
|
const results = [];
|
|
|
|
for (const { id } of elements) {
|
|
|
|
results.push(parseInt(id.slice(prefix.length)));
|
|
|
|
}
|
|
|
|
results.sort();
|
|
|
|
return results;
|
|
|
|
}, editorPrefix.slice(1));
|
|
|
|
}
|
|
|
|
exports.getSelectedEditors = getSelectedEditors;
|