browser/extensions/pdfjs/test/browser_pdfjs_views.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 function runTests(document, window, callback) {
michael@0 41 // check that PDF is opened with internal viewer
michael@0 42 ok(document.querySelector('div#viewer'), "document content has viewer UI");
michael@0 43 ok('PDFJS' in window.wrappedJSObject, "window content has PDFJS object");
michael@0 44
michael@0 45 //open sidebar
michael@0 46 var sidebar = document.querySelector('button#sidebarToggle');
michael@0 47 var outerContainer = document.querySelector('div#outerContainer');
michael@0 48
michael@0 49 sidebar.click();
michael@0 50 ok(outerContainer.classList.contains('sidebarOpen'), 'sidebar opens on click');
michael@0 51
michael@0 52 // check that thumbnail view is open
michael@0 53 var thumbnailView = document.querySelector('div#thumbnailView');
michael@0 54 var outlineView = document.querySelector('div#outlineView');
michael@0 55
michael@0 56 is(thumbnailView.getAttribute('class'), null, 'Initial view is thumbnail view');
michael@0 57 is(outlineView.getAttribute('class'), 'hidden', 'Outline view is hidden initially');
michael@0 58
michael@0 59 //switch to outline view
michael@0 60 var viewOutlineButton = document.querySelector('button#viewOutline');
michael@0 61 viewOutlineButton.click();
michael@0 62
michael@0 63 is(outlineView.getAttribute('class'), '', 'Outline view is visible when selected');
michael@0 64 is(thumbnailView.getAttribute('class'), 'hidden', 'Thumbnail view is hidden when outline is selected');
michael@0 65
michael@0 66 //switch back to thumbnail view
michael@0 67 var viewThumbnailButton = document.querySelector('button#viewThumbnail');
michael@0 68 viewThumbnailButton.click();
michael@0 69
michael@0 70 is(thumbnailView.getAttribute('class'), '', 'Thumbnail view is visible when selected');
michael@0 71 is(outlineView.getAttribute('class'), 'hidden', 'Outline view is hidden when thumbnail is selected');
michael@0 72
michael@0 73 sidebar.click();
michael@0 74
michael@0 75 callback();
michael@0 76 }

mercurial