tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

browser_post_file.js (1765B)


      1 /*
      2 * Tests for bug 1241100: Post to local file should not overwrite the file.
      3 */
      4 "use strict";
      5 
      6 async function createTestFile(filename, content) {
      7  let path = PathUtils.join(PathUtils.tempDir, filename);
      8  await IOUtils.writeUTF8(path, content);
      9  return path;
     10 }
     11 
     12 add_task(async function () {
     13  var postFilename = "post_file.html";
     14  var actionFilename = "action_file.html";
     15 
     16  var postFileContent = `
     17 <!DOCTYPE html>
     18 <html>
     19 <head>
     20 <meta charset="utf-8">
     21 <title>post file</title>
     22 </head>
     23 <body onload="document.getElementById('form').submit();">
     24 <form id="form" action="${actionFilename}" method="post" enctype="text/plain" target="frame">
     25 <input type="hidden" name="foo" value="bar">
     26 <input type="submit">
     27 </form>
     28 <iframe id="frame" name="frame"></iframe>
     29 </body>
     30 </html>
     31 `;
     32 
     33  var actionFileContent = `
     34 <!DOCTYPE html>
     35 <html>
     36 <head>
     37 <meta charset="utf-8">
     38 <title>action file</title>
     39 </head>
     40 <body>
     41 <div id="action_file_ok">ok</div>
     42 </body>
     43 </html>
     44 `;
     45 
     46  var postPath = await createTestFile(postFilename, postFileContent);
     47  var actionPath = await createTestFile(actionFilename, actionFileContent);
     48 
     49  var postURI = PathUtils.toFileURI(postPath);
     50  var actionURI = PathUtils.toFileURI(actionPath);
     51 
     52  let tab = await BrowserTestUtils.openNewForegroundTab(
     53    gBrowser,
     54    "about:blank"
     55  );
     56  let browserLoadedPromise = BrowserTestUtils.browserLoaded(
     57    tab.linkedBrowser,
     58    true,
     59    actionURI
     60  );
     61  BrowserTestUtils.startLoadingURIString(tab.linkedBrowser, postURI);
     62  await browserLoadedPromise;
     63 
     64  var actionFileContentAfter = await IOUtils.readUTF8(actionPath);
     65  is(actionFileContentAfter, actionFileContent, "action file is not modified");
     66 
     67  await IOUtils.remove(postPath);
     68  await IOUtils.remove(actionPath);
     69 
     70  gBrowser.removeCurrentTab();
     71 });