Bug 793644 - Test case r=jlebar

This commit is contained in:
Patrick Wang 2012-10-19 18:39:22 +08:00
parent 5e25ff0126
commit 4d65265854
5 changed files with 163 additions and 1 deletions

View File

@ -147,6 +147,9 @@ MOCHITEST_FILES = \
browserElement_FrameWrongURI.js \
test_browserElement_inproc_FrameWrongURI.html \
file_browserElement_FrameWrongURI.html \
file_post_request.html \
test_browserElement_inproc_ReloadPostRequest.html \
browserElement_ReloadPostRequest.js \
$(NULL)
# Disabled due to https://bugzilla.mozilla.org/show_bug.cgi?id=774100
@ -212,7 +215,8 @@ MOCHITEST_FILES += \
test_browserElement_oop_AppFramePermission.html \
test_browserElement_oop_ExposableURI.html \
test_browserElement_oop_FrameWrongURI.html \
$(NULL)
test_browserElement_oop_ReloadPostRequest.html \
$(NULL)
endif #}
endif #}

View File

@ -0,0 +1,117 @@
/* Any copyright is dedicated to the public domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
// Bug 793644, fire an event when attempting to reloads browser element after
// POST respest.
"use strict";
SimpleTest.waitForExplicitFinish();
var iframe;
var gotConfirmRepost = false;
var doRepost = true;
var timer;
var isPostRequestSubmitted;
function getExpectedStrings() {
let result = {};
let bundleService = SpecialPowers.Cc['@mozilla.org/intl/stringbundle;1'].
getService(SpecialPowers.Ci.nsIStringBundleService);
let appBundle = bundleService.createBundle("chrome://global/locale/appstrings.properties");
let brandBundle = bundleService.createBundle("chrome://branding/locale/brand.properties");
try {
let brandName = brandBundle.GetStringFromName("brandShortName");
result.message = appBundle.formatStringFromName("confirmRepostPrompt",
[brandName], 1);
} catch (e) {
// for the case that we don't have brandShortName
result.message = appBundle.GetStringFromName("confirmRepostPrompt");
}
result.resend = appBundle.GetStringFromName("resendButton.label");
return result;
}
function failBecauseReloaded() {
window.clearTimeout(timer);
timer = null;
iframe.removeEventListener('mozbrowserloadend', failBecauseReloaded);
ok(false, "We don't expect browser element to reload, but it did");
SimpleTest.finish();
};
function reloadDone() {
iframe.removeEventListener('mozbrowserloadend', reloadDone);
ok(gotConfirmRepost, "Didn't get confirmEx prompt before reload");
// Run again, with repost disallowed.
doRepost = false;
isPostRequestSubmitted = false;
iframe.src = 'file_post_request.html';
iframe.addEventListener('mozbrowserloadend', pageLoadDone);
}
function pageLoadDone() {
if (!isPostRequestSubmitted) {
// This loadend is done by setting url in address bar, so we don't need to
// do anything. The test page will submit a POST request.
isPostRequestSubmitted = true;
return;
}
gotConfirmRepost = false;
iframe.removeEventListener('mozbrowserloadend', pageLoadDone);
if (doRepost) {
iframe.addEventListener('mozbrowserloadend', reloadDone);
} else {
// We don't expect browserelement to reload; use a timer to make sure
// it is not reloaded.
iframe.addEventListener('mozbrowserloadend', failBecauseReloaded);
}
iframe.reload();
}
function runTest() {
browserElementTestHelpers.setEnabledPref(true);
browserElementTestHelpers.addPermission();
iframe = document.createElement('iframe');
iframe.mozbrowser = true;
isPostRequestSubmitted = false;
iframe.src = 'file_post_request.html';
document.body.appendChild(iframe);
iframe.addEventListener('mozbrowserloadend', pageLoadDone);
let expectedMessage = getExpectedStrings();
iframe.addEventListener('mozbrowsershowmodalprompt', function(e) {
if (e.detail.promptType == 'custom-prompt') {
gotConfirmRepost = true;
e.preventDefault();
e.detail.returnValue = {
selectedButton: doRepost ? 0 : 1,
};
is(e.detail.returnValue.checked, undefined);
is(e.detail.buttons[0].messageType, 'custom');
is(e.detail.buttons[0].message, expectedMessage.resend);
is(e.detail.buttons[1].messageType, 'builtin');
is(e.detail.buttons[1].message, 'cancel');
is(e.detail.message, expectedMessage.message);
is(e.detail.buttons.length, 2);
is(e.detail.showCheckbox, false);
is(e.detail.checkMessage, null);
e.detail.unblock();
if (!doRepost) {
// To make sure the page doesn't reload in 1 sec.
timer = window.setTimeout(function() {
iframe.removeEventListener('mozbrowserloadend', failBecauseReloaded);
SimpleTest.finish();
}, 1000);
}
}
});
}
runTest();

View File

@ -0,0 +1,15 @@
<html>
<head>
<script>
addEventListener('load', function() {
document.getElementsByTagName('form')[0].submit();
});
</script>
</head>
<body>
<form action="file_empty.html" method="POST">
<input type="text" name="postvalue" value="I am a test string!!" />
<input type="submit" />
</form>
</body>
</html>

View File

@ -0,0 +1,13 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Test of browser element.</title>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="application/javascript" src="browserElementTestHelpers.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<script type="application/javascript;version=1.7" src="browserElement_ReloadPostRequest.js">
</script>
</body>
</html>

View File

@ -0,0 +1,13 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Test of browser element.</title>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="application/javascript" src="browserElementTestHelpers.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<script type="application/javascript;version=1.7" src="browserElement_ReloadPostRequest.js">
</script>
</body>
</html>