browser/extensions/pdfjs/test/browser_pdfjs_main.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* Any copyright is dedicated to the Public Domain.
michael@0 2 * http://creativecommons.org/publicdomain/zero/1.0/ */
michael@0 3
michael@0 4 const RELATIVE_DIR = "browser/extensions/pdfjs/test/";
michael@0 5 const TESTROOT = "http://example.com/browser/" + RELATIVE_DIR;
michael@0 6
michael@0 7 function test() {
michael@0 8 var tab;
michael@0 9
michael@0 10 let handlerService = Cc["@mozilla.org/uriloader/handler-service;1"].getService(Ci.nsIHandlerService);
michael@0 11 let mimeService = Cc["@mozilla.org/mime;1"].getService(Ci.nsIMIMEService);
michael@0 12 let handlerInfo = mimeService.getFromTypeAndExtension('application/pdf', 'pdf');
michael@0 13
michael@0 14 // Make sure pdf.js is the default handler.
michael@0 15 is(handlerInfo.alwaysAskBeforeHandling, false, 'pdf handler defaults to always-ask is false');
michael@0 16 is(handlerInfo.preferredAction, Ci.nsIHandlerInfo.handleInternally, 'pdf handler defaults to internal');
michael@0 17
michael@0 18 info('Pref action: ' + handlerInfo.preferredAction);
michael@0 19
michael@0 20 waitForExplicitFinish();
michael@0 21 registerCleanupFunction(function() {
michael@0 22 gBrowser.removeTab(tab);
michael@0 23 });
michael@0 24
michael@0 25 tab = gBrowser.addTab(TESTROOT + "file_pdfjs_test.pdf");
michael@0 26 var newTabBrowser = gBrowser.getBrowserForTab(tab);
michael@0 27 newTabBrowser.addEventListener("load", function eventHandler() {
michael@0 28 newTabBrowser.removeEventListener("load", eventHandler, true);
michael@0 29
michael@0 30 var document = newTabBrowser.contentDocument,
michael@0 31 window = newTabBrowser.contentWindow;
michael@0 32
michael@0 33 // Runs tests after all 'load' event handlers have fired off
michael@0 34 window.addEventListener("documentload", function() {
michael@0 35 runTests(document, window, finish);
michael@0 36 }, false, true);
michael@0 37 }, true);
michael@0 38 }
michael@0 39
michael@0 40
michael@0 41 function runTests(document, window, callback) {
michael@0 42
michael@0 43 //
michael@0 44 // Overall sanity tests
michael@0 45 //
michael@0 46 ok(document.querySelector('div#viewer'), "document content has viewer UI");
michael@0 47 ok('PDFJS' in window.wrappedJSObject, "window content has PDFJS object");
michael@0 48
michael@0 49 //
michael@0 50 // Sidebar: open
michael@0 51 //
michael@0 52 var sidebar = document.querySelector('button#sidebarToggle'),
michael@0 53 outerContainer = document.querySelector('div#outerContainer');
michael@0 54
michael@0 55 sidebar.click();
michael@0 56 ok(outerContainer.classList.contains('sidebarOpen'), 'sidebar opens on click');
michael@0 57
michael@0 58 //
michael@0 59 // Sidebar: close
michael@0 60 //
michael@0 61 sidebar.click();
michael@0 62 ok(!outerContainer.classList.contains('sidebarOpen'), 'sidebar closes on click');
michael@0 63
michael@0 64 //
michael@0 65 // Page change from prev/next buttons
michael@0 66 //
michael@0 67 var prevPage = document.querySelector('button#previous'),
michael@0 68 nextPage = document.querySelector('button#next');
michael@0 69
michael@0 70 var pageNumber = document.querySelector('input#pageNumber');
michael@0 71 is(parseInt(pageNumber.value), 1, 'initial page is 1');
michael@0 72
michael@0 73 //
michael@0 74 // Bookmark button
michael@0 75 //
michael@0 76 var viewBookmark = document.querySelector('a#viewBookmark');
michael@0 77 viewBookmark.click();
michael@0 78 ok(viewBookmark.href.length > 0, 'viewBookmark button has href');
michael@0 79
michael@0 80 callback();
michael@0 81 }

mercurial