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) {
11 this.scrollCallback = f;
13 this.resizeCallback = f;
15 this.scrollTo = function(x, y) {
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();
25 sizer.resizeCallback_ = function() {
26 this.scrollTo(this.pageXOffset, this.pageYOffset);
31 this.scrollCallback = null;
32 this.resizeCallback = null;
35 function MockSizer() {
40 get height() { return this.height_; },
42 this.height_ = height;
43 if (sizer.resizeCallback_)
44 sizer.resizeCallback_();
46 get width() { return this.width_; },
49 if (sizer.resizeCallback_)
50 sizer.resizeCallback_();
55 function MockViewportChangedCallback() {
56 this.wasCalled = false;
57 this.callback = function() {
58 this.wasCalled = true;
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) {
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);
77 this.pageDimensions.push({
84 this.reset = function() {
87 this.pageDimensions = [];