// not enabled by default yet.
SimpleTest.waitForExplicitFinish();
SpecialPowers.pushPrefEnv({'set': [["beacon.enabled", true]]}, runNextTest);
function getBeaconServerStatus(id, callback) { var request = new XMLHttpRequest();
let getBeaconUri = "http://mochi.test:8888/tests/dom/tests/mochitest/beacon/beacon-handler.sjs?getBeacon=" + id;
request.open("GET", getBeaconUri, true);
request.onload = function() {
if (request.readyState === request.DONE) {
callback(request.responseText);
}
};
request.send(null);
}
function createIframeWithData(data, mimetype, convert) {
beaconConvert = convert;
varframe = document.createElement("IFRAME"); frame.setAttribute("src", "beacon-frame.html"); frame.id = "frame"; frame.setAttribute("data", data.toString()); frame.setAttribute("mimetype", mimetype); var c = document.getElementById("content");
c.appendChild(frame);
}
function beaconSent(result) {
// This function gets called from beacon-frame.html in the inner frame
// Check that the beacon was actually sent
ok(result, "Beacon should be sent");
// remove the frame. varframe = document.getElementById("frame"); var id = frame.getAttribute("data"); var data = frame.getAttribute("data"); var mimetype = frame.getAttribute("mimetype");
var c = document.getElementById("content");
c.removeChild(frame);
getBeaconServerStatus(id, function(response) {
console.log(response); var result = JSON.parse(response);
is(result.data, data, "Beacon status should match expected. is: " + result.data + " should be: " + data);
is(result.mimetype, mimetype, "Beacon mimetype should match expected. is: " + result.mimetype + " should be: " + mimetype);
runNextTest();
});
}
function runNextTest() { var test = tests.shift();
setTimeout(test, 0);
}
var beaconConvert = function() {};
function stringToArrayBuffer(input) {
var buffer = new ArrayBuffer(input.length * 2); var array = new Uint16Array(buffer);
// dumbly copy over the bytes
for (vari = 0, len = input.length; i < len; i++) {
array[i] = input.charCodeAt(i);
}
return array;
}
function stringToBlob(input) { var blob = new Blob([input], {type : 'text/html'});
return blob;
}
function stringToFormData(input) { var formdata = new FormData();
formdata.append(input, new Blob(['hi']));
return formdata;
}
function identity(data) {
return data;
}
var tests = [
// "data" is used as an id, so should be unique for each call to createIframeWithData
function() { createIframeWithData("hi!", "text/plain;charset=UTF-8", identity); },
function() { createIframeWithData("123", "", stringToArrayBuffer); },
function() { createIframeWithData("abc", "text/html", stringToBlob); },
function() { createIframeWithData("qwerty", "multipart/form-data", stringToFormData); },
function() { SimpleTest.finish(); },
];
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.