OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 function resetDocument() { |
| 6 window.viewer.viewport.goToPage(0); |
| 7 window.viewer.viewport.setZoom(1); |
| 8 window.viewer.isFormFieldFocused_ = false; |
| 9 } |
| 10 |
| 11 function getCurrentPage() { |
| 12 return window.viewer.viewport.getMostVisiblePage(); |
| 13 } |
| 14 |
| 15 var tests = [ |
| 16 /** |
| 17 * Test that the left/right arrows change page back and forth. |
| 18 */ |
| 19 function testPageChangesWithArrows() { |
| 20 // Right arrow -> Go to page 2. |
| 21 MockInteractions.pressAndReleaseKeyOn(document, 39); |
| 22 chrome.test.assertEq(1, getCurrentPage()); |
| 23 |
| 24 // Left arrow -> Back to page 1. |
| 25 MockInteractions.pressAndReleaseKeyOn(document, 37); |
| 26 chrome.test.assertEq(0, getCurrentPage()); |
| 27 |
| 28 resetDocument(); |
| 29 chrome.test.succeed(); |
| 30 }, |
| 31 |
| 32 /** |
| 33 * Test that when a PDF form field is focused, the left/right shortcuts are |
| 34 * disabled. This doesn't test the plugin side of this feature. |
| 35 */ |
| 36 function testPageDoesntChangeWhenFormFocused() { |
| 37 // This should be set by a message from plugin -> page when a field is |
| 38 // focused. |
| 39 window.viewer.isFormFieldFocused_ = true; |
| 40 |
| 41 // Page should not change when left/right are pressed. |
| 42 MockInteractions.pressAndReleaseKeyOn(document, 39); |
| 43 chrome.test.assertEq(0, getCurrentPage()); |
| 44 |
| 45 MockInteractions.pressAndReleaseKeyOn(document, 37); |
| 46 chrome.test.assertEq(0, getCurrentPage()); |
| 47 |
| 48 resetDocument(); |
| 49 chrome.test.succeed(); |
| 50 }, |
| 51 |
| 52 /** |
| 53 * Test that when the document is in fit to page, pressing page up/page down |
| 54 * changes page back/forth. |
| 55 */ |
| 56 function testPageDownInFitPage() { |
| 57 window.viewer.viewport.fitToPage(); |
| 58 |
| 59 // Page down -> Go to page 2. |
| 60 MockInteractions.pressAndReleaseKeyOn(document, 34); |
| 61 chrome.test.assertEq(1, getCurrentPage()); |
| 62 |
| 63 // Page up -> Back to page 1. |
| 64 MockInteractions.pressAndReleaseKeyOn(document, 33); |
| 65 chrome.test.assertEq(0, getCurrentPage()); |
| 66 |
| 67 resetDocument(); |
| 68 chrome.test.succeed(); |
| 69 } |
| 70 ]; |
| 71 |
| 72 importTestHelpers().then(function() { |
| 73 chrome.test.runTests(tests); |
| 74 }); |
OLD | NEW |