Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(15)

Side by Side Diff: chrome/test/data/pdf/params_parser_test.js

Issue 918953002: Fix for PDFs with lots of named destinations take a long time to load. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Changes with new approach. Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 var tests = [ 5 var tests = [
6 /** 6 /**
7 * Test named destinations. 7 * Test named destinations.
8 */ 8 */
9 function testParamsParser() { 9 function testParamsParser() {
10 var paramsParser = new OpenPDFParamsParser(); 10 var paramsParser = new OpenPDFParamsParser();
11 // Assigning page number for #nameddests. 11 // Assigning page number for #nameddests.
12 paramsParser.namedDestinations['RU'] = 26; 12 paramsParser.namedDestinations['RU'] = 26;
13 paramsParser.namedDestinations['US'] = 0; 13 paramsParser.namedDestinations['US'] = 0;
14 paramsParser.namedDestinations['UY'] = 22; 14 paramsParser.namedDestinations['UY'] = 22;
raymes 2015/02/16 22:44:03 Same thing here.
15 15
16 var url = "http://xyz.pdf"; 16 var url = "http://xyz.pdf";
17 17
18 // Checking #nameddest. 18 // Checking #nameddest.
19 var urlParams = paramsParser.getViewportFromUrlParams(url + "#RU"); 19 paramsParser.getViewportFromUrlParams(url + "#RU", function(urlParams) {
raymes 2015/02/16 02:02:31 nit: here and below urlParams->viewportPosition
Deepak 2015/02/16 06:45:38 Done.
20 chrome.test.assertEq(urlParams.page, 26); 20 chrome.test.assertEq(urlParams.page, 26);
21 });
21 22
22 // Checking #nameddest=name. 23 // Checking #nameddest=name.
23 urlParams = paramsParser.getViewportFromUrlParams(url + "#nameddest=US"); 24 paramsParser.getViewportFromUrlParams(
24 chrome.test.assertEq(urlParams.page, 0); 25 url + "#nameddest=US", function(urlParams) {
26 chrome.test.assertEq(urlParams.page, 0);
27 });
25 28
26 // Checking #page=pagenum nameddest.The document first page has a pagenum 29 // Checking #page=pagenum nameddest.The document first page has a pagenum
27 // value of 1. 30 // value of 1.
28 urlParams = paramsParser.getViewportFromUrlParams(url + "#page=6"); 31 paramsParser.getViewportFromUrlParams(url + "#page=6", function(urlParams) {
29 chrome.test.assertEq(urlParams.page, 5); 32 chrome.test.assertEq(urlParams.page, 5);
33 });
30 34
31 // Checking #zoom=scale. 35 // Checking #zoom=scale.
32 urlParams = paramsParser.getViewportFromUrlParams(url + "#zoom=200"); 36 paramsParser.getViewportFromUrlParams(
33 chrome.test.assertEq(urlParams.zoom, 2); 37 url + "#zoom=200", function(urlParams) {
38 chrome.test.assertEq(urlParams.zoom, 2);
39 });
34 40
35 // Checking #zoom=scale,left,top. 41 // Checking #zoom=scale,left,top.
36 urlParams = paramsParser.getViewportFromUrlParams(url + 42 paramsParser.getViewportFromUrlParams(
37 "#zoom=200,100,200"); 43 url + "#zoom=200,100,200", function(urlParams) {
38 chrome.test.assertEq(urlParams.zoom, 2); 44 chrome.test.assertEq(urlParams.zoom, 2);
39 chrome.test.assertEq(urlParams.position.x, 100); 45 chrome.test.assertEq(urlParams.position.x, 100);
40 chrome.test.assertEq(urlParams.position.y, 200); 46 chrome.test.assertEq(urlParams.position.y, 200);
47 });
41 48
42 // Checking #nameddest=name and zoom=scale. 49 // Checking #nameddest=name and zoom=scale.
43 urlParams = paramsParser.getViewportFromUrlParams(url + 50 paramsParser.getViewportFromUrlParams(
44 "#nameddest=UY&zoom=150"); 51 url + "#nameddest=UY&zoom=150", function(urlParams) {
45 chrome.test.assertEq(urlParams.page, 22); 52 chrome.test.assertEq(urlParams.page, 22);
46 chrome.test.assertEq(urlParams.zoom, 1.5); 53 chrome.test.assertEq(urlParams.zoom, 1.5);
54 });
47 55
48 // Checking #page=pagenum and zoom=scale. 56 // Checking #page=pagenum and zoom=scale.
49 urlParams = paramsParser.getViewportFromUrlParams(url + 57 paramsParser.getViewportFromUrlParams(
50 "#page=2&zoom=250"); 58 url + "#page=2&zoom=250", function(urlParams) {
51 chrome.test.assertEq(urlParams.page, 1); 59 chrome.test.assertEq(urlParams.page, 1);
52 chrome.test.assertEq(urlParams.zoom, 2.5); 60 chrome.test.assertEq(urlParams.zoom, 2.5);
61 });
53 62
54 // Checking #nameddest=name and zoom=scale,left,top. 63 // Checking #nameddest=name and zoom=scale,left,top.
55 urlParams = paramsParser.getViewportFromUrlParams(url + 64 paramsParser.getViewportFromUrlParams(
56 "#nameddest=UY&zoom=150,100,200"); 65 url + "#nameddest=UY&zoom=150,100,200", function(urlParams) {
57 chrome.test.assertEq(urlParams.page, 22); 66 chrome.test.assertEq(urlParams.page, 22);
58 chrome.test.assertEq(urlParams.zoom, 1.5); 67 chrome.test.assertEq(urlParams.zoom, 1.5);
59 chrome.test.assertEq(urlParams.position.x, 100); 68 chrome.test.assertEq(urlParams.position.x, 100);
60 chrome.test.assertEq(urlParams.position.y, 200); 69 chrome.test.assertEq(urlParams.position.y, 200);
70 });
61 71
62 // Checking #page=pagenum and zoom=scale,left,top. 72 // Checking #page=pagenum and zoom=scale,left,top.
63 urlParams = paramsParser.getViewportFromUrlParams(url + 73 paramsParser.getViewportFromUrlParams(
64 "#page=2&zoom=250,100,200"); 74 url + "#page=2&zoom=250,100,200", function(urlParams) {
65 chrome.test.assertEq(urlParams.page, 1); 75 chrome.test.assertEq(urlParams.page, 1);
66 chrome.test.assertEq(urlParams.zoom, 2.5); 76 chrome.test.assertEq(urlParams.zoom, 2.5);
67 chrome.test.assertEq(urlParams.position.x, 100); 77 chrome.test.assertEq(urlParams.position.x, 100);
68 chrome.test.assertEq(urlParams.position.y, 200); 78 chrome.test.assertEq(urlParams.position.y, 200);
69 79 });
70 chrome.test.succeed(); 80 chrome.test.succeed();
71 } 81 }
72 ]; 82 ];
73 83
74 var scriptingAPI = new PDFScriptingAPI(window, window); 84 var scriptingAPI = new PDFScriptingAPI(window, window);
75 scriptingAPI.setLoadCallback(function() { 85 scriptingAPI.setLoadCallback(function() {
76 chrome.test.runTests(tests); 86 chrome.test.runTests(tests);
77 }); 87 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698