These setRequestHeader lines seem to be problematic. If I remove them, the test passes just fine.

The third argument is not necessary - the nsIXMLHttpRequest interface defines setRequestHeader as taking only two parameters - the key and the value (https://mxr.mozilla.org/mozilla-central/source/content/base/public/nsIXMLHttpRequest.idl).