summaryrefslogtreecommitdiffstats
path: root/netwerk/test/browser/browser_post_file.js
blob: 8b156dff9e8da58f8287da2eaf79c0ba21cba662 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/*
 * Tests for bug 1241100: Post to local file should not overwrite the file.
 */
"use strict";

async function createTestFile(filename, content) {
  let path = PathUtils.join(PathUtils.tempDir, filename);
  await IOUtils.writeUTF8(path, content);
  return path;
}

add_task(async 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 = await createTestFile(postFilename, postFileContent);
  var actionPath = await createTestFile(actionFilename, actionFileContent);

  var postURI = PathUtils.toFileURI(postPath);
  var actionURI = PathUtils.toFileURI(actionPath);

  let tab = await BrowserTestUtils.openNewForegroundTab(
    gBrowser,
    "about:blank"
  );
  let browserLoadedPromise = BrowserTestUtils.browserLoaded(
    tab.linkedBrowser,
    true,
    actionURI
  );
  BrowserTestUtils.startLoadingURIString(tab.linkedBrowser, postURI);
  await browserLoadedPromise;

  var actionFileContentAfter = await IOUtils.readUTF8(actionPath);
  is(actionFileContentAfter, actionFileContent, "action file is not modified");

  await IOUtils.remove(postPath);
  await IOUtils.remove(actionPath);

  gBrowser.removeCurrentTab();
});