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

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

Issue 838723003: Testcases for nameddests and navigate for PDF (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/test_util.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 function MockWindow(width, height, sizer) {
6 this.innerWidth = width;
7 this.innerHeight = height;
8 this.addEventListener = function(e, f) {
9 if (e == 'scroll')
10 this.scrollCallback = f;
11 if (e == 'resize')
12 this.resizeCallback = f;
13 };
14 this.scrollTo = function(x, y) {
15 if (sizer) {
16 x = Math.min(x, parseInt(sizer.style.width) - width);
17 y = Math.min(y, parseInt(sizer.style.height) - height);
18 }
19 this.pageXOffset = Math.max(0, x);
20 this.pageYOffset = Math.max(0, y);
21 this.scrollCallback();
22 };
23 if (sizer) {
24 sizer.resizeCallback_ = function() {
25 this.scrollTo(this.pageXOffset, this.pageYOffset);
26 }.bind(this);
27 }
28 this.pageXOffset = 0;
29 this.pageYOffset = 0;
30 this.scrollCallback = null;
31 this.resizeCallback = null;
32 }
33
34 function MockSizer() {
35 var sizer = this;
36 this.style = {
37 width_: '0px',
38 height_: '0px',
39 get height() { return this.height_; },
40 set height(height) {
41 this.height_ = height;
42 if (sizer.resizeCallback_)
43 sizer.resizeCallback_();
44 },
45 get width() { return this.width_; },
46 set width(width) {
47 this.width_ = width;
48 if (sizer.resizeCallback_)
49 sizer.resizeCallback_();
50 },
51 };
52 }
53
54 function MockViewportChangedCallback() {
55 this.wasCalled = false;
56 this.callback = function() {
57 this.wasCalled = true;
58 }.bind(this);
59 this.reset = function() {
60 this.wasCalled = false;
61 };
62 }
63
64 function MockDocumentDimensions(width, height) {
65 this.width = width || 0;
66 this.height = height ? height : 0;
67 this.pageDimensions = [];
68 this.addPage = function(w, h) {
69 var y = 0;
70 if (this.pageDimensions.length != 0) {
71 y = this.pageDimensions[this.pageDimensions.length - 1].y +
72 this.pageDimensions[this.pageDimensions.length - 1].height;
73 }
74 this.width = Math.max(this.width, w);
75 this.height += h;
76 this.pageDimensions.push({
77 x: 0,
78 y: y,
79 width: w,
80 height: h
81 });
82 };
83 this.reset = function() {
84 this.width = 0;
85 this.height = 0;
86 this.pageDimensions = [];
87 };
88 }
89
90 var tests = [ 5 var tests = [
91 function testDocumentNeedsScrollbars() { 6 function testDocumentNeedsScrollbars() {
92 var viewport = 7 var viewport =
93 new Viewport(new MockWindow(100, 100), new MockSizer(), function() {}, 8 new Viewport(new MockWindow(100, 100), new MockSizer(), function() {},
94 function() {}, function() {}, 10, 0); 9 function() {}, function() {}, 10, 0);
95 var scrollbars; 10 var scrollbars;
96 11
97 viewport.setDocumentDimensions(new MockDocumentDimensions(90, 90)); 12 viewport.setDocumentDimensions(new MockDocumentDimensions(90, 90));
98 scrollbars = viewport.documentNeedsScrollbars_(1); 13 scrollbars = viewport.documentNeedsScrollbars_(1);
99 chrome.test.assertFalse(scrollbars.vertical); 14 chrome.test.assertFalse(scrollbars.vertical);
(...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after
498 chrome.test.assertEq(1, viewport.zoom); 413 chrome.test.assertEq(1, viewport.zoom);
499 }; 414 };
500 viewport = new Viewport(mockWindow, mockSizer, function() {}, 415 viewport = new Viewport(mockWindow, mockSizer, function() {},
501 beforeZoom, afterZoom, 0, 0); 416 beforeZoom, afterZoom, 0, 0);
502 viewport.setZoom(0.5); 417 viewport.setZoom(0.5);
503 chrome.test.succeed(); 418 chrome.test.succeed();
504 } 419 }
505 ]; 420 ];
506 421
507 chrome.test.runTests(tests); 422 chrome.test.runTests(tests);
OLDNEW
« no previous file with comments | « chrome/test/data/pdf/test_util.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698