|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 * http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 const Cc = Components.classes; |
|
5 const Ci = Components.interfaces; |
|
6 |
|
7 const gPostData = "postdata=true"; |
|
8 |
|
9 function test() { |
|
10 waitForExplicitFinish(); |
|
11 |
|
12 let tab = gBrowser.selectedTab = gBrowser.addTab(); |
|
13 registerCleanupFunction(function () { |
|
14 gBrowser.removeTab(tab); |
|
15 }); |
|
16 |
|
17 var dataStream = Cc["@mozilla.org/io/string-input-stream;1"]. |
|
18 createInstance(Ci.nsIStringInputStream); |
|
19 dataStream.data = gPostData; |
|
20 |
|
21 var postStream = Cc["@mozilla.org/network/mime-input-stream;1"]. |
|
22 createInstance(Ci.nsIMIMEInputStream); |
|
23 postStream.addHeader("Content-Type", "application/x-www-form-urlencoded"); |
|
24 postStream.addContentLength = true; |
|
25 postStream.setData(dataStream); |
|
26 |
|
27 tab.linkedBrowser.loadURIWithFlags("http://mochi.test:8888/browser/docshell/test/browser/print_postdata.sjs", 0, null, null, postStream); |
|
28 onTabLoad(tab, function (doc) { |
|
29 var bodyText = doc.body.textContent; |
|
30 is(bodyText, gPostData, "post data was submitted correctly"); |
|
31 finish(); |
|
32 }); |
|
33 } |
|
34 |
|
35 function onTabLoad(tab, cb) { |
|
36 tab.linkedBrowser.addEventListener("load", function listener(event) { |
|
37 if (event.originalTarget != tab.linkedBrowser.contentDocument || |
|
38 event.target.location.href == "about:blank") { |
|
39 info("skipping spurious load event"); |
|
40 return; |
|
41 } |
|
42 tab.linkedBrowser.removeEventListener("load", listener, true); |
|
43 cb(tab.linkedBrowser.contentDocument); |
|
44 }, true); |
|
45 } |