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 add_task(async function test_loaded_model_in_two_tabs() {
37 let mimeService = Cc["@mozilla.org/mime;1"].getService(Ci.nsIMIMEService);
38 let handlerInfo = mimeService.getFromTypeAndExtension(
43 // Make sure pdf.js is the default handler.
45 handlerInfo.alwaysAskBeforeHandling,
47 "pdf handler defaults to always-ask is false"
50 handlerInfo.preferredAction,
51 Ci.nsIHandlerInfo.handleInternally,
52 "pdf handler defaults to internal"
55 info("Pref action: " + handlerInfo.preferredAction);
57 await SpecialPowers.pushPrefEnv({
60 [browserMLPref, true],
61 [guessAltTextPref, true],
62 [annotationEditorModePref, 0],
65 const setRC = await setupRemoteClient();
66 const { EngineProcess } = ChromeUtils.importESModule(
67 "chrome://global/content/ml/EngineProcess.sys.mjs"
71 for (let i = 0; i < 2; i++) {
72 const tab = await BrowserTestUtils.openNewForegroundTab(
76 const browser = tab.linkedBrowser;
77 browsers.push(browser);
79 await waitForPdfJS(browser, pdfUrl);
80 await enableEditor(browser, "Stamp", 1);
82 const isEnabled = await SpecialPowers.spawn(browser, [], () => {
83 const viewer = content.wrappedJSObject.PDFViewerApplication;
84 return viewer.mlManager.isEnabledFor("altText");
86 ok(isEnabled, `AltText is enabled in tab number ${i + 1}`);
89 for (const browser of browsers) {
90 await waitForPdfJSClose(browser, /* closeTab = */ true);
93 await setRC.remoteClients["ml-onnx-runtime"].resolvePendingDownloads(1);
94 await EngineProcess.destroyMLEngine();
95 await setRC.cleanup();
97 await SpecialPowers.popPrefEnv();