gecko/toolkit/components/places/tests/mochitest/test_bug_405924.html

116 lines
4.1 KiB
HTML

<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=405924
-->
<head>
<title>Test for Bug 405924</title>
<script type="text/javascript" src="/MochiKit/packed.js"></script>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="text/javascript" src="prompt_common.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=405924">
Mozilla Bug 405924</a>
<p id="display"></p>
<div id="content" style="display: none">
<iframe id="iframe"></iframe>
</div>
<pre id="test">
<script class="testbody" type="text/javascript">
/** Test for Bug 405924 **/
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
var isDone = false;
// This is called from prompt_common when the error dialog shows up
function handleDialog(doc) {
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
// Verify the error message is correct - the string (places) is not
// translated
var dialog = doc.getElementById("commonDialog");
var desc = doc.getElementById("info.body");
var errmsg = desc.childNodes[0].data;
ok(errmsg.match(/\(place\)/) || errmsg.match(/^place /), "Check for the correct message");
// Clear the dialog
dialog.acceptDialog();
// Declared in prompt_common and used to show that we flashed the error
// message
didDialog = true;
if (isDone) {
// Finish up
SimpleTest.finish();
}
}
// Called when the iFrame or the Window is reloaded
function onloadHandler() {
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
// Make sure the alert dialog was shown if we do manage to complete
// the onload. (Usually the alert dialog blocks the onload event)
ok(didDialog, "Alert Dialog was shown");
}
function useXMLHttpRequest(aType, aUri, aValueToSend) {
var req = new XMLHttpRequest();
req.onreadystatechange=function() {
// If this completes, it's an error
if (req.readyState == 4)
ok(false, "XMLHttpRequest to Places URI succeeded: security breach");
}
try {
req.open(aType, aUri, false);
req.send(aValueToSend);
ok(false, "XMLHttpRequest did not throw - security breach");
} catch (ex) {
// Unfortunately it's an unknown error, so no use in trying to see
// what it was
// XMLHttpRequest to Places URI threw: expected behavior
}
}
// First try requesting a places URI from javascript - fails silently
useXMLHttpRequest("GET",
"place:folder=BOOKMARKS_MENU&folder=UNFILED_BOOKMARKS&folder=TOOLBAR&sort=12&excludeQueries=1&queryType=1",
null);
// Second, try posting to a places URI just for grins
useXMLHttpRequest("POST",
"place:folder=UNFILED_BOOKMARKS&sort=12&queryType=1",
"SELECT%20*%20FROM%20moz_places");
// Third test, use the iFrame and try loading directly
var iframe = document.getElementById("iframe");
iframe.onload = onloadHandler;
startCallbackTimer();
try {
// This one probably won't throw but it will show the Error Dialog
iframe.src = "place:sort=14&type=6&maxResults=10";
todo(false, "This should throw: bug 428585")
} catch (ex) {
// Bug 428585: This should throw
}
// And finally, go for broke
window.onload = onloadHandler;
isDone = true;
startCallbackTimer();
try {
window.content.document.location.href = "place:sort=8&maxResults=10";
ok(false, "Window set to places URI did not throw - security breach");
} catch (ex) {
// Window set to places URI threw exception: expected behavior
}
// We finish up in the onloadHandler
SimpleTest.waitForExplicitFinish();
</script>
</pre>
</body>
</html>