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",
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,
26 await
waitForCondition(
27 () => EngineProcess
.areAllEnginesTerminated(),
28 "Waiting for all of the engines to be terminated.",
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(
44 // Make sure pdf.js is the default handler.
46 handlerInfo
.alwaysAskBeforeHandling
,
48 "pdf handler defaults to always-ask is false"
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({
68 [browserMLPref
, true],
69 [guessAltTextPref
, true],
70 [annotationEditorModePref
, 0],
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");
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();