OLD | NEW |
(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 // 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; |
| 14 }; |
| 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); |
| 19 } |
| 20 this.pageXOffset = Math.max(0, x); |
| 21 this.pageYOffset = Math.max(0, y); |
| 22 this.scrollCallback(); |
| 23 }; |
| 24 if (sizer) { |
| 25 sizer.resizeCallback_ = function() { |
| 26 this.scrollTo(this.pageXOffset, this.pageYOffset); |
| 27 }.bind(this); |
| 28 } |
| 29 this.pageXOffset = 0; |
| 30 this.pageYOffset = 0; |
| 31 this.scrollCallback = null; |
| 32 this.resizeCallback = null; |
| 33 } |
| 34 |
| 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_(); |
| 45 }, |
| 46 get width() { return this.width_; }, |
| 47 set width(width) { |
| 48 this.width_ = width; |
| 49 if (sizer.resizeCallback_) |
| 50 sizer.resizeCallback_(); |
| 51 }, |
| 52 }; |
| 53 } |
| 54 |
| 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; |
| 62 }; |
| 63 } |
| 64 |
| 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; |
| 74 } |
| 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 }); |
| 83 }; |
| 84 this.reset = function() { |
| 85 this.width = 0; |
| 86 this.height = 0; |
| 87 this.pageDimensions = []; |
| 88 }; |
| 89 } |
OLD | NEW |