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