tor-browser

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

test_bug383369.html (3069B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <head>
      4  <title>Bug 383369 test</title>
      5  <script src="/tests/SimpleTest/SimpleTest.js"></script>
      6  <script type="text/javascript" src="mixedContentTest.js"></script>
      7  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
      8 
      9  <script class="testbody" type="text/javascript">
     10  "use strict";
     11 
     12  // We want to start this test from an insecure context
     13  loadAsInsecure = true;
     14  // We don't want to go through the navigation back/forward test
     15  bypassNavigationTest = true;
     16 
     17  async function runTest() {
     18    let script = SpecialPowers.loadChromeScript(function() {
     19      /* eslint-env mozilla/chrome-script */
     20      // Force download to be w/o user assistance for our testing mime type
     21      const mimeSvc = Cc["@mozilla.org/mime;1"].getService(Ci.nsIMIMEService);
     22      let handlerInfo =
     23        mimeSvc.getFromTypeAndExtension("application/x-auto-download", "auto");
     24      handlerInfo.preferredAction = Ci.nsIHandlerInfo.saveToDisk;
     25      handlerInfo.alwaysAskBeforeHandling = false;
     26      handlerInfo.preferredApplicationHandler = null;
     27 
     28      const handlerSvc = Cc["@mozilla.org/uriloader/handler-service;1"]
     29                           .getService(Ci.nsIHandlerService);
     30      handlerSvc.store(handlerInfo);
     31 
     32      let profileDir = Services.dirsvc.get("ProfDS", Ci.nsIFile);
     33      profileDir.append("downloads");
     34 
     35      let prefBranch = Services.prefs.getBranch("browser.download.");
     36 
     37      prefBranch.setCharPref("dir", profileDir.path);
     38      prefBranch.setBoolPref("useDownloadDir", true);
     39      prefBranch.setIntPref("folderList", 2);
     40 
     41      const { Downloads } =
     42        ChromeUtils.importESModule("resource://gre/modules/Downloads.sys.mjs");
     43      Downloads.getList(Downloads.PUBLIC).then(list => {
     44        list.addView({
     45          onDownloadAdded(aDownload) {
     46            list.removeView(this);
     47            aDownload.whenSucceeded().then(() => {
     48              list.removeFinished();
     49              sendAsyncMessage("navigate", "bug383369step2.html");
     50            });
     51          },
     52        });
     53        sendAsyncMessage("navigate", "download.auto");
     54      }).catch(console.error);
     55    });
     56    script.addMessageListener("navigate", function(url) {
     57      window.location = url;
     58    });
     59  }
     60 
     61  async function afterNavigationTest() {}
     62 
     63  testCleanUp = function cleanup() {
     64    SpecialPowers.loadChromeScript(function() {
     65      const mimeSvc = Cc["@mozilla.org/mime;1"].getService(Ci.nsIMIMEService);
     66      let handlerInfo =
     67        mimeSvc.getFromTypeAndExtension("application/x-auto-download", "auto");
     68 
     69      const handlerSvc = Cc["@mozilla.org/uriloader/handler-service;1"]
     70                           .getService(Ci.nsIHandlerService);
     71      handlerSvc.remove(handlerInfo);
     72 
     73      let prefBranch = Services.prefs.getBranch("browser.download.");
     74 
     75      const prefKeys = ["dir", "useDownloadDir", "folderList"];
     76      for (let prefKey of prefKeys) {
     77        if (prefBranch.prefHasUserValue(prefKey)) {
     78          prefBranch.clearUserPref(prefKey);
     79        }
     80      }
     81    });
     82  };
     83 
     84  </script>
     85 </head>
     86 
     87 <body>
     88 </body>
     89 </html>