dom/workers/test/test_xhr.html

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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 <!DOCTYPE HTML>
michael@0 6 <html>
michael@0 7 <!--
michael@0 8 Tests of DOM Worker Threads XHR(Bug 450452 )
michael@0 9 -->
michael@0 10 <head>
michael@0 11 <title>Test for DOM Worker Threads XHR (Bug 450452 )</title>
michael@0 12 <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
michael@0 13 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
michael@0 14 </head>
michael@0 15 <body>
michael@0 16 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=450452">DOM Worker Threads XHR (Bug 450452)</a>
michael@0 17 <p id="display"></p>
michael@0 18 <div id="content" style="display: none">
michael@0 19
michael@0 20 </div>
michael@0 21 <pre id="test">
michael@0 22 <script class="testbody" type="text/javascript">
michael@0 23
michael@0 24 var worker = new Worker("xhr_worker.js");
michael@0 25
michael@0 26 var gotUploadLoad = false, gotLoadend = false;
michael@0 27
michael@0 28 worker.onmessage = function(event) {
michael@0 29 is(event.target, worker);
michael@0 30 var args = event.data;
michael@0 31 switch (args.type) {
michael@0 32 case "progress": {
michael@0 33 ok(parseInt(args.current) <= parseInt(args.total));
michael@0 34 } break;
michael@0 35 case "error": {
michael@0 36 ok(false, "XHR error: " + args.error);
michael@0 37 } break;
michael@0 38 case "upload.load": {
michael@0 39 gotUploadLoad = true;
michael@0 40 } break;
michael@0 41 case "load": {
michael@0 42 ok(gotUploadLoad, "Should have gotten upload load event");
michael@0 43 gotLoadend = true;
michael@0 44 is(args.data, "A noisy noise annoys an oyster.", "correct data");
michael@0 45 document.getElementById("content").textContent = args.data;
michael@0 46 } break;
michael@0 47 case "loadend": {
michael@0 48 ok(gotLoadend, "Should have gotten load.");
michael@0 49 SimpleTest.finish();
michael@0 50 break;
michael@0 51 }
michael@0 52 default: {
michael@0 53 ok(false, "Unexpected message");
michael@0 54 SimpleTest.finish();
michael@0 55 }
michael@0 56 }
michael@0 57 };
michael@0 58
michael@0 59 worker.onerror = function(event) {
michael@0 60 is(event.target, worker);
michael@0 61 ok(false, "Worker had an error:" + event.data);
michael@0 62 SimpleTest.finish();
michael@0 63 }
michael@0 64
michael@0 65 worker.postMessage("testXHR.txt");
michael@0 66
michael@0 67 SimpleTest.waitForExplicitFinish();
michael@0 68
michael@0 69 </script>
michael@0 70 </pre>
michael@0 71 </body>
michael@0 72 </html>
michael@0 73

mercurial