mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-19 08:15:31 +00:00
Bug 1378402 - Add tests for budget throttling. r=bkelly
This commit is contained in:
parent
ad4646fe98
commit
66345bc361
@ -8,6 +8,21 @@
|
||||
{}
|
||||
]
|
||||
],
|
||||
"dom/throttling/resources/test.html": [
|
||||
[
|
||||
{}
|
||||
]
|
||||
],
|
||||
"dom/throttling/resources/throttling.js": [
|
||||
[
|
||||
{}
|
||||
]
|
||||
],
|
||||
"dom/throttling/resources/ws.sub.js": [
|
||||
[
|
||||
{}
|
||||
]
|
||||
],
|
||||
"fetch/api/redirect/redirect-referrer-mixed-content.js": [
|
||||
[
|
||||
{}
|
||||
@ -406,6 +421,54 @@
|
||||
{}
|
||||
]
|
||||
],
|
||||
"dom/throttling/throttling-1.window.js": [
|
||||
[
|
||||
"/_mozilla/dom/throttling/throttling-1.window.html",
|
||||
{}
|
||||
]
|
||||
],
|
||||
"dom/throttling/throttling-2.window.js": [
|
||||
[
|
||||
"/_mozilla/dom/throttling/throttling-2.window.html",
|
||||
{}
|
||||
]
|
||||
],
|
||||
"dom/throttling/throttling-3.window.js": [
|
||||
[
|
||||
"/_mozilla/dom/throttling/throttling-3.window.html",
|
||||
{}
|
||||
]
|
||||
],
|
||||
"dom/throttling/throttling-4.window.js": [
|
||||
[
|
||||
"/_mozilla/dom/throttling/throttling-4.window.html",
|
||||
{}
|
||||
]
|
||||
],
|
||||
"dom/throttling/throttling-indexeddb.window.js": [
|
||||
[
|
||||
"/_mozilla/dom/throttling/throttling-indexeddb.window.html",
|
||||
{}
|
||||
]
|
||||
],
|
||||
"dom/throttling/throttling-webaudio.window.js": [
|
||||
[
|
||||
"/_mozilla/dom/throttling/throttling-webaudio.window.html",
|
||||
{}
|
||||
]
|
||||
],
|
||||
"dom/throttling/throttling-webrtc.window.js": [
|
||||
[
|
||||
"/_mozilla/dom/throttling/throttling-webrtc.window.html",
|
||||
{}
|
||||
]
|
||||
],
|
||||
"dom/throttling/throttling-ws.window.js": [
|
||||
[
|
||||
"/_mozilla/dom/throttling/throttling-ws.window.html",
|
||||
{}
|
||||
]
|
||||
],
|
||||
"fetch/api/redirect/redirect-referrer.https.html": [
|
||||
[
|
||||
"/_mozilla/fetch/api/redirect/redirect-referrer.https.html",
|
||||
@ -915,6 +978,50 @@
|
||||
"f289334e7b3486259b9aae54b4282a7211b8813e",
|
||||
"testharness"
|
||||
],
|
||||
"dom/throttling/resources/test.html": [
|
||||
"15bf447545bf4ccd8b6a71d5d2cf2e5bba303293",
|
||||
"support"
|
||||
],
|
||||
"dom/throttling/resources/throttling.js": [
|
||||
"2dc138ec9298d31711bc33fc47af12da1f64c4ce",
|
||||
"support"
|
||||
],
|
||||
"dom/throttling/resources/ws.sub.js": [
|
||||
"66306649fb96efc2d5f13c566fac3da18339bc38",
|
||||
"support"
|
||||
],
|
||||
"dom/throttling/throttling-1.window.js": [
|
||||
"609c0d54b0aaf81b28a590217abde69c5e23f168",
|
||||
"testharness"
|
||||
],
|
||||
"dom/throttling/throttling-2.window.js": [
|
||||
"1c6900b823d95ee84791fb04eeae8b61311f5c58",
|
||||
"testharness"
|
||||
],
|
||||
"dom/throttling/throttling-3.window.js": [
|
||||
"a9b4b0ade8a22eae9c804735513d89370311d471",
|
||||
"testharness"
|
||||
],
|
||||
"dom/throttling/throttling-4.window.js": [
|
||||
"aeabd55bbb829c92d69bfc44f5e6fe3ad3105a84",
|
||||
"testharness"
|
||||
],
|
||||
"dom/throttling/throttling-indexeddb.window.js": [
|
||||
"275a900b501e54cadc5ca224240489ad27464081",
|
||||
"testharness"
|
||||
],
|
||||
"dom/throttling/throttling-webaudio.window.js": [
|
||||
"fd5cd3bd05b749e871e5a3e746e2cfc10a48d794",
|
||||
"testharness"
|
||||
],
|
||||
"dom/throttling/throttling-webrtc.window.js": [
|
||||
"1d832a4e14ad10c5a2143c6b0d7f5cad2c29bdcd",
|
||||
"testharness"
|
||||
],
|
||||
"dom/throttling/throttling-ws.window.js": [
|
||||
"df9b37384c42984fe80ea8a35164089f977268b0",
|
||||
"testharness"
|
||||
],
|
||||
"fetch/api/redirect/redirect-referrer-mixed-content.js": [
|
||||
"f9d7ec9cf9fa8c847e45664b05482e3f8c191385",
|
||||
"support"
|
||||
|
@ -0,0 +1,5 @@
|
||||
prefs: [dom.timeout.enable_budget_timer_throttling: true,
|
||||
dom.timeout.foreground_budget_regeneration_rate: 100,
|
||||
dom.timeout.foreground_throttling_max_budget: 10,
|
||||
dom.timeout.budget_throttling_max_delay: 2000,
|
||||
dom.timeout.throttling_delay: 1]
|
@ -0,0 +1,4 @@
|
||||
[throttling-1.window.html]
|
||||
type: testharness
|
||||
disabled:
|
||||
if debug: "disabled"
|
@ -0,0 +1,4 @@
|
||||
[throttling-2.window.html]
|
||||
type: testharness
|
||||
disabled:
|
||||
if debug: "disabled"
|
@ -0,0 +1,4 @@
|
||||
[throttling-3.window.html]
|
||||
type: testharness
|
||||
disabled:
|
||||
if debug: "disabled"
|
@ -0,0 +1,4 @@
|
||||
[throttling-4.window.html]
|
||||
type: testharness
|
||||
disabled:
|
||||
if debug: "disabled"
|
@ -0,0 +1,4 @@
|
||||
[throttling-indexeddb.window.html]
|
||||
type: testharness
|
||||
disabled:
|
||||
if debug: "disabled"
|
@ -0,0 +1,4 @@
|
||||
[throttling-webaudio.window.html]
|
||||
type: testharness
|
||||
disabled:
|
||||
if debug: "disabled"
|
@ -0,0 +1,4 @@
|
||||
[throttling-webrtc.window.html]
|
||||
type: testharness
|
||||
disabled:
|
||||
if debug: "disabled"
|
@ -0,0 +1,4 @@
|
||||
[throttling-ws.window.html]
|
||||
type: testharness
|
||||
disabled:
|
||||
if debug: "disabled"
|
@ -0,0 +1,5 @@
|
||||
<!doctype html>
|
||||
<meta charset=utf-8>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<script src="throttling.js"></script>
|
@ -0,0 +1,136 @@
|
||||
function waitForLoad() {
|
||||
return new Promise(resolve => addEventListener('load', resolve))
|
||||
.then(() => delay(10));
|
||||
}
|
||||
|
||||
function delay(timeout) {
|
||||
return new Promise(resolve => step_timeout(() => resolve(), 10));
|
||||
}
|
||||
|
||||
function busy(work) {
|
||||
return delay(10).then(() => new Promise(resolve => {
|
||||
step_timeout(() => {
|
||||
let end = performance.now() + work;
|
||||
while (performance.now() < end) {
|
||||
|
||||
}
|
||||
|
||||
resolve();
|
||||
}, 1);
|
||||
}));
|
||||
}
|
||||
|
||||
function getThrottlingRate(delay) {
|
||||
return new Promise(resolve => {
|
||||
let start = performance.now();
|
||||
setTimeout(() => {
|
||||
let rate = Math.floor((performance.now() - start) / delay);
|
||||
resolve(rate);
|
||||
}, delay);
|
||||
});
|
||||
}
|
||||
|
||||
function addElement(t, element, src) {
|
||||
return new Promise((resolve, reject) => {
|
||||
let e = document.createElement(element);
|
||||
e.addEventListener('load', () => resolve(e));
|
||||
if (src) {
|
||||
e.src = src;
|
||||
}
|
||||
document.body.appendChild(e);
|
||||
t.add_cleanup(() => e.remove());
|
||||
});
|
||||
}
|
||||
|
||||
function inFrame(t) {
|
||||
return addElement(t, "iframe", "resources/test.html")
|
||||
.then(frame => delay(10).then(() => Promise.resolve(frame.contentWindow)));
|
||||
}
|
||||
|
||||
function addWebSocket(t, url) {
|
||||
return new Promise((resolve, reject) => {
|
||||
let socket = new WebSocket(url);
|
||||
socket.onopen = () => {
|
||||
t.add_cleanup(() => socket.close());
|
||||
resolve();
|
||||
};
|
||||
socket.onerror = reject;
|
||||
});
|
||||
}
|
||||
|
||||
function addRTCPeerConnection(t) {
|
||||
return new Promise((resolve, reject) => {
|
||||
let connection = new RTCPeerConnection();
|
||||
t.add_cleanup(() => {
|
||||
connection.close()
|
||||
});
|
||||
|
||||
resolve();
|
||||
});
|
||||
}
|
||||
|
||||
function addIndexedDB(t) {
|
||||
return new Promise((resolve, reject) => {
|
||||
let iDBState = {
|
||||
running: false,
|
||||
db: null
|
||||
};
|
||||
|
||||
let req = indexedDB.open("testDB", 1);
|
||||
|
||||
req.onupgradeneeded = e => {
|
||||
let db = e.target.result;
|
||||
let store = db.createObjectStore("testOS", {keyPath: "id"});
|
||||
let index = store.createIndex("index", ["col"]);
|
||||
};
|
||||
|
||||
req.onsuccess = e => {
|
||||
let db = iDBState.db = e.target.result;
|
||||
let store = db.transaction("testOS", "readwrite").objectStore("testOS");
|
||||
let ctr = 0;
|
||||
|
||||
iDBState.running = true;
|
||||
|
||||
function putLoop() {
|
||||
if (!iDBState.running) {
|
||||
return;
|
||||
}
|
||||
|
||||
let req = store.put({id: ctr++, col: "foo"});
|
||||
req.onsuccess = putLoop;
|
||||
|
||||
if (!iDBState.request) {
|
||||
iDBState.request = req;
|
||||
}
|
||||
}
|
||||
|
||||
putLoop();
|
||||
resolve();
|
||||
};
|
||||
|
||||
t.add_cleanup(() => {
|
||||
iDBState.running = false;
|
||||
iDBState.db && iDBState.db.close();
|
||||
iDBState.db = null;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function addWebAudio(t) {
|
||||
return new Promise(resolve => {
|
||||
let context = new (window.AudioContext || window.webkitAudioContext)();
|
||||
context.onstatechange = () => (context.state === "running") && resolve();
|
||||
|
||||
let gain = context.createGain();
|
||||
gain.gain.value = 0.1;
|
||||
gain.connect(context.destination);
|
||||
|
||||
let webaudionode = context.createOscillator();
|
||||
webaudionode.type = 'square';
|
||||
webaudionode.frequency.value = 440; // value in hertz
|
||||
webaudionode.connect(gain);
|
||||
webaudionode.start();
|
||||
|
||||
t.add_cleanup(() => webaudionode.stop());
|
||||
});
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
var __SERVER__NAME = "{{host}}";
|
||||
var __PORT = "{{ports[ws][0]}}";
|
||||
var __PATH = "echo";
|
@ -0,0 +1,10 @@
|
||||
// META: script=resources/throttling.js
|
||||
|
||||
setup(() => waitForLoad()
|
||||
.then(() => "setup done"));
|
||||
|
||||
promise_test(t => busy(100)
|
||||
.then(() => getThrottlingRate(100))
|
||||
.then(rate => {
|
||||
assert_greater_than(rate, 10, "Timeout wasn't throttled");
|
||||
}), "Throttle when all budget has been used.");
|
@ -0,0 +1,11 @@
|
||||
// META: script=resources/throttling.js
|
||||
|
||||
setup(() => waitForLoad()
|
||||
.then(() => "setup done"));
|
||||
|
||||
promise_test(t => inFrame(t)
|
||||
.then(win => win.busy(100)
|
||||
.then(() => win.getThrottlingRate(100)))
|
||||
.then(rate => {
|
||||
assert_greater_than(rate, 10, "Timeout wasn't throttled");
|
||||
}), "Throttle iframe when all budget has been used");
|
@ -0,0 +1,11 @@
|
||||
// META: script=resources/throttling.js
|
||||
|
||||
setup(() => waitForLoad()
|
||||
.then(() => "setup done"));
|
||||
|
||||
promise_test(t => inFrame(t)
|
||||
.then(win => busy(100)
|
||||
.then(() => win.getThrottlingRate(100)))
|
||||
.then(rate => {
|
||||
assert_less_than(rate, 10, "Timeout was throttled");
|
||||
}), "Don't throttle iframe when all budget in parent has been used");
|
@ -0,0 +1,11 @@
|
||||
// META: script=resources/throttling.js
|
||||
|
||||
setup(() => waitForLoad()
|
||||
.then(() => "setup done"));
|
||||
|
||||
promise_test(t => inFrame(t)
|
||||
.then(win => win.busy(100))
|
||||
.then(() => getThrottlingRate(100))
|
||||
.then(rate => {
|
||||
assert_less_than(rate, 10, "Timeout was throttled");
|
||||
}), "Don't throttle parent when all budget in iframe has been used");
|
@ -0,0 +1,35 @@
|
||||
// META: script=resources/throttling.js
|
||||
|
||||
setup(() => waitForLoad()
|
||||
.then(() => "setup done"));
|
||||
|
||||
promise_test(t => addIndexedDB(t)
|
||||
.then(() => busy(100))
|
||||
.then(() => getThrottlingRate(100))
|
||||
.then(rate => {
|
||||
assert_less_than(rate, 10, "Timeout was throttled");
|
||||
}), "Don't throttle when there are open IndexedDB transactions.");
|
||||
|
||||
promise_test(t => inFrame(t)
|
||||
.then(win => win.addIndexedDB(t))
|
||||
.then(() => busy(100))
|
||||
.then(() => getThrottlingRate(100))
|
||||
.then(rate => {
|
||||
assert_less_than(rate, 10, "Timeout was throttled");
|
||||
}), "Don't throttle when there are open IndexedDB transactions in iframe.");
|
||||
|
||||
promise_test(t => inFrame(t)
|
||||
.then(win => addIndexedDB(t)
|
||||
.then(() => win.busy(100))
|
||||
.then(() => win.getThrottlingRate(100)))
|
||||
.then(rate => {
|
||||
assert_less_than(rate, 10, "Timeout was throttled");
|
||||
}), "Don't throttle iframe when there are open IndexedDB transactions in parent.");
|
||||
|
||||
promise_test(t => inFrame(t)
|
||||
.then(win => win.addIndexedDB(t)
|
||||
.then(() => win.busy(100))
|
||||
.then(() => win.getThrottlingRate(100)))
|
||||
.then(rate => {
|
||||
assert_less_than(rate, 10, "Timeout was throttled");
|
||||
}), "Don't throttle iframe when there are open IndexedDB transactions in iframe.");
|
@ -0,0 +1,35 @@
|
||||
// META: script=resources/throttling.js
|
||||
|
||||
setup(() => waitForLoad()
|
||||
.then(() => "setup done"));
|
||||
|
||||
promise_test(t => addWebAudio(t)
|
||||
.then(() => busy(100))
|
||||
.then(() => getThrottlingRate(100))
|
||||
.then(rate => {
|
||||
assert_less_than(rate, 10, "Timeout was throttled");
|
||||
}), "Don't throttle when there is active WebAudio.");
|
||||
|
||||
promise_test(t => inFrame(t)
|
||||
.then(win => win.addWebAudio(t))
|
||||
.then(() => busy(100))
|
||||
.then(() => getThrottlingRate(100))
|
||||
.then(rate => {
|
||||
assert_less_than(rate, 10, "Timeout was throttled");
|
||||
}), "Don't throttle when there is active WebAudio in iframe.");
|
||||
|
||||
promise_test(t => inFrame(t)
|
||||
.then(win => addWebAudio(t)
|
||||
.then(() => win.busy(100))
|
||||
.then(() => win.getThrottlingRate(100)))
|
||||
.then(rate => {
|
||||
assert_less_than(rate, 10, "Timeout was throttled");
|
||||
}), "Don't throttle iframe when there is active WebAudio in parent.");
|
||||
|
||||
promise_test(t => inFrame(t)
|
||||
.then(win => win.addWebAudio(t)
|
||||
.then(() => win.busy(100))
|
||||
.then(() => win.getThrottlingRate(100)))
|
||||
.then(rate => {
|
||||
assert_less_than(rate, 10, "Timeout was throttled");
|
||||
}), "Don't throttle iframe when there is active WebAudio in iframe.");
|
@ -0,0 +1,35 @@
|
||||
// META: script=resources/throttling.js
|
||||
|
||||
setup(() => waitForLoad()
|
||||
.then(() => "setup done"));
|
||||
|
||||
promise_test(t => addRTCPeerConnection(t)
|
||||
.then(() => busy(100))
|
||||
.then(() => getThrottlingRate(100))
|
||||
.then(rate => {
|
||||
assert_less_than(rate, 10, "Timeout was throttled");
|
||||
}), "Don't throttle when there are open RTCPeerConnections.");
|
||||
|
||||
promise_test(t => inFrame(t)
|
||||
.then(win => win.addRTCPeerConnection(t))
|
||||
.then(() => busy(100))
|
||||
.then(() => getThrottlingRate(100))
|
||||
.then(rate => {
|
||||
assert_less_than(rate, 10, "Timeout was throttled");
|
||||
}), "Don't throttle when there are open RTCPeerConnections in iframe.");
|
||||
|
||||
promise_test(t => inFrame(t)
|
||||
.then(win => addRTCPeerConnection(t)
|
||||
.then(() => win.busy(100))
|
||||
.then(() => win.getThrottlingRate(100)))
|
||||
.then(rate => {
|
||||
assert_less_than(rate, 10, "Timeout was throttled");
|
||||
}), "Don't throttle iframe when there are open RTCPeerConnections in parent.");
|
||||
|
||||
promise_test(t => inFrame(t)
|
||||
.then(win => win.addRTCPeerConnection(t)
|
||||
.then(() => win.busy(100))
|
||||
.then(() => win.getThrottlingRate(100)))
|
||||
.then(rate => {
|
||||
assert_less_than(rate, 10, "Timeout was throttled");
|
||||
}), "Don't throttle iframe when there are open RTCPeerConnections in iframe.");
|
@ -0,0 +1,37 @@
|
||||
// META: script=resources/ws.sub.js
|
||||
// META: script=resources/throttling.js
|
||||
let server = "ws://" + __SERVER__NAME + ":" + __PORT + "/" + __PATH;
|
||||
|
||||
setup(() => waitForLoad()
|
||||
.then(() => "setup done"));
|
||||
|
||||
promise_test(t => addWebSocket(t, server)
|
||||
.then(() => busy(100))
|
||||
.then(() => getThrottlingRate(100))
|
||||
.then(rate => {
|
||||
assert_less_than(rate, 10, "Timeout was throttled");
|
||||
}), "Don't throttle when there are open WebSockets.");
|
||||
|
||||
promise_test(t => inFrame(t)
|
||||
.then(win => win.addWebSocket(t, server))
|
||||
.then(() => busy(100))
|
||||
.then(() => getThrottlingRate(100))
|
||||
.then(rate => {
|
||||
assert_less_than(rate, 10, "Timeout was throttled");
|
||||
}), "Don't throttle when there are open WebSockets in iframe.");
|
||||
|
||||
promise_test(t => inFrame(t)
|
||||
.then(win => addWebSocket(t, server)
|
||||
.then(() => win.busy(100))
|
||||
.then(() => win.getThrottlingRate(100)))
|
||||
.then(rate => {
|
||||
assert_less_than(rate, 10, "Timeout was throttled");
|
||||
}), "Don't throttle iframe when there are open WebSockets in parent.");
|
||||
|
||||
promise_test(t => inFrame(t)
|
||||
.then(win => win.addWebSocket(t, server)
|
||||
.then(() => win.busy(100))
|
||||
.then(() => win.getThrottlingRate(100)))
|
||||
.then(rate => {
|
||||
assert_less_than(rate, 10, "Timeout was throttled");
|
||||
}), "Don't throttle iframe when there are open WebSockets in iframe.");
|
Loading…
Reference in New Issue
Block a user