Implementation of the NetworkingConfigService
[chromium-blink-merge.git] / chrome / test / data / pdf / test_util.js
blob8ea2a81cd9fd3ec609836f67690a9ee49ec1dea3
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.scrollTo = function(x, y) {
16 if (sizer) {
17 x = Math.min(x, parseInt(sizer.style.width) - width);
18 y = Math.min(y, parseInt(sizer.style.height) - height);
20 this.pageXOffset = Math.max(0, x);
21 this.pageYOffset = Math.max(0, y);
22 this.scrollCallback();
24 if (sizer) {
25 sizer.resizeCallback_ = function() {
26 this.scrollTo(this.pageXOffset, this.pageYOffset);
27 }.bind(this);
29 this.pageXOffset = 0;
30 this.pageYOffset = 0;
31 this.scrollCallback = null;
32 this.resizeCallback = null;
35 function MockSizer() {
36 var sizer = this;
37 this.style = {
38 width_: '0px',
39 height_: '0px',
40 get height() { return this.height_; },
41 set height(height) {
42 this.height_ = height;
43 if (sizer.resizeCallback_)
44 sizer.resizeCallback_();
46 get width() { return this.width_; },
47 set width(width) {
48 this.width_ = width;
49 if (sizer.resizeCallback_)
50 sizer.resizeCallback_();
55 function MockViewportChangedCallback() {
56 this.wasCalled = false;
57 this.callback = function() {
58 this.wasCalled = true;
59 }.bind(this);
60 this.reset = function() {
61 this.wasCalled = false;
65 function MockDocumentDimensions(width, height) {
66 this.width = width || 0;
67 this.height = height ? height : 0;
68 this.pageDimensions = [];
69 this.addPage = function(w, h) {
70 var y = 0;
71 if (this.pageDimensions.length != 0) {
72 y = this.pageDimensions[this.pageDimensions.length - 1].y +
73 this.pageDimensions[this.pageDimensions.length - 1].height;
75 this.width = Math.max(this.width, w);
76 this.height += h;
77 this.pageDimensions.push({
78 x: 0,
79 y: y,
80 width: w,
81 height: h
82 });
84 this.reset = function() {
85 this.width = 0;
86 this.height = 0;
87 this.pageDimensions = [];