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

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

Issue 838723003: Testcases for nameddests and navigate for PDF (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressing nit. 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
(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 function NavigateInCurrentTabCallback() {
6 this.navigateInCurrentTabCalled = false;
7 this.callback = function() {
8 this.navigateInCurrentTabCalled = true;
9 }.bind(this);
10 this.reset = function() {
11 this.navigateInCurrentTabCalled = false;
12 };
13 }
14
15 function NavigateInNewTabCallback() {
16 this.navigateInNewTabCalled = false;
17 this.callback = function() {
18 this.navigateInNewTabCalled = true;
19 }.bind(this);
20 this.reset = function() {
21 this.navigateInNewTabCalled = false;
22 };
23 }
24
25 var tests = [
26 /**
27 * Test navigation with in the page, opening url in the same tab and
raymes 2015/01/30 03:45:03 nit: with in->within nit: opening a url
Deepak 2015/01/30 04:39:21 Done.
28 * opening url in the new tab.
29 */
30 function testNavigate() {
31 var mockWindow = new MockWindow(100, 100);
32 var mockSizer = new MockSizer();
33 var mockCallback = new MockViewportChangedCallback();
34 var viewport = new Viewport(mockWindow, mockSizer, mockCallback.callback,
35 function() {}, function() {}, 0, 0);
36
37 var paramsParser = new OpenPDFParamsParser();
38 paramsParser.namedDestinations['US'] = 0;
39 paramsParser.namedDestinations['UY'] = 2;
40 var url = "http://xyz.pdf";
41
42 var navigateInCurrentTabCallback = new NavigateInCurrentTabCallback();
43 var navigateInNewTabCallback = new NavigateInNewTabCallback();
44 var navigator = new Navigator(url, viewport, paramsParser,
45 navigateInCurrentTabCallback.callback,
46 navigateInNewTabCallback.callback);
47
48 var documentDimensions = new MockDocumentDimensions();
49 documentDimensions.addPage(100, 100);
50 documentDimensions.addPage(200, 200);
51 documentDimensions.addPage(100, 400);
52 viewport.setDocumentDimensions(documentDimensions);
53 viewport.setZoom(1);
54
55 mockCallback.reset();
56 // This should move viewport to page 0.
57 navigator.navigate(url + "#US", false);
58 chrome.test.assertTrue(mockCallback.wasCalled);
59 chrome.test.assertEq(0, viewport.position.x);
60 chrome.test.assertEq(0, viewport.position.y);
61
62 mockCallback.reset();
63 navigateInNewTabCallback.reset();
64 // This should open "http://xyz.pdf#US" in a new tab. So current tab
65 // viewport should not update and viewport position should remain same.
66 navigator.navigate(url + "#US", true);
67 chrome.test.assertFalse(mockCallback.wasCalled);
68 chrome.test.assertTrue(navigateInNewTabCallback.navigateInNewTabCalled);
69 chrome.test.assertEq(0, viewport.position.x);
70 chrome.test.assertEq(0, viewport.position.y);
71
72 mockCallback.reset();
73 // This should move viewport to page 2.
74 navigator.navigate(url + "#UY", false);
75 chrome.test.assertTrue(mockCallback.wasCalled);
76 chrome.test.assertEq(0, viewport.position.x);
77 chrome.test.assertEq(300, viewport.position.y);
78
79 mockCallback.reset();
80 navigateInCurrentTabCallback.reset();
81 // #ABC is not a named destination in the page so viewport should not
82 // update and viewport position should remain same. As this link will open
83 // in the same tab.
84 navigator.navigate(url + "#ABC", false);
85 chrome.test.assertFalse(mockCallback.wasCalled);
86 chrome.test.assertTrue(
87 navigateInCurrentTabCallback.navigateInCurrentTabCalled);
88 chrome.test.assertEq(0, viewport.position.x);
89 chrome.test.assertEq(300, viewport.position.y);
90
91 chrome.test.succeed();
92 }
93 ];
94
95 var scriptingAPI = new PDFScriptingAPI(window, window);
96 scriptingAPI.setLoadCallback(function() {
97 chrome.test.runTests(tests);
98 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698