Update CrOS OOBE throbber to MD throbber; delete old asset
[chromium-blink-merge.git] / chrome / test / data / pdf / test_util.js
blob69380d0f44c40d54064a75a2a68d02e89d71c823
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.setSize = function(width, height) {
16 this.innerWidth = width;
17 this.innerHeight = height;
18 this.resizeCallback();
20 this.scrollTo = function(x, y) {
21 if (sizer) {
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();
29 this.setTimeout = function(callback, time) {
30 this.timerCallback = callback;
31 return "timerId";
33 this.runTimeout = function() {
34 if (this.timerCallback)
35 this.timerCallback();
37 if (sizer) {
38 sizer.resizeCallback_ = function() {
39 this.scrollTo(this.pageXOffset, this.pageYOffset);
40 }.bind(this);
42 this.pageXOffset = 0;
43 this.pageYOffset = 0;
44 this.scrollCallback = null;
45 this.resizeCallback = null;
46 this.timerCallback = null;
49 function MockSizer() {
50 var sizer = this;
51 this.style = {
52 width_: '0px',
53 height_: '0px',
54 get height() { return this.height_; },
55 set height(height) {
56 this.height_ = height;
57 if (sizer.resizeCallback_)
58 sizer.resizeCallback_();
60 get width() { return this.width_; },
61 set width(width) {
62 this.width_ = width;
63 if (sizer.resizeCallback_)
64 sizer.resizeCallback_();
69 function MockViewportChangedCallback() {
70 this.wasCalled = false;
71 this.callback = function() {
72 this.wasCalled = true;
73 }.bind(this);
74 this.reset = function() {
75 this.wasCalled = false;
79 function MockDocumentDimensions(width, height) {
80 this.width = width || 0;
81 this.height = height ? height : 0;
82 this.pageDimensions = [];
83 this.addPage = function(w, h) {
84 var y = 0;
85 if (this.pageDimensions.length != 0) {
86 y = this.pageDimensions[this.pageDimensions.length - 1].y +
87 this.pageDimensions[this.pageDimensions.length - 1].height;
89 this.width = Math.max(this.width, w);
90 this.height += h;
91 this.pageDimensions.push({
92 x: 0,
93 y: y,
94 width: w,
95 height: h
96 });
98 this.reset = function() {
99 this.width = 0;
100 this.height = 0;
101 this.pageDimensions = [];
105 function importHTML(src) {
106 var link = document.createElement('link');
107 var promise = new Promise(function(resolve, reject) {
108 link.onload = resolve;
109 link.onerror = reject;
111 link.rel = 'import';
112 link.href = src;
113 document.head.appendChild(link);
114 return promise;
118 * Import iron-test-helpers into the test document.
119 * @example
120 * importTestHelpers().then(function() {
121 * chrome.test.runTests(...);
122 * })
124 function importTestHelpers() {
125 return importHTML('chrome://resources/polymer/v1_0/iron-test-helpers/' +
126 'iron-test-helpers.html');