Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
|
raymes
2015/01/28 01:33:45
We could really split this into 2 files:
params_pa
Deepak
2015/01/28 05:57:24
Done.
| |
| 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 by navigate. | |
| 8 */ | |
| 9 function testNamedDestinationsByNavigate() { | |
|
raymes
2015/01/28 01:33:45
nit: testNavigate
Deepak
2015/01/28 05:57:24
Done.
| |
| 10 var mockWindow = new MockWindow(100, 100); | |
| 11 var mockSizer = new MockSizer(); | |
| 12 var mockCallback = new MockViewportChangedCallback(); | |
| 13 var viewport = new Viewport(mockWindow, mockSizer, mockCallback.callback, | |
| 14 function() {}, function() {}, 0, 0); | |
| 15 | |
| 16 var paramsParser = new OpenPDFParamsParser(); | |
| 17 paramsParser.namedDestinations['US'] = 0; | |
| 18 paramsParser.namedDestinations['UY'] = 2; | |
| 19 var url = "http://xyz.pdf"; | |
| 20 var navigator = new Navigator(url, viewport, paramsParser); | |
|
raymes
2015/01/28 01:33:45
Can we change Navigator to also pass in:
-A functi
Deepak
2015/01/28 05:57:24
Done.
| |
| 21 | |
| 22 var documentDimensions = new MockDocumentDimensions(); | |
| 23 | |
|
raymes
2015/01/28 01:33:45
nit: no need for a blank line
Deepak
2015/01/28 05:57:24
Done.
| |
| 24 documentDimensions.addPage(100, 100); | |
| 25 documentDimensions.addPage(200, 200); | |
| 26 documentDimensions.addPage(100, 400); | |
| 27 viewport.setDocumentDimensions(documentDimensions); | |
| 28 viewport.setZoom(1); | |
| 29 | |
| 30 mockCallback.reset(); | |
| 31 // This should move viewport to page 0. | |
| 32 navigator.navigate(url + "#US", false); | |
| 33 chrome.test.assertTrue(mockCallback.wasCalled); | |
| 34 chrome.test.assertEq(0, viewport.position.x); | |
| 35 chrome.test.assertEq(0, viewport.position.y); | |
| 36 | |
| 37 mockCallback.reset(); | |
| 38 // This shouldl open "http://xyz.pdf#US" in newTab. So current tab viewport | |
|
raymes
2015/01/28 01:33:45
nit: shouldl->should
nit: newTab->a new tab
Deepak
2015/01/28 05:57:24
Done.
| |
| 39 // should not change and viewport position should remain same. | |
| 40 navigator.navigate(url + "#US", true); | |
| 41 chrome.test.assertFalse(mockCallback.wasCalled); | |
| 42 chrome.test.assertEq(0, viewport.position.x); | |
| 43 chrome.test.assertEq(0, viewport.position.y); | |
| 44 | |
| 45 mockCallback.reset(); | |
| 46 // This should move viewport to page 2. | |
| 47 navigator.navigate(url + "#UY", false); | |
| 48 chrome.test.assertTrue(mockCallback.wasCalled); | |
| 49 chrome.test.assertEq(0, viewport.position.x); | |
| 50 chrome.test.assertEq(300, viewport.position.y); | |
| 51 | |
| 52 mockCallback.reset(); | |
| 53 // #ABC is not a nemeddestination in the page so viewport should not change | |
|
raymes
2015/01/28 01:33:45
nit: nemeddestination->named destination
Deepak
2015/01/28 05:57:24
Done.
| |
| 54 // and viewport position should remain same. | |
| 55 navigator.navigate(url + "#ABC", false); | |
| 56 chrome.test.assertFalse(mockCallback.wasCalled); | |
| 57 chrome.test.assertEq(0, viewport.position.x); | |
| 58 chrome.test.assertEq(300, viewport.position.y); | |
| 59 | |
| 60 chrome.test.succeed(); | |
| 61 }, | |
| 62 | |
| 63 /** | |
| 64 * Test named destinations by getViewportFromUrlParams. | |
| 65 */ | |
| 66 function testNamedDestinations() { | |
|
raymes
2015/01/28 01:33:45
nit: testParamsParser
Deepak
2015/01/28 05:57:24
Done.
Deepak
2015/01/28 05:57:24
Done.
| |
| 67 var paramsParser = new OpenPDFParamsParser(); | |
| 68 // Assigning page number for #nameddests. | |
| 69 paramsParser.namedDestinations['RU'] = 26; | |
| 70 paramsParser.namedDestinations['US'] = 0; | |
| 71 paramsParser.namedDestinations['UY'] = 22; | |
| 72 | |
| 73 var url = "http://xyz.pdf"; | |
| 74 | |
| 75 // Checking #nameddest. | |
| 76 var urlParams = paramsParser.getViewportFromUrlParams(url + "#RU"); | |
| 77 chrome.test.assertEq(urlParams.page, 26); | |
| 78 | |
| 79 // Checking #nameddest=name. | |
| 80 urlParams = paramsParser.getViewportFromUrlParams(url + "#nameddest=US"); | |
| 81 chrome.test.assertEq(urlParams.page, 0); | |
| 82 | |
| 83 // Checking #page=pagenum nameddest.The document first page has a pagenum | |
| 84 // value of 1. | |
| 85 urlParams = paramsParser.getViewportFromUrlParams(url + "#page=6"); | |
| 86 chrome.test.assertEq(urlParams.page, 5); | |
| 87 | |
| 88 // Checking #zoom=scale. | |
| 89 urlParams = paramsParser.getViewportFromUrlParams(url + "#zoom=200"); | |
| 90 chrome.test.assertEq(urlParams.zoom, 2); | |
| 91 | |
| 92 // Checking #zoom=scale,left,top. | |
| 93 urlParams = paramsParser.getViewportFromUrlParams(url + | |
| 94 "#zoom=200,100,200"); | |
|
raymes
2015/01/28 01:33:45
nit: indentation. Use 4 space indent
Deepak
2015/01/28 05:57:24
Done.
| |
| 95 chrome.test.assertEq(urlParams.zoom, 2); | |
| 96 chrome.test.assertEq(urlParams.position.x, 100); | |
| 97 chrome.test.assertEq(urlParams.position.y, 200); | |
| 98 | |
| 99 // Checking #nameddest=name and zoom=scale. | |
| 100 urlParams = paramsParser.getViewportFromUrlParams(url + | |
| 101 "#nameddest=UY&zoom=150"); | |
| 102 chrome.test.assertEq(urlParams.page, 22); | |
| 103 chrome.test.assertEq(urlParams.zoom, 1.5); | |
| 104 | |
| 105 // Checking #page=pagenum and zoom=scale. | |
| 106 urlParams = paramsParser.getViewportFromUrlParams(url + | |
| 107 "#page=2&zoom=250"); | |
| 108 chrome.test.assertEq(urlParams.page, 1); | |
| 109 chrome.test.assertEq(urlParams.zoom, 2.5); | |
| 110 | |
| 111 // Checking #nameddest=name and zoom=scale,left,top. | |
| 112 urlParams = paramsParser.getViewportFromUrlParams(url + | |
| 113 "#nameddest=UY&zoom=150,100,200"); | |
| 114 chrome.test.assertEq(urlParams.page, 22); | |
| 115 chrome.test.assertEq(urlParams.zoom, 1.5); | |
| 116 chrome.test.assertEq(urlParams.position.x, 100); | |
| 117 chrome.test.assertEq(urlParams.position.y, 200); | |
| 118 | |
| 119 // Checking #page=pagenum and zoom=scale,left,top. | |
| 120 urlParams = paramsParser.getViewportFromUrlParams(url + | |
| 121 "#page=2&zoom=250,100,200"); | |
| 122 chrome.test.assertEq(urlParams.page, 1); | |
| 123 chrome.test.assertEq(urlParams.zoom, 2.5); | |
| 124 chrome.test.assertEq(urlParams.position.x, 100); | |
| 125 chrome.test.assertEq(urlParams.position.y, 200); | |
| 126 | |
| 127 chrome.test.succeed(); | |
| 128 } | |
| 129 ]; | |
| 130 | |
| 131 var scriptingAPI = new PDFScriptingAPI(window, window); | |
| 132 scriptingAPI.setLoadCallback(function() { | |
| 133 chrome.test.runTests(tests); | |
| 134 }); | |
| OLD | NEW |