2016-10-23 22:37:15 +02:00
|
|
|
/**
|
|
|
|
* @license
|
|
|
|
* Copyright Google Inc. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by an MIT-style license that can be
|
|
|
|
* found in the LICENSE file at https://angular.io/license
|
|
|
|
*/
|
|
|
|
|
2016-08-26 15:44:05 -07:00
|
|
|
import {NgFor, NgIf} from '@angular/common';
|
|
|
|
import {Component, Directive} from '@angular/core';
|
2016-08-03 12:32:26 -07:00
|
|
|
import {TimerWrapper} from '@angular/facade/src/async';
|
|
|
|
import {document} from '@angular/facade/src/browser';
|
2016-08-26 15:44:05 -07:00
|
|
|
import {isPresent} from '@angular/facade/src/lang';
|
|
|
|
import {DOM} from '@angular/platform-browser/src/dom/dom_adapter';
|
|
|
|
import {bindAction, getIntParameter} from '@angular/testing/src/benchmark_util';
|
2015-02-05 18:33:57 -08:00
|
|
|
|
2016-08-26 15:44:05 -07:00
|
|
|
import {ScrollAreaComponent} from './scroll_area';
|
2015-05-29 21:40:15 -07:00
|
|
|
|
2015-04-09 17:53:36 -07:00
|
|
|
|
2016-03-08 13:36:48 -08:00
|
|
|
@Component({
|
|
|
|
selector: 'scroll-app',
|
2015-05-11 17:04:55 -07:00
|
|
|
directives: [ScrollAreaComponent, NgIf, NgFor],
|
2015-04-09 17:53:36 -07:00
|
|
|
template: `
|
|
|
|
<div>
|
|
|
|
<div style="display: flex">
|
|
|
|
<scroll-area id="testArea"></scroll-area>
|
|
|
|
</div>
|
2018-03-14 17:27:38 -07:00
|
|
|
<div *ngIf="scrollAreas.length > 0">
|
2015-04-09 17:53:36 -07:00
|
|
|
<p>Following tables are only here to add weight to the UI:</p>
|
2018-03-14 17:27:38 -07:00
|
|
|
<scroll-area *ngFor="let scrollArea of scrollAreas"></scroll-area>
|
2015-04-09 17:53:36 -07:00
|
|
|
</div>
|
|
|
|
</div>`
|
|
|
|
})
|
2015-02-05 18:33:57 -08:00
|
|
|
export class App {
|
2015-08-28 11:29:19 -07:00
|
|
|
scrollAreas: number[];
|
2015-08-20 16:25:34 -07:00
|
|
|
iterationCount: number;
|
|
|
|
scrollIncrement: number;
|
2015-02-05 18:33:57 -08:00
|
|
|
|
|
|
|
constructor() {
|
2016-11-12 14:08:58 +01:00
|
|
|
let appSize = getIntParameter('appSize');
|
2015-02-05 18:33:57 -08:00
|
|
|
this.iterationCount = getIntParameter('iterationCount');
|
|
|
|
this.scrollIncrement = getIntParameter('scrollIncrement');
|
|
|
|
appSize = appSize > 1 ? appSize - 1 : 0; // draw at least one table
|
|
|
|
this.scrollAreas = [];
|
2016-11-12 14:08:58 +01:00
|
|
|
for (let i = 0; i < appSize; i++) {
|
2015-06-17 11:17:21 -07:00
|
|
|
this.scrollAreas.push(i);
|
2015-02-05 18:33:57 -08:00
|
|
|
}
|
2020-04-13 16:40:21 -07:00
|
|
|
bindAction('#run-btn', () => {
|
|
|
|
this.runBenchmark();
|
|
|
|
});
|
2015-02-27 09:07:16 -08:00
|
|
|
bindAction('#reset-btn', () => {
|
2015-02-05 18:33:57 -08:00
|
|
|
this._getScrollDiv().scrollTop = 0;
|
2016-11-12 14:08:58 +01:00
|
|
|
const existingMarker = this._locateFinishedMarker();
|
2017-03-02 09:37:01 -08:00
|
|
|
if (existingMarker != null) {
|
2015-02-05 18:33:57 -08:00
|
|
|
DOM.removeChild(document.body, existingMarker);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
runBenchmark() {
|
2016-11-12 14:08:58 +01:00
|
|
|
const scrollDiv = this._getScrollDiv();
|
|
|
|
let n: number = this.iterationCount;
|
|
|
|
let scheduleScroll;
|
2015-02-05 18:33:57 -08:00
|
|
|
scheduleScroll = () => {
|
2015-05-19 16:47:30 +02:00
|
|
|
TimerWrapper.setTimeout(() => {
|
2015-02-05 18:33:57 -08:00
|
|
|
scrollDiv.scrollTop += this.scrollIncrement;
|
|
|
|
n--;
|
|
|
|
if (n > 0) {
|
|
|
|
scheduleScroll();
|
|
|
|
} else {
|
|
|
|
this._scheduleFinishedMarker();
|
|
|
|
}
|
|
|
|
}, 0);
|
2015-05-29 21:40:15 -07:00
|
|
|
};
|
2015-02-05 18:33:57 -08:00
|
|
|
scheduleScroll();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Puts a marker indicating that the test is finished.
|
2016-10-23 23:07:33 +02:00
|
|
|
private _scheduleFinishedMarker() {
|
2016-11-12 14:08:58 +01:00
|
|
|
const existingMarker = this._locateFinishedMarker();
|
2017-03-02 09:37:01 -08:00
|
|
|
if (existingMarker != null) {
|
2015-02-05 18:33:57 -08:00
|
|
|
// Nothing to do, the marker is already there
|
|
|
|
return;
|
|
|
|
}
|
2015-05-19 16:47:30 +02:00
|
|
|
TimerWrapper.setTimeout(() => {
|
2016-11-12 14:08:58 +01:00
|
|
|
const finishedDiv = DOM.createElement('div');
|
2015-02-05 18:33:57 -08:00
|
|
|
finishedDiv.id = 'done';
|
|
|
|
DOM.setInnerHTML(finishedDiv, 'Finished');
|
|
|
|
DOM.appendChild(document.body, finishedDiv);
|
|
|
|
}, 0);
|
|
|
|
}
|
|
|
|
|
2020-04-13 16:40:21 -07:00
|
|
|
private _locateFinishedMarker() {
|
|
|
|
return DOM.querySelector(document.body, '#done');
|
|
|
|
}
|
2015-02-05 18:33:57 -08:00
|
|
|
|
2020-04-13 16:40:21 -07:00
|
|
|
private _getScrollDiv() {
|
|
|
|
return DOM.query('body /deep/ #scrollDiv');
|
|
|
|
}
|
2015-02-05 18:33:57 -08:00
|
|
|
}
|