summaryrefslogtreecommitdiffstats
path: root/dom/plugins/test/mochitest/test_streamNotify.html
blob: d1aa8be8da49f4b9134621a1103b6e7cc96854b5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<head>
  <title>NPN_Get/PostURLNotify tests</title>
  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  <script type="application/javascript" src="plugin-utils.js"></script>

<body onload="runTests()">
  <script class="testbody" type="application/javascript">
  SimpleTest.waitForExplicitFinish();
  SimpleTest.requestFlakyTimeout("untriaged");
  setTestPluginEnabledState(SpecialPowers.Ci.nsIPluginTag.STATE_ENABLED);

  var pending = 5;
  function testDone() {
    dump("testDone: " + pending + "\n")
    --pending;

    // Wait for a bit so that any unexpected notifications from the
    // malformed data or null-post tests are received.
    if (0 == pending)
      window.setTimeout(SimpleTest.finish, 2000);
  }

  function runTests() {
    var p = document.getElementById('plugin1');

    ok(p.streamTest("loremipsum.txt", false, null, null,
                    function(r, t) {
                      is(r, 0, "GET loremipsum.txt");
                      is(t.substr(0, 11), "Lorem ipsum",
                         "GET loremipsum.txt correct");
                      testDone();
                    }, null, true), "streamTest GET");

    ok(!p.streamTest("post.sjs", true, null, null,
                     function(r, t) {
                       ok(false, "Shouldn't get callback from null post");
                     }, null, true), "streamTest POST null postdata");

    ok(p.streamTest("post.sjs", true, "Something good", null,
                    function(r, t) {
                      is(r, 0, "POST something good");
                      is(t, "Something good", "POST non-null correct");
                      testDone();
                    }, null, true), "streamTest POST valid postdata");

    ok(p.streamTest("http://example.invalid/", false, null, null,
                    function(r, t) {
                      is(r, 1, "Shouldn't load example.invalid DNS name");
                      testDone();
                    }, null, true), "streamTest GET bad DNS");

    ok(!p.streamTest("http://localhost:-8/", false, null, null,
                    function(r, t) {
                      ok(false, "Shouldn't get callback from malformed URI");
                    }, null, true), "streamTest GET invalid URL");

    ok(p.streamTest("javascript:'Hello';", false, null, null,
                    function(r, t) {
                      is(r, 0, "GET javascript: URI");
                      is(t, "Hello", "GET javascript: URI correct");
                      testDone();
                    }, null, true), "streamTest GET javascript: URI");

/*
 * XXX/cjones: disabled for now because it appears to be hard to make
 * mochitest ignore the malformed javascript

    ok(!p.streamTest("javascript:syntax##$&*@error-*", false, null,
                     function(r, t) {
                       is(r, 1, "Shouldn't load invalid javascript: URI");
                       testDone();
                     }), "streamTest GET bad javascript: URI");
*/

    ok(p.streamTest("data:text/plain,World", false, null, null,
                    function(r, t) {
                      is(r, 0, "GET data: URI");
                      is(t, "World", "GET data: URI correct");
                      testDone();
                    }, null, true), "streamTest GET data: URI");

    ok(!p.streamTest("data:malformed?", false, null, null,
                     function(r, t) {
                       todo(false, "Shouldn't get callback for invalid data: URI");
                     }, null, true), "streamTest GET bad data: URI");
  }
  </script>

  <embed id="plugin1" type="application/x-test" width="400" height="400"></embed>