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

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 as per review comments. 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
« no previous file with comments | « chrome/test/data/pdf/navigator_test.js ('k') | pdf/out_of_process_instance.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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(function(name) {
11 // Assigning page number for #nameddests. 11 if (name == 'RU')
12 paramsParser.namedDestinations['RU'] = 26; 12 paramsParser.onNamedDestinationReceived(26);
13 paramsParser.namedDestinations['US'] = 0; 13 else if (name == 'US')
14 paramsParser.namedDestinations['UY'] = 22; 14 paramsParser.onNamedDestinationReceived(0);
15 else if (name == 'UY')
16 paramsParser.onNamedDestinationReceived(22);
17 else
18 paramsParser.onNamedDestinationReceived(-1);
19 });
15 20
16 var url = "http://xyz.pdf"; 21 var url = "http://xyz.pdf";
17 22
18 // Checking #nameddest. 23 // Checking #nameddest.
19 var urlParams = paramsParser.getViewportFromUrlParams(url + "#RU"); 24 paramsParser.getViewportFromUrlParams(
20 chrome.test.assertEq(urlParams.page, 26); 25 url + "#RU", function(viewportPosition) {
26 chrome.test.assertEq(viewportPosition.page, 26);
27 });
21 28
22 // Checking #nameddest=name. 29 // Checking #nameddest=name.
23 urlParams = paramsParser.getViewportFromUrlParams(url + "#nameddest=US"); 30 paramsParser.getViewportFromUrlParams(
24 chrome.test.assertEq(urlParams.page, 0); 31 url + "#nameddest=US", function(viewportPosition) {
32 chrome.test.assertEq(viewportPosition.page, 0);
33 });
25 34
26 // Checking #page=pagenum nameddest.The document first page has a pagenum 35 // Checking #page=pagenum nameddest.The document first page has a pagenum
27 // value of 1. 36 // value of 1.
28 urlParams = paramsParser.getViewportFromUrlParams(url + "#page=6"); 37 paramsParser.getViewportFromUrlParams(
29 chrome.test.assertEq(urlParams.page, 5); 38 url + "#page=6", function(viewportPosition) {
39 chrome.test.assertEq(viewportPosition.page, 5);
40 });
30 41
31 // Checking #zoom=scale. 42 // Checking #zoom=scale.
32 urlParams = paramsParser.getViewportFromUrlParams(url + "#zoom=200"); 43 paramsParser.getViewportFromUrlParams(
33 chrome.test.assertEq(urlParams.zoom, 2); 44 url + "#zoom=200", function(viewportPosition) {
45 chrome.test.assertEq(viewportPosition.zoom, 2);
46 });
34 47
35 // Checking #zoom=scale,left,top. 48 // Checking #zoom=scale,left,top.
36 urlParams = paramsParser.getViewportFromUrlParams(url + 49 paramsParser.getViewportFromUrlParams(
37 "#zoom=200,100,200"); 50 url + "#zoom=200,100,200", function(viewportPosition) {
38 chrome.test.assertEq(urlParams.zoom, 2); 51 chrome.test.assertEq(viewportPosition.zoom, 2);
39 chrome.test.assertEq(urlParams.position.x, 100); 52 chrome.test.assertEq(viewportPosition.position.x, 100);
40 chrome.test.assertEq(urlParams.position.y, 200); 53 chrome.test.assertEq(viewportPosition.position.y, 200);
54 });
41 55
42 // Checking #nameddest=name and zoom=scale. 56 // Checking #nameddest=name and zoom=scale.
43 urlParams = paramsParser.getViewportFromUrlParams(url + 57 paramsParser.getViewportFromUrlParams(
44 "#nameddest=UY&zoom=150"); 58 url + "#nameddest=UY&zoom=150", function(viewportPosition) {
45 chrome.test.assertEq(urlParams.page, 22); 59 chrome.test.assertEq(viewportPosition.page, 22);
46 chrome.test.assertEq(urlParams.zoom, 1.5); 60 chrome.test.assertEq(viewportPosition.zoom, 1.5);
61 });
47 62
48 // Checking #page=pagenum and zoom=scale. 63 // Checking #page=pagenum and zoom=scale.
49 urlParams = paramsParser.getViewportFromUrlParams(url + 64 paramsParser.getViewportFromUrlParams(
50 "#page=2&zoom=250"); 65 url + "#page=2&zoom=250", function(viewportPosition) {
51 chrome.test.assertEq(urlParams.page, 1); 66 chrome.test.assertEq(viewportPosition.page, 1);
52 chrome.test.assertEq(urlParams.zoom, 2.5); 67 chrome.test.assertEq(viewportPosition.zoom, 2.5);
68 });
53 69
54 // Checking #nameddest=name and zoom=scale,left,top. 70 // Checking #nameddest=name and zoom=scale,left,top.
55 urlParams = paramsParser.getViewportFromUrlParams(url + 71 paramsParser.getViewportFromUrlParams(
56 "#nameddest=UY&zoom=150,100,200"); 72 url + "#nameddest=UY&zoom=150,100,200", function(viewportPosition) {
57 chrome.test.assertEq(urlParams.page, 22); 73 chrome.test.assertEq(viewportPosition.page, 22);
58 chrome.test.assertEq(urlParams.zoom, 1.5); 74 chrome.test.assertEq(viewportPosition.zoom, 1.5);
59 chrome.test.assertEq(urlParams.position.x, 100); 75 chrome.test.assertEq(viewportPosition.position.x, 100);
60 chrome.test.assertEq(urlParams.position.y, 200); 76 chrome.test.assertEq(viewportPosition.position.y, 200);
77 });
61 78
62 // Checking #page=pagenum and zoom=scale,left,top. 79 // Checking #page=pagenum and zoom=scale,left,top.
63 urlParams = paramsParser.getViewportFromUrlParams(url + 80 paramsParser.getViewportFromUrlParams(
64 "#page=2&zoom=250,100,200"); 81 url + "#page=2&zoom=250,100,200", function(viewportPosition) {
65 chrome.test.assertEq(urlParams.page, 1); 82 chrome.test.assertEq(viewportPosition.page, 1);
66 chrome.test.assertEq(urlParams.zoom, 2.5); 83 chrome.test.assertEq(viewportPosition.zoom, 2.5);
67 chrome.test.assertEq(urlParams.position.x, 100); 84 chrome.test.assertEq(viewportPosition.position.x, 100);
68 chrome.test.assertEq(urlParams.position.y, 200); 85 chrome.test.assertEq(viewportPosition.position.y, 200);
69 86 });
70 chrome.test.succeed(); 87 chrome.test.succeed();
71 } 88 }
72 ]; 89 ];
73 90
74 var scriptingAPI = new PDFScriptingAPI(window, window); 91 var scriptingAPI = new PDFScriptingAPI(window, window);
75 scriptingAPI.setLoadCallback(function() { 92 scriptingAPI.setLoadCallback(function() {
76 chrome.test.runTests(tests); 93 chrome.test.runTests(tests);
77 }); 94 });
OLDNEW
« no previous file with comments | « chrome/test/data/pdf/navigator_test.js ('k') | pdf/out_of_process_instance.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698