Bug 1942239 - Add option to explicitly enable incremental origin initialization in...
[gecko.git] / toolkit / components / pdfjs / test / browser_pdfjs_alttext_load_engine.js
blobef53901db30f47d1d6bca65859f5acd9a122575f
1 /* Any copyright is dedicated to the Public Domain.
2 * http://creativecommons.org/publicdomain/zero/1.0/ */
4 Services.scriptloader.loadSubScript(
5 "chrome://mochitests/content/browser/toolkit/components/ml/tests/browser/head.js",
6 this
7 );
9 const RELATIVE_DIR = "toolkit/components/pdfjs/test/";
10 const TESTROOT = "https://example.com/browser/" + RELATIVE_DIR;
11 const pdfUrl = TESTROOT + "file_pdfjs_test.pdf";
12 const altTextPref = "pdfjs.enableAltText";
13 const guessAltTextPref = "pdfjs.enableGuessAltText";
14 const browserMLPref = "browser.ml.enable";
15 const annotationEditorModePref = "pdfjs.annotationEditorMode";
17 async function setupRemoteClient() {
18 const { removeMocks, remoteClients } = await createAndMockMLRemoteSettings({
19 autoDownloadFromRemoteSettings: false,
20 });
22 return {
23 remoteClients,
24 async cleanup() {
25 await removeMocks();
26 await waitForCondition(
27 () => EngineProcess.areAllEnginesTerminated(),
28 "Waiting for all of the engines to be terminated.",
29 100,
30 200
36 // Test that the model is loaded.
37 add_task(async function test() {
38 let mimeService = Cc["@mozilla.org/mime;1"].getService(Ci.nsIMIMEService);
39 let handlerInfo = mimeService.getFromTypeAndExtension(
40 "application/pdf",
41 "pdf"
44 // Make sure pdf.js is the default handler.
45 is(
46 handlerInfo.alwaysAskBeforeHandling,
47 false,
48 "pdf handler defaults to always-ask is false"
50 is(
51 handlerInfo.preferredAction,
52 Ci.nsIHandlerInfo.handleInternally,
53 "pdf handler defaults to internal"
56 info("Pref action: " + handlerInfo.preferredAction);
58 await BrowserTestUtils.withNewTab(
59 { gBrowser, url: "about:blank" },
60 async function test_alttext_load_engine(browser) {
61 const { EngineProcess } = ChromeUtils.importESModule(
62 "chrome://global/content/ml/EngineProcess.sys.mjs"
65 await SpecialPowers.pushPrefEnv({
66 set: [
67 [altTextPref, true],
68 [browserMLPref, true],
69 [guessAltTextPref, true],
70 [annotationEditorModePref, 0],
72 });
74 const setRC = await setupRemoteClient();
76 await waitForPdfJS(browser, pdfUrl);
77 await enableEditor(browser, "Stamp", 1);
79 const isEnabled = await SpecialPowers.spawn(browser, [], () => {
80 const viewer = content.wrappedJSObject.PDFViewerApplication;
81 return viewer.mlManager.isEnabledFor("altText");
82 });
83 ok(isEnabled, "AltText is enabled");
85 await setRC.remoteClients["ml-onnx-runtime"].resolvePendingDownloads(1);
86 await EngineProcess.destroyMLEngine();
87 await setRC.cleanup();
89 await waitForPdfJSClose(browser);
90 await SpecialPowers.popPrefEnv();
93 });