Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
86 lines (71 sloc) 3.75 KB
<!doctype html>
<meta charset="utf-8" />
<title>pmxdr demo</title>
<script type="text/javascript" src="client/latest/pmxdr.min.js"></script>
<h1>pmxdr demo</h1>
<em id="testing">Automated tests in progress...</em>
<strong>All tests are being requested from the remote domain, does not usually have access to through XMLHttpRequests</strong>
<div id="results"></div>
<script type="text/javascript">
var pmxdrInterface = new pmxdr("");
function doPmxdrTests() {
var results = document.getElementById("results");
results.innerHTML = ""; // clear results case there is anything in it
pmxdrInterface.onload = function() {
var tests = [
["Requesting malicous JSON data using GET", "{uri:\"/pmxdr/example.php?x=1\"}", false],
["Requesting malicous JSON data using POST", "{method:\"post\", uri:\"/pmxdr/example.php\", data:\"x=1\", contentType:\"application/x-www-form-urlencoded\"}", false],
["Requesting a resource That is not explicitly allowed to access\nThis should cause a DISALLOWED_ORIGIN security error.", "{uri:\"/\"}", true],
["Requesting a non-existant resource that gives a 404 error.\nThis should cause a LOAD_ERROR.", "{uri:\"/nonexistant-page-blarg\"}", true],
["Requesting a resource that only allows POST requests using a GET request.\nThe page sends this header: Access-Control-Allow-Methods: POST\nThis should cause a DISALLOWED_REQUEST_METHOD", "{uri:\"/pmxdr/example2.php\"}", true],
["Requesting a resource that only allows POST requests using a POST request.", "{method: \"post\", uri:\"/pmxdr/example2.php\", data:\"some data to send\", contentType:\"application/x-www-form-urlencoded\"}", false],
["Requesting a non-existant resource with a 5ms timeout.\nThis should cause a TIMEOUT error (Opera versions under 10 give a LOAD_ERROR instead due to an Opera bug)", "{uri:\"/nonexistant-page-blarg2\", timeout:5}", true]
], testsCompleted = 0;
function pmxdrTest(desc, req, errorIsGood) {
var code = desc+"\n> pmxdr.request("+req+")\n\n",
codeContainer = document.createElement("pre");
var request = eval("("+req+")");
request.callback = function(response) {
if ( !response.error ) {
code += "(PASS) Request Success"
code += "\nContent-Type == "+JSON.stringify(response.headers["content-type"]);
code += "\nAccess-Control-Allow-Origin == "+JSON.stringify(response.headers["access-control-allow-origin"]);
code += "\nAccess-Control-Allow-Methods == "+JSON.stringify(response.headers["access-control-allow-methods"]);
code += "\n\ndata:\n";
} else code += (errorIsGood? "(PASS) " : "(FAIL) ")+"Error: "+response.error;
if (testsCompleted >= tests.length) finishTesting();
for (var i=0; i<tests.length; i++)
pmxdrTest.apply(this, tests[i]);
function finishTesting() {
document.getElementById("testing").innerHTML = "Automated tests finished. [<a href=\"#\" onclick=\"doPmxdrTests();return false;\">restart tests</a>]";
delete pmxdrInterface;
<script type="text/javascript" src =""></script>
<script type="text/javascript">
try {
var pageTracker = _gat._getTracker("UA-4364432-7");
} catch(err) {}