dom/plugins/test/mochitest/test_streamNotify.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/plugins/test/mochitest/test_streamNotify.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,88 @@
     1.4 +<head>
     1.5 +  <title>NPN_Get/PostURLNotify tests</title>
     1.6 +  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
     1.7 +  <script type="application/javascript" src="utils.js"></script>
     1.8 +
     1.9 +<body onload="runTests()">
    1.10 +  <script class="testbody" type="application/javascript">
    1.11 +  SimpleTest.waitForExplicitFinish();
    1.12 +  setTestPluginEnabledState(SpecialPowers.Ci.nsIPluginTag.STATE_ENABLED);
    1.13 +
    1.14 +  var pending = 5;
    1.15 +  function testDone() {
    1.16 +    dump("testDone: " + pending + "\n")
    1.17 +    --pending;
    1.18 +
    1.19 +    // Wait for a bit so that any unexpected notifications from the
    1.20 +    // malformed data or null-post tests are received.
    1.21 +    if (0 == pending)
    1.22 +      window.setTimeout(SimpleTest.finish, 2000);
    1.23 +  }
    1.24 +
    1.25 +  function runTests() {
    1.26 +    var p = document.getElementById('plugin1');
    1.27 +
    1.28 +    ok(p.streamTest("loremipsum.txt", false, null, null,
    1.29 +                    function(r, t) {
    1.30 +                      is(r, 0, "GET loremipsum.txt");
    1.31 +                      is(t.substr(0, 11), "Lorem ipsum",
    1.32 +                         "GET loremipsum.txt correct");
    1.33 +                      testDone();
    1.34 +                    }, null, true), "streamTest GET");
    1.35 +
    1.36 +    ok(!p.streamTest("post.sjs", true, null, null,
    1.37 +                     function(r, t) {
    1.38 +                       ok(false, "Shouldn't get callback from null post");
    1.39 +                     }, null, true), "streamTest POST null postdata");
    1.40 +
    1.41 +    ok(p.streamTest("post.sjs", true, "Something good", null,
    1.42 +                    function(r, t) {
    1.43 +                      is(r, 0, "POST something good");
    1.44 +                      is(t, "Something good", "POST non-null correct");
    1.45 +                      testDone();
    1.46 +                    }, null, true), "streamTest POST valid postdata");
    1.47 +
    1.48 +    ok(p.streamTest("http://example.invalid/", false, null, null,
    1.49 +                    function(r, t) {
    1.50 +                      is(r, 1, "Shouldn't load example.invalid DNS name");
    1.51 +                      testDone();
    1.52 +                    }, null, true), "streamTest GET bad DNS");
    1.53 +
    1.54 +    ok(!p.streamTest("http://localhost:-8/", false, null, null,
    1.55 +                    function(r, t) {
    1.56 +                      ok(false, "Shouldn't get callback from malformed URI");
    1.57 +                    }, null, true), "streamTest GET invalid URL");
    1.58 +
    1.59 +    ok(p.streamTest("javascript:'Hello';", false, null, null,
    1.60 +                    function(r, t) {
    1.61 +                      is(r, 0, "GET javascript: URI");
    1.62 +                      is(t, "Hello", "GET javascript: URI correct");
    1.63 +                      testDone();
    1.64 +                    }, null, true), "streamTest GET javascript: URI");
    1.65 +
    1.66 +/*
    1.67 + * XXX/cjones: disabled for now because it appears to be hard to make
    1.68 + * mochitest ignore the malformed javascript
    1.69 +
    1.70 +    ok(!p.streamTest("javascript:syntax##$&*@error-*", false, null,
    1.71 +                     function(r, t) {
    1.72 +                       is(r, 1, "Shouldn't load invalid javascript: URI");
    1.73 +                       testDone();
    1.74 +                     }), "streamTest GET bad javascript: URI");
    1.75 +*/
    1.76 +
    1.77 +    ok(p.streamTest("data:text/plain,World", false, null, null,
    1.78 +                    function(r, t) {
    1.79 +                      is(r, 0, "GET data: URI");
    1.80 +                      is(t, "World", "GET data: URI correct");
    1.81 +                      testDone();
    1.82 +                    }, null, true), "streamTest GET data: URI");
    1.83 +
    1.84 +    ok(!p.streamTest("data:malformed?", false, null, null,
    1.85 +                     function(r, t) {
    1.86 +                       todo(false, "Shouldn't get callback for invalid data: URI");
    1.87 +                     }, null, true), "streamTest GET bad data: URI");
    1.88 +  }
    1.89 +  </script>
    1.90 +
    1.91 +  <embed id="plugin1" type="application/x-test" width="400" height="400"></embed>

mercurial