Commit 6b6934da authored by Andrey Lushnikov's avatar Andrey Lushnikov Committed by Commit Bot

DevTools: unflake http/tests/devtools/components/throttler.js

The test was mocking time only partially: the window.performance.now()
should be mocked as well.

BUG=610464
TBR=dgozman

Change-Id: If9c81662235e43ee2ffafef2ed772158f3a74968
Reviewed-on: https://chromium-review.googlesource.com/828443Reviewed-by: default avatarAndrey Lushnikov <lushnikov@chromium.org>
Commit-Queue: Andrey Lushnikov <lushnikov@chromium.org>
Cr-Commit-Position: refs/heads/master@{#524327}
parent 6fd1b88c
......@@ -1822,7 +1822,6 @@ crbug.com/611658 [ Win7 ] fast/writing-mode/english-lr-text.html [ Failure ]
crbug.com/605059 [ Retina ] fast/text/international/rtl-negative-letter-spacing.html [ Failure ]
crbug.com/610464 [ Linux Win7 Debug ] http/tests/devtools/components/throttler.js [ Failure Pass ]
crbug.com/654477 [ Win ] compositing/video/video-controls-layer-creation.html [ Pass Failure ]
crbug.com/654477 fast/hidpi/video-controls-in-hidpi.html [ Failure ]
crbug.com/654477 fast/layers/video-layer.html [ Failure ]
......
......@@ -8,91 +8,91 @@
class TimeoutMock {
constructor() {
this._timeoutId = 0;
this._timeoutIdToProcess = {};
this._timeoutIdToMillis = {};
this._timeoutIdToProcess = new Map();
this._timeoutIdToMillis = new Map();
this._time = 1;
this.setTimeout = this.setTimeout.bind(this);
this.clearTimeout = this.clearTimeout.bind(this);
this.getTime = this.getTime.bind(this);
}
/**
* @param {!Function} operation
* @param {number} timeout
*/
* @param {!Function} operation
* @param {number} timeout
*/
setTimeout(operation, timeout) {
this._timeoutIdToProcess[++this._timeoutId] = operation;
this._timeoutIdToMillis[this._timeoutId] = timeout;
this._timeoutIdToProcess.set(++this._timeoutId, operation);
this._timeoutIdToMillis.set(this._timeoutId, timeout);
return this._timeoutId;
}
/**
*
* @param {number} timeoutId
*/
*
* @param {number} timeoutId
*/
clearTimeout(timeoutId) {
delete this._timeoutIdToProcess[timeoutId];
delete this._timeoutIdToMillis[timeoutId];
this._timeoutIdToProcess.delete(timeoutId);
this._timeoutIdToMillis.delete(timeoutId);
}
/**
* @return {!Array<number>}
*/
* @return {!Array<number>}
*/
activeTimersTimeouts() {
return Object.values(this._timeoutIdToMillis);
return Array.from(this._timeoutIdToMillis.values());
}
getTime() {
return this._time;
}
fireAllTimers() {
for (const timeoutId in this._timeoutIdToProcess)
this._timeoutIdToProcess[timeoutId].call(window);
this._timeoutIdToProcess = {};
this._timeoutIdToMillis = {};
this._time = Math.max(...this.activeTimersTimeouts()) + 1;
for (const timeoutId of this._timeoutIdToProcess.keys())
this._timeoutIdToProcess.get(timeoutId).call(window);
this._timeoutIdToProcess.clear();
this._timeoutIdToMillis.clear();
}
}
var ProcessMock = function(name, runnable) {
this._runnable = runnable;
this.processName = name;
this.run = this.run.bind(this);
this.run.processName = name;
this.startPromise = new Promise(onStart.bind(this));
this.finishPromise = new Promise(onFinish.bind(this));
class ProcessMock {
constructor(name, runnable) {
this._runnable = runnable;
this.processName = name;
this.run = this.run.bind(this);
this.run.processName = name;
function onStart(startCallback) {
this._startCallback = startCallback;
this.startPromise = new Promise(fulfill => this._startCallback = fulfill);
this.finishPromise = new Promise(fulfill => this._finishCallback = fulfill);
}
function onFinish(finishCallback) {
this._finishCallback = finishCallback;
}
};
ProcessMock.create = function(name, runnable) {
return new ProcessMock(name, runnable);
};
ProcessMock.prototype = {
run: function() {
run() {
TestRunner.addResult('Process \'' + this.processName + '\' STARTED.');
this._startCallback();
if (this._runnable)
this._runnable.call(null);
return this.finishPromise;
},
}
finish: function() {
finish() {
this.startPromise.then(onFinish.bind(this));
function onFinish() {
TestRunner.addResult('Process \'' + this.processName + '\' FINISHED.');
this._finishCallback();
}
},
};
}
static create(name, runnable) {
return new ProcessMock(name, runnable);
}
}
var throttler = new Common.Throttler(1989);
var timeoutMock = new TimeoutMock();
throttler._setTimeout = timeoutMock.setTimeout;
throttler._clearTimeout = timeoutMock.clearTimeout;
throttler._getTime = timeoutMock.getTime;
TestRunner.addSniffer(throttler, 'schedule', logSchedule, true);
function testSimpleSchedule(next, runningProcess) {
......@@ -107,14 +107,12 @@
promise = waitForProcessFinish();
}
promise
.then(function() {
assertThrottlerTimeout();
timeoutMock.fireAllTimers();
process.finish();
return waitForProcessFinish();
})
.then(next);
promise.then(() => {
assertThrottlerTimeout();
timeoutMock.fireAllTimers();
process.finish();
return waitForProcessFinish();
}).then(next);
}
function testAsSoonAsPossibleOverrideTimeout(next, runningProcess) {
......
......@@ -18,7 +18,7 @@ Common.Throttler = class {
}
_processCompleted() {
this._lastCompleteTime = window.performance.now();
this._lastCompleteTime = this._getTime();
this._isRunningProcess = false;
if (this._process)
this._innerSchedule(false);
......@@ -48,7 +48,7 @@ Common.Throttler = class {
// Run the first scheduled task instantly.
var hasScheduledTasks = !!this._processTimeout || this._isRunningProcess;
var okToFire = window.performance.now() - this._lastCompleteTime > this._timeout;
var okToFire = this._getTime() - this._lastCompleteTime > this._timeout;
asSoonAsPossible = !!asSoonAsPossible || (!hasScheduledTasks && okToFire);
var forceTimerUpdate = asSoonAsPossible && !this._asSoonAsPossible;
......@@ -87,6 +87,13 @@ Common.Throttler = class {
_setTimeout(operation, timeout) {
return setTimeout(operation, timeout);
}
/**
* @return {number}
*/
_getTime() {
return window.performance.now();
}
};
/** @typedef {function(!Error=)} */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment