Import from 1.9a8 tarball
[mozilla-extra.git] / extensions / xmlextras / tests / xpost.html
blob1ab0f12e7de9550b21d76788ca601e7843c633e6
1 <html>
2 <head><title>POST test</title>
3 <style type="text/css">
4 .box {
5 display: box;
6 border: 1px solid black;
7 margin-bottom: 0.5em;
9 .boxheader {
10 font-weight: bold;
11 color: maroon;
13 pre {
14 margin-left: 2em;
16 </style>
17 <script type="text/javascript">
18 var p;
19 try {
20 p = new XMLHttpRequest();
21 } catch (e) {
22 p = new ActiveXObject("Msxml2.XMLHTTP");
25 // In Mozilla, you can only create the text string if you can bybass security, like in chrome
26 var sendPlainTextData = false;
28 var docsize = 400; // the document has docsize*2+1 elements
29 var x;
30 if (!sendPlainTextData) {
31 try {
32 x = document.implementation.createDocument("", "test", null);
33 var i;
34 for (i = 0; i < docsize; i++) {
35 var fooElement = document.createElement("Foo");
36 fooElement.appendChild(document.createTextNode("My Stuff\nYeah"));
37 x.documentElement.appendChild(fooElement);
38 x.documentElement.appendChild(document.createElement("Bar"));
40 } catch (e) {
41 x = new ActiveXObject("Msxml2.DOMDocument");
42 var str = "<?xml version='1.0'?>\n<test>";
43 var i;
44 for (i = 0; i < docsize; i++) {
45 str += "<Foo>My Stuff\nYeah</Foo><Bar/>";
47 str += "</test>";
48 x.loadXML(str);
52 var interactiveCount = 0;
54 function myfunc()
56 if (p.readyState == 3) {
57 interactiveCount++;
59 //alert("myfunc readyState=" + p.readyState);
60 //if (p.readyState == 2) {
61 // alert(p.getAllResponseHeaders());
62 // alert(p.status);
63 //}
64 if (p.readyState != 4)
65 return;
67 document.getElementById("id1").firstChild.nodeValue = p.responseText;
68 if (p.responseXML) {
69 var str;
70 try {
71 var s = new XMLSerializer();
72 var d = p.responseXML;
73 str = s.serializeToString(d);
74 } catch (e) {
75 str = "@@TODO@@";
77 document.getElementById("id2").firstChild.nodeValue = str;
79 document.getElementById("id3").firstChild.nodeValue = p.getAllResponseHeaders();
80 document.getElementById("id4").firstChild.nodeValue = p.status;
81 document.getElementById("id5").firstChild.nodeValue = p.statusText;
82 document.getElementById("id6").firstChild.nodeValue = p.readyState;
83 document.getElementById("id7").firstChild.nodeValue = interactiveCount;
86 // p.onload would also work in Mozilla
87 p.onreadystatechange = myfunc;
89 try {
90 // Needed for Mozilla if local file tries to access an http URL
91 netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
92 } catch (e) {
93 // ignore
96 //alert("before open():" +p.readyState);// 0 = UNINITIALIZED
97 p.open("POST", "http://green/cgi-bin/echo_xml.cgi");
98 //alert("after open():" +p.readyState);// 1 = LOADING
100 if (!sendPlainTextData) {
101 //alert("Going to send");
102 p.send(x);
103 //alert("Done to send");
104 } else {
105 var mystr;
106 try {
107 var WSTRING_CONTRACTID = "@mozilla.org/supports-string;1";
108 mystr = Components.classes[WSTRING_CONTRACTID].createInstance(Components.interfaces.nsISupportsString);
109 mystr.data = "Heikki's data";
110 } catch (e) {
111 mystr = "Heikki's data";
113 p.send(mystr);
115 //alert("after send():" +p.readyState);// 1 = LOADING
116 </script>
117 </head>
118 <body>
119 <h1>POST test</h1>
121 <div class="box"><span class="boxheader">responseText</span>
122 <pre id="id1">@@No result@@</pre>
123 </div>
124 <div class="box"><span class="boxheader">responseXML serialized</span>
125 <pre id="id2">@@No result@@</pre>
126 </div>
127 <div class="box"><span class="boxheader">getAllResponseHeaders()</span>
128 <pre id="id3">@@No result@@</pre>
129 </div>
130 <div class="box"><span class="boxheader">status</span>
131 <pre id="id4">@@No result@@</pre>
132 </div>
133 <div class="box"><span class="boxheader">statusText</span>
134 <pre id="id5">@@No result@@</pre>
135 </div>
136 <div class="box"><span class="boxheader">readyState</span>
137 <pre id="id6">@@No result@@</pre>
138 </div>
139 <div class="box"><span class="boxheader"># of times onreadystatechanged handler called with INTERACTIVE status</span>
140 <pre id="id7">@@No result@@</pre>
141 </div>
143 </body>
144 </html>