Reland "Non-SFI mode: Switch to newlib. (patchset #4 id:60001 of https://codereview...
[chromium-blink-merge.git] / chrome / test / data / pdf / test_util.js
blobbf2093ae2d5d9706dbeee3c37c81e233583d4c14
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.
5 // Utilities that are used in multiple tests.
6 function MockWindow(width, height, sizer) {
7 this.innerWidth = width;
8 this.innerHeight = height;
9 this.addEventListener = function(e, f) {
10 if (e == 'scroll')
11 this.scrollCallback = f;
12 if (e == 'resize')
13 this.resizeCallback = f;
15 this.setSize = function(width, height) {
16 this.innerWidth = width;
17 this.innerHeight = height;
18 this.resizeCallback();
20 this.scrollTo = function(x, y) {
21 if (sizer) {
22 x = Math.min(x, parseInt(sizer.style.width) - width);
23 y = Math.min(y, parseInt(sizer.style.height) - height);
25 this.pageXOffset = Math.max(0, x);
26 this.pageYOffset = Math.max(0, y);
27 this.scrollCallback();
29 if (sizer) {
30 sizer.resizeCallback_ = function() {
31 this.scrollTo(this.pageXOffset, this.pageYOffset);
32 }.bind(this);
34 this.pageXOffset = 0;
35 this.pageYOffset = 0;
36 this.scrollCallback = null;
37 this.resizeCallback = null;
40 function MockSizer() {
41 var sizer = this;
42 this.style = {
43 width_: '0px',
44 height_: '0px',
45 get height() { return this.height_; },
46 set height(height) {
47 this.height_ = height;
48 if (sizer.resizeCallback_)
49 sizer.resizeCallback_();
51 get width() { return this.width_; },
52 set width(width) {
53 this.width_ = width;
54 if (sizer.resizeCallback_)
55 sizer.resizeCallback_();
60 function MockViewportChangedCallback() {
61 this.wasCalled = false;
62 this.callback = function() {
63 this.wasCalled = true;
64 }.bind(this);
65 this.reset = function() {
66 this.wasCalled = false;
70 function MockDocumentDimensions(width, height) {
71 this.width = width || 0;
72 this.height = height ? height : 0;
73 this.pageDimensions = [];
74 this.addPage = function(w, h) {
75 var y = 0;
76 if (this.pageDimensions.length != 0) {
77 y = this.pageDimensions[this.pageDimensions.length - 1].y +
78 this.pageDimensions[this.pageDimensions.length - 1].height;
80 this.width = Math.max(this.width, w);
81 this.height += h;
82 this.pageDimensions.push({
83 x: 0,
84 y: y,
85 width: w,
86 height: h
87 });
89 this.reset = function() {
90 this.width = 0;
91 this.height = 0;
92 this.pageDimensions = [];