OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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 // Utilities that are used in multiple tests. | 5 // Utilities that are used in multiple tests. |
6 function MockWindow(width, height, sizer) { | 6 function MockWindow(width, height, sizer) { |
7 this.innerWidth = width; | 7 this.innerWidth = width; |
8 this.innerHeight = height; | 8 this.innerHeight = height; |
9 this.addEventListener = function(e, f) { | 9 this.addEventListener = function(e, f) { |
10 if (e == 'scroll') | 10 if (e == 'scroll') |
11 this.scrollCallback = f; | 11 this.scrollCallback = f; |
12 if (e == 'resize') | 12 if (e == 'resize') |
13 this.resizeCallback = f; | 13 this.resizeCallback = f; |
14 }; | 14 }; |
| 15 this.setSize = function(width, height) { |
| 16 this.innerWidth = width; |
| 17 this.innerHeight = height; |
| 18 this.resizeCallback(); |
| 19 } |
15 this.scrollTo = function(x, y) { | 20 this.scrollTo = function(x, y) { |
16 if (sizer) { | 21 if (sizer) { |
17 x = Math.min(x, parseInt(sizer.style.width) - width); | 22 x = Math.min(x, parseInt(sizer.style.width) - width); |
18 y = Math.min(y, parseInt(sizer.style.height) - height); | 23 y = Math.min(y, parseInt(sizer.style.height) - height); |
19 } | 24 } |
20 this.pageXOffset = Math.max(0, x); | 25 this.pageXOffset = Math.max(0, x); |
21 this.pageYOffset = Math.max(0, y); | 26 this.pageYOffset = Math.max(0, y); |
22 this.scrollCallback(); | 27 this.scrollCallback(); |
23 }; | 28 }; |
24 if (sizer) { | 29 if (sizer) { |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 width: w, | 85 width: w, |
81 height: h | 86 height: h |
82 }); | 87 }); |
83 }; | 88 }; |
84 this.reset = function() { | 89 this.reset = function() { |
85 this.width = 0; | 90 this.width = 0; |
86 this.height = 0; | 91 this.height = 0; |
87 this.pageDimensions = []; | 92 this.pageDimensions = []; |
88 }; | 93 }; |
89 } | 94 } |
OLD | NEW |