diff options
Diffstat (limited to 'toolkit/components/pdfjs/test/head.js')
-rw-r--r-- | toolkit/components/pdfjs/test/head.js | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/toolkit/components/pdfjs/test/head.js b/toolkit/components/pdfjs/test/head.js new file mode 100644 index 0000000000..bca608e1f0 --- /dev/null +++ b/toolkit/components/pdfjs/test/head.js @@ -0,0 +1,71 @@ +async function waitForPdfJS(browser, url) { + await SpecialPowers.pushPrefEnv({ + set: [["pdfjs.eventBusDispatchToDOM", true]], + }); + // Runs tests after all "load" event handlers have fired off + let loadPromise = BrowserTestUtils.waitForContentEvent( + browser, + "documentloaded", + false, + null, + true + ); + await SpecialPowers.spawn(browser, [url], contentUrl => { + content.location = contentUrl; + }); + return loadPromise; +} + +async function waitForPdfJSAnnotationLayer(browser, url) { + await SpecialPowers.pushPrefEnv({ + set: [["pdfjs.eventBusDispatchToDOM", true]], + }); + let loadPromise = BrowserTestUtils.waitForContentEvent( + browser, + "annotationlayerrendered", + false, + null, + true + ); + await SpecialPowers.spawn(browser, [url], contentUrl => { + content.location = contentUrl; + }); + return loadPromise; +} + +function changeMimeHandler(preferredAction, alwaysAskBeforeHandling) { + let handlerService = Cc[ + "@mozilla.org/uriloader/handler-service;1" + ].getService(Ci.nsIHandlerService); + let mimeService = Cc["@mozilla.org/mime;1"].getService(Ci.nsIMIMEService); + let handlerInfo = mimeService.getFromTypeAndExtension( + "application/pdf", + "pdf" + ); + var oldAction = [ + handlerInfo.preferredAction, + handlerInfo.alwaysAskBeforeHandling, + ]; + + // Change and save mime handler settings + handlerInfo.alwaysAskBeforeHandling = alwaysAskBeforeHandling; + handlerInfo.preferredAction = preferredAction; + handlerService.store(handlerInfo); + + // Refresh data + handlerInfo = mimeService.getFromTypeAndExtension("application/pdf", "pdf"); + + // Test: Mime handler was updated + is( + handlerInfo.alwaysAskBeforeHandling, + alwaysAskBeforeHandling, + "always-ask prompt change successful" + ); + is( + handlerInfo.preferredAction, + preferredAction, + "mime handler change successful" + ); + + return oldAction; +} |