dom/plugins/test/mochitest/test_streamNotify.html

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 <head>
michael@0 2 <title>NPN_Get/PostURLNotify tests</title>
michael@0 3 <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
michael@0 4 <script type="application/javascript" src="utils.js"></script>
michael@0 5
michael@0 6 <body onload="runTests()">
michael@0 7 <script class="testbody" type="application/javascript">
michael@0 8 SimpleTest.waitForExplicitFinish();
michael@0 9 setTestPluginEnabledState(SpecialPowers.Ci.nsIPluginTag.STATE_ENABLED);
michael@0 10
michael@0 11 var pending = 5;
michael@0 12 function testDone() {
michael@0 13 dump("testDone: " + pending + "\n")
michael@0 14 --pending;
michael@0 15
michael@0 16 // Wait for a bit so that any unexpected notifications from the
michael@0 17 // malformed data or null-post tests are received.
michael@0 18 if (0 == pending)
michael@0 19 window.setTimeout(SimpleTest.finish, 2000);
michael@0 20 }
michael@0 21
michael@0 22 function runTests() {
michael@0 23 var p = document.getElementById('plugin1');
michael@0 24
michael@0 25 ok(p.streamTest("loremipsum.txt", false, null, null,
michael@0 26 function(r, t) {
michael@0 27 is(r, 0, "GET loremipsum.txt");
michael@0 28 is(t.substr(0, 11), "Lorem ipsum",
michael@0 29 "GET loremipsum.txt correct");
michael@0 30 testDone();
michael@0 31 }, null, true), "streamTest GET");
michael@0 32
michael@0 33 ok(!p.streamTest("post.sjs", true, null, null,
michael@0 34 function(r, t) {
michael@0 35 ok(false, "Shouldn't get callback from null post");
michael@0 36 }, null, true), "streamTest POST null postdata");
michael@0 37
michael@0 38 ok(p.streamTest("post.sjs", true, "Something good", null,
michael@0 39 function(r, t) {
michael@0 40 is(r, 0, "POST something good");
michael@0 41 is(t, "Something good", "POST non-null correct");
michael@0 42 testDone();
michael@0 43 }, null, true), "streamTest POST valid postdata");
michael@0 44
michael@0 45 ok(p.streamTest("http://example.invalid/", false, null, null,
michael@0 46 function(r, t) {
michael@0 47 is(r, 1, "Shouldn't load example.invalid DNS name");
michael@0 48 testDone();
michael@0 49 }, null, true), "streamTest GET bad DNS");
michael@0 50
michael@0 51 ok(!p.streamTest("http://localhost:-8/", false, null, null,
michael@0 52 function(r, t) {
michael@0 53 ok(false, "Shouldn't get callback from malformed URI");
michael@0 54 }, null, true), "streamTest GET invalid URL");
michael@0 55
michael@0 56 ok(p.streamTest("javascript:'Hello';", false, null, null,
michael@0 57 function(r, t) {
michael@0 58 is(r, 0, "GET javascript: URI");
michael@0 59 is(t, "Hello", "GET javascript: URI correct");
michael@0 60 testDone();
michael@0 61 }, null, true), "streamTest GET javascript: URI");
michael@0 62
michael@0 63 /*
michael@0 64 * XXX/cjones: disabled for now because it appears to be hard to make
michael@0 65 * mochitest ignore the malformed javascript
michael@0 66
michael@0 67 ok(!p.streamTest("javascript:syntax##$&*@error-*", false, null,
michael@0 68 function(r, t) {
michael@0 69 is(r, 1, "Shouldn't load invalid javascript: URI");
michael@0 70 testDone();
michael@0 71 }), "streamTest GET bad javascript: URI");
michael@0 72 */
michael@0 73
michael@0 74 ok(p.streamTest("data:text/plain,World", false, null, null,
michael@0 75 function(r, t) {
michael@0 76 is(r, 0, "GET data: URI");
michael@0 77 is(t, "World", "GET data: URI correct");
michael@0 78 testDone();
michael@0 79 }, null, true), "streamTest GET data: URI");
michael@0 80
michael@0 81 ok(!p.streamTest("data:malformed?", false, null, null,
michael@0 82 function(r, t) {
michael@0 83 todo(false, "Shouldn't get callback for invalid data: URI");
michael@0 84 }, null, true), "streamTest GET bad data: URI");
michael@0 85 }
michael@0 86 </script>
michael@0 87
michael@0 88 <embed id="plugin1" type="application/x-test" width="400" height="400"></embed>

mercurial