tor-browser

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

test_filepicker_default_directory.html (2556B)


      1 <!DOCTYPE html>
      2 <html>
      3 <!--
      4 https://bugzilla.mozilla.org/show_bug.cgi?id=1194893
      5 -->
      6 <head>
      7  <title>Test for filepicker default directory</title>
      8  <script src="/tests/SimpleTest/SimpleTest.js"></script>
      9  <script src="/tests/SimpleTest/EventUtils.js"></script>
     10  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
     11 </head>
     12 <body>
     13 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1194893">Mozilla Bug 1194893</a>
     14 <div id="content">
     15  <input type="file" id="f">
     16 </div>
     17 <pre id="text">
     18 <script class="testbody" type="application/javascript">
     19 
     20 SimpleTest.waitForExplicitFinish();
     21 const { Cc: Cc, Ci: Ci } = SpecialPowers;
     22 
     23 // Platform-independent directory names are #define'd in xpcom/io/nsDirectoryServiceDefs.h
     24 
     25 // When we want to test an upload directory other than the default, we need to
     26 // get a valid directory in a platform-independent way. Since NS_OS_DESKTOP_DIR
     27 // may fallback to NS_OS_HOME_DIR, let's use NS_OS_TMP_DIR.
     28 var customUploadDirectory = Cc["@mozilla.org/file/directory_service;1"]
     29                            .getService(Ci.nsIDirectoryService)
     30                            .QueryInterface(Ci.nsIProperties)
     31                            .get("TmpD", Ci.nsIFile);
     32 
     33 // Useful for debugging
     34 //info("customUploadDirectory" + customUploadDirectory.path);
     35 
     36 var MockFilePicker = SpecialPowers.MockFilePicker;
     37 MockFilePicker.init(SpecialPowers.wrap(window).browsingContext);
     38 
     39 // need to show the MockFilePicker so .displayDirectory gets set
     40 var f = document.getElementById("f");
     41 f.focus();
     42 
     43 var testIndex = 0;
     44 var tests = [
     45  ["", null, "Desk"],
     46  [customUploadDirectory.path, customUploadDirectory.path, ""]
     47 ]
     48 
     49 MockFilePicker.showCallback = function(filepicker) {
     50  if (tests[testIndex][1] === null) {
     51    is(SpecialPowers.wrap(MockFilePicker).displayDirectory, null, "DisplayDirectory is null");
     52  } else {
     53    is(SpecialPowers.wrap(MockFilePicker).displayDirectory.path, tests[testIndex][1], "DisplayDirectory matches the path");
     54  }
     55 
     56  is(SpecialPowers.wrap(MockFilePicker).displaySpecialDirectory, tests[testIndex][2], "DisplaySpecialDirectory matches the path");
     57 
     58  if (++testIndex == tests.length) {
     59    MockFilePicker.cleanup();
     60    SimpleTest.finish();
     61  } else {
     62    launchNextTest();
     63  }
     64 }
     65 
     66 function launchNextTest() {
     67  SpecialPowers.pushPrefEnv(
     68    { 'set': [
     69      ['dom.input.fallbackUploadDir', tests[testIndex][0]],
     70    ]},
     71  function () {
     72    SpecialPowers.wrap(document).notifyUserGestureActivation();
     73    f.click();
     74  });
     75 }
     76 
     77 launchNextTest();
     78 
     79 </script>
     80 </pre>
     81 </body>
     82 </html>