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 var tests = [ |
| 6 /** |
| 7 * Test named destinations. |
| 8 */ |
| 9 function testParamsParser() { |
| 10 var paramsParser = new OpenPDFParamsParser(); |
| 11 // Assigning page number for #nameddests. |
| 12 paramsParser.namedDestinations['RU'] = 26; |
| 13 paramsParser.namedDestinations['US'] = 0; |
| 14 paramsParser.namedDestinations['UY'] = 22; |
| 15 |
| 16 var url = "http://xyz.pdf"; |
| 17 |
| 18 // Checking #nameddest. |
| 19 var urlParams = paramsParser.getViewportFromUrlParams(url + "#RU"); |
| 20 chrome.test.assertEq(urlParams.page, 26); |
| 21 |
| 22 // Checking #nameddest=name. |
| 23 urlParams = paramsParser.getViewportFromUrlParams(url + "#nameddest=US"); |
| 24 chrome.test.assertEq(urlParams.page, 0); |
| 25 |
| 26 // Checking #page=pagenum nameddest.The document first page has a pagenum |
| 27 // value of 1. |
| 28 urlParams = paramsParser.getViewportFromUrlParams(url + "#page=6"); |
| 29 chrome.test.assertEq(urlParams.page, 5); |
| 30 |
| 31 // Checking #zoom=scale. |
| 32 urlParams = paramsParser.getViewportFromUrlParams(url + "#zoom=200"); |
| 33 chrome.test.assertEq(urlParams.zoom, 2); |
| 34 |
| 35 // Checking #zoom=scale,left,top. |
| 36 urlParams = paramsParser.getViewportFromUrlParams(url + |
| 37 "#zoom=200,100,200"); |
| 38 chrome.test.assertEq(urlParams.zoom, 2); |
| 39 chrome.test.assertEq(urlParams.position.x, 100); |
| 40 chrome.test.assertEq(urlParams.position.y, 200); |
| 41 |
| 42 // Checking #nameddest=name and zoom=scale. |
| 43 urlParams = paramsParser.getViewportFromUrlParams(url + |
| 44 "#nameddest=UY&zoom=150"); |
| 45 chrome.test.assertEq(urlParams.page, 22); |
| 46 chrome.test.assertEq(urlParams.zoom, 1.5); |
| 47 |
| 48 // Checking #page=pagenum and zoom=scale. |
| 49 urlParams = paramsParser.getViewportFromUrlParams(url + |
| 50 "#page=2&zoom=250"); |
| 51 chrome.test.assertEq(urlParams.page, 1); |
| 52 chrome.test.assertEq(urlParams.zoom, 2.5); |
| 53 |
| 54 // Checking #nameddest=name and zoom=scale,left,top. |
| 55 urlParams = paramsParser.getViewportFromUrlParams(url + |
| 56 "#nameddest=UY&zoom=150,100,200"); |
| 57 chrome.test.assertEq(urlParams.page, 22); |
| 58 chrome.test.assertEq(urlParams.zoom, 1.5); |
| 59 chrome.test.assertEq(urlParams.position.x, 100); |
| 60 chrome.test.assertEq(urlParams.position.y, 200); |
| 61 |
| 62 // Checking #page=pagenum and zoom=scale,left,top. |
| 63 urlParams = paramsParser.getViewportFromUrlParams(url + |
| 64 "#page=2&zoom=250,100,200"); |
| 65 chrome.test.assertEq(urlParams.page, 1); |
| 66 chrome.test.assertEq(urlParams.zoom, 2.5); |
| 67 chrome.test.assertEq(urlParams.position.x, 100); |
| 68 chrome.test.assertEq(urlParams.position.y, 200); |
| 69 |
| 70 chrome.test.succeed(); |
| 71 } |
| 72 ]; |
| 73 |
| 74 var scriptingAPI = new PDFScriptingAPI(window, window); |
| 75 scriptingAPI.setLoadCallback(function() { |
| 76 chrome.test.runTests(tests); |
| 77 }); |
OLD | NEW |