зеркало из https://github.com/mozilla/gecko-dev.git
Bug 762569: followup to add additional test coverage
--HG-- extra : rebase_source : 84f8eec269b759e1b3e9525570c3cabc9267c726
This commit is contained in:
Родитель
01e9e718a5
Коммит
6f12f59b71
|
@ -18,7 +18,6 @@ _TEST_FILES = \
|
||||||
head.js \
|
head.js \
|
||||||
data.json \
|
data.json \
|
||||||
worker_xhr.js \
|
worker_xhr.js \
|
||||||
worker_localStorage.js \
|
|
||||||
browser_frameworker.js \
|
browser_frameworker.js \
|
||||||
worker_relative.js \
|
worker_relative.js \
|
||||||
relative_import.js \
|
relative_import.js \
|
||||||
|
|
|
@ -213,9 +213,27 @@ let tests = {
|
||||||
},
|
},
|
||||||
|
|
||||||
testLocalStorage: function(cbnext) {
|
testLocalStorage: function(cbnext) {
|
||||||
// NOTE: this url MUST be in the same origin as worker_xhr.js fetches from!
|
let run = function() {
|
||||||
let url = "https://example.com/browser/toolkit/components/social/test/browser/worker_localStorage.js";
|
onconnect = function(e) {
|
||||||
let worker = modules.FrameWorker(url, undefined, "testLocalStorage");
|
let port = e.ports[0];
|
||||||
|
try {
|
||||||
|
localStorage.setItem("foo", "1");
|
||||||
|
} catch(e) {
|
||||||
|
port.postMessage({topic: "done", result: "FAILED to set localStorage, " + e.toString() });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var ok;
|
||||||
|
try {
|
||||||
|
ok = localStorage["foo"] == 1;
|
||||||
|
} catch (e) {
|
||||||
|
port.postMessage({topic: "done", result: "FAILED to read localStorage, " + e.toString() });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
port.postMessage({topic: "done", result: "ok"});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let worker = modules.FrameWorker(makeWorkerUrl(run), undefined, "testLocalStorage");
|
||||||
worker.port.onmessage = function(e) {
|
worker.port.onmessage = function(e) {
|
||||||
if (e.data.topic == "done") {
|
if (e.data.topic == "done") {
|
||||||
is(e.data.result, "ok", "check the localStorage test worked");
|
is(e.data.result, "ok", "check the localStorage test worked");
|
||||||
|
@ -225,6 +243,120 @@ let tests = {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
testBase64: function (cbnext) {
|
||||||
|
let run = function() {
|
||||||
|
onconnect = function(e) {
|
||||||
|
let port = e.ports[0];
|
||||||
|
var ok = false;
|
||||||
|
try {
|
||||||
|
ok = btoa("1234") == "MTIzNA==";
|
||||||
|
} catch(e) {
|
||||||
|
port.postMessage({topic: "done", result: "FAILED to call btoa, " + e.toString() });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!ok) {
|
||||||
|
port.postMessage({topic: "done", result: "FAILED calling btoa"});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
ok = atob("NDMyMQ==") == "4321";
|
||||||
|
} catch (e) {
|
||||||
|
port.postMessage({topic: "done", result: "FAILED to call atob, " + e.toString() });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!ok) {
|
||||||
|
port.postMessage({topic: "done", result: "FAILED calling atob"});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
port.postMessage({topic: "done", result: "ok"});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let worker = modules.FrameWorker(makeWorkerUrl(run), undefined, "testBase64");
|
||||||
|
worker.port.onmessage = function(e) {
|
||||||
|
if (e.data.topic == "done") {
|
||||||
|
is(e.data.result, "ok", "check the atob/btoa test worked");
|
||||||
|
worker.terminate();
|
||||||
|
cbnext();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
testTimeouts: function (cbnext) {
|
||||||
|
let run = function() {
|
||||||
|
onconnect = function(e) {
|
||||||
|
let port = e.ports[0];
|
||||||
|
|
||||||
|
var timeout;
|
||||||
|
try {
|
||||||
|
timeout = setTimeout(function () {
|
||||||
|
port.postMessage({topic: "done", result: "FAILED cancelled timeout was called"});
|
||||||
|
}, 100);
|
||||||
|
} catch (ex) {
|
||||||
|
port.postMessage({topic: "done", result: "FAILED calling setTimeout: " + ex});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
clearTimeout(timeout);
|
||||||
|
} catch (ex) {
|
||||||
|
port.postMessage({topic: "done", result: "FAILED calling clearTimeout: " + ex});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var counter = 0;
|
||||||
|
try {
|
||||||
|
timeout = setInterval(function () {
|
||||||
|
if (++counter == 2) {
|
||||||
|
clearInterval(timeout);
|
||||||
|
setTimeout(function () {
|
||||||
|
port.postMessage({topic: "done", result: "ok"});
|
||||||
|
return;
|
||||||
|
}, 0);
|
||||||
|
}
|
||||||
|
}, 100);
|
||||||
|
} catch (ex) {
|
||||||
|
port.postMessage({topic: "done", result: "FAILED calling setInterval: " + ex});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let worker = modules.FrameWorker(makeWorkerUrl(run), undefined, "testTimeouts");
|
||||||
|
worker.port.onmessage = function(e) {
|
||||||
|
if (e.data.topic == "done") {
|
||||||
|
is(e.data.result, "ok", "check that timeouts worked");
|
||||||
|
worker.terminate();
|
||||||
|
cbnext();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
testWebSocket: function (cbnext) {
|
||||||
|
let run = function() {
|
||||||
|
onconnect = function(e) {
|
||||||
|
let port = e.ports[0];
|
||||||
|
|
||||||
|
try {
|
||||||
|
var exampleSocket = new WebSocket("ws://www.example.com/socketserver");
|
||||||
|
} catch (e) {
|
||||||
|
port.postMessage({topic: "done", result: "FAILED calling WebSocket constructor: " + e});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
port.postMessage({topic: "done", result: "ok"});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let worker = modules.FrameWorker(makeWorkerUrl(run), undefined, "testWebSocket");
|
||||||
|
worker.port.onmessage = function(e) {
|
||||||
|
if (e.data.topic == "done") {
|
||||||
|
is(e.data.result, "ok", "check that websockets worked");
|
||||||
|
worker.terminate();
|
||||||
|
cbnext();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
testSameOriginImport: function(cbnext) {
|
testSameOriginImport: function(cbnext) {
|
||||||
let run = function() {
|
let run = function() {
|
||||||
onconnect = function(e) {
|
onconnect = function(e) {
|
||||||
|
|
|
@ -1,17 +0,0 @@
|
||||||
// Used to test XHR in the worker.
|
|
||||||
onconnect = function(e) {
|
|
||||||
let port = e.ports[0];
|
|
||||||
try {
|
|
||||||
localStorage.setItem("foo", "1");
|
|
||||||
} catch(e) {
|
|
||||||
port.postMessage({topic: "done", result: "FAILED to set localStorage, " + e.toString() });
|
|
||||||
}
|
|
||||||
|
|
||||||
var ok;
|
|
||||||
try {
|
|
||||||
ok = localStorage["foo"] == 1;
|
|
||||||
} catch (e) {
|
|
||||||
ok = false;
|
|
||||||
}
|
|
||||||
port.postMessage({topic: "done", result: ok ? "ok" : "FAILED to read localStorage"});
|
|
||||||
}
|
|
Загрузка…
Ссылка в новой задаче