dom/workers/test/test_csp.js

Fri, 16 Jan 2015 18:13:44 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Fri, 16 Jan 2015 18:13:44 +0100
branch
TOR_BUG_9701
changeset 14
925c144e1f1f
permissions
-rw-r--r--

Integrate suggestion from review to improve consistency with existing code.

michael@0 1 /**
michael@0 2 * Any copyright is dedicated to the Public Domain.
michael@0 3 * http://creativecommons.org/publicdomain/zero/1.0/
michael@0 4 */
michael@0 5 msg = null;
michael@0 6 var errors = 5;
michael@0 7
michael@0 8 onerror = function(event) {
michael@0 9 ok(true, msg);
michael@0 10 if (!--errors) SimpleTest.finish();
michael@0 11 }
michael@0 12
michael@0 13 msg = "No Eval allowed";
michael@0 14 worker = new Worker("csp_worker.js");
michael@0 15 worker.postMessage(0);
michael@0 16 worker.onmessage = function(event) {
michael@0 17 ok(false, "Eval succeeded!");
michael@0 18 }
michael@0 19
michael@0 20 msg = "No Eval allowed 2";
michael@0 21 worker = new Worker("csp_worker.js");
michael@0 22 worker.postMessage(4);
michael@0 23 worker.onmessage = function(event) {
michael@0 24 ok(false, "Eval succeeded!");
michael@0 25 }
michael@0 26
michael@0 27 msg = "ImportScripts data:";
michael@0 28 worker = new Worker("csp_worker.js");
michael@0 29 worker.postMessage(-1);
michael@0 30 worker.onmessage = function(event) {
michael@0 31 ok(false, "Eval succeeded!");
michael@0 32 }
michael@0 33
michael@0 34 msg = "ImportScripts javascript:";
michael@0 35 worker = new Worker("csp_worker.js");
michael@0 36 worker.postMessage(-2);
michael@0 37 worker.onmessage = function(event) {
michael@0 38 ok(false, "Eval succeeded!");
michael@0 39 }
michael@0 40
michael@0 41 msg = "Loading data:something";
michael@0 42 try {
michael@0 43 worker = new Worker("data:application/javascript;base64,ZHVtcCgnaGVsbG8gd29ybGQnKQo=");
michael@0 44 ok(false, "Should have thrown!");
michael@0 45 } catch (e) {
michael@0 46 ok(true, "Threw as expected.");
michael@0 47 }
michael@0 48
michael@0 49 worker = new Worker("javascript:dump(123);");
michael@0 50 SimpleTest.waitForExplicitFinish();

mercurial