michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: * http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: const RELATIVE_DIR = "browser/extensions/pdfjs/test/"; michael@0: const TESTROOT = "http://example.com/browser/" + RELATIVE_DIR; michael@0: michael@0: function test() { michael@0: var tab; michael@0: michael@0: let handlerService = Cc["@mozilla.org/uriloader/handler-service;1"].getService(Ci.nsIHandlerService); michael@0: let mimeService = Cc["@mozilla.org/mime;1"].getService(Ci.nsIMIMEService); michael@0: let handlerInfo = mimeService.getFromTypeAndExtension('application/pdf', 'pdf'); michael@0: michael@0: // Make sure pdf.js is the default handler. michael@0: is(handlerInfo.alwaysAskBeforeHandling, false, 'pdf handler defaults to always-ask is false'); michael@0: is(handlerInfo.preferredAction, Ci.nsIHandlerInfo.handleInternally, 'pdf handler defaults to internal'); michael@0: michael@0: info('Pref action: ' + handlerInfo.preferredAction); michael@0: michael@0: waitForExplicitFinish(); michael@0: registerCleanupFunction(function() { michael@0: gBrowser.removeTab(tab); michael@0: }); michael@0: michael@0: tab = gBrowser.addTab(TESTROOT + "file_pdfjs_test.pdf"); michael@0: var newTabBrowser = gBrowser.getBrowserForTab(tab); michael@0: newTabBrowser.addEventListener("load", function eventHandler() { michael@0: newTabBrowser.removeEventListener("load", eventHandler, true); michael@0: michael@0: var document = newTabBrowser.contentDocument, michael@0: window = newTabBrowser.contentWindow; michael@0: michael@0: // Runs tests after all 'load' event handlers have fired off michael@0: window.addEventListener("documentload", function() { michael@0: runTests(document, window, finish); michael@0: }, false, true); michael@0: }, true); michael@0: } michael@0: michael@0: function runTests(document, window, callback) { michael@0: // check that PDF is opened with internal viewer michael@0: ok(document.querySelector('div#viewer'), "document content has viewer UI"); michael@0: ok('PDFJS' in window.wrappedJSObject, "window content has PDFJS object"); michael@0: michael@0: //open sidebar michael@0: var sidebar = document.querySelector('button#sidebarToggle'); michael@0: var outerContainer = document.querySelector('div#outerContainer'); michael@0: michael@0: sidebar.click(); michael@0: ok(outerContainer.classList.contains('sidebarOpen'), 'sidebar opens on click'); michael@0: michael@0: // check that thumbnail view is open michael@0: var thumbnailView = document.querySelector('div#thumbnailView'); michael@0: var outlineView = document.querySelector('div#outlineView'); michael@0: michael@0: is(thumbnailView.getAttribute('class'), null, 'Initial view is thumbnail view'); michael@0: is(outlineView.getAttribute('class'), 'hidden', 'Outline view is hidden initially'); michael@0: michael@0: //switch to outline view michael@0: var viewOutlineButton = document.querySelector('button#viewOutline'); michael@0: viewOutlineButton.click(); michael@0: michael@0: is(outlineView.getAttribute('class'), '', 'Outline view is visible when selected'); michael@0: is(thumbnailView.getAttribute('class'), 'hidden', 'Thumbnail view is hidden when outline is selected'); michael@0: michael@0: //switch back to thumbnail view michael@0: var viewThumbnailButton = document.querySelector('button#viewThumbnail'); michael@0: viewThumbnailButton.click(); michael@0: michael@0: is(thumbnailView.getAttribute('class'), '', 'Thumbnail view is visible when selected'); michael@0: is(outlineView.getAttribute('class'), 'hidden', 'Outline view is hidden when thumbnail is selected'); michael@0: michael@0: sidebar.click(); michael@0: michael@0: callback(); michael@0: }