summaryrefslogtreecommitdiffstats
path: root/netwerk/test/browser/browser_post_file.js
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /netwerk/test/browser/browser_post_file.js
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip
Add m-esr52 at 52.6.0
Diffstat (limited to 'netwerk/test/browser/browser_post_file.js')
-rw-r--r--netwerk/test/browser/browser_post_file.js101
1 files changed, 101 insertions, 0 deletions
diff --git a/netwerk/test/browser/browser_post_file.js b/netwerk/test/browser/browser_post_file.js
new file mode 100644
index 000000000..6c9fd7a2f
--- /dev/null
+++ b/netwerk/test/browser/browser_post_file.js
@@ -0,0 +1,101 @@
+/*
+ * Tests for bug 1241100: Post to local file should not overwrite the file.
+ */
+
+Components.utils.import("resource://gre/modules/osfile.jsm");
+
+function* createTestFile(filename, content) {
+ let path = OS.Path.join(OS.Constants.Path.tmpDir, filename);
+ yield OS.File.writeAtomic(path, content);
+ return path;
+}
+
+function* readFile(path) {
+ var array = yield OS.File.read(path);
+ var decoder = new TextDecoder();
+ return decoder.decode(array);
+}
+
+function frameScript() {
+ addMessageListener("Test:WaitForIFrame", function() {
+ var check = function() {
+ if (content) {
+ var frame = content.document.getElementById("frame");
+ if (frame) {
+ var okBox = frame.contentDocument.getElementById("action_file_ok");
+ if (okBox) {
+ sendAsyncMessage("Test:IFrameLoaded");
+ return;
+ }
+ }
+ }
+
+ setTimeout(check, 100);
+ };
+
+ check();
+ });
+}
+
+add_task(function*() {
+ var postFilename = "post_file.html";
+ var actionFilename = "action_file.html";
+
+ var postFileContent = `
+<!DOCTYPE html>
+<html>
+<head>
+<meta charset="utf-8">
+<title>post file</title>
+</head>
+<body onload="document.getElementById('form').submit();">
+<form id="form" action="${actionFilename}" method="post" enctype="text/plain" target="frame">
+<input type="hidden" name="foo" value="bar">
+<input type="submit">
+</form>
+<iframe id="frame" name="frame"></iframe>
+</body>
+</html>
+`;
+
+ var actionFileContent = `
+<!DOCTYPE html>
+<html>
+<head>
+<meta charset="utf-8">
+<title>action file</title>
+</head>
+<body>
+<div id="action_file_ok">ok</div>
+</body>
+</html>
+`;
+
+ var postPath = yield* createTestFile(postFilename, postFileContent);
+ var actionPath = yield* createTestFile(actionFilename, actionFileContent);
+
+ var postURI = OS.Path.toFileURI(postPath);
+
+ gBrowser.selectedTab = gBrowser.addTab(postURI);
+ let browser = gBrowser.selectedBrowser;
+ browser.messageManager.loadFrameScript("data:,(" + frameScript.toString() + ")();", true);
+ yield new Promise(resolve => {
+ let manager = browser.messageManager;
+
+ function listener() {
+ manager.removeMessageListener("Test:IFrameLoaded", listener);
+ resolve();
+ }
+
+ manager.addMessageListener("Test:IFrameLoaded", listener);
+ manager.sendAsyncMessage("Test:WaitForIFrame");
+ });
+
+ var actionFileContentAfter = yield* readFile(actionPath);
+ is(actionFileContentAfter, actionFileContent, "action file is not modified");
+
+ yield OS.File.remove(postPath);
+ yield OS.File.remove(actionPath);
+
+ gBrowser.removeCurrentTab();
+});