mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-20 15:18:08 +02:00
Add the possibility to copy all the pdf text whatever the rendered pages are (bug 1788035)
This commit is contained in:
parent
342dc760da
commit
ca54ea12b3
10 changed files with 253 additions and 3 deletions
|
@ -26,13 +26,13 @@ async function runTests(results) {
|
|||
random: false,
|
||||
spec_dir: "integration",
|
||||
spec_files: [
|
||||
"scripting_spec.js",
|
||||
"annotation_spec.js",
|
||||
"accessibility_spec.js",
|
||||
"annotation_spec.js",
|
||||
"copy_paste_spec.js",
|
||||
"find_spec.js",
|
||||
"freetext_editor_spec.js",
|
||||
"ink_editor_spec.js",
|
||||
"a11y_spec.js",
|
||||
"scripting_spec.js",
|
||||
],
|
||||
});
|
||||
|
||||
|
|
120
test/integration/copy_paste_spec.js
Normal file
120
test/integration/copy_paste_spec.js
Normal file
|
@ -0,0 +1,120 @@
|
|||
/* Copyright 2023 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.
|
||||
*/
|
||||
|
||||
const { closePages, loadAndWait, mockClipboard } = require("./test_utils.js");
|
||||
|
||||
describe("Copy and paste", () => {
|
||||
describe("all text", () => {
|
||||
let pages;
|
||||
|
||||
beforeAll(async () => {
|
||||
pages = await loadAndWait("tracemonkey.pdf", ".textLayer");
|
||||
await mockClipboard(pages);
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
await closePages(pages);
|
||||
});
|
||||
|
||||
it("must check that we've all the contents", async () => {
|
||||
await Promise.all(
|
||||
pages.map(async ([browserName, page]) => {
|
||||
await page.keyboard.down("Control");
|
||||
await page.keyboard.press("a");
|
||||
await page.keyboard.up("Control");
|
||||
|
||||
await page.waitForTimeout(500);
|
||||
|
||||
await page.keyboard.down("Control");
|
||||
await page.keyboard.press("c");
|
||||
await page.keyboard.up("Control");
|
||||
|
||||
await page.waitForTimeout(500);
|
||||
|
||||
await page.waitForFunction(
|
||||
`document.querySelector('#viewerContainer').style.cursor !== "wait"`
|
||||
);
|
||||
|
||||
const text = await page.evaluate(() =>
|
||||
navigator.clipboard.readText()
|
||||
);
|
||||
|
||||
expect(!!text).withContext(`In ${browserName}`).toEqual(true);
|
||||
expect(text.includes("Dynamic languages such as JavaScript"))
|
||||
.withContext(`In ${browserName}`)
|
||||
.toEqual(true);
|
||||
expect(
|
||||
text.includes("This section provides an overview of our system")
|
||||
)
|
||||
.withContext(`In ${browserName}`)
|
||||
.toEqual(true);
|
||||
expect(
|
||||
text.includes(
|
||||
"are represented by function calls. This makes the LIR used by"
|
||||
)
|
||||
)
|
||||
.withContext(`In ${browserName}`)
|
||||
.toEqual(true);
|
||||
expect(
|
||||
text.includes("When compiling loops, we consult the oracle before")
|
||||
)
|
||||
.withContext(`In ${browserName}`)
|
||||
.toEqual(true);
|
||||
expect(text.includes("Nested Trace Tree Formation"))
|
||||
.withContext(`In ${browserName}`)
|
||||
.toEqual(true);
|
||||
expect(
|
||||
text.includes(
|
||||
"An important detail is that the call to the inner trace"
|
||||
)
|
||||
)
|
||||
.withContext(`In ${browserName}`)
|
||||
.toEqual(true);
|
||||
expect(text.includes("When trace recording is completed, nanojit"))
|
||||
.withContext(`In ${browserName}`)
|
||||
.toEqual(true);
|
||||
expect(
|
||||
text.includes(
|
||||
"SpiderMonkey, like many VMs, needs to preempt the user program"
|
||||
)
|
||||
)
|
||||
.withContext(`In ${browserName}`)
|
||||
.toEqual(true);
|
||||
expect(
|
||||
text.includes(
|
||||
"Using similar computations, we find that trace recording takes"
|
||||
)
|
||||
)
|
||||
.withContext(`In ${browserName}`)
|
||||
.toEqual(true);
|
||||
expect(
|
||||
text.includes(
|
||||
"specialization algorithm. We also described our trace compiler"
|
||||
)
|
||||
)
|
||||
.withContext(`In ${browserName}`)
|
||||
.toEqual(true);
|
||||
expect(
|
||||
text.includes(
|
||||
"dynamic optimization system. In Proceedings of the ACM SIGPLAN"
|
||||
)
|
||||
)
|
||||
.withContext(`In ${browserName}`)
|
||||
.toEqual(true);
|
||||
})
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
|
@ -118,3 +118,19 @@ const waitForSelectedEditor = async (page, selector) => {
|
|||
);
|
||||
};
|
||||
exports.waitForSelectedEditor = waitForSelectedEditor;
|
||||
|
||||
const mockClipboard = async pages => {
|
||||
await Promise.all(
|
||||
pages.map(async ([_, page]) => {
|
||||
await page.evaluate(() => {
|
||||
let data = null;
|
||||
const clipboard = {
|
||||
writeText: async text => (data = text),
|
||||
readText: async () => data,
|
||||
};
|
||||
Object.defineProperty(navigator, "clipboard", { value: clipboard });
|
||||
});
|
||||
})
|
||||
);
|
||||
};
|
||||
exports.mockClipboard = mockClipboard;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue