1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
6 * Standalone unit tests of the PDF Polymer elements.
10 * Test that viewer-page-selector reacts correctly to text entry. The page
11 * selector validates that input is an integer, but does not check for
14 function testPageSelectorChange() {
16 Polymer.Base.create('viewer-page-selector', {docLength: 1234});
18 var input = selector.$.input;
19 // Simulate entering text into `input` and pressing enter.
20 function changeInput(newValue) {
21 input.bindValue = newValue;
22 input.dispatchEvent(new CustomEvent('change'));
25 var navigatedPages = [];
26 selector.addEventListener('change-page', function(e) {
27 navigatedPages.push(e.detail.page);
36 chrome.test.assertEq(4, navigatedPages.length);
37 // The event page number is 0-based.
38 chrome.test.assertEq(999, navigatedPages[0]);
39 chrome.test.assertEq(1233, navigatedPages[1]);
40 chrome.test.assertEq(11, navigatedPages[2]);
41 chrome.test.assertEq(2, navigatedPages[3]);
43 chrome.test.succeed();
47 * Test that viewer-page-selector changes in response to setting docLength.
49 function testPageSelectorDocLength() {
51 Polymer.Base.create('viewer-page-selector', {docLength: 1234});
52 chrome.test.assertEq('1234', selector.$.pagelength.textContent);
53 chrome.test.assertEq('4ch', selector.$.pageselector.style.width);
54 chrome.test.succeed();
58 * Test that clicking the dropdown icon opens/closes the dropdown.
60 function testToolbarDropdownShowHide() {
61 var dropdown = Polymer.Base.create('viewer-toolbar-dropdown', {
63 closedIcon: 'closedIcon',
67 chrome.test.assertFalse(dropdown.dropdownOpen);
68 chrome.test.assertEq('closedIcon', dropdown.dropdownIcon);
70 MockInteractions.tap(dropdown.$.icon);
72 chrome.test.assertTrue(dropdown.dropdownOpen);
73 chrome.test.assertEq('openIcon', dropdown.dropdownIcon);
75 MockInteractions.tap(dropdown.$.icon);
77 chrome.test.assertFalse(dropdown.dropdownOpen);
79 chrome.test.succeed();
83 * Test that viewer-bookmarks-content creates a bookmark tree with the correct
84 * structure and behaviour.
86 function testBookmarkStructure() {
87 var bookmarkContent = Polymer.Base.create('viewer-bookmarks-content', {
105 // Force templates to render.
109 bookmarkContent.shadowRoot.querySelectorAll('viewer-bookmark');
110 chrome.test.assertEq(1, rootBookmarks.length, "one root bookmark");
111 var rootBookmark = rootBookmarks[0];
114 rootBookmark.shadowRoot.querySelectorAll('viewer-bookmark');
115 chrome.test.assertEq(2, subBookmarks.length, "two sub bookmarks");
116 chrome.test.assertEq(1, subBookmarks[1].depth,
117 "sub bookmark depth correct");
120 rootBookmark.addEventListener('change-page', function(e) {
121 lastPageChange = e.detail.page;
124 MockInteractions.tap(rootBookmark.$.item);
125 chrome.test.assertEq(1, lastPageChange);
127 MockInteractions.tap(subBookmarks[1].$.item);
128 chrome.test.assertEq(3, lastPageChange);
131 rootBookmark.shadowRoot.querySelector('.sub-bookmark');
133 chrome.test.assertTrue(subBookmarkDiv.hidden);
134 MockInteractions.tap(rootBookmark.$.expand);
135 chrome.test.assertFalse(subBookmarkDiv.hidden);
136 chrome.test.assertEq('hidden', subBookmarks[1].$.expand.style.visibility);
138 chrome.test.succeed();
142 * Test that the zoom toolbar toggles between showing the fit-to-page and
143 * fit-to-width buttons.
145 function testZoomToolbarToggle() {
146 var zoomToolbar = Polymer.Base.create('viewer-zoom-toolbar', {});
147 var fitButton = zoomToolbar.$['fit-button'];
148 var fab = fitButton.$['button'];
150 var fitWidthIcon = 'fullscreen';
151 var fitPageIcon = 'fullscreen-exit';
153 var lastEvent = null;
154 var logEvent = function(e) {
157 var assertEvent = function(type) {
158 chrome.test.assertEq(type, lastEvent);
161 zoomToolbar.addEventListener('fit-to-width', logEvent);
162 zoomToolbar.addEventListener('fit-to-page', logEvent);
164 // Initial: Show fit-to-page.
165 chrome.test.assertEq(fitPageIcon, fab.icon);
167 // Tap 1: Fire fit-to-page, show fit-to-width.
168 MockInteractions.tap(fab);
169 assertEvent('fit-to-page');
170 chrome.test.assertEq(fitWidthIcon, fab.icon);
172 // Tap 2: Fire fit-to-width, show fit-to-page.
173 MockInteractions.tap(fab);
174 assertEvent('fit-to-width');
175 chrome.test.assertEq(fitPageIcon, fab.icon);
177 // Tap 3: Fire fit-to-page again.
178 MockInteractions.tap(fab);
179 assertEvent('fit-to-page');
181 chrome.test.succeed();
185 importTestHelpers().then(function() {
186 chrome.test.runTests(tests);