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.
7 * Test named destinations.
9 function testParamsParser() {
10 var paramsParser
= new OpenPDFParamsParser(function(name
) {
12 paramsParser
.onNamedDestinationReceived(26);
13 else if (name
== 'US')
14 paramsParser
.onNamedDestinationReceived(0);
15 else if (name
== 'UY')
16 paramsParser
.onNamedDestinationReceived(22);
18 paramsParser
.onNamedDestinationReceived(-1);
21 var url
= "http://xyz.pdf";
23 // Checking #nameddest.
24 paramsParser
.getViewportFromUrlParams(
25 url
+ "#RU", function(viewportPosition
) {
26 chrome
.test
.assertEq(viewportPosition
.page
, 26);
29 // Checking #nameddest=name.
30 paramsParser
.getViewportFromUrlParams(
31 url
+ "#nameddest=US", function(viewportPosition
) {
32 chrome
.test
.assertEq(viewportPosition
.page
, 0);
35 // Checking #page=pagenum nameddest.The document first page has a pagenum
37 paramsParser
.getViewportFromUrlParams(
38 url
+ "#page=6", function(viewportPosition
) {
39 chrome
.test
.assertEq(viewportPosition
.page
, 5);
42 // Checking #zoom=scale.
43 paramsParser
.getViewportFromUrlParams(
44 url
+ "#zoom=200", function(viewportPosition
) {
45 chrome
.test
.assertEq(viewportPosition
.zoom
, 2);
48 // Checking #zoom=scale,left,top.
49 paramsParser
.getViewportFromUrlParams(
50 url
+ "#zoom=200,100,200", function(viewportPosition
) {
51 chrome
.test
.assertEq(viewportPosition
.zoom
, 2);
52 chrome
.test
.assertEq(viewportPosition
.position
.x
, 100);
53 chrome
.test
.assertEq(viewportPosition
.position
.y
, 200);
56 // Checking #nameddest=name and zoom=scale.
57 paramsParser
.getViewportFromUrlParams(
58 url
+ "#nameddest=UY&zoom=150", function(viewportPosition
) {
59 chrome
.test
.assertEq(viewportPosition
.page
, 22);
60 chrome
.test
.assertEq(viewportPosition
.zoom
, 1.5);
63 // Checking #page=pagenum and zoom=scale.
64 paramsParser
.getViewportFromUrlParams(
65 url
+ "#page=2&zoom=250", function(viewportPosition
) {
66 chrome
.test
.assertEq(viewportPosition
.page
, 1);
67 chrome
.test
.assertEq(viewportPosition
.zoom
, 2.5);
70 // Checking #nameddest=name and zoom=scale,left,top.
71 paramsParser
.getViewportFromUrlParams(
72 url
+ "#nameddest=UY&zoom=150,100,200", function(viewportPosition
) {
73 chrome
.test
.assertEq(viewportPosition
.page
, 22);
74 chrome
.test
.assertEq(viewportPosition
.zoom
, 1.5);
75 chrome
.test
.assertEq(viewportPosition
.position
.x
, 100);
76 chrome
.test
.assertEq(viewportPosition
.position
.y
, 200);
79 // Checking #page=pagenum and zoom=scale,left,top.
80 paramsParser
.getViewportFromUrlParams(
81 url
+ "#page=2&zoom=250,100,200", function(viewportPosition
) {
82 chrome
.test
.assertEq(viewportPosition
.page
, 1);
83 chrome
.test
.assertEq(viewportPosition
.zoom
, 2.5);
84 chrome
.test
.assertEq(viewportPosition
.position
.x
, 100);
85 chrome
.test
.assertEq(viewportPosition
.position
.y
, 200);
87 chrome
.test
.succeed();
91 var scriptingAPI
= new PDFScriptingAPI(window
, window
);
92 scriptingAPI
.setLoadCallback(function() {
93 chrome
.test
.runTests(tests
);