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.setSize = function(width
, height
) {
16 this.innerWidth
= width
;
17 this.innerHeight
= height
;
18 this.resizeCallback();
20 this.scrollTo = function(x
, y
) {
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();
30 sizer
.resizeCallback_ = function() {
31 this.scrollTo(this.pageXOffset
, this.pageYOffset
);
36 this.scrollCallback
= null;
37 this.resizeCallback
= null;
40 function MockSizer() {
45 get height() { return this.height_
; },
47 this.height_
= height
;
48 if (sizer
.resizeCallback_
)
49 sizer
.resizeCallback_();
51 get width() { return this.width_
; },
54 if (sizer
.resizeCallback_
)
55 sizer
.resizeCallback_();
60 function MockViewportChangedCallback() {
61 this.wasCalled
= false;
62 this.callback = function() {
63 this.wasCalled
= true;
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
) {
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
);
82 this.pageDimensions
.push({
89 this.reset = function() {
92 this.pageDimensions
= [];